00001 #ifndef MPICOMM_H
00002 #define MPICOMM_H
00003
00004 #include "SundanceDefs.h"
00005 #include "TSFArray.h"
00006 #include "TSFSmartPtr.h"
00007
00008 #ifdef HAVE_MPI
00009 #include "mpi.h"
00010 #endif
00011
00012
00013
00014
00015
00016 namespace Sundance
00017 {
00018 using namespace TSF;
00019
00020
00021
00022
00023
00024
00025
00026 class MPIComm
00027 {
00028 #ifdef USE_MPI_GROUPS
00029 friend class MPIGroup;
00030 #endif
00031 public:
00032
00033 MPIComm();
00034
00035 #ifdef HAVE_MPI
00036
00037 MPIComm(MPI_Comm comm);
00038 #endif
00039
00040
00041 static MPIComm& world();
00042
00043 #ifdef USE_MPI_GROUPS
00044
00045 MPIComm(const MPIComm& parent, const MPIGroup& group);
00046 #endif
00047
00048
00049 void init();
00050
00051
00052 static void init(int* argc, void*** argv);
00053
00054
00055 static void finalize();
00056
00057
00058 int getRank() const {return myRank_;}
00059
00060
00061 int getNProc() const {return nProc_;}
00062
00063
00064 string getMachineName() const ;
00065
00066
00067 void synchronize() const ;
00068
00069
00070
00071
00072 void send(void* msg, int length, int type, int tag, int dest) const ;
00073
00074 int recv(void* msg, int length, int type, int tag, int src) const ;
00075
00076 int irecv(void* msg, int length, int type, int tag, int src) const ;
00077
00078
00079 void disableIrecv(int proc) const ;
00080 void wait(int handler) const ;
00081 int testAny() const ;
00082 int waitAny() const ;
00083 void bcast(void* msg, int length, int type, int src) const ;
00084
00085
00086
00087
00088
00089 void allToAll(void* sendBuf, int sendCount, int sendType,
00090 void* recvBuf, int recvCount, int recvType) const ;
00091
00092 void allToAllv(void* sendBuf, int* sendCount, int* sendDisplacements,
00093 int sendType,
00094 void* recvBuf, int* recvCount,
00095 int* recvDisplacements,
00096 int recvType) const ;
00097
00098
00099 void allReduce(void* input, void* result, int inputCount, int type,
00100 int op) const ;
00101
00102
00103 void gather(void* sendBuf, int sendCount, int sendType,
00104 void* recvBuf, int recvCount, int recvType,
00105 int root) const ;
00106
00107
00108 void allGather(void* sendBuf, int sendCount, int sendType,
00109 void* recvBuf, int recvCount, int recvType) const ;
00110
00111
00112 void allGatherv(void* sendBuf, int sendCount, int sendType,
00113 void* recvBuf, int* recvCount, int* recvDisplacements,
00114 int recvType) const ;
00115
00116
00117
00118 #ifdef HAVE_MPI
00119
00120 MPI_Comm getComm() const {return comm_;}
00121
00122
00123 MPI_Request* getRequestTSFArray() const {return (MPI_Request*) &((*req_)[0]);}
00124 MPI_Request getRequest(int pid) const {return (*req_)[pid];}
00125 void setRequest(int pid, MPI_Request req) const {(*req_)[pid] = req;}
00126 #endif
00127
00128
00129
00130
00131
00132
00133 const static int INT;
00134
00135 const static int FLOAT;
00136
00137 const static int DOUBLE;
00138
00139 const static int CHAR;
00140
00141
00142
00143
00144
00145 const static int SUM;
00146
00147 const static int MIN;
00148
00149 const static int MAX;
00150
00151 const static int PROD;
00152
00153
00154
00155
00156
00157 static void errCheck(int errCode, const string& methodName);
00158
00159 #ifdef HAVE_MPI
00160
00161 static MPI_Datatype getDataType(int type);
00162
00163
00164 static MPI_Op getOp(int op);
00165 #endif
00166 private:
00167 #ifdef HAVE_MPI
00168 MPI_Comm comm_;
00169 mutable TSFSmartPtr<TSFArray<MPI_Request> > req_;
00170 #endif
00171
00172 int nProc_;
00173 int myRank_;
00174 static string machineName_;
00175
00176
00177 };
00178 }
00179 #endif
00180