Bridge++  Ver. 2.0.2
communicator.cpp
Go to the documentation of this file.
1 
14 #include "layout.h"
15 
16 //====================================================================
17 
27 int Communicator::init(int *pargc, char ***pargv)
28 {
29  return Communicator_impl::init(pargc, pargv);
30 }
31 
32 
33 //====================================================================
35 {
37 }
38 
39 
40 //====================================================================
42 {
43  return Communicator_impl::abort();
44 }
45 
46 
47 //====================================================================
48 int Communicator::setup(int Ninstance)
49 {
50  return Communicator_impl::setup(Ninstance);
51 }
52 
53 
54 //====================================================================
56  const std::vector<int>& lattice_size,
57  std::vector<int>& grid_size,
58  int Ninstance)
59 {
60  return Communicator_impl::setup(lattice_size, grid_size, Ninstance);
61 }
62 
63 
64 //====================================================================
66 {
68 }
69 
70 
71 //====================================================================
73 {
74  return Communicator_impl::is_primary_master();
75 }
76 
77 
78 //====================================================================
80 {
81  return Communicator_impl::self();
82 }
83 
84 
85 //====================================================================
87 {
88  return Communicator_impl::size();
89 }
90 
91 
92 //====================================================================
93 #ifdef ENABLE_MULTI_INSTANCE
94 int Communicator::self_global()
95 {
96  return Communicator_impl::self_global();
97 }
98 
99 
100 //====================================================================
101 int Communicator::world_id()
102 {
103  return Communicator_impl::world_id();
104 }
105 
106 
107 #endif
108 
109 //====================================================================
110 int Communicator::ipe(const int idir)
111 {
112  return Communicator_impl::Layout::ipe(idir);
113 }
114 
115 
116 //====================================================================
117 int Communicator::npe(const int idir)
118 {
119  return Communicator_impl::Layout::npe(idir);
120 }
121 
122 
123 //====================================================================
124 int Communicator::grid_rank(int *rank, const int *grid_coord)
125 {
127 }
128 
129 
130 //====================================================================
131 int Communicator::grid_coord(int *grid_coord, const int rank)
132 {
134 }
135 
136 
137 //====================================================================
138 int Communicator::grid_dims(int *grid_dims)
139 {
141 }
142 
143 
144 //====================================================================
145 int Communicator::sync()
146 {
147  return Communicator_impl::sync();
148 }
149 
150 
151 //====================================================================
153 {
155 }
156 
157 
158 //====================================================================
159 #ifdef ENABLE_MULTI_INSTANCE
160 int Communicator::sync_global()
161 {
162  return Communicator_impl::sync_global();
163 }
164 
165 
166 #endif
167 
168 //====================================================================
169 int Communicator::Base::broadcast(size_t size, void *data, int sender)
170 {
171  return Communicator_impl::Base::broadcast(size, data, sender);
172 }
173 
174 
175 int Communicator::broadcast(int count, dcomplex *data, int sender)
176 {
177  return Communicator_impl::Base::broadcast(sizeof(dcomplex) * count, (void *)data, sender);
178 }
179 
180 
181 int Communicator::broadcast(int count, double *data, int sender)
182 {
183  return Communicator_impl::Base::broadcast(sizeof(double) * count, (void *)data, sender);
184 }
185 
186 
187 int Communicator::broadcast(int count, float *data, int sender)
188 {
189  return Communicator_impl::Base::broadcast(sizeof(float) * count, (void *)data, sender);
190 }
191 
192 
193 int Communicator::broadcast(int count, int *data, int sender)
194 {
195  return Communicator_impl::Base::broadcast(sizeof(int) * count, (void *)data, sender);
196 }
197 
198 
199 int Communicator::broadcast(int count, string& data, int sender)
200 {
201  return Communicator_impl::broadcast_string(count, data, sender);
202 }
203 
204 
205 //====================================================================
206 int Communicator::Base::exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int itag)
207 {
208  return Communicator_impl::Base::exchange(size, recv_buf, send_buf, idir, ipm, itag);
209 }
210 
211 
212 int Communicator::exchange(int count, dcomplex *recv_buf, dcomplex *send_buf, int idir, int ipm, int itag)
213 {
214  return Communicator_impl::Base::exchange(sizeof(dcomplex) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
215 }
216 
217 
218 int Communicator::exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int itag)
219 {
220  return Communicator_impl::Base::exchange(sizeof(double) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
221 }
222 
223 
224 int Communicator::exchange(int count, float *recv_buf, float *send_buf, int idir, int ipm, int itag)
225 {
226  return Communicator_impl::Base::exchange(sizeof(float) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
227 }
228 
229 
230 int Communicator::exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int itag)
231 {
232  return Communicator_impl::Base::exchange(sizeof(int) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
233 }
234 
235 
236 //====================================================================
237 int Communicator::Base::send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
238 {
239  return Communicator_impl::Base::send_1to1(size, recv_buf, send_buf, send_to, recv_from, tag);
240 }
241 
242 
243 int Communicator::send_1to1(int count, dcomplex *recv_buf, dcomplex *send_buf, int send_to, int recv_from, int tag)
244 {
245  return Communicator_impl::Base::send_1to1(sizeof(dcomplex) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
246 }
247 
248 
249 int Communicator::send_1to1(int count, double *recv_buf, double *send_buf, int send_to, int recv_from, int tag)
250 {
251  return Communicator_impl::Base::send_1to1(sizeof(double) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
252 }
253 
254 
255 int Communicator::send_1to1(int count, float *recv_buf, float *send_buf, int send_to, int recv_from, int tag)
256 {
257  return Communicator_impl::Base::send_1to1(sizeof(float) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
258 }
259 
260 
261 int Communicator::send_1to1(int count, int *recv_buf, int *send_buf, int send_to, int recv_from, int tag)
262 {
263  return Communicator_impl::Base::send_1to1(sizeof(int) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
264 }
265 
266 
267 //====================================================================
268 int Communicator::reduce_sum(int count, dcomplex *recv_buf, dcomplex *send_buf, int pattern)
269 {
270  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE_COMPLEX, MPI_SUM, pattern);
271 }
272 
273 
274 int Communicator::reduce_sum(int count, double *recv_buf, double *send_buf, int pattern)
275 {
276  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_SUM, pattern);
277 }
278 
279 
280 int Communicator::reduce_sum(int count, float *recv_buf, float *send_buf, int pattern)
281 {
282  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_SUM, pattern);
283 }
284 
285 
286 int Communicator::reduce_sum(int count, int *recv_buf, int *send_buf, int pattern)
287 {
288  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_SUM, pattern);
289 }
290 
291 
292 //====================================================================
293 //- NB. no reduce_max for dcomplex
294 
295 int Communicator::reduce_max(int count, double *recv_buf, double *send_buf, int pattern)
296 {
297  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_MAX, pattern);
298 }
299 
300 
301 int Communicator::reduce_max(int count, float *recv_buf, float *send_buf, int pattern)
302 {
303  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_MAX, pattern);
304 }
305 
306 
307 int Communicator::reduce_max(int count, int *recv_buf, int *send_buf, int pattern)
308 {
309  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_MAX, pattern);
310 }
311 
312 
313 //====================================================================
314 //- NB. no reduce_min for dcomplex
315 
316 int Communicator::reduce_min(int count, double *recv_buf, double *send_buf, int pattern)
317 {
318  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_MIN, pattern);
319 }
320 
321 
322 int Communicator::reduce_min(int count, float *recv_buf, float *send_buf, int pattern)
323 {
324  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_MIN, pattern);
325 }
326 
327 
328 int Communicator::reduce_min(int count, int *recv_buf, int *send_buf, int pattern)
329 {
330  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_MIN, pattern);
331 }
332 
333 
334 //====================================================================
335 dcomplex Communicator::reduce_sum(dcomplex a)
336 {
337  dcomplex ar = dcomplex();
338 
339  reduce_sum(1, &ar, &a, 0);
340  return ar;
341 }
342 
343 
344 //- NB. no reduce_{max,min} for dcomplex
345 // dcomplex Communicator::reduce_max(dcomplex v);
346 // dcomplex Communicator::reduce_min(dcomplex v);
347 
348 
349 //====================================================================
350 double Communicator::reduce_sum(double a)
351 {
352  double ar = double();
353 
354  reduce_sum(1, &ar, &a, 0);
355  return ar;
356 }
357 
358 
359 double Communicator::reduce_max(double a)
360 {
361  double ar = double();
362 
363  reduce_max(1, &ar, &a, 0);
364  return ar;
365 }
366 
367 
368 double Communicator::reduce_min(double a)
369 {
370  double ar = double();
371 
372  reduce_min(1, &ar, &a, 0);
373  return ar;
374 }
375 
376 
377 //====================================================================
378 float Communicator::reduce_sum(float a)
379 {
380  float ar = float();
381 
382  reduce_sum(1, &ar, &a, 0);
383  return ar;
384 }
385 
386 
387 float Communicator::reduce_max(float a)
388 {
389  float ar = float();
390 
391  reduce_max(1, &ar, &a, 0);
392  return ar;
393 }
394 
395 
396 float Communicator::reduce_min(float a)
397 {
398  float ar = float();
399 
400  reduce_min(1, &ar, &a, 0);
401  return ar;
402 }
403 
404 
405 //====================================================================
406 double Communicator::get_time()
407 {
409 }
410 
411 
412 //====================================================================
414 {
415  return Communicator_impl::status();
416 }
417 
418 
419 //====================================================================
420 //============================================================END=====
Communicator::sync
static int sync()
synchronize within small world.
Definition: communicator.cpp:140
Communicator_impl::Base::reduce
static int reduce(int count, void *recv_buf, void *send_buf, MPI_Datatype type, MPI_Op op, int pattern)
Definition: communicator_mpi.cpp:323
Communicator::get_time
static double get_time()
obtain a wall-clock time.
Definition: communicator.cpp:401
layout.h
Communicator::reduce_max
static int reduce_max(int count, double *recv_buf, double *send_buf, int pattern=0)
find a global maximum of an array of double over the communicator. pattern specifies the dimensions t...
Definition: communicator.cpp:290
Communicator::Base::broadcast
static int broadcast(size_t size, void *data, int sender)
Definition: communicator.cpp:164
Communicator::broadcast
static int broadcast(int count, dcomplex *data, int sender)
broadcast array of dcomplex from sender.
Definition: communicator.cpp:170
Communicator::self
static int self()
rank within small world.
Definition: communicator.cpp:74
Communicator_impl::setup
static int setup(int Ninstance=1)
Definition: communicator_mpi.cpp:86
Communicator::size
static int size()
size of small world.
Definition: communicator.cpp:81
Communicator_impl::sync
static int sync()
Definition: communicator_mpi.cpp:216
Communicator::grid_dims
static int grid_dims(int *grid_dims)
find grid dimensions.
Definition: communicator.cpp:133
Communicator_impl::Base::send_1to1
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
Definition: communicator_mpi.cpp:300
Communicator::Base::exchange
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
Definition: communicator.cpp:201
Communicator_impl::Layout::grid_coord
static int grid_coord(int *gcoord, const int rank)
find grid coordinate corresponding to rank.
Definition: physical_map.cpp:41
Communicator::is_primary_master
static bool is_primary_master()
check if the present node is primary in global communicator.
Definition: communicator.cpp:67
Communicator_impl::Layout::ipe
static int ipe(const int idir)
grid coordinate along idir direction.
Definition: layout.cpp:43
Communicator_impl::status
static int status()
Definition: communicator_mpi.cpp:376
Communicator::status
static int status()
Definition: communicator.cpp:408
Communicator_impl::abort
static void abort()
Definition: communicator_mpi.cpp:159
Communicator::sync_usleep
static int sync_usleep()
synchronize within small world. (slow but no busy wait)
Definition: communicator.cpp:147
Communicator_impl::self
static int self()
Definition: communicator_mpi.cpp:176
Communicator::setup
static int setup(int ninstance=1)
setup communicator
Definition: communicator.cpp:43
Communicator_impl::Base::broadcast
static int broadcast(size_t size, void *data, int sender)
Definition: communicator_mpi.cpp:259
Communicator_impl::init
static int init(int *pargc, char ***pargv)
Definition: communicator_mpi.cpp:38
Communicator::reduce_sum
static int reduce_sum(int count, dcomplex *recv_buf, dcomplex *send_buf, int pattern=0)
make a global sum of an array of dcomplex over the communicator. pattern specifies the dimensions to ...
Definition: communicator.cpp:263
Communicator::npe
static int npe(const int dir)
logical grid extent
Definition: communicator.cpp:112
Communicator::abort
static void abort()
terminate communicator
Definition: communicator.cpp:36
Communicator::reduce_min
static int reduce_min(int count, double *recv_buf, double *send_buf, int pattern=0)
find a global minimum of an array of double over the communicator. pattern specifies the dimensions t...
Definition: communicator.cpp:311
Communicator_impl::Layout::npe
static int npe(const int idir)
grid size in idir direction.
Definition: layout.cpp:50
Communicator_impl::get_time
static double get_time()
Definition: communicator_mpi.cpp:368
Communicator::Base::send_1to1
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
Definition: communicator.cpp:232
Communicator_impl::Layout::grid_rank
static int grid_rank(int *rank, const int *gcoord)
find rank from grid coordinate.
Definition: physical_map.cpp:24
Communicator::send_1to1
static int send_1to1(int count, dcomplex *recv_buf, dcomplex *send_buf, int p_to, int p_from, int tag)
send array of dcomplex from rank p_from to rank p_to. communication distinguished by tag.
Definition: communicator.cpp:238
Communicator_impl::Base::exchange
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
Definition: communicator_mpi.cpp:267
Communicator::is_primary
static bool is_primary()
check if the present node is primary in small communicator.
Definition: communicator.cpp:60
Communicator_impl::Layout::grid_dims
static int grid_dims(int *gdims)
find grid size.
Definition: layout.cpp:57
Communicator_impl::finalize
static int finalize()
Definition: communicator_mpi.cpp:78
Communicator::finalize
static int finalize()
finalize communicator
Definition: communicator.cpp:29
Communicator_impl::is_primary
static bool is_primary()
Definition: communicator_mpi.cpp:169
Communicator_impl::sync_usleep
static int sync_usleep()
Definition: communicator_mpi.cpp:225
Communicator::ipe
static int ipe(const int dir)
logical coordinate of current proc.
Definition: communicator.cpp:105
Communicator::grid_coord
static int grid_coord(int *grid_coord, const int rank)
find grid coordinate from rank number.
Definition: communicator.cpp:126
Communicator::init
static int init(int *pargc, char ***pargv)
initialize communicator
Definition: communicator.cpp:22
Communicator::exchange
static int exchange(int count, dcomplex *recv_buf, dcomplex *send_buf, int idir, int ipm, int tag)
receive array of dcomplex from upstream specified by idir and ipm, and send array to downstream.
Definition: communicator.cpp:207
Communicator_impl::size
static int size()
Definition: communicator_mpi.cpp:183
Communicator::grid_rank
static int grid_rank(int *rank, const int *grid_coord)
find rank number from grid coordinate.
Definition: communicator.cpp:119
Communicator_impl::broadcast_string
static int broadcast_string(int count, string &data, int sender)
Definition: communicator_mpi.cpp:332