Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

toolbox_p/communicators.hh
Go to the documentation of this file.
00001 /* -*- c++ -*-
00002  * communication between the processors
00003  */
00004 
00005 #ifndef communicators_hh
00006 #define communicators_hh
00007 
00008 #include "basics.hh"
00009 #include "using_p.hh"
00010 
00011 // ********************************* forward declarations **
00012 
00013 #ifdef MPICH
00014 typedef union MPIR_HANDLE *MPI_Request;
00015 #else
00016 typedef struct _req *MPI_Request;
00017 #endif
00018 
00019 namespace parallel {
00020 
00021   // ************************************ MissingDataType **
00022 
00027   class MissingDataType : public concepts::ExceptionBase {};
00028 
00029 
00030   // *************************************** Communicator **
00031 
00034   class Communicator : public concepts::OutputOperator {
00035 
00036   public:
00037     virtual ~Communicator() {};
00038 
00039     virtual int rank() const = 0;
00040     virtual int nrank() const = 0;
00041 
00042     // receive
00043     virtual int receive(void *rbuf, uint cnt, uint src) = 0;
00044     virtual int receive(uint *rbuf, uint cnt, uint src) = 0;
00045     virtual int receive(Real *rbuf, uint cnt, uint src) = 0;
00046 
00047     // non-blocking operations
00048     virtual int nbsend(void *sbuf, uint cnt, uint* dest, uint ndest) = 0;
00049     virtual int nbsend(uint *sbuf, uint cnt, uint* dest, uint ndest) = 0;
00050     virtual int nbsend(Real *sbuf, uint cnt, uint* dest, uint ndest) = 0;
00051     virtual int waitall() = 0;
00052 
00053     // allgather
00054     virtual int allgather(void *sbuf, uint cnt, void *rbuf) = 0;
00055     virtual int allgather(uint *sbuf, uint cnt, uint *rbuf) = 0;
00056     virtual int allgather(Real *sbuf, uint cnt, Real *rbuf) = 0;
00057 
00058     // alltoall
00059     virtual int alltoallV(void *sbuf, int *nsdata, int *sdataoffset,
00060         void *rbuf, int *nrdata, int *rdataoffset) = 0;
00061     virtual int alltoallV(uint *sbuf, int *nsdata, int *sdataoffset,
00062         uint *rbuf, int *nrdata, int *rdataoffset) = 0;
00063 
00064     // barrier
00065     virtual int barrier() = 0;
00066   };
00067 
00068 
00069   // ********************************************* ComMPI **
00070 
00073   class ComMPI : public Communicator {
00074 
00075     class Request {
00076       Request   *lnk_;
00077       MPI_Request *request_;
00078       uint    nreq_;
00079 
00080     public:
00081       Request(Request *lnk, uint nreq);
00082       ~Request();
00083 
00084       MPI_Request* operator[](uint i);
00085       inline MPI_Request* request() {return request_;};
00086       inline uint nrequest() const {return nreq_;};
00087       inline Request* link() const {return lnk_;};
00088     };
00089 
00091     int rnk_;
00092     int nrnk_;
00093 
00094     Request *request_;
00095 
00096   protected:
00097     std::ostream& info(std::ostream& os) const {
00098       return os << "ComMPI(rank=" << rnk_ << ", nrank=" << nrnk_ << ")";
00099     };
00100 
00101   public:
00102     ComMPI(int *argc, char ***argv);
00103     ~ComMPI();
00104 
00105     int rank() const {return rnk_;};
00106     int nrank() const {return nrnk_;};
00107 
00108     // receive
00109     int receive(void *rbuf, uint cnt, uint src);
00110     int receive(uint *rbuf, uint cnt, uint src);
00111     int receive(Real *rbuf, uint cnt, uint src);
00112 
00113     // non-blocking operations
00114     int nbsend(void *sbuf, uint cnt, uint* dest, uint ndest);
00115     int nbsend(uint *sbuf, uint cnt, uint* dest, uint ndest);
00116     int nbsend(Real *sbuf, uint cnt, uint* dest, uint ndest);
00117     int waitall();
00118 
00119     // allgather
00120     int allgather(void *sbuf, uint cnt, void *rbuf);
00121     int allgather(uint *sbuf, uint cnt, uint *rbuf);
00122     int allgather(Real *sbuf, uint cnt, Real *rbuf);
00123 
00124     // alltoall
00125     int alltoallV(void *sndbuf, int *sndcounts, int *sdispls,
00126       void *recvbuf, int *recvcounts, int *rdispls);
00127     int alltoallV(uint *sndbuf, int *sndcounts, int *sdispls,
00128       uint *recvbuf, int *recvcounts, int *rdispls);
00129 
00130     // barrier
00131     int barrier();
00132   };
00133 
00134 
00135 } // namespace parallel
00136 
00137 #endif // communicators_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)