queso-0.53.0
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 (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

 MpiComm ()
 Default Constructor. More...
 
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 ( 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 32 of file MpiComm.C.

References m_myPid, m_numProc, m_worldRank, and queso_require_equal_to_msg.

33  :
34  m_env (env),
35 #ifdef QUESO_HAS_TRILINOS
36  m_epetraMpiComm( new Epetra_MpiComm(inputRawComm) ),
37 #endif
38  m_rawComm (inputRawComm),
39  m_worldRank (-1),
40  m_myPid (-1),
41  m_numProc (-1)
42 {
43  int mpiRC = MPI_Comm_rank(inputRawComm,&m_worldRank);
44  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_rank() on full rank");
45 
46  mpiRC = MPI_Comm_rank(inputRawComm,&m_myPid);
47  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_rank() on inputRawComm");
48 
49  mpiRC = MPI_Comm_size(inputRawComm,&m_numProc);
50  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_size() on inputRawComm");
51 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
const BaseEnvironment & m_env
Definition: MpiComm.h:206
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
int m_worldRank
World rank.
Definition: MpiComm.h:216
int m_myPid
Process ID of this process.
Definition: MpiComm.h:219
QUESO::MpiComm::MpiComm ( const MpiComm src)

Copy Constructor.

Makes an exact copy of an existing MpiComm instance.

Definition at line 54 of file MpiComm.C.

References copy().

55  :
56  m_env (src.m_env)
57 #ifdef QUESO_HAS_TRILINOS
58  ,
59  m_epetraMpiComm(NULL)
60 #endif
61 {
62  this->copy(src);
63 }
const BaseEnvironment & m_env
Definition: MpiComm.h:206
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:230
QUESO::MpiComm::~MpiComm ( )

Destructor.

Definition at line 66 of file MpiComm.C.

67 {
68 #ifdef QUESO_HAS_TRILINOS
69  delete m_epetraMpiComm;
70  m_epetraMpiComm = NULL;
71 #endif
72 }
QUESO::MpiComm::MpiComm ( )
private

Default Constructor.

It should not be used by user.

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 113 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

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

114 {
115  int mpiRC = MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, m_rawComm);
116  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
117 
118  return;
119 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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 122 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

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

123 {
124 #ifdef QUESO_HAS_TRILINOS
125  return m_epetraMpiComm->Barrier();
126 #endif
127  int mpiRC = MPI_Barrier(m_rawComm);
128  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "mpiRC indicates failure"); // whatMsg);
129  return;
130 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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 133 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

Referenced by QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiAllQuantile(), QUESO::GslVector::mpiBcast(), QUESO::InterpolationSurrogateIOASCII< V, M >::read(), and QUESO::InterpolationSurrogateData< V, M >::sync_values().

134 {
135  int mpiRC = MPI_Bcast(buffer, count, datatype, root, m_rawComm);
136  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
137  return;
138 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
RawType_MPI_Comm QUESO::MpiComm::Comm ( ) const

Extract MPI Communicator from a MpiComm object.

Definition at line 85 of file MpiComm.C.

References m_rawComm.

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

86 {
87 #ifdef QUESO_HAS_TRILINOS
88  return m_epetraMpiComm->Comm();
89 #endif
90  return m_rawComm;
91 }
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 230 of file MpiComm.C.

References m_myPid, m_numProc, m_rawComm, and m_worldRank.

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

231 {
232 #ifdef QUESO_HAS_TRILINOS
233  delete m_epetraMpiComm;
234  m_epetraMpiComm = new Epetra_MpiComm(*src.m_epetraMpiComm);
235 #endif
236  m_rawComm = src.m_rawComm;
237  m_worldRank = src.m_worldRank;
238  m_myPid = src.m_myPid;
239  m_numProc = src.m_numProc;
240 
241  return;
242 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
int m_worldRank
World rank.
Definition: MpiComm.h:216
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 141 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

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

146 {
147  //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype,
148  // void *recvbuf, int recvcount, MPI_Datatype recvtype,
149  // int root, MPI_Comm comm )
150  int mpiRC = MPI_Gather(sendbuf, sendcnt, sendtype,
151  recvbuf, recvcount, recvtype,
152  root, m_rawComm);
153  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
154  return;
155 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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 158 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

Referenced by QUESO::InterpolationSurrogateBuilder< V, M >::sync_data().

163 {
164  //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
165  // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype,
166  // int root, MPI_Comm comm )
167  int mpiRC = MPI_Gatherv(sendbuf, sendcnt, sendtype,
168  recvbuf, recvcnts, displs, recvtype,
169  root, m_rawComm);
170  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
171  return;
172 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
int QUESO::MpiComm::MyPID ( ) const

Return my process ID.

Definition at line 94 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().

95 {
96 #ifdef QUESO_HAS_TRILINOS
97  return m_epetraMpiComm->MyPID();
98 #endif
99  return m_myPid;
100 }
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 77 of file MpiComm.C.

References copy().

78 {
79  this->copy(rhs);
80  return *this;
81 }
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:230
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 175 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

178 {
179  int mpiRC = MPI_Recv(buf, count, datatype, source, tag, m_rawComm, status);
180  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
181  return;
182 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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 185 of file MpiComm.C.

References m_rawComm, and queso_require_equal_to_msg.

188 {
189  int mpiRC = MPI_Send(buf, count, datatype, dest, tag, m_rawComm);
190  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
191  return;
192 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:213
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
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 195 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().

196 {
197  if (m_env.syncVerbosity() >= msgVerbosity) {
198  this->Barrier();
199  for (int i = 0; i < this->NumProc(); ++i) {
200  if (i == this->MyPID()) {
201  std::cout << msg
202  << ": fullRank " << m_env.fullRank()
203  << ", subEnvironment " << m_env.subId()
204  << ", subRank " << m_env.subRank()
205  << ", inter0Rank " << m_env.inter0Rank()
206  << std::endl;
207  }
208  usleep(numUSecs);
209  this->Barrier();
210  }
211  //if (this->fullRank() == 0) std::cout << "Sleeping " << numUSecs << " microseconds..."
212  // << std::endl;
213  //usleep(numUSecs);
214  this->Barrier();
215  }
216 
217  return;
218 }
int subRank() const
Access function for sub-rank.
Definition: Environment.C:241
int MyPID() const
Return my process ID.
Definition: MpiComm.C:94
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
int fullRank() const
Returns the process full rank.
Definition: Environment.C:222
const BaseEnvironment & m_env
Definition: MpiComm.h:206
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:403
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:261
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:295

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 copy(), and MpiComm().


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

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