00001
00002
00003
00004
00005 #ifndef PLAYA_MPICOMM_H
00006 #define PLAYA_MPICOMM_H
00007
00008
00009
00010
00011
00012 #include "PlayaDefs.hpp"
00013 #include "PlayaMPIOp.hpp"
00014 #include "PlayaMPIDataType.hpp"
00015 #include "Teuchos_ConfigDefs.hpp"
00016 #include "Teuchos_Array.hpp"
00017 #include "Teuchos_RCP.hpp"
00018
00019 #ifdef HAVE_MPI
00020 #include "mpi.h"
00021 #endif
00022
00023
00024 namespace Playa
00025 {
00026
00027
00028
00029
00030
00031
00032
00033
00034 class MPIComm
00035 {
00036 public:
00037
00038
00039 MPIComm();
00040
00041 #ifdef HAVE_MPI
00042
00043 MPIComm(MPI_Comm comm);
00044 #endif
00045
00046
00047 static MPIComm& world();
00048
00049 static MPIComm& self();
00050
00051
00052 int getRank() const {return myRank_;}
00053
00054
00055 int getNProc() const {return nProc_;}
00056
00057
00058 void synchronize() const ;
00059
00060
00061
00062
00063
00064 void allToAll(void* sendBuf, int sendCount, const MPIDataType& sendType,
00065 void* recvBuf, int recvCount,
00066 const MPIDataType& recvType) const ;
00067
00068
00069 void allToAllv(void* sendBuf, int* sendCount, int* sendDisplacements,
00070 const MPIDataType& sendType,
00071 void* recvBuf, int* recvCount,
00072 int* recvDisplacements,
00073 const MPIDataType& recvType) const ;
00074
00075
00076 void allReduce(void* input, void* result, int inputCount,
00077 const MPIDataType& type,
00078 const MPIOp& op) const ;
00079
00080
00081
00082 void gather(void* sendBuf, int sendCount, const MPIDataType& sendType,
00083 void* recvBuf, int recvCount, const MPIDataType& recvType,
00084 int root) const ;
00085
00086
00087 void gatherv(void* sendBuf, int sendCount, const MPIDataType& sendType,
00088 void* recvBuf, int* recvCount, int* displacements,
00089 const MPIDataType& recvType, int root) const ;
00090
00091
00092 void allGather(void* sendBuf, int sendCount,
00093 const MPIDataType& sendType,
00094 void* recvBuf, int recvCount,
00095 const MPIDataType& recvType) const ;
00096
00097
00098 void allGatherv(void* sendBuf, int sendCount,
00099 const MPIDataType& sendType,
00100 void* recvBuf, int* recvCount, int* recvDisplacements,
00101 const MPIDataType& recvType) const ;
00102
00103
00104 void bcast(void* msg, int length,
00105 const MPIDataType& type, int src) const ;
00106
00107
00108
00109 #ifdef HAVE_MPI
00110
00111 MPI_Comm getComm() const {return comm_;}
00112 #endif
00113
00114
00115
00116
00117
00118 static void errCheck(int errCode, const std::string& methodName);
00119
00120 private:
00121 #ifdef HAVE_MPI
00122 MPI_Comm comm_;
00123 #endif
00124
00125 int nProc_;
00126 int myRank_;
00127
00128
00129 void init();
00130
00131
00132 int mpiIsRunning() const ;
00133 };
00134 }
00135 #endif
00136