Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
121  return Communicator_impl::Layout::grid_rank(rank, grid_coord);
122 }
123 
124 
125 //====================================================================
126 int Communicator::grid_coord(int *grid_coord, const int rank)
127 {
128  return Communicator_impl::Layout::grid_coord(grid_coord, rank);
129 }
130 
131 
132 //====================================================================
133 int Communicator::grid_dims(int *grid_dims)
134 {
135  return Communicator_impl::Layout::grid_dims(grid_dims);
136 }
137 
138 
139 //====================================================================
141 {
142  return Communicator_impl::sync();
143 }
144 
145 
146 //====================================================================
148 {
150 }
151 
152 //====================================================================
153 #ifdef ENABLE_MULTI_INSTANCE
154 int Communicator::sync_global()
155 {
156  return Communicator_impl::sync_global();
157 }
158 
159 
160 #endif
161 
162 //====================================================================
163 int Communicator::Base::broadcast(size_t size, void *data, int sender)
164 {
165  return Communicator_impl::Base::broadcast(size, data, sender);
166 }
167 
168 
169 int Communicator::broadcast(int count, double *data, int sender)
170 {
171  return Communicator_impl::Base::broadcast(sizeof(double) * count, (void *)data, sender);
172 }
173 
174 
175 int Communicator::broadcast(int count, float *data, int sender)
176 {
177  return Communicator_impl::Base::broadcast(sizeof(float) * count, (void *)data, sender);
178 }
179 
180 
181 int Communicator::broadcast(int count, int *data, int sender)
182 {
183  return Communicator_impl::Base::broadcast(sizeof(int) * count, (void *)data, sender);
184 }
185 
186 
187 int Communicator::broadcast(int count, string& data, int sender)
188 {
189  return Communicator_impl::broadcast_string(count, data, sender);
190 }
191 
192 
193 //====================================================================
194 int Communicator::Base::exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int itag)
195 {
196  return Communicator_impl::Base::exchange(size, recv_buf, send_buf, idir, ipm, itag);
197 }
198 
199 
200 int Communicator::exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int itag)
201 {
202  return Communicator_impl::Base::exchange(sizeof(double) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
203 }
204 
205 
206 int Communicator::exchange(int count, float *recv_buf, float *send_buf, int idir, int ipm, int itag)
207 {
208  return Communicator_impl::Base::exchange(sizeof(float) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
209 }
210 
211 
212 int Communicator::exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int itag)
213 {
214  return Communicator_impl::Base::exchange(sizeof(int) * count, (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
215 }
216 
217 
218 //====================================================================
219 int Communicator::Base::send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
220 {
221  return Communicator_impl::Base::send_1to1(size, recv_buf, send_buf, send_to, recv_from, tag);
222 }
223 
224 
225 int Communicator::send_1to1(int count, double *recv_buf, double *send_buf, int send_to, int recv_from, int tag)
226 {
227  return Communicator_impl::Base::send_1to1(sizeof(double) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
228 }
229 
230 
231 int Communicator::send_1to1(int count, float *recv_buf, float *send_buf, int send_to, int recv_from, int tag)
232 {
233  return Communicator_impl::Base::send_1to1(sizeof(float) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
234 }
235 
236 
237 int Communicator::send_1to1(int count, int *recv_buf, int *send_buf, int send_to, int recv_from, int tag)
238 {
239  return Communicator_impl::Base::send_1to1(sizeof(int) * count, (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
240 }
241 
242 
243 //====================================================================
244 int Communicator::reduce_sum(int count, double *recv_buf, double *send_buf, int pattern)
245 {
246  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_SUM, pattern);
247 }
248 
249 
250 int Communicator::reduce_sum(int count, float *recv_buf, float *send_buf, int pattern)
251 {
252  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_SUM, pattern);
253 }
254 
255 
256 int Communicator::reduce_sum(int count, int *recv_buf, int *send_buf, int pattern)
257 {
258  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_SUM, pattern);
259 }
260 
261 
262 //====================================================================
263 int Communicator::reduce_max(int count, double *recv_buf, double *send_buf, int pattern)
264 {
265  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_MAX, pattern);
266 }
267 
268 
269 int Communicator::reduce_max(int count, float *recv_buf, float *send_buf, int pattern)
270 {
271  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_MAX, pattern);
272 }
273 
274 
275 int Communicator::reduce_max(int count, int *recv_buf, int *send_buf, int pattern)
276 {
277  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_MAX, pattern);
278 }
279 
280 
281 //====================================================================
282 int Communicator::reduce_min(int count, double *recv_buf, double *send_buf, int pattern)
283 {
284  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_DOUBLE, MPI_MIN, pattern);
285 }
286 
287 
288 int Communicator::reduce_min(int count, float *recv_buf, float *send_buf, int pattern)
289 {
290  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_FLOAT, MPI_MIN, pattern);
291 }
292 
293 
294 int Communicator::reduce_min(int count, int *recv_buf, int *send_buf, int pattern)
295 {
296  return Communicator_impl::Base::reduce(count, (void *)recv_buf, (void *)send_buf, MPI_INT, MPI_MIN, pattern);
297 }
298 
299 
300 //====================================================================
301 double Communicator::reduce_sum(double a)
302 {
303  double ar = double();
304 
305  reduce_sum(1, &ar, &a, 0);
306  return ar;
307 }
308 
309 
310 //====================================================================
311 double Communicator::reduce_max(double a)
312 {
313  double ar = double();
314 
315  reduce_max(1, &ar, &a, 0);
316  return ar;
317 }
318 
319 
320 //====================================================================
321 double Communicator::reduce_min(double a)
322 {
323  double ar = double();
324 
325  reduce_min(1, &ar, &a, 0);
326  return ar;
327 }
328 
329 
330 //====================================================================
332 {
333  float ar = float();
334 
335  reduce_sum(1, &ar, &a, 0);
336  return ar;
337 }
338 
339 
340 //====================================================================
342 {
343  float ar = float();
344 
345  reduce_max(1, &ar, &a, 0);
346  return ar;
347 }
348 
349 
350 //====================================================================
352 {
353  float ar = float();
354 
355  reduce_min(1, &ar, &a, 0);
356  return ar;
357 }
358 
359 
360 //====================================================================
362 {
364 }
365 
366 
367 //====================================================================
369 {
370  return Communicator_impl::status();
371 }
372 
373 
374 //====================================================================
375 Channel *Communicator::send_init(int count, int idir, int ipm)
376 {
377  return Communicator_impl::send_init(count, idir, ipm);
378 }
379 
380 
381 //====================================================================
382 Channel *Communicator::recv_init(int count, int idir, int ipm)
383 {
384  return Communicator_impl::recv_init(count, idir, ipm);
385 }
386 
387 
388 //====================================================================
389 //============================================================END=====
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static int broadcast(size_t size, void *data, int sender)
static int npe(const int dir)
logical grid extent
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...
static void abort()
terminate communicator
static int self()
rank within small world.
static bool is_primary_master()
check if the present node is primary in global communicator.
static int init(int *pargc, char ***pargv)
initialize communicator
static int grid_coord(int *gcoord, const int rank)
find grid coordinate corresponding to rank.
static int grid_coord(int *grid_coord, const int rank)
find grid coordinate from rank number.
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...
static int setup(int ninstance=1)
static Channel * recv_init(int count, int idir, int ipm)
static int broadcast(size_t size, void *data, int sender)
static int ipe(const int dir)
logical coordinate of current proc.
static int grid_rank(int *rank, const int *gcoord)
find rank from grid coordinate.
static bool is_primary()
static int npe(const int idir)
grid size in idir direction.
Definition: layout.cpp:50
Channel class for asynchronous communication.
Definition: channel.h:48
static int finalize()
finalize communicator
static int init(int *pargc, char ***pargv)
static int send_1to1(int count, double *recv_buf, double *send_buf, int p_to, int p_from, int tag)
send array of double from rank p_from to rank p_to. communication distinguished by tag...
static int grid_dims(int *gdims)
find grid size.
Definition: layout.cpp:57
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
static int grid_dims(int *grid_dims)
find grid dimensions.
static int broadcast_string(int count, string &data, int sender)
static double get_time()
static int exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag)
receive array of double from upstream specified by idir and ipm, and send array to downstream...
static int sync_usleep()
static int status()
static int grid_rank(int *rank, const int *grid_coord)
find rank number from grid coordinate.
static int setup(int ninstance=1)
setup communicator
static int reduce(int count, void *recv_buf, void *send_buf, MPI_Datatype type, MPI_Op op, int pattern)
static int ipe(const int idir)
grid coordinate along idir direction.
Definition: layout.cpp:43
static int sync_usleep()
synchronize within small world. (slow but no busy wait)
static Channel * recv_init(int count, int idir, int ipm)
Definition: channel.cpp:65
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static Channel * send_init(int count, int idir, int ipm)
Definition: channel.cpp:28
static int size()
size of small world.
static double get_time()
obtain a wall-clock time.
static Channel * send_init(int count, int idir, int ipm)
static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern=0)
make a global sum of an array of double over the communicator. pattern specifies the dimensions to be...
static int sync()
synchronize within small world.
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
static bool is_primary()
check if the present node is primary in small communicator.
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)