PlayaMPIComm.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 
00003 // @HEADER
00004 
00005 #ifndef PLAYA_MPICOMM_H
00006 #define PLAYA_MPICOMM_H
00007 
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 
00034 class MPIComm
00035 {
00036 public:
00037 
00039   MPIComm();
00040 
00041 #ifdef HAVE_MPI
00043   MPIComm(MPI_Comm comm);
00044 #endif
00045 
00047   static MPIComm& world();
00049   static MPIComm& self();
00050 
00052   int getRank() const {return myRank_;}
00053 
00055   int getNProc() const {return nProc_;}
00056 
00058   void synchronize() const ;
00059 
00061 
00062 
00064   void allToAll(void* sendBuf, int sendCount, const MPIDataType& sendType,
00065     void* recvBuf, int recvCount, 
00066     const MPIDataType& recvType) const ;
00067 
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 
00076   void allReduce(void* input, void* result, int inputCount, 
00077     const MPIDataType& type,
00078     const MPIOp& op) const ;
00079 
00080 
00082   void gather(void* sendBuf, int sendCount, const MPIDataType& sendType,
00083     void* recvBuf, int recvCount, const MPIDataType& recvType,
00084     int root) const ;
00085 
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 
00092   void allGather(void* sendBuf, int sendCount, 
00093     const MPIDataType& sendType,
00094     void* recvBuf, int recvCount, 
00095     const MPIDataType& recvType) const ;
00096 
00098   void allGatherv(void* sendBuf, int sendCount, 
00099     const MPIDataType& sendType,
00100     void* recvBuf, int* recvCount, int* recvDisplacements,
00101     const MPIDataType& recvType) const ;
00102 
00104   void bcast(void* msg, int length, 
00105     const MPIDataType& type, int src) const ;
00106 
00108 
00109 #ifdef HAVE_MPI
00111   MPI_Comm getComm() const {return comm_;}
00112 #endif
00113 
00114   
00115 
00116   // errCheck() checks the return value of an MPI call and throws
00117   // a ParallelException upon failure.
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 
00129   void init();
00130 
00132   int mpiIsRunning() const ;
00133 };
00134 }
00135 #endif
00136 

doxygen