queso-0.53.0
MpiComm.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #ifndef UQ_MPI_COMM_H
26 #define UQ_MPI_COMM_H
27 
28 #include <queso/Defines.h>
29 
30 #ifdef QUESO_HAS_TRILINOS
31 #include <Epetra_MpiComm.h>
32 #endif
33 
34 #include <mpi.h>
35 
36 namespace QUESO {
37 
38 typedef MPI_Comm RawType_MPI_Comm ;
39 typedef MPI_Group RawType_MPI_Group ;
40 typedef MPI_Datatype RawType_MPI_Datatype ;
41 typedef MPI_Op RawType_MPI_Op ;
42 typedef MPI_Status RawType_MPI_Status ;
43 #define RawValue_MPI_COMM_SELF MPI_COMM_SELF
44 #define RawValue_MPI_IN_PLACE MPI_IN_PLACE
45 #define RawValue_MPI_ANY_SOURCE MPI_ANY_SOURCE
46 #define RawValue_MPI_CHAR MPI_CHAR
47 #define RawValue_MPI_INT MPI_INT
48 #define RawValue_MPI_DOUBLE MPI_DOUBLE
49 #define RawValue_MPI_UNSIGNED MPI_UNSIGNED
50 #define RawValue_MPI_MIN MPI_MIN
51 #define RawValue_MPI_MAX MPI_MAX
52 #define RawValue_MPI_SUM MPI_SUM
53 
54 } // End namespace QUESO
55 
56 
57 namespace QUESO {
58 
73 class BaseEnvironment;
74 
75 class MpiComm
76 {
77 public:
79 
80 
82 
84  MpiComm(const BaseEnvironment& env, RawType_MPI_Comm inputRawComm);
85 
87 
88  MpiComm(const MpiComm& src);
89 
91  ~MpiComm();
93 
95 
96  MpiComm& operator= (const MpiComm& rhs);
99 
100 
102 
103  RawType_MPI_Comm Comm () const;
105 
107  int MyPID () const;
108 
110  int NumProc () const;
112 
114 
115 
121  void Allreduce(void* sendbuf, void* recvbuf, int count, RawType_MPI_Datatype datatype,
122  RawType_MPI_Op op, const char* whereMsg, const char* whatMsg) const;
123 
125 
127  void Barrier () const; // const char* whereMsg, const char* whatMsg) const;
128 
130 
135  void Bcast (void* buffer, int count, RawType_MPI_Datatype datatype, int root,
136  const char* whereMsg, const char* whatMsg) const;
137 
139 
146  void Gather (void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype,
147  void *recvbuf, int recvcount, RawType_MPI_Datatype recvtype,
148  int root,
149  const char* whereMsg, const char* whatMsg) const;
150 
152 
161  void Gatherv (void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype,
162  void *recvbuf, int *recvcnts, int *displs, RawType_MPI_Datatype recvtype,
163  int root,
164  const char* whereMsg, const char* whatMsg) const;
165 
167 
173  void Recv (void *buf, int count, RawType_MPI_Datatype datatype, int source, int tag, RawType_MPI_Status *status,
174  const char* whereMsg, const char* whatMsg) const;
175 
177 
182  void Send (void *buf, int count, RawType_MPI_Datatype datatype, int dest, int tag,
183  const char* whereMsg, const char* whatMsg) const;
185 
187 
188  void syncPrintDebugMsg(const char* msg, unsigned int msgVerbosity, unsigned int numUSecs) const;
190 
191 #ifdef QUESO_HAS_TRILINOS
192  const Epetra_MpiComm& epetraMpiComm() const;
194 #endif
195 
197 private:
199 
200  MpiComm();
201 
203  void copy (const MpiComm& src);
204 
205  // QUESO environment
207 #ifdef QUESO_HAS_TRILINOS
208 
209  // Epetra MPI communicator
210  Epetra_MpiComm* m_epetraMpiComm;
211 #endif
214 
217 
219  int m_myPid;
220 
221  // Total number of processes
223 };
224 
225 } // End namespace QUESO
226 
227 #endif // UQ_MPI_COMM_H
MPI_Comm RawType_MPI_Comm
Definition: MpiComm.h:38
int MyPID() const
Return my process ID.
Definition: MpiComm.C:94
MPI_Status RawType_MPI_Status
Definition: MpiComm.h:42
MPI_Op RawType_MPI_Op
Definition: MpiComm.h:41
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:122
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:103
const BaseEnvironment & m_env
Definition: MpiComm.h:206
void Send(void *buf, int count, RawType_MPI_Datatype datatype, int dest, int tag, const char *whereMsg, const char *whatMsg) const
Possibly blocking send of data from this process to another process.
Definition: MpiComm.C:185
MPI_Datatype RawType_MPI_Datatype
Definition: MpiComm.h:40
The QUESO MPI Communicator Class.
Definition: MpiComm.h:75
int m_worldRank
World rank.
Definition: MpiComm.h:216
void Gatherv(void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype, void *recvbuf, int *recvcnts, int *displs, RawType_MPI_Datatype recvtype, int root, const char *whereMsg, const char *whatMsg) const
Gathers into specified locations from all processes in a group.
Definition: MpiComm.C:158
RawType_MPI_Comm Comm() const
Extract MPI Communicator from a MpiComm object.
Definition: MpiComm.C:85
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
void Bcast(void *buffer, int count, RawType_MPI_Datatype datatype, int root, const char *whereMsg, const char *whatMsg) const
Broadcast values from the root process to the slave processes.
Definition: MpiComm.C:133
MpiComm & operator=(const MpiComm &rhs)
Assignment operator.
Definition: MpiComm.C:77
MpiComm()
Default Constructor.
void Recv(void *buf, int count, RawType_MPI_Datatype datatype, int source, int tag, RawType_MPI_Status *status, const char *whereMsg, const char *whatMsg) const
Blocking receive of data from this process to another process.
Definition: MpiComm.C:175
~MpiComm()
Destructor.
Definition: MpiComm.C:66
int m_myPid
Process ID of this process.
Definition: MpiComm.h:219
void Gather(void *sendbuf, int sendcnt, RawType_MPI_Datatype sendtype, void *recvbuf, int recvcount, RawType_MPI_Datatype recvtype, int root, const char *whereMsg, const char *whatMsg) const
Gather values from each process to collect on all processes.
Definition: MpiComm.C:141
void Allreduce(void *sendbuf, void *recvbuf, int count, RawType_MPI_Datatype datatype, RawType_MPI_Op op, const char *whereMsg, const char *whatMsg) const
Combines values from all processes and distributes the result back to all processes.
Definition: MpiComm.C:113
void syncPrintDebugMsg(const char *msg, unsigned int msgVerbosity, unsigned int numUSecs) const
Synchronizes all the processes and print debug message.
Definition: MpiComm.C:195
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:230
MPI_Group RawType_MPI_Group
Definition: MpiComm.h:39

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5