queso-0.51.1
Private Member Functions | Private Attributes | List of all members
QUESO::MpiComm Class Reference

The QUESO MPI Communicator Class. More...

#include <MpiComm.h>

Collaboration diagram for QUESO::MpiComm:
Collaboration graph
[legend]

Public Member Functions

Constructor/Destructor methods
 MpiComm ()
 Default Constructor. More...
 
 MpiComm (const BaseEnvironment &env, RawType_MPI_Comm inputRawComm)
 QUESO MpiComm MPI Constructor. More...
 
 MpiComm (const MpiComm &src)
 Copy Constructor. More...
 
 ~MpiComm ()
 Destructor. More...
 
Set methods
MpiCommoperator= (const MpiComm &rhs)
 Assignment operator. More...
 
Attribute Accessor Methods
RawType_MPI_Comm Comm () const
 Extract MPI Communicator from a MpiComm object. More...
 
int MyPID () const
 Return my process ID. More...
 
int NumProc () const
 Returns total number of processes. More...
 
Methods Overridden from Comm
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. More...
 
void Barrier () const
 Pause every process in *this communicator until all the processes reach this point. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
Miscellaneous Methods
void syncPrintDebugMsg (const char *msg, unsigned int msgVerbosity, unsigned int numUSecs) const
 Synchronizes all the processes and print debug message. More...
 

Private Member Functions

void copy (const MpiComm &src)
 Copies from an existing MpiComm instance. More...
 

Private Attributes

const BaseEnvironmentm_env
 
RawType_MPI_Comm m_rawComm
 Embedded wrapped opaque MPI_Comm object. More...
 
int m_worldRank
 World rank. More...
 
int m_myPid
 Process ID of this process. More...
 
int m_numProc
 

Detailed Description

The QUESO MPI Communicator Class.

This class uses MPI (the Message Passing Interface) for distributed-memory communication between one or more parallel processes. It is meant to insulate the user from the specifics of communication that are not required for normal manipulation of linear algebra objects.

Definition at line 75 of file MpiComm.h.

Constructor & Destructor Documentation

QUESO::MpiComm::MpiComm ( )

Default Constructor.

It should not be used by user.

Definition at line 31 of file MpiComm.C.

References UQ_FATAL_TEST_MACRO, and QUESO::UQ_UNAVAILABLE_RANK.

32  :
33  m_env( *(new EmptyEnvironment()) )
34 {
37  "MpiComm::constructor()",
38  "should not be called");
39 }
const BaseEnvironment & m_env
Definition: MpiComm.h:206
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
QUESO::MpiComm::MpiComm ( const BaseEnvironment env,
RawType_MPI_Comm  inputRawComm 
)

QUESO MpiComm MPI Constructor.

This constructs an MpiComm that uses the given "raw" MPI communicator underneath. The MPI_Comm must be valid for the lifetime of this MpiComm.

Definition at line 41 of file MpiComm.C.

References m_myPid, m_numProc, m_worldRank, UQ_FATAL_TEST_MACRO, and QUESO::UQ_UNAVAILABLE_RANK.

42  :
43  m_env (env),
44 #ifdef QUESO_HAS_TRILINOS
45  m_epetraMpiComm( new Epetra_MpiComm(inputRawComm) ),
46 #endif
47  m_rawComm (inputRawComm),
48  m_worldRank (-1),
49  m_myPid (-1),
50  m_numProc (-1)
51 {
52  int mpiRC = MPI_Comm_rank(inputRawComm,&m_worldRank);
53  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
55  "MpiComm::constructor()",
56  "failed MPI_Comm_rank() on full rank");
57 
58  mpiRC = MPI_Comm_rank(inputRawComm,&m_myPid);
59  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
61  "MpiComm::constructor()",
62  "failed MPI_Comm_rank() on inputRawComm");
63 
64  mpiRC = MPI_Comm_size(inputRawComm,&m_numProc);
65  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
67  "MpiComm::constructor()",
68  "failed MPI_Comm_size() on inputRawComm");
69 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
const BaseEnvironment & m_env
Definition: MpiComm.h:206
int m_myPid
Process ID of this process.
Definition: MpiComm.h:219
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
QUESO::MpiComm::MpiComm ( const MpiComm src)

Copy Constructor.

Makes an exact copy of an existing MpiComm instance.

Definition at line 72 of file MpiComm.C.

References copy().

73  :
74  m_env (src.m_env)
75 #ifdef QUESO_HAS_TRILINOS
76  ,
77  m_epetraMpiComm(NULL)
78 #endif
79 {
80  this->copy(src);
81 }
const BaseEnvironment & m_env
Definition: MpiComm.h:206
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:269
QUESO::MpiComm::~MpiComm ( )

Destructor.

Definition at line 84 of file MpiComm.C.

85 {
86 #ifdef QUESO_HAS_TRILINOS
87  delete m_epetraMpiComm;
88  m_epetraMpiComm = NULL;
89 #endif
90 }

Member Function Documentation

