ESyS-Particle  4.0.1
comm.h
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 #ifndef __COMM_H
00014 #define __COMM_H
00015 
00016 //--- MPI ---
00017 #include <mpi.h>
00018 
00019 //--- project includes ---
00020 #include "Foundation/console.h"
00021 
00022 //--- TML includes ---
00023 #include "tml/type/gettype.h"
00024 
00025 //--- STL includes ---
00026 #include <vector>
00027 #include <map>
00028 #include <utility>
00029 #include <string>
00030 
00031 #undef barrier
00032 
00033 using std::vector;
00034 using std::multimap;
00035 using std::pair;
00036 using std::string;
00037 
00046 class TML_Comm
00047 {
00048 protected:
00049   MPI_Status m_status;
00050   MPI_Comm m_comm;
00051 
00052 public:
00053   bool isNull() const {return m_comm==MPI_COMM_NULL;};
00054   int rank() const;
00055   int size();
00056   MPI_Comm comm() const {return m_comm;};
00057 
00058   // assignment
00059   TML_Comm& operator=(const TML_Comm&);
00060   void setComm(MPI_Comm);
00061 
00062   // construction of new communicators
00063   TML_Comm();
00064   TML_Comm(MPI_Comm);
00065   TML_Comm include(const vector<int>&);
00066   TML_Comm exclude(const vector<int>&);
00067 
00068   // send/recv for single data
00069   template <typename T> void send(T,int,int=0);
00070   template <typename T> void receive(T&,int,int=MPI_ANY_TAG);
00071 
00072   // send/recv for C-arrays with known dimension
00073   template <typename T> void send_array(T*,int,int,int=0);
00074   template <typename T> void receive_array(T*,int,int,int=MPI_ANY_TAG);
00075 
00076   // send/recv for STL containers
00077   template <typename T> void send_cont(const T&,int,int=0);
00078   template <typename T> void receive_cont(T&,int,int=MPI_ANY_TAG);
00079 
00080   // send/recv for STL containers of packable objects
00081   template <typename T> void send_cont_packed(T,int,bool,int=0);
00082   template <typename T> void receive_cont_packed(T&,int,bool,int=MPI_ANY_TAG);
00083 
00084   // sendrecv for single data
00085   template <typename T,typename P> void sendrecv(T,P&,int,int,int=0);
00086   
00087   // sendrecv for C-arrays with known dimension
00088   template <typename T,typename P> void sendrecv_array(T*,int,P*,int,int,int,int=0);
00089 
00090   // sendrecv for STL containers 
00091   template <typename T,typename P> void sendrecv_cont(T,P&,int,int,int=0);
00092   template <typename T> void sendrecv_cont_replace(T&,int,int,int=0);
00093 
00094   // sendrecv for STL containers of packable objects
00095   template <typename T,typename P> void sendrecv_cont_packed(T,P&,int,int,bool,int=0);
00096   template <typename T> void sendrecv_cont_packed_replace(T&,int,int,bool,int=0);
00097 
00098   // broadcast
00099   template <typename T> void broadcast(T);
00100   template <typename T> void broadcast_array(T*,int);
00101   template <typename T> void broadcast_cont(const T&);
00102   template <typename T> void broadcast_cont_packed(const T &);
00103 
00104   // receive_broadcast
00105   template <typename T> void recv_broadcast(T&,int);
00106   template <typename T> void recv_broadcast_array(T*,int,int);
00107   template <typename T> void recv_broadcast_cont(T&,int);
00108   template <typename T> void recv_broadcast_cont_packed(T&,int);
00109 
00110   // scatter/gather 
00111   template <typename T> void scatter(const multimap<int,T>);
00112   template <typename T> void recv_scatter(T&,int);
00113   template <typename T> void gather(multimap<int,T>&);
00114   template <typename T> void send_gather(T&,int);
00115 
00116   // debug versions
00117   template <typename T> void gather_debug(multimap<int,T>&);
00118   template <typename T> void send_gather_debug(T&,int);
00119 
00120   // scatter/gather packed
00121   template <typename T> void scatter_packed(const multimap<int,T>);
00122   template <typename T> void recv_scatter_packed(T&,int);
00123   template <typename T> void gather_packed(multimap<int,T>&);
00124   template <typename T> void send_gather_packed(const T &,int);
00125 
00126   // reduce ops
00127   template <typename T> T sum_all(const T&);
00128 
00129   // syncronisation
00130   void barrier();
00131   void barrier(const string&);
00132 };
00133 
00134 #include "tml/comm/comm.hpp"
00135 #include "tml/comm/comm_coll.hpp"
00136 
00137 #endif //__COMM_H