Chombo + EB  3.0
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 long long CH_MAX_MPI_MESSAGE_SIZE;
48 
49 extern long long CH_MaxMPISendSize;
50 extern long long CH_MaxMPIRecvSize;
51 
52 
53 int reportMPIStats();
54 
55 /// local process ID
56 /**
57  Returns the ID of the locally running process in the range 0 <=
58  procID() < numProc(). This has no relation to the operating system
59  pid. There is always a procID() == 0. */
60 int procID();
61 
62 inline int CHprocID()
63 {
64  return procID();
65 }
66 
67 /// number of parallel processes
68 /**
69  Returns the number of parallel processes running.
70  Always returns at least 1. */
71 unsigned int numProc();
72 
73 ///all ranks wait here to sync-up
74 /**
75  All MPI ranks wait here to sync-up. Calls MPI_Barrier(comm) */
76 void barrier(void);
77 
78 template <class T>
79 int linearSize(const T& inputT);
80 
81 template <class T>
82 void linearIn(T& a_outputT, const void* const inBuf);
83 
84 template <class T>
85 void linearOut(void* const a_outBuf, const T& inputT);
86 
87 #ifdef CH_MPI
88 ///gather from multiple processes
89 /**
90  Gathers a_input of every process onto Vector<T> a_outVec on process
91  number a_dest. It is an error if a_dest < 0 or a_dest >= numProc().
92  a_outVec is numProc() long with the value of a_input on every
93  process in its elements.\\
94 
95 T must have have the following functions:
96  \\
97 
98  int linearSize<T>(const T& inputT); \\
99  void linearIn<T>(T& a_outputT, const void* const inBuf); \\
100  void linearOut<T>(void* a_outBuf, const T& inputT); \\
101 
102 */
103 template <class T>
104 void gather(Vector<T>& a_outVec, const T& a_input, int a_dest);
105 
106 // this has to be here so that linearSize<IntVectSet>, linearIn<IntVectSet>,
107 // and linearOut<IntVectSet> are defined.
108 // template < >
109 // void gather(Vector<IntVectSet>& a_outVec,
110 // const IntVectSet& a_input,
111 // int a_dest);
112 #endif
113 
114 ///broadcast to every process
115 /**
116  Broadcasts a_inAndOut to every process from process number a_src.
117  It is an error if a_src < 0 or a_src >= numProc(). \\
118 
119  T must have have the following functions: \\
120 
121  int linearSize<T>(const T& inputT); \\
122  void linearIn<T>(T& a_outputT, const void* const inBuf); \\
123  void linearOut<T>(void* a_outBuf, const T& inputT); \\ */
124 template <class T>
125 void broadcast(T& a_inAndOut, int a_src);
126 
127 //integer specialization of linearSize
128 template < >
129 int linearSize(const int& a_input);
130 
131 
132 //u l l specialization of linearSize
133 template < >
134 int linearSize(const unsigned long long& a_input);
135 
136 //integer specialization of linearIn
137 template < >
138 void linearIn(int& a_outputT, const void* const inBuf);
139 
140 
141 //u l l specialization of linearIn
142 template < >
143 void linearIn(unsigned long long& a_outputT, const void* const inBuf);
144 
145 //integer specialization of linearOut
146 template < >
147 void linearOut(void* const a_outBuf, const int& a_inputT);
148 
149 
150 //unsigned long long specialization of linearOut
151 template < >
152 void linearOut(void* const a_outBuf, const unsigned long long& a_inputT);
153 
154 //long integer specialization of linearSize
155 template < >
156 int linearSize(const long& a_input);
157 
158 //long integer specialization of linearIn
159 template < >
160 void linearIn(long& a_outputT, const void* const inBuf);
161 
162 //long integer specialization of linearOut
163 template < >
164 void linearOut(void* const a_outBuf, const long& a_inputT);
165 
166 //unsigned long integer specialization of linearSize
167 template < >
168 int linearSize(const unsigned long& a_input);
169 
170 //unsigned long integer specialization of linearIn
171 template < >
172 void linearIn(unsigned long& a_outputT, const void* const inBuf);
173 
174 //unsigned long integer specialization of linearOut
175 template < >
176 void linearOut(void* const a_outBuf, const unsigned long& a_inputT);
177 
178 //Real specialization of linearSize
179 template < >
180 int linearSize(const float& a_input);
181 
182 template < >
183 int linearSize(const double& a_input);
184 
185 //Real specialization of linearIn
186 template < >
187 void linearIn(float& a_outputT, const void* const a_inBuf);
188 
189 template < >
190 void linearIn(double& a_outputT, const void* const a_inBuf);
191 
192 //Real specialization of linearOut
193 template < >
194 void linearOut(void* const a_outBuf, const float& a_inputT);
195 
196 template < >
197 void linearOut(void* const a_outBuf, const double& a_inputT);
198 
199 // std::string specialization.
200 template <>
201 int linearSize(const std::string& a_input);
202 template <>
203 void linearIn(std::string& a_outputT, const void* const a_inBuf);
204 template <>
205 void linearOut(void* const a_outBuf, const std::string& a_inputT);
206 
207 //Vector<int> specialization
208 template < >
209 int linearSize(const Vector<int>& a_input);
210 template < >
211 void linearIn(Vector<int>& a_outputT, const void* const inBuf);
212 template < >
213 void linearOut(void* const a_outBuf, const Vector<int>& a_inputT);
214 
215 //Vector<unsigned long long> specialization
216 template < >
217 int linearSize(const Vector<unsigned long long>& a_input);
218 template < >
219 void linearIn(Vector<unsigned long long>& a_outputT, const void* const inBuf);
220 template < >
221 void linearOut(void* const a_outBuf, const Vector<unsigned long long>& a_inputT);
222 
223 //Vector<long> specialization
224 template < >
225 int linearSize(const Vector<long>& a_input);
226 template < >
227 void linearIn(Vector<long>& a_outputT, const void* const inBuf);
228 template < >
229 void linearOut(void* const a_outBuf, const Vector<long>& a_inputT);
230 
231 //Vector<Real> specialization
232 template < >
233 int linearSize(const Vector<float>& a_input);
234 template < >
235 void linearIn(Vector<float>& a_outputT, const void* const inBuf);
236 template < >
237 void linearOut(void* const a_outBuf, const Vector<float>& a_inputT);
238 
239 template < >
240 int linearSize(const Vector<double>& a_input);
241 template < >
242 void linearIn(Vector<double>& a_outputT, const void* const inBuf);
243 template < >
244 void linearOut(void* const a_outBuf, const Vector<double>& a_inputT);
245 
246 //Vector<std::string> specialization
247 template < >
248 int linearSize(const Vector<std::string>& a_input);
249 template < >
250 void linearIn(Vector<std::string>& a_outputT, const void* const inBuf);
251 template < >
252 void linearOut(void* const a_outBuf, const Vector<std::string>& a_inputT);
253 
254 //Vector<Vector<int> > specialization
255 template < >
256 int linearSize(const Vector<Vector<int> >& a_input);
257 template < >
258 void linearIn(Vector<Vector<int> >& a_outputT, const void* const inBuf);
259 template < >
260 void linearOut(void* const a_outBuf, const Vector<Vector<int> >& a_inputT);
261 
262 //Vector<T> specialization of linearSize
263 template <class T>
264 int linearListSize(const Vector<T>& a_input);
265 
266 //Vector<T> specialization of linearIn
267 template <class T>
268 void linearListIn(Vector<T>& a_outputT, const void* const a_inBuf);
269 
270 //Vector<T> specialization of linearOut
271 template <class T>
272 void linearListOut(void* const a_outBuf, const Vector<T>& a_inputT);
273 
275 {
276 public:
277  enum task
278  {
279  compute=0
280  };
281 };
282 
283 int GetPID(int rank);
284 int GetRank(int pid);
285 
286 // return id of unique processor for special serial tasks
287 int
288 uniqueProc(const SerialTask::task& a_task);
289 
290 #include "BaseNamespaceFooter.H"
291 
292 #include "SPMDI.H"
293 
294 #endif
one dimensional dynamic array
Definition: Vector.H:52
long long CH_MaxMPISendSize
void linearListOut(void *const a_outBuf, const Vector< T > &a_inputT)
Definition: SPMDI.H:255
int GetPID(int rank)
void barrier(void)
all ranks wait here to sync-up
Definition: SPMDI.H:212
long long CH_MaxMPIRecvSize
int num_procs
unsigned int numProc()
number of parallel processes
int uniqueProc(const SerialTask::task &a_task)
Definition: SPMD.H:274
int GetRank(int pid)
void gather(Vector< T > &a_outVec, const T &a_input, int a_dest)
Definition: SPMDI.H:194
long long CH_MAX_MPI_MESSAGE_SIZE
void linearOut(void *const a_outBuf, const T &inputT)
Definition: SPMDI.H:32
int linearSize(const T &inputT)
Definition: SPMDI.H:20
int reportMPIStats()
void linearListIn(Vector< T > &a_outputT, const void *const a_inBuf)
Definition: SPMDI.H:226
int linearListSize(const Vector< T > &a_input)
Definition: SPMDI.H:287
void broadcast(T &a_inAndOut, int a_src)
broadcast to every process
Definition: SPMDI.H:204
void linearIn(T &a_outputT, const void *const inBuf)
Definition: SPMDI.H:26
int procID()
local process ID
task
Definition: SPMD.H:277
int CHprocID()
Definition: SPMD.H:62