IFEM  90A354
ProcessAdm.h
Go to the documentation of this file.
1 //==============================================================================
12 //==============================================================================
13 
14 #ifndef _PROCESS_ADM_H
15 #define _PROCESS_ADM_H
16 
17 #ifdef HAS_PETSC
18 #include "petscsys.h"
19 #elif defined(HAVE_MPI)
20 #include "mpi.h"
21 #endif
22 #include <vector>
23 
24 #include "DomainDecomposition.h"
25 #include "LogStream.h"
26 
27 
33 {
34  int myPid;
35  int nProc;
36  bool parallel;
37 
38 #if defined(HAS_PETSC) || defined(HAVE_MPI)
39  MPI_Comm comm;
40 #endif
41 
42 public:
43  mutable utl::LogStream cout;
44 
46 
48  ProcessAdm();
49 #if defined(HAS_PETSC) || defined(HAVE_MPI)
51  explicit ProcessAdm(MPI_Comm& mpi_comm);
52 #endif
54  ProcessAdm(const ProcessAdm& adm);
55 
56 #ifdef HAVE_MPI
59  explicit ProcessAdm(bool hack);
60 #endif
61 
63  ~ProcessAdm();
64 
66  int getProcId() const { return myPid; }
68  int getNoProcs() const { return nProc; }
70  int isParallel() const { return parallel; }
71 
75  void broadcast(std::vector<double>& vec, int root) const;
76 
80  void broadcast(std::vector<int>& vec, int root) const;
81 
82 #if defined(HAS_PETSC) || defined(HAVE_MPI)
84  MPI_Comm* getCommunicator() { return &comm; }
86  const MPI_Comm* getCommunicator() const { return &comm; }
87 
90  void setCommunicator(const MPI_Comm* comm2);
91 
93  ProcessAdm& operator=(const ProcessAdm&);
94 
98  void send(int value, int dest) const;
102  void send(std::vector<int>& ivec, int dest) const;
106  void send(double value, int dest) const;
110  void send(std::vector<double>& rvec, int dest) const;
111 
115  void receive(int& value, int source) const;
119  void receive(std::vector<int>& ivec, int source) const;
123  void receive(double& value, int source) const;
127  void receive(std::vector<double>& rvec, int source) const;
128 
132  int allReduce(int value, MPI_Op oper) const;
136  void allReduce(std::vector<int>& vec, MPI_Op oper) const;
137 
141  double allReduce(double value, MPI_Op oper) const;
145  void allReduce(std::vector<double>& vec, MPI_Op oper) const;
146 #endif
147 
149  template<class T> void allReduceAsSum(std::vector<T>& vec) const
150  {
151 #ifdef HAS_PETSC
152  if (parallel)
153  this->allReduce(vec,MPI_SUM);
154 #endif
155  }
156 };
157 
158 #endif
Domain decomposition related partitioning for FE models.
Log stream class.
Class containing domain decomposition related partitioning.
Definition: DomainDecomposition.h:38
Class for administration of MPI processes in IFEM library.
Definition: ProcessAdm.h:33
~ProcessAdm()
The destructor releases the process administrator.
Definition: ProcessAdm.C:85
int isParallel() const
Return if parallel.
Definition: ProcessAdm.h:70
void allReduceAsSum(std::vector< T > &vec) const
AllReduce with MPI_SUM for a vector.
Definition: ProcessAdm.h:149
ProcessAdm()
Construct an empty (serial) process administrator.
Definition: ProcessAdm.C:19
int nProc
Number of processes in communicator.
Definition: ProcessAdm.h:35
utl::LogStream cout
Combined standard out for this process group.
Definition: ProcessAdm.h:43
bool parallel
If Processor is parallel.
Definition: ProcessAdm.h:36
void broadcast(std::vector< double > &vec, int root) const
Broadcast for a double vector.
Definition: ProcessAdm.C:56
int getNoProcs() const
Return rank.
Definition: ProcessAdm.h:68
int getProcId() const
Return process id.
Definition: ProcessAdm.h:66
int myPid
Process id.
Definition: ProcessAdm.h:34
DomainDecomposition dd
Decomain decomposition.
Definition: ProcessAdm.h:45
Logging stream class.
Definition: LogStream.h:26