queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::MpiComm Class Reference

The QUESO MPI Communicator Class. More...

#include <MpiComm.h>

Public Member Functions

Constructor/Destructor methods
 MpiComm (const BaseEnvironment &env, RawType_MPI_Comm inputRawComm)
 QUESO MpiComm MPI parallel constructor. More...
 
 MpiComm (const BaseEnvironment &env)
 QUESO MpiComm MPI serial 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...
 
template<typename T >
void Allreduce (const T *sendbuf, T *recvbuf, int count, 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...
 
template<typename T >
void Gather (const T *sendbuf, int sendcnt, T *recvbuf, int recvcount, 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...
 
template<typename T >
void Gatherv (const T *sendbuf, int sendcnt, T *recvbuf, int *recvcnts, int *displs, 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...
 
const Epetra_Comm & epetraMpiComm () const
 Extract MPI Communicator from a Epetra_MpiComm object. 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
 
Epetra_Comm * m_epetraComm
 
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 203 of file MpiComm.h.

Constructor & Destructor Documentation

QUESO::MpiComm::MpiComm ( const BaseEnvironment env,
RawType_MPI_Comm  inputRawComm 
)

QUESO MpiComm MPI parallel constructor.

This constructs an MpiComm that uses the given "raw" MPI communicator underneath. MPI_Init must have been called before instantiating an object of this type.

The MPI_Comm must be valid for the lifetime of this MpiComm.

Definition at line 38 of file MpiComm.C.

References m_myPid, m_numProc, m_worldRank, and QUESO::queso_require_equal_to_msg.

39  :
40  m_env (env),
41 #ifdef QUESO_HAS_TRILINOS
42  m_epetraComm( new Epetra_MpiComm(inputRawComm) ),
43 #endif
44  m_rawComm (inputRawComm),
45  m_worldRank (-1),
46  m_myPid (-1),
47  m_numProc (-1)
48 {
49 #ifdef QUESO_HAS_MPI
50  int mpiRC = MPI_Comm_rank(inputRawComm,&m_worldRank);
51  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_rank() on full rank");
52 
53  mpiRC = MPI_Comm_rank(inputRawComm,&m_myPid);
54  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_rank() on inputRawComm");
55 
56  mpiRC = MPI_Comm_size(inputRawComm,&m_numProc);
57  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "failed MPI_Comm_size() on inputRawComm");
58 #else
59  m_worldRank = 0;
60  m_myPid = 0;
61  m_numProc = 1;
62 #endif
63 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
const BaseEnvironment & m_env
Definition: MpiComm.h:395
int m_myPid
Process ID of this process.
Definition: MpiComm.h:409
int m_worldRank
World rank.
Definition: MpiComm.h:406
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
QUESO::MpiComm::MpiComm ( const BaseEnvironment env)

QUESO MpiComm MPI serial constructor.

This constructs an MpiComm that defaults to MPI_COMM_SELF underneath. MPI_Init need not be called before using this constructor.

The MPI_Comm must be valid for the lifetime of this MpiComm.

Definition at line 65 of file MpiComm.C.

66  :
67  m_env (env),
68 #ifdef QUESO_HAS_TRILINOS
69  m_epetraComm( new Epetra_SerialComm() ),
70 #endif
71  m_rawComm (RawValue_MPI_COMM_SELF),
72  m_worldRank (0),
73  m_myPid (0),
74  m_numProc (1)
75 {
76 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
const BaseEnvironment & m_env
Definition: MpiComm.h:395
int m_myPid
Process ID of this process.
Definition: MpiComm.h:409
int m_worldRank
World rank.
Definition: MpiComm.h:406
QUESO::MpiComm::MpiComm ( const MpiComm src)

Copy Constructor.

Makes an exact copy of an existing MpiComm instance.

QUESO::MpiComm::~MpiComm ( )

Destructor.

QUESO::MpiComm::MpiComm ( )
private

Default Constructor.

It should not be used by user.

Definition at line 91 of file MpiComm.C.

References m_epetraComm.

92 {
93 #ifdef QUESO_HAS_TRILINOS
94  delete m_epetraComm;
95  m_epetraComm = NULL;
96 #endif
97 }
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399

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

This method is deprecated. Use the templated Allreduce method instead.

Definition at line 143 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

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

144 {
145  queso_deprecated();
146  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
147 #ifdef QUESO_HAS_MPI
148  int mpiRC = MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, m_rawComm);
149  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
150 #endif
151  }
152 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
template<typename T >
void QUESO::MpiComm::Allreduce ( const T *  sendbuf,
T *  recvbuf,
int  count,
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 containing elements of type T
countnumber of elements in send buffer
opoperation
recvbuf(output) starting address of receive buffer containing elements of type T

Definition at line 156 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

158 {
159  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
160 #ifdef QUESO_HAS_MPI
161  T * sendbuf_noconst = const_cast<T *>(sendbuf);
162  int mpiRC = MPI_Allreduce(sendbuf_noconst, recvbuf, count, StandardType<T>(sendbuf), op, m_rawComm);
163  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
164 #endif
165  }
166  else {
167  size_t dataTypeSize = sizeof(T);
168  size_t dataTotal = dataTypeSize*count;
169  std::memcpy(recvbuf, sendbuf, dataTotal);
170  }
171 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
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 174 of file MpiComm.C.

References m_epetraComm, m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

Referenced by QUESO::VectorFunctionSynchronizer< P_V, P_M, Q_V, Q_M >::callFunction(), QUESO::ComputeCovCorrMatricesBetweenVectorSequences(), QUESO::MiscCheckForSameValueInAllNodes(), QUESO::GslVector::mpiBcast(), QUESO::TeuchosVector::mpiBcast(), and syncPrintDebugMsg().

175 {
176 #ifdef QUESO_HAS_TRILINOS
177  return m_epetraComm->Barrier();
178 #endif
179 
180  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
181 #ifdef QUESO_HAS_MPI
182  int mpiRC = MPI_Barrier(m_rawComm);
183  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, "mpiRC indicates failure"); // whatMsg);
184 #endif
185  }
186 
187  return;
188 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
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 191 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

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

192 {
193  if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI
194 #ifdef QUESO_HAS_MPI
195  int mpiRC = MPI_Bcast(buffer, count, datatype, root, m_rawComm);
196  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
197 #endif
198  }
199 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
RawType_MPI_Comm QUESO::MpiComm::Comm ( ) const

Extract MPI Communicator from a MpiComm object.

Definition at line 111 of file MpiComm.C.

References m_epetraComm, and m_rawComm.

Referenced by QUESO::GPMSAEmulator< V, M >::lnValue(), and QUESO::GPMSAFactory< V, M >::setUpHyperpriors().

112 {
113 #ifdef QUESO_HAS_TRILINOS
114 #ifdef QUESO_HAS_MPI
115  return dynamic_cast<Epetra_MpiComm *>(m_epetraComm)->Comm();
116 #endif
117 #endif
118  return m_rawComm;
119 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
RawType_MPI_Comm Comm() const
Extract MPI Communicator from a MpiComm object.
Definition: MpiComm.C:111
void QUESO::MpiComm::copy ( const MpiComm src)
private

Copies from an existing MpiComm instance.

Definition at line 368 of file MpiComm.C.

References m_epetraComm, m_myPid, m_numProc, m_rawComm, and m_worldRank.

Referenced by operator=().

369 {
370 #ifdef QUESO_HAS_TRILINOS
371  delete m_epetraComm;
372  m_epetraComm = src.m_epetraComm->Clone();
373 #endif
374  m_rawComm = src.m_rawComm;
375  m_worldRank = src.m_worldRank;
376  m_myPid = src.m_myPid;
377  m_numProc = src.m_numProc;
378 
379  return;
380 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
int m_myPid
Process ID of this process.
Definition: MpiComm.h:409
int m_worldRank
World rank.
Definition: MpiComm.h:406
const Epetra_Comm & QUESO::MpiComm::epetraMpiComm ( ) const

Extract MPI Communicator from a Epetra_MpiComm object.

Definition at line 360 of file MpiComm.C.

References m_epetraComm.

361 {
362  return *m_epetraComm;
363 }
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
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

This method is deprecated. Use the templated Gather method instead.

Definition at line 202 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

Referenced by QUESO::GslVector::mpiAllQuantile(), and QUESO::TeuchosVector::mpiAllQuantile().

207 {
208  queso_deprecated();
209  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
210 #ifdef QUESO_HAS_MPI
211  //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype,
212  // void *recvbuf, int recvcount, MPI_Datatype recvtype,
213  // int root, MPI_Comm comm )
214  int mpiRC = MPI_Gather(sendbuf, sendcnt, sendtype,
215  recvbuf, recvcount, recvtype,
216  root, m_rawComm);
217  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
218 #endif
219  }
220 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
template<typename T >
void QUESO::MpiComm::Gather ( const T *  sendbuf,
int  sendcnt,
T *  recvbuf,
int  recvcount,
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 containing elements of type T
sendcntnumber of elements in send buffer
recvcountnumber of elements for any single receive
rootrank of receiving process
recvbuf(output) address of receive buffer containing elements of type T

Definition at line 224 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

226 {
227  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
228 #ifdef QUESO_HAS_MPI
229  //int MPI_Gather (void *sendbuf, int sendcnt, MPI_Datatype sendtype,
230  // void *recvbuf, int recvcount, MPI_Datatype recvtype,
231  // int root, MPI_Comm comm )
232  T * sendbuf_noconst = const_cast<T *>(sendbuf);
233  int mpiRC = MPI_Gather(sendbuf_noconst, sendcnt, StandardType<T>(sendbuf),
234  recvbuf, recvcount, StandardType<T>(sendbuf),
235  root, m_rawComm);
236  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
237 #endif
238  }
239  else {
240  size_t dataTypeSize = sizeof(T);
241  size_t sendTotal = dataTypeSize*sendcnt;
242  size_t recvTotal = dataTypeSize*recvcount;
243  if (sendTotal != recvTotal) {
244  std::cerr << "MpiCommClass::Gather()"
245  << ": sendTotal != recvTotal"
246  << std::endl;
247  }
248  queso_require_equal_to_msg(sendTotal, recvTotal, whatMsg);
249  std::memcpy(recvbuf, sendbuf, sendTotal);
250  }
251 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
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 254 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

259 {
260  queso_deprecated();
261  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
262 #ifdef QUESO_HAS_MPI
263  //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
264  // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype,
265  // int root, MPI_Comm comm )
266  int mpiRC = MPI_Gatherv(sendbuf, sendcnt, sendtype,
267  recvbuf, recvcnts, displs, recvtype,
268  root, m_rawComm);
269  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
270 #endif
271  }
272 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
template<typename T >
void QUESO::MpiComm::Gatherv ( const T *  sendbuf,
int  sendcnt,
T *  recvbuf,
int *  recvcnts,
int *  displs,
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 containing elements of type T
sendcntnumber of elements in send buffer
recvcntsinteger 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
rootrank of receiving process

Definition at line 276 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

279 {
280  if (NumProc() > 1) { // Necessarily true if QUESO_HAS_MPI
281 #ifdef QUESO_HAS_MPI
282  //int MPI_Gatherv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
283  // void *recvbuf, int *recvcnts, int *displs, MPI_Datatype recvtype,
284  // int root, MPI_Comm comm )
285  T * sendbuf_noconst = const_cast<T *>(sendbuf);
286  int mpiRC = MPI_Gatherv(sendbuf_noconst, sendcnt, StandardType<T>(sendbuf),
287  recvbuf, recvcnts, displs,
288  StandardType<T>(recvbuf), root, m_rawComm);
289  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
290 #endif
291  }
292  else {
293  size_t dataTypeSize = sizeof(T);
294  size_t sendTotal = dataTypeSize*sendcnt;
295  size_t recvTotal = dataTypeSize*recvcnts[0];
296  if (sendTotal != recvTotal) {
297  std::cerr << "MpiCommClass::Gatherv()"
298  << ": sendTotal != recvTotal"
299  << std::endl;
300  }
301  queso_require_equal_to_msg(sendTotal, recvTotal, whatMsg);
302  std::memcpy(recvbuf, sendbuf, sendTotal);
303  }
304 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
int QUESO::MpiComm::MyPID ( ) const

Return my process ID.

Definition at line 124 of file MpiComm.C.

References m_epetraComm, and m_myPid.

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

125 {
126 #ifdef QUESO_HAS_TRILINOS
127  return m_epetraComm->MyPID();
128 #endif
129  return m_myPid;
130 }
Epetra_Comm * m_epetraComm
Definition: MpiComm.h:399
int m_myPid
Process ID of this process.
Definition: MpiComm.h:409
MpiComm & QUESO::MpiComm::operator= ( const MpiComm rhs)

Assignment operator.

Definition at line 102 of file MpiComm.C.

References copy().

103 {
104  this->copy(rhs);
105  return *this;
106 }
void copy(const MpiComm &src)
Copies from an existing MpiComm instance.
Definition: MpiComm.C:368
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 307 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

310 {
311  if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI
312 #ifdef QUESO_HAS_MPI
313  int mpiRC = MPI_Recv(buf, count, datatype, source, tag, m_rawComm, status);
314  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
315 #endif
316  }
317 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
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 320 of file MpiComm.C.

References m_rawComm, NumProc(), and QUESO::queso_require_equal_to_msg.

323 {
324  if (NumProc() > 1) { // Necesarrily true if QUESO_HAS_MPI
325 #ifdef QUESO_HAS_MPI
326  int mpiRC = MPI_Send(buf, count, datatype, dest, tag, m_rawComm);
327  queso_require_equal_to_msg(mpiRC, MPI_SUCCESS, whatMsg);
328 #endif
329  }
330 }
RawType_MPI_Comm m_rawComm
Embedded wrapped opaque MPI_Comm object.
Definition: MpiComm.h:403
MonteCarloSGOptions::MonteCarloSGOptions(const BaseEnvironment &env, const char *prefix, const McOptionsValues &alternativeOptionsValues queso_require_equal_to_msg)(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"))
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
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 333 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().

334 {
335  if (m_env.syncVerbosity() >= msgVerbosity) {
336  this->Barrier();
337  for (int i = 0; i < this->NumProc(); ++i) {
338  if (i == this->MyPID()) {
339  std::cout << msg
340  << ": fullRank " << m_env.fullRank()
341  << ", subEnvironment " << m_env.subId()
342  << ", subRank " << m_env.subRank()
343  << ", inter0Rank " << m_env.inter0Rank()
344  << std::endl;
345  }
346  usleep(numUSecs);
347  this->Barrier();
348  }
349  //if (this->fullRank() == 0) std::cout << "Sleeping " << numUSecs << " microseconds..."
350  // << std::endl;
351  //usleep(numUSecs);
352  this->Barrier();
353  }
354 
355  return;
356 }
unsigned int subId() const
Access function to the number of each sub-environment Id: m_subId.
Definition: Environment.C:342
void Barrier() const
Pause every process in *this communicator until all the processes reach this point.
Definition: MpiComm.C:174
const BaseEnvironment & m_env
Definition: MpiComm.h:395
int subRank() const
Returns the rank of the MPI process in the sub-communicator subComm()
Definition: Environment.C:287
int MyPID() const
Return my process ID.
Definition: MpiComm.C:124
int fullRank() const
Returns the rank of the MPI process in QUESO&#39;s full communicator.
Definition: Environment.C:268
unsigned int syncVerbosity() const
Access function to private attribute m_syncVerbosity.
Definition: Environment.C:457
int NumProc() const
Returns total number of processes.
Definition: MpiComm.C:133
int inter0Rank() const
Returns the process inter0 rank.
Definition: Environment.C:307

Member Data Documentation

const BaseEnvironment& QUESO::MpiComm::m_env
private

Definition at line 395 of file MpiComm.h.

Referenced by syncPrintDebugMsg().

Epetra_Comm* QUESO::MpiComm::m_epetraComm
private

Definition at line 399 of file MpiComm.h.

Referenced by Barrier(), Comm(), copy(), epetraMpiComm(), MpiComm(), MyPID(), and NumProc().

int QUESO::MpiComm::m_myPid
private

Process ID of this process.

Definition at line 409 of file MpiComm.h.

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

int QUESO::MpiComm::m_numProc
private

Definition at line 412 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 403 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 406 of file MpiComm.h.

Referenced by copy(), and MpiComm().


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

Generated on Tue Jun 5 2018 19:49:10 for queso-0.57.1 by  doxygen 1.8.5