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