ESyS-Particle  4.0.1
comm.h
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef __COMM_H
14 #define __COMM_H
15 
16 //--- MPI ---
17 #include <mpi.h>
18 
19 //--- project includes ---
20 #include "Foundation/console.h"
21 
22 //--- TML includes ---
23 #include "tml/type/gettype.h"
24 
25 //--- STL includes ---
26 #include <vector>
27 #include <map>
28 #include <utility>
29 #include <string>
30 
31 #undef barrier
32 
33 using std::vector;
34 using std::multimap;
35 using std::pair;
36 using std::string;
37 
46 class TML_Comm
47 {
48 protected:
49  MPI_Status m_status;
50  MPI_Comm m_comm;
51 
52 public:
53  bool isNull() const {return m_comm==MPI_COMM_NULL;};
54  int rank() const;
55  int size();
56  MPI_Comm comm() const {return m_comm;};
57 
58  // assignment
59  TML_Comm& operator=(const TML_Comm&);
60  void setComm(MPI_Comm);
61 
62  // construction of new communicators
63  TML_Comm();
64  TML_Comm(MPI_Comm);
65  TML_Comm include(const vector<int>&);
66  TML_Comm exclude(const vector<int>&);
67 
68  // send/recv for single data
69  template <typename T> void send(T,int,int=0);
70  template <typename T> void receive(T&,int,int=MPI_ANY_TAG);
71 
72  // send/recv for C-arrays with known dimension
73  template <typename T> void send_array(T*,int,int,int=0);
74  template <typename T> void receive_array(T*,int,int,int=MPI_ANY_TAG);
75 
76  // send/recv for STL containers
77  template <typename T> void send_cont(const T&,int,int=0);
78  template <typename T> void receive_cont(T&,int,int=MPI_ANY_TAG);
79 
80  // send/recv for STL containers of packable objects
81  template <typename T> void send_cont_packed(T,int,bool,int=0);
82  template <typename T> void receive_cont_packed(T&,int,bool,int=MPI_ANY_TAG);
83 
84  // sendrecv for single data
85  template <typename T,typename P> void sendrecv(T,P&,int,int,int=0);
86 
87  // sendrecv for C-arrays with known dimension
88  template <typename T,typename P> void sendrecv_array(T*,int,P*,int,int,int,int=0);
89 
90  // sendrecv for STL containers
91  template <typename T,typename P> void sendrecv_cont(T,P&,int,int,int=0);
92  template <typename T> void sendrecv_cont_replace(T&,int,int,int=0);
93 
94  // sendrecv for STL containers of packable objects
95  template <typename T,typename P> void sendrecv_cont_packed(T,P&,int,int,bool,int=0);
96  template <typename T> void sendrecv_cont_packed_replace(T&,int,int,bool,int=0);
97 
98  // broadcast
99  template <typename T> void broadcast(T);
100  template <typename T> void broadcast_array(T*,int);
101  template <typename T> void broadcast_cont(const T&);
102  template <typename T> void broadcast_cont_packed(const T &);
103 
104  // receive_broadcast
105  template <typename T> void recv_broadcast(T&,int);
106  template <typename T> void recv_broadcast_array(T*,int,int);
107  template <typename T> void recv_broadcast_cont(T&,int);
108  template <typename T> void recv_broadcast_cont_packed(T&,int);
109 
110  // scatter/gather
111  template <typename T> void scatter(const multimap<int,T>);
112  template <typename T> void recv_scatter(T&,int);
113  template <typename T> void gather(multimap<int,T>&);
114  template <typename T> void send_gather(T&,int);
115 
116  // debug versions
117  template <typename T> void gather_debug(multimap<int,T>&);
118  template <typename T> void send_gather_debug(T&,int);
119 
120  // scatter/gather packed
121  template <typename T> void scatter_packed(const multimap<int,T>);
122  template <typename T> void recv_scatter_packed(T&,int);
123  template <typename T> void gather_packed(multimap<int,T>&);
124  template <typename T> void send_gather_packed(const T &,int);
125 
126  // reduce ops
127  template <typename T> T sum_all(const T&);
128 
129  // syncronisation
130  void barrier();
131  void barrier(const string&);
132 };
133 
134 #include "tml/comm/comm.hpp"
135 #include "tml/comm/comm_coll.hpp"
136 
137 #endif //__COMM_H