void QUESO::MpiComm::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.

Parameters
sendbufstarting address of send buffer
countnumber of elements in send buffer
datatypedata type of elements of send buffer
opoperation
recvbuf(output) starting address of receive buffer

Definition at line 131 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

Referenced by QUESO::ComputeCovCorrBetweenScalarSequences(), QUESO::ComputeCovCorrMatricesBetweenVectorSequences(), QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiAllReduce(), QUESO::GslVector::mpiBcast(), QUESO::MHRawChainInfoStruct::mpiSum(), and QUESO::GslMatrix::mpiSum().

132 {
133  int mpiRC = MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, m_rawComm);
134  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
135  m_worldRank,
136  whereMsg,
137  whatMsg);
138 
139  return;
140 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void QUESO::MpiComm::Barrier ( ) const

Pause every process in *this communicator until all the processes reach this point.

Blocks the caller until all processes in the communicator have called it; that is, the call returns at any process only after all members of the communicator have entered the call.

Definition at line 143 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

Referenced by QUESO::ComputeCovCorrMatricesBetweenVectorSequences(), QUESO::FullEnvironment::FullEnvironment(), QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiBcast(), and syncPrintDebugMsg().

144 {
145 #ifdef QUESO_HAS_TRILINOS
146  return m_epetraMpiComm->Barrier();
147 #endif
148  int mpiRC = MPI_Barrier(m_rawComm);
149  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
150  m_worldRank,
151  "MPIComm::Barrier()", // whereMsg,
152  "mpiRC indicates failure"); // whatMsg);
153  return;
154 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void QUESO::MpiComm::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.

Broadcasts a message from the process with rank "root" to all other processes of the communicator.

Parameters
buffer(input/output) starting address of buffer
countnumber of entries in buffer
datatypedata type of buffer
rootrank of broadcast root

Definition at line 157 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

Referenced by QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiAllQuantile(), and QUESO::GslVector::mpiBcast().

158 {
159  int mpiRC = MPI_Bcast(buffer, count, datatype, root, m_rawComm);
160  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
161  m_worldRank,
162  whereMsg,
163  whatMsg);
164  return;
165 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
RawType_MPI_Comm QUESO::MpiComm::Comm ( ) const

Extract MPI Communicator from a MpiComm object.

Definition at line 103 of file MpiComm.C.

References m_rawComm.

Referenced by QUESO::FullEnvironment::FullEnvironment().

