Chombo + EB + MF  3.2
SPMD.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 //
12 // These are the inevitable functions that people
13 // can't avoid using when writing a SPMD program.
14 // It is a minimal set from which more elaborate
15 // functionality can be generated. As always, a
16 // user is free to utilize the entire MPI programming
17 // on their own platform. The functions are
18 // assured to work on all machines supported.
19 //
20 
21 #ifndef _SPMD_H_
22 #define _SPMD_H_
23 
24 #include "REAL.H"
25 #include <string>
26 #include "Vector.H"
27 #include "MayDay.H"
28 #include "Misc.H"
29 
30 #ifdef CH_MPI
31 #include "mpi.h"
32 #endif
33 
34 #include "BaseNamespaceHeader.H"
35 
36 #ifdef CH_MPI
37 struct Chombo_MPI
38 {
39  static MPI_Comm comm;
40 };
41 
42 #else
43 // this can be changed for debugging parallel code in serial
44 extern int num_procs ;
45 #endif
46 
47 extern unsigned long long CH_MAX_MPI_MESSAGE_SIZE;
48 
49 extern unsigned long long CH_MaxMPISendSize;
50 extern unsigned long long CH_MaxMPIRecvSize;
51 
52 int reportMPIStats();
53 
54 /// local process ID
55 /**
56  Returns the ID of the locally running process in the range 0 <=
57  procID() < numProc(). This has no relation to the operating system
58  pid. There is always a procID() == 0. */
59 int procID();
60 
61 inline int CHprocID()
62 {
63  return procID();
64 }
65 
66 /// number of parallel processes
67 /**
68  Returns the number of parallel processes running.
69  Always returns at least 1. */
70 unsigned int numProc();
71 
72 ///all ranks wait here to sync-up
73 /**
74  All MPI ranks wait here to sync-up. Calls MPI_Barrier(comm) */
75 void barrier(void);
76 
77 template <class T>
78 int linearSize(const T& inputT);
79 
80 template <class T>
81 void linearIn(T& a_outputT, const void* const inBuf);
82 
83 template <class T>
84 void linearOut(void* const a_outBuf, const T& inputT);
85 
86 #ifdef CH_MPI
87 ///gather from multiple processes
88 /**
89  Gathers a_input of every process onto Vector<T> a_outVec on process
90  number a_dest. It is an error if a_dest < 0 or a_dest >= numProc().
91  a_outVec is numProc() long with the value of a_input on every
92  process in its elements.\\
93 
94 T must have have the following functions:
95  \\
96 
97  int linearSize<T>(const T& inputT); \\
98  void linearIn<T>(T& a_outputT, const void* const inBuf); \\
99  void linearOut<T>(void* a_outBuf, const T& inputT); \\
100 
101 */
102 template <class T>
103 void gather(Vector<T>& a_outVec, const T& a_input, int a_dest);
104 
105 #endif
106 
107 ///broadcast to every process
108 /**
109  Broadcasts a_inAndOut to every process from process number a_src.
110  It is an error if a_src < 0 or a_src >= numProc(). \\
111 
112  T must have have the following functions: \\
113 
114  int linearSize<T>(const T& inputT); \\
115  void linearIn<T>(T& a_outputT, const void* const inBuf); \\
116  void linearOut<T>(void* a_outBuf, const T& inputT); \\ */
117 template <class T>
118 void broadcast(T& a_inAndOut, int a_src);
119 
120 //u l l specialization of linearSize
121 template < >
122 int linearSize(const long long& a_input);
123 
124 //u l l specialization of linearIn
125 template < >
126 void linearIn(long long& a_outputT, const void* const inBuf);
127 
128 //unsigned long long specialization of linearOut
129 template < >
130 void linearOut(void* const a_outBuf, const long long& a_inputT);
131 
132 //integer specialization of linearSize
133 template < >
134 int linearSize(const int& a_input);
135 
136 //u l l specialization of linearSize
137 template < >
138 int linearSize(const unsigned long long& a_input);
139 
140 //integer specialization of linearIn
141 template < >
142 void linearIn(int& a_outputT, const void* const inBuf);
143 
144 //u l l specialization of linearIn
145 template < >
146 void linearIn(unsigned long long& a_outputT, const void* const inBuf);
147 
148 //integer specialization of linearOut
149 template < >
150 void linearOut(void* const a_outBuf, const int& a_inputT);
151 
152 //unsigned long long specialization of linearOut
153 template < >
154 void linearOut(void* const a_outBuf, const unsigned long long& a_inputT);
155 
156 //long integer specialization of linearSize
157 template < >
158 int linearSize(const long& a_input);
159 
160 //long integer specialization of linearIn
161 template < >
162 void linearIn(long& a_outputT, const void* const inBuf);
163 
164 //long integer specialization of linearOut
165 template < >
166 void linearOut(void* const a_outBuf, const long& a_inputT);
167 
168 //unsigned long integer specialization of linearSize
169 template < >
170 int linearSize(const unsigned long& a_input);
171 
172 //unsigned long integer specialization of linearIn
173 template < >
174 void linearIn(unsigned long& a_outputT, const void* const inBuf);
175 
176 //unsigned long integer specialization of linearOut
177 template < >
178 void linearOut(void* const a_outBuf, const unsigned long& a_inputT);
179 
180 //Real specialization of linearSize
181 template < >
182 int linearSize(const float& a_input);
183 
184 template < >
185 int linearSize(const double& a_input);
186 
187 //Real specialization of linearIn
188 template < >
189 void linearIn(float& a_outputT, const void* const a_inBuf);
190 
191 template < >
192 void linearIn(double& a_outputT, const void* const a_inBuf);
193 
194 //Real specialization of linearOut
195 template < >
196 void linearOut(void* const a_outBuf, const float& a_inputT);
197 
198 template < >
199 void linearOut(void* const a_outBuf, const double& a_inputT);
200 
201 // std::string specialization.
202 template <>
203 int linearSize(const std::string& a_input);
204 template <>
205 void linearIn(std::string& a_outputT, const void* const a_inBuf);
206 template <>
207 void linearOut(void* const a_outBuf, const std::string& a_inputT);
208 
209 //Vector<int> specialization
210 template < >
211 int linearSize(const Vector<int>& a_input);
212 template < >
213 void linearIn(Vector<int>& a_outputT, const void* const inBuf);
214 template < >
215 void linearOut(void* const a_outBuf, const Vector<int>& a_inputT);
216 
217 //Vector<unsigned long long> specialization
218 template < >
219 int linearSize(const Vector<unsigned long long>& a_input);
220 template < >
221 void linearIn(Vector<unsigned long long>& a_outputT, const void* const inBuf);
222 template < >
223 void linearOut(void* const a_outBuf, const Vector<unsigned long long>& a_inputT);
224 
225 //Vector<long> specialization
226 template < >
227 int linearSize(const Vector<long>& a_input);
228 template < >
229 void linearIn(Vector<long>& a_outputT, const void* const inBuf);
230 template < >
231 void linearOut(void* const a_outBuf, const Vector<long>& a_inputT);
232 
233 //Vector<Real> specialization
234 template < >
235 int linearSize(const Vector<float>& a_input);
236 template < >
237 void linearIn(Vector<float>& a_outputT, const void* const inBuf);
238 template < >
239 void linearOut(void* const a_outBuf, const Vector<float>& a_inputT);
240 
241 template < >
242 int linearSize(const Vector<double>& a_input);
243 template < >
244 void linearIn(Vector<double>& a_outputT, const void* const inBuf);
245 template < >
246 void linearOut(void* const a_outBuf, const Vector<double>& a_inputT);
247 
248 //Vector<std::string> specialization
249 template < >
250 int linearSize(const Vector<std::string>& a_input);
251 template < >
252 void linearIn(Vector<std::string>& a_outputT, const void* const inBuf);
253 template < >
254 void linearOut(void* const a_outBuf, const Vector<std::string>& a_inputT);
255 
256 //Vector<Vector<int> > specialization
257 template < >
258 int linearSize(const Vector<Vector<int> >& a_input);
259 template < >
260 void linearIn(Vector<Vector<int> >& a_outputT, const void* const inBuf);
261 template < >
262 void linearOut(void* const a_outBuf, const Vector<Vector<int> >& a_inputT);
263 
264 //Vector<T> specialization of linearSize
265 template <class T>
266 int linearListSize(const Vector<T>& a_input);
267 
268 //Vector<T> specialization of linearIn
269 template <class T>
270 void linearListIn(Vector<T>& a_outputT, const void* const a_inBuf);
271 
272 //Vector<T> specialization of linearOut
273 template <class T>
274 void linearListOut(void* const a_outBuf, const Vector<T>& a_inputT);
275 
277 {
278 public:
279  enum task
280  {
281  compute=0
282  };
283 };
284 
285 int GetPID(int rank);
286 int GetRank(int pid);
287 
288 // return id of unique processor for special serial tasks
289 int
290 uniqueProc(const SerialTask::task& a_task);
291 
292 #include "BaseNamespaceFooter.H"
293 
294 #include "SPMDI.H"
295 
296 #endif
one dimensional dynamic array
Definition: Vector.H:53
void linearListOut(void *const a_outBuf, const Vector< T > &a_inputT)
Definition: SPMDI.H:258
int GetPID(int rank)
void barrier(void)
all ranks wait here to sync-up
Definition: SPMDI.H:215
int num_procs
unsigned long long CH_MaxMPIRecvSize
unsigned long long CH_MaxMPISendSize
unsigned int numProc()
number of parallel processes
int uniqueProc(const SerialTask::task &a_task)
Definition: SPMD.H:276
int GetRank(int pid)
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:197
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:33
int linearSize(const T &inputT)
Definition: SPMDI.H:21
int reportMPIStats()
void linearListIn(Vector< T > &a_outputT, const void *const a_inBuf)
Definition: SPMDI.H:229
unsigned long long CH_MAX_MPI_MESSAGE_SIZE
int linearListSize(const Vector< T > &a_input)
Definition: SPMDI.H:290
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:207
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:27
int procID()
local process ID
task
Definition: SPMD.H:279
int CHprocID()
Definition: SPMD.H:61