Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
communicator.cpp
Go to the documentation of this file.
1 
14 // The following implementation is almost calls of Communicator::impl,
15 // but several function explicitly depend on BGNET library.
16 // They may be replaced with calls of Communicator::impl, while
17 // unnecessary function calls maight be not welcome.
18 // [2 Mar 2013 H.Matsufuru]
19 
20 #include "configure.h"
21 #include "defs.h"
22 #include "communicator.h"
23 #include "communicator_bgnet.h"
24 #include "layout.h"
25 
26 static const char rcsid[]
27  = "$Id: communicator.cpp 1145 2014-09-16 09:27:22Z namekawa $";
28 
29 //====================================================================
30 int Communicator::init(int *pargc, char ***pargv)
31 {
32  return Communicator_impl::init(pargc, pargv);
33 }
34 
35 
36 //====================================================================
38 {
40 }
41 
42 
43 //====================================================================
45 {
46  return Communicator_impl::abort();
47 }
48 
49 
50 //====================================================================
51 int Communicator::setup(int ninstance)
52 {
53  return Communicator_impl::setup(ninstance);
54 }
55 
56 
57 //====================================================================
59 {
61 }
62 
63 
64 //====================================================================
66 {
67  return Communicator_impl::is_primary_master();
68 }
69 
70 
71 //====================================================================
73 {
74  return Communicator_impl::self();
75 }
76 
77 
78 //====================================================================
80 {
81  return Communicator_impl::size();
82 }
83 
84 
85 //====================================================================
86 #ifdef ENABLE_MULTI_INSTANCE
87 int Communicator::self_global()
88 {
89  return Communicator_impl::self_global();
90 }
91 
92 
93 #endif
94 //====================================================================
95 #ifdef ENABLE_MULTI_INSTANCE
96 int Communicator::world_id()
97 {
98  return Communicator_impl::world_id();
99 }
100 
101 
102 #endif
103 //====================================================================
104 int Communicator::ipe(const int idir)
105 {
106  return Communicator_impl::Layout::ipe(idir);
107 }
108 
109 
110 //====================================================================
111 int Communicator::npe(const int idir)
112 {
113  return Communicator_impl::Layout::npe(idir);
114 }
115 
116 
117 //====================================================================
118 int Communicator::grid_rank(int *rank, const int *grid_coord)
119 {
120  return Communicator_impl::Layout::grid_rank(rank, grid_coord);
121 }
122 
123 
124 //====================================================================
125 int Communicator::grid_coord(int *grid_coord, const int rank)
126 {
127  return Communicator_impl::Layout::grid_coord(grid_coord, rank);
128 }
129 
130 
131 //====================================================================
132 int Communicator::grid_dims(int *grid_dims)
133 {
134  return Communicator_impl::Layout::grid_dims(grid_dims);
135 }
136 
137 
138 //====================================================================
140 {
141  return Communicator_impl::sync();
142 }
143 
144 
145 //====================================================================
146 #ifdef ENABLE_MULTI_INSTANCE
147 int Communicator::sync_global()
148 {
149  return Communicator_impl::sync_global();
150 }
151 
152 
153 #endif
154 //====================================================================
155 int Communicator::Base::broadcast(size_t size, void *data, int sender)
156 {
157  return Communicator_impl::Base::broadcast(size, data, sender);
158 }
159 
160 
161 //====================================================================
162 int Communicator::broadcast(int count, double *data, int sender)
163 {
164  return Communicator_impl::broadcast_double(count, data, sender);
165 }
166 
167 
168 //====================================================================
169 int Communicator::broadcast(int count, int *data, int sender)
170 {
171  return Communicator_impl::broadcast_int(count, data, sender);
172 }
173 
174 
175 //====================================================================
176 int Communicator::broadcast(int count, string& data, int sender)
177 {
178  return Communicator_impl::broadcast_string(count, data, sender);
179 }
180 
181 
182 //====================================================================
184  double *recv_buf, double *send_buf,
185  int idir, int ipm, int itag)
186 {
187  return Communicator_impl::Base::exchange(sizeof(double) * count,
188  (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
189 }
190 
191 
192 //====================================================================
194  int *recv_buf, int *send_buf,
195  int idir, int ipm, int itag)
196 {
197  return Communicator_impl::Base::exchange(sizeof(int) * count,
198  (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
199 }
200 
201 
202 //====================================================================
204  double *recv_buf, double *send_buf,
205  int send_to, int recv_from, int tag)
206 {
207  return Communicator_impl::Base::send_1to1(sizeof(double) * count,
208  (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
209 }
210 
211 
212 //====================================================================
214  int *recv_buf, int *send_buf,
215  int send_to, int recv_from, int tag)
216 {
217  return Communicator_impl::Base::send_1to1(sizeof(int) * count,
218  (void *)recv_buf, (void *)send_buf,
219  send_to, recv_from, tag);
220 }
221 
222 
223 //====================================================================
224 int Communicator::reduce_sum(int count, double *recv_buf,
225  double *send_buf, int pattern)
226 {
227  return Communicator_impl::Base::reduce(count,
228  (void *)recv_buf, (void *)send_buf,
229  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_ADD, pattern);
230 }
231 
232 
233 //====================================================================
234 int Communicator::reduce_sum(int count, int *recv_buf,
235  int *send_buf, int pattern)
236 {
237  return Communicator_impl::Base::reduce(count,
238  (void *)recv_buf, (void *)send_buf,
239  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_ADD, pattern);
240 }
241 
242 
243 //====================================================================
244 int Communicator::reduce_max(int count, double *recv_buf,
245  double *send_buf, int pattern)
246 {
247  return Communicator_impl::Base::reduce(count,
248  (void *)recv_buf, (void *)send_buf,
249  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_MAX, pattern);
250 }
251 
252 
253 //====================================================================
254 int Communicator::reduce_max(int count, int *recv_buf,
255  int *send_buf, int pattern)
256 {
257  return Communicator_impl::Base::reduce(count,
258  (void *)recv_buf, (void *)send_buf,
259  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_MAX, pattern);
260 }
261 
262 
263 //====================================================================
264 int Communicator::reduce_min(int count, double *recv_buf,
265  double *send_buf, int pattern)
266 {
267  return Communicator_impl::Base::reduce(count,
268  (void *)recv_buf, (void *)send_buf,
269  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_MIN, pattern);
270 }
271 
272 
273 //====================================================================
274 int Communicator::reduce_min(int count, int *recv_buf,
275  int *send_buf, int pattern)
276 {
277  return Communicator_impl::Base::reduce(count,
278  (void *)recv_buf, (void *)send_buf,
279  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_MIN, pattern);
280 }
281 
282 
283 //====================================================================
284 double Communicator::reduce_sum(double a)
285 {
286  double ar = double();
287 
288  reduce_sum(1, &ar, &a, 0);
289 
290  return ar;
291 }
292 
293 
294 //====================================================================
295 double Communicator::reduce_max(double a)
296 {
297  double ar = double();
298 
299  reduce_max(1, &ar, &a, 0);
300  return ar;
301 }
302 
303 
304 //====================================================================
305 double Communicator::reduce_min(double a)
306 {
307  double ar = double();
308 
309  reduce_min(1, &ar, &a, 0);
310  return ar;
311 }
312 
313 
314 //====================================================================
316 {
318 }
319 
320 
321 //====================================================================
322 Channel *Communicator::send_init(int count, int idir, int ipm)
323 {
324  return Communicator_impl::send_init(count, idir, ipm);
325 }
326 
327 
328 //====================================================================
329 Channel *Communicator::recv_init(int count, int idir, int ipm)
330 {
331  return Communicator_impl::recv_init(count, idir, ipm);
332 }
333 
334 
335 //====================================================================
337 {
338  return Communicator_impl::status();
339 }
340 
341 
342 //====================================================================
343 //============================================================END=====
static const char rcsid[]
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 int broadcast_double(int count, double *data, int sender)
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)
static int grid_coord(int *grid_coord, const int rank)
find grid coordinate from rank number.
static int sync()
synchronize within small world.
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 status()
for debug
static int broadcast(size_t size, void *data, int sender)
static int broadcast_int(int count, int *data, int sender)
static int ipe(const int dir)
logical coordinate of current proc.
static int grid_rank(int *rank, const int *gcoord)
static bool is_primary()
info about rank
static int npe(const int idir)
Definition: layout.cpp:67
Channel class for asynchronous communication.
Definition: channel.h:16
static int reduce(int count, void *recv_buf, void *send_buf, int type, int op, int pattern)
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)
Definition: layout.cpp:73
static int grid_dims(int *grid_dims)
find grid dimensions.
static int broadcast_string(int count, string &data, int sender)
for specific datatypes
static double get_time()
for getting time interval using clock count.
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 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 ipe(const int idir)
Definition: layout.cpp:61
static Channel * recv_init(int count, int idir, int ipm)
Definition: channel.cpp:100
static Channel * send_init(int count, int idir, int ipm)
async communication
Definition: channel.cpp:63
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)