00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TEUCHOS_MPICOMM_H
00030 #define TEUCHOS_MPICOMM_H
00031
00036 #include "Teuchos_ConfigDefs.hpp"
00037 #include "Teuchos_Array.hpp"
00038 #include "Teuchos_RCP.hpp"
00039
00040 #ifdef HAVE_MPI
00041 #include "mpi.h"
00042 #endif
00043
00044
00045 namespace Teuchos
00046 {
00053 class TEUCHOS_LIB_DLL_EXPORT MPIComm
00054 {
00055 public:
00056
00058 MPIComm();
00059
00060 #ifdef HAVE_MPI
00062 MPIComm(MPI_Comm comm);
00063 #endif
00064
00066 static MPIComm& world();
00067
00069 int getRank() const {return myRank_;}
00070
00072 int getNProc() const {return nProc_;}
00073
00075 void synchronize() const ;
00076
00078
00079
00081 void allToAll(void* sendBuf, int sendCount, int sendType,
00082 void* recvBuf, int recvCount, int recvType) const ;
00083
00085 void allToAllv(void* sendBuf, int* sendCount, int* sendDisplacements,
00086 int sendType,
00087 void* recvBuf, int* recvCount,
00088 int* recvDisplacements,
00089 int recvType) const ;
00090
00092 void allReduce(void* input, void* result, int inputCount, int type,
00093 int op) const ;
00094
00095
00097 void gather(void* sendBuf, int sendCount, int sendType,
00098 void* recvBuf, int recvCount, int recvType,
00099 int root) const ;
00100
00102 void gatherv(void* sendBuf, int sendCount, int sendType,
00103 void* recvBuf, int* recvCount, int* displacements,
00104 int recvType, int root) const ;
00105
00107 void allGather(void* sendBuf, int sendCount, int sendType,
00108 void* recvBuf, int recvCount, int recvType) const ;
00109
00111 void allGatherv(void* sendBuf, int sendCount, int sendType,
00112 void* recvBuf, int* recvCount, int* recvDisplacements,
00113 int recvType) const ;
00114
00116 void bcast(void* msg, int length, int type, int src) const ;
00117
00119
00120 #ifdef HAVE_MPI
00122 MPI_Comm getComm() const {return comm_;}
00123 #endif
00124
00126
00127
00128 static const int INT;
00130 static const int FLOAT;
00132 static const int DOUBLE;
00134 static const int CHAR;
00136
00138
00139
00140 static const int SUM;
00142 static const int MIN;
00144 static const int MAX;
00146 static const int PROD;
00148
00149
00150
00151 static void errCheck(int errCode, const std::string& methodName);
00152
00153 #ifdef HAVE_MPI
00155 static MPI_Datatype getDataType(int type);
00156
00158 static MPI_Op getOp(int op);
00159 #endif
00160 private:
00161 #ifdef HAVE_MPI
00162 MPI_Comm comm_;
00163 #endif
00164
00165 int nProc_;
00166 int myRank_;
00167
00169 void init();
00170
00172 int mpiIsRunning() const ;
00173 };
00174 }
00175 #endif
00176