Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

MPIComm.h

Go to the documentation of this file.
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   /** \ingroup MPI
00021    * Object representation of an MPI communicator.
00022    *
00023    * At present, groups are not implemented so the only communicator
00024    * is MPI_COMM_WORLD.
00025    */
00026   class MPIComm
00027     {
00028 #ifdef USE_MPI_GROUPS
00029       friend class MPIGroup;
00030 #endif
00031     public:
00032       /** empty ctor builds an object for MPI_COMM_WORLD */
00033       MPIComm();
00034 
00035 #ifdef HAVE_MPI
00036       /** construct a MPIComm for a given MPI communicator */
00037       MPIComm(MPI_Comm comm);
00038 #endif
00039 
00040       /** get an object representing MPI_COMM_WORLD */
00041       static MPIComm& world();
00042 
00043 #ifdef USE_MPI_GROUPS
00044       /** get a subcommunicator from a parent */
00045       MPIComm(const MPIComm& parent, const MPIGroup& group);
00046 #endif
00047 
00048       /** common initialization function, called by all ctors */
00049       void init();
00050 
00051       /** call MPI_Init */
00052       static void init(int* argc, void*** argv);
00053 
00054       /** call MPI_Finalize */
00055       static void finalize();
00056 
00057       /** return process rank */
00058       int getRank() const {return myRank_;}
00059 
00060       /** return number of processors in the communicator */
00061       int getNProc() const {return nProc_;}
00062 
00063       /** get the name of the machine on which this process is running */
00064       string getMachineName() const ;
00065 
00066       /** synchronize all the processors in the communicator */
00067       void synchronize() const ;
00068 
00069       /** \name Point to point communications */
00070       //@{
00071       /** blocking send */
00072       void send(void* msg, int length, int type, int tag, int dest) const ;
00073       /** blocking recv */
00074       int recv(void* msg, int length, int type, int tag, int src) const ;
00075       /** non-blocking recv */
00076       int irecv(void* msg, int length, int type, int tag, int src) const ;
00077 
00078       /** shut off a pending irecv */
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       /** {\bf Collective communications} */
00087       //@{
00088       /** all-to-all gather-scatter */
00089       void allToAll(void* sendBuf, int sendCount, int sendType,
00090                     void* recvBuf, int recvCount, int recvType) const ;
00091       /** variable-length gather-scatter */
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       /** do a collective operation, scattering the results to all procs */
00099       void allReduce(void* input, void* result, int inputCount, int type,
00100                      int op) const ;
00101 
00102       /** gather to root */
00103       void gather(void* sendBuf, int sendCount, int sendType,
00104                   void* recvBuf, int recvCount, int recvType,
00105                   int root) const ;
00106 
00107       /** gather to all procs */
00108       void allGather(void* sendBuf, int sendCount, int sendType,
00109                      void* recvBuf, int recvCount, int recvType) const ;
00110 
00111       /** gather to all procs */
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       /** get the MPI_Comm communicator handle */
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       /** \name Constants */
00129       //@{
00130       /** \name Data types  */
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       /** \name Operations */
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       // errCheck() checks the return value of an MPI call and throws
00156       // a ParallelException upon failure.
00157       static void errCheck(int errCode, const string& methodName);
00158 
00159 #ifdef HAVE_MPI
00160       // getDataType converts a PMachine data type code to a MPI_Datatype
00161       static MPI_Datatype getDataType(int type);
00162 
00163       // getOp converts a PMachine operator code to a MPI_Op operator code.
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 

Contact:
Kevin Long (krlong@ca.sandia.gov)


Documentation generated by