104 {
105 #ifdef QUESO_HAS_TRILINOS
106  return m_epetraMpiComm->Comm();
107 #endif
108  return m_rawComm;
109 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
void QUESO::MpiComm::copy ( const MpiComm src)
private

Copies from an existing MpiComm instance.

Definition at line 269 of file MpiComm.C.

References m_myPid, m_numProc, m_rawComm, and m_worldRank.

Referenced by MpiComm(), and operator=().

270 {
271 #ifdef QUESO_HAS_TRILINOS
272  delete m_epetraMpiComm;
273  m_epetraMpiComm = new Epetra_MpiComm(*src.m_epetraMpiComm);
274 #endif
275  m_rawComm = src.m_rawComm;
276  m_worldRank = src.m_worldRank;
277  m_myPid = src.m_myPid;
278  m_numProc = src.m_numProc;
279 
280  return;
281 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
int m_myPid
Process ID of this process.
Definition: MpiComm.h:219
void QUESO::MpiComm::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.

Parameters
sendbufstarting address of send buffer
sendcntnumber of elements in send buffer
sendtypedata type of send buffer elements
recvcountnumber of elements for any single receive
recvtypedata type of recv buffer elements
rootrank of receiving process
recvbuf(output) address of receive buffer

Definition at line 168 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

Referenced by QUESO::GslVector::mpiAllQuantile().

173 {
174  //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype,
175  // void *recvbuf, int recvcount, MPI_Datatype recvtype,
176  // int root, MPI_Comm comm )
177  int mpiRC = MPI_Gather(sendbuf, sendcnt, sendtype,
178  recvbuf, recvcount, recvtype,
179  root, m_rawComm);
180  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
181  m_worldRank,
182  whereMsg,
183  whatMsg);
184  return;
185 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void QUESO::MpiComm::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.

Parameters
sendbufstarting address of send buffer
sendcountnumber of elements in send buffer
sendtypedata type of send buffer elements
recvcountsinteger array (of length group size) containing the number of elements that are received from each process
displsinteger array (of length group size). Entry i specifies the displacement relative to recvbuf at which to place the incoming data from process i
recvtypedata type of recv buffer elements
rootrank of receiving process

Definition at line 188 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

193 {
194  //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
195  // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype,
196  // int root, MPI_Comm comm )
197  int mpiRC = MPI_Gatherv(sendbuf, sendcnt, sendtype,
198  recvbuf, recvcnts, displs, recvtype,
199  root, m_rawComm);
200  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
201  m_worldRank,
202  whereMsg,
203  whatMsg);
204  return;
205 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
int QUESO::MpiComm::MyPID ( ) const

Return my process ID.

Definition at line 112 of file MpiComm.C.

References m_myPid.

Referenced by QUESO::FullEnvironment::FullEnvironment(), QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiAllQuantile(), QUESO::GslVector::mpiAllReduce(), QUESO::GslVector::mpiBcast(), and syncPrintDebugMsg().

113 {
114 #ifdef QUESO_HAS_TRILINOS
115  return m_epetraMpiComm->MyPID();
116 #endif
117  return m_myPid;
118 }
int m_myPid
Process ID of this process.
Definition: MpiComm.h:219
int QUESO::MpiComm::NumProc ( ) const
MpiComm & QUESO::MpiComm::operator= ( const MpiComm rhs)

Assignment operator.

Definition at line 95 of file MpiComm.C.

References copy().

96 {
97  this->copy(rhs);
98  return *this;
99 }
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:269
void QUESO::MpiComm::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.

Parameters
buf(output) initial address of receive buffer
status(output) status object
countmaximum number of elements in receive buffer
datatypedatatype of each receive buffer element
sourcerank of source
tagmessage tag

Definition at line 208 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

211 {
212  int mpiRC = MPI_Recv(buf, count, datatype, source, tag, m_rawComm, status);
213  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
214  m_worldRank,
215  whereMsg,
216  whatMsg);
217  return;
218 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void QUESO::MpiComm::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.

Parameters
bufinitial address of send buffer
countnumber of elements in send buffer
datatypedatatype of each send buffer element
destrank of destination
tagmessage tag

Definition at line 221 of file MpiComm.C.

References m_rawComm, m_worldRank, and UQ_FATAL_TEST_MACRO.

224 {
225  int mpiRC = MPI_Send(buf, count, datatype, dest, tag, m_rawComm);
226  UQ_FATAL_TEST_MACRO(mpiRC != MPI_SUCCESS,
227  m_worldRank,
228  whereMsg,
229  whatMsg);
230  return;
231 }
int m_worldRank
World rank.
Definition: MpiComm.h:216
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void QUESO::MpiComm::syncPrintDebugMsg ( const char *  msg,
unsigned int  msgVerbosity,
unsigned int  numUSecs 
) const

Synchronizes all the processes and print debug message.

Definition at line 234 of file MpiComm.C.

References Barrier(), QUESO::BaseEnvironment::fullRank(), QUESO::BaseEnvironment::inter0Rank(), m_env, MyPID(), NumProc(), QUESO::BaseEnvironment::subId(), QUESO::BaseEnvironment::subRank(), and QUESO::BaseEnvironment::syncVerbosity().

235 {
236  if (m_env.syncVerbosity() >= msgVerbosity) {
237  this->Barrier();
238  for (int i = 0; i < this->NumProc(); ++i) {
239  if (i == this->MyPID()) {
240  std::cout << msg
241  << ": fullRank " << m_env.fullRank()
242  << ", subEnvironment " << m_env.subId()
243  << ", subRank " << m_env.subRank()
244  << ", inter0Rank " << m_env.inter0Rank()
245  << std::endl;
246  }
247  usleep(numUSecs);
248  this->Barrier();
249  }
250  //if (this->fullRank() == 0) std::cout << "Sleeping " << numUSecs << " microseconds..."
251  // << std::endl;
252  //usleep(numUSecs);
253  this->Barrier();
254  }
255 
256  return;
257 }
int subRank() const
Access function for sub-rank.
Definition: Environment.C:263
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:446
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:289
const BaseEnvironment & m_env
Definition: MpiComm.h:206
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:121
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:143
int fullRank() const
Returns the process full rank.
Definition: Environment.C:241
int MyPID() const
Return my process ID.
Definition: MpiComm.C:112
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:329

Member Data Documentation

const BaseEnvironment& QUESO::MpiComm::m_env
private

Definition at line 206 of file MpiComm.h.

Referenced by syncPrintDebugMsg().

int QUESO::MpiComm::m_myPid
private

Process ID of this process.

Definition at line 219 of file MpiComm.h.

Referenced by copy(), MpiComm(), and MyPID().

int QUESO::MpiComm::m_numProc
private

Definition at line 222 of file MpiComm.h.

Referenced by copy(), MpiComm(), and NumProc().

RawType_MPI_Comm QUESO::MpiComm::m_rawComm
private

Embedded wrapped opaque MPI_Comm object.

Definition at line 213 of file MpiComm.h.

Referenced by Allreduce(), Barrier(), Bcast(), Comm(), copy(), Gather(), Gatherv(), Recv(), and Send().

int QUESO::MpiComm::m_worldRank
private

World rank.

Definition at line 216 of file MpiComm.h.

Referenced by Allreduce(), Barrier(), Bcast(), copy(), Gather(), Gatherv(), MpiComm(), Recv(), and Send().


The documentation for this class was generated from the following files:

Generated on Thu Apr 23 2015 19:26:17 for queso-0.51.1 by  doxygen 1.8.5