SU2
mpi_structure.hpp
Go to the documentation of this file.
1 
35 #pragma once
36 
37 #ifdef HAVE_MPI
38 #include "mpi.h"
39 #include <map>
40 #endif
41 
42 #include "./datatype_structure.hpp"
43 
44 #ifdef HAVE_MPI
45 
46 typedef MPI_Comm SU2_Comm;
47 
48 /*--- Depending on the datatype used, the correct MPI wrapper class is defined.
49  * For the default (double type) case this results in using the normal MPI routines. ---*/
50 
51 #if defined COMPLEX_TYPE || \
52  defined ADOLC_FORWARD_TYPE || \
53  defined CODI_FORWARD_TYPE
54 class CAuxMPIWrapper;
55 typedef CAuxMPIWrapper SU2_MPI;
56 #elif defined CODI_REVERSE_TYPE
57 class CAdjointMPIWrapper;
58 typedef CAdjointMPIWrapper SU2_MPI;
59 #else
60 class CMPIWrapper;
61 typedef CMPIWrapper SU2_MPI;
62 #endif
63 
72 class CMPIWrapper {
73 public:
74  static void Init(int *argc, char***argv);
75 
76  static void Isend(void *buf, int count, MPI_Datatype datatype, int dest,
77  int tag, MPI_Comm comm, MPI_Request* request);
78 
79  static void Irecv(void *buf, int count, MPI_Datatype datatype, int source,
80  int tag, MPI_Comm comm, MPI_Request* request);
81 
82  static void Wait(MPI_Request *request, MPI_Status *status);
83 
84  static void Waitall(int nrequests, MPI_Request *request, MPI_Status *status);
85 
86  static void Waitany(int nrequests, MPI_Request *request,
87  int *index, MPI_Status *status);
88 
89  static void Send(void *buf, int count, MPI_Datatype datatype, int dest,
90  int tag, MPI_Comm comm);
91 
92  static void Recv(void *buf, int count, MPI_Datatype datatype, int dest,
93  int tag, MPI_Comm comm, MPI_Status *status);
94 
95  static void Bcast(void *buf, int count, MPI_Datatype datatype, int root,
96  MPI_Comm comm);
97 
98  static void Bsend(void *buf, int count, MPI_Datatype datatype, int dest,
99  int tag, MPI_Comm comm);
100 
101  static void Reduce(void *sendbuf, void *recvbuf, int count,
102  MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
103 
104  static void Allreduce(void *sendbuf, void *recvbuf, int count,
105  MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
106 
107  static void Gather(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
108  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
109 
110  static void Scatter(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
111  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
112 
113  static void Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
114  void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm);
115 
116  static void Sendrecv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
117  int dest, int sendtag, void *recvbuf, int recvcnt,
118  MPI_Datatype recvtype,int source, int recvtag,
119  MPI_Comm comm, MPI_Status *status);
120 
121 protected:
122  static char* buff;
123 
124 };
132 #if defined COMPLEX_TYPE || \
133  defined ADOLC_FORWARD_TYPE || \
134  defined CODI_FORWARD_TYPE
135 
136 class CAuxMPIWrapper : public CMPIWrapper{
137 public:
138  static void Isend(void *buf, int count, MPI_Datatype datatype, int dest,
139  int tag, MPI_Comm comm, MPI_Request* request);
140 
141  static void Irecv(void *buf, int count, MPI_Datatype datatype, int source,
142  int tag, MPI_Comm comm, MPI_Request* request);
143 
144  static void Wait(MPI_Request *request, MPI_Status *status);
145 
146  static void Waitall(int nrequests, MPI_Request *request, MPI_Status *status);
147 
148  static void Waitany(int nrequests, MPI_Request *request,
149  int *index, MPI_Status *status);
150 
151  static void Send(void *buf, int count, MPI_Datatype datatype, int dest,
152  int tag, MPI_Comm comm);
153 
154  static void Recv(void *buf, int count, MPI_Datatype datatype, int dest,
155  int tag, MPI_Comm comm, MPI_Status *status);
156 
157  static void Bcast(void *buf, int count, MPI_Datatype datatype, int root,
158  MPI_Comm comm);
159 
160  static void Bsend(void *buf, int count, MPI_Datatype datatype, int dest,
161  int tag, MPI_Comm comm);
162 
163  static void Reduce(void *sendbuf, void *recvbuf, int count,
164  MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
165 
166  static void Allreduce(void *sendbuf, void *recvbuf, int count,
167  MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
168 
169  static void Gather(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
170  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
171 
172  static void Scatter(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
173  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
174 
175  static void Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
176  void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm);
177 
178  static void Sendrecv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
179  int dest, int sendtag, void *recvbuf, int recvcnt,
180  MPI_Datatype recvtype,int source, int recvtag,
181  MPI_Comm comm, MPI_Status *status);
182 
183 private:
184 
185  enum CommType {
186  ISEND,
187  IRECV
188  };
189 
190  struct CommInfo{
191  CommType Type;
192  MPI_Request* RequestAux;
193  double* ValueBuffer;
194  double* AuxBuffer;
195  su2double* su2doubleBuffer;
196  int count;
197  };
198 
199  struct ValRank{
200  double value;
201  int rank;
202  };
203 
204  static std::map<MPI_Request*, CommInfo>::iterator CommInfoIterator;
205 
206  static std::map<MPI_Request*, CommInfo> CommInfoMap;
207 
208  static void FinalizeCommunication(std::map<MPI_Request*, CommInfo>::iterator &CommInfo);
209 
210 };
211 #endif
212 #ifdef CODI_REVERSE_TYPE
213 #include "ampi_tape.hpp"
214 
222 class CAdjointMPIWrapper: public CMPIWrapper {
223 public:
224  static void Init(int *argc, char***argv);
225 
226  static void Isend(void *buf, int count, MPI_Datatype datatype, int dest,
227  int tag, MPI_Comm comm, MPI_Request* request);
228 
229  static void Irecv(void *buf, int count, MPI_Datatype datatype, int source,
230  int tag, MPI_Comm comm, MPI_Request* request);
231 
232  static void Wait(MPI_Request *request, MPI_Status *status);
233 
234  static void Waitall(int nrequests, MPI_Request *request, MPI_Status *status);
235 
236  static void Waitany(int nrequests, MPI_Request *request,
237  int *index, MPI_Status *status);
238 
239  static void Send(void *buf, int count, MPI_Datatype datatype, int dest,
240  int tag, MPI_Comm comm);
241 
242  static void Recv(void *buf, int count, MPI_Datatype datatype, int dest,
243  int tag, MPI_Comm comm, MPI_Status *status);
244 
245  static void Bcast(void *buf, int count, MPI_Datatype datatype, int root,
246  MPI_Comm comm);
247 
248  static void Bsend(void *buf, int count, MPI_Datatype datatype, int dest,
249  int tag, MPI_Comm comm);
250 
251  static void Reduce(void *sendbuf, void *recvbuf, int count,
252  MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
253 
254  static void Allreduce(void *sendbuf, void *recvbuf, int count,
255  MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
256 
257  static void Gather(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
258  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
259 
260  static void Scatter(void *sendbuf, int sendcnt,MPI_Datatype sendtype,
261  void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm);
262 
263  static void Allgather(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
264  void *recvbuf, int recvcnt, MPI_Datatype recvtype, MPI_Comm comm);
265 
266  static void Sendrecv(void *sendbuf, int sendcnt, MPI_Datatype sendtype,
267  int dest, int sendtag, void *recvbuf, int recvcnt,
268  MPI_Datatype recvtype,int source, int recvtag,
269  MPI_Comm comm, MPI_Status *status);
270 
271 protected:
272  static char* buff;
273 
274 };
275 #endif
276 
277 #else //HAVE_MPI
278 typedef unsigned short SU2_Comm;
279 #endif
280 #include "mpi_structure.inl"
Headers for generalized datatypes. The subroutines and functions are in the datatype_structure.cpp file.