Bridge++  Version 1.4.4
 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 functions explicitly depend on BGNET library.
16 // They may be replaced with calls of Communicator::impl, while
17 // unnecessary function calls might be not welcome.
18 // [2 Mar 2013 H.Matsufuru]
19 
21 
22 #include "communicator_bgnet.h"
23 #include "layout.h"
24 
25 
26 //====================================================================
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 {
58 }
59 
60 
61 //====================================================================
63 {
64  return Communicator_impl::is_primary_master();
65 }
66 
67 
68 //====================================================================
70 {
71  return Communicator_impl::self();
72 }
73 
74 
75 //====================================================================
77 {
78  return Communicator_impl::size();
79 }
80 
81 
82 //====================================================================
83 #ifdef ENABLE_MULTI_INSTANCE
84 int Communicator::self_global()
85 {
86  return Communicator_impl::self_global();
87 }
88 #endif
89 //====================================================================
90 #ifdef ENABLE_MULTI_INSTANCE
91 int Communicator::world_id()
92 {
93  return Communicator_impl::world_id();
94 }
95 #endif
96 //====================================================================
97 int Communicator::ipe(const int idir)
98 {
99  return Communicator_impl::Layout::ipe(idir);
100 }
101 
102 
103 //====================================================================
104 int Communicator::npe(const int idir)
105 {
106  return Communicator_impl::Layout::npe(idir);
107 }
108 
109 
110 //====================================================================
111 int Communicator::grid_rank(int *rank, const int *grid_coord)
112 {
113  return Communicator_impl::Layout::grid_rank(rank, grid_coord);
114 }
115 
116 
117 //====================================================================
118 int Communicator::grid_coord(int *grid_coord, const int rank)
119 {
120  return Communicator_impl::Layout::grid_coord(grid_coord, rank);
121 }
122 
123 
124 //====================================================================
125 int Communicator::grid_dims(int *grid_dims)
126 {
127  return Communicator_impl::Layout::grid_dims(grid_dims);
128 }
129 
130 
131 //====================================================================
133 {
134  return Communicator_impl::sync();
135 }
136 
137 
138 //====================================================================
139 #ifdef ENABLE_MULTI_INSTANCE
140 int Communicator::sync_global()
141 {
142  return Communicator_impl::sync_global();
143 }
144 #endif
145 //====================================================================
146 int Communicator::Base::broadcast(size_t size, void *data, int sender)
147 {
148  return Communicator_impl::Base::broadcast(size, data, sender);
149 }
150 
151 
152 //====================================================================
153 int Communicator::broadcast(int count, double *data, int sender)
154 {
155  return Communicator_impl::broadcast_double(count, data, sender);
156 }
157 
158 
159 //====================================================================
160 int Communicator::broadcast(int count, int *data, int sender)
161 {
162  return Communicator_impl::broadcast_int(count, data, sender);
163 }
164 
165 
166 //====================================================================
167 int Communicator::broadcast(int count, string& data, int sender)
168 {
169  return Communicator_impl::broadcast_string(count, data, sender);
170 }
171 
172 
173 //====================================================================
175  double *recv_buf, double *send_buf,
176  int idir, int ipm, int itag)
177 {
178  return Communicator_impl::Base::exchange(sizeof(double) * count,
179  (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
180 }
181 
182 
183 //====================================================================
185  int *recv_buf, int *send_buf,
186  int idir, int ipm, int itag)
187 {
188  return Communicator_impl::Base::exchange(sizeof(int) * count,
189  (void *)recv_buf, (void *)send_buf, idir, ipm, itag);
190 }
191 
192 
193 //====================================================================
195  double *recv_buf, double *send_buf,
196  int send_to, int recv_from, int tag)
197 {
198  return Communicator_impl::Base::send_1to1(sizeof(double) * count,
199  (void *)recv_buf, (void *)send_buf, send_to, recv_from, tag);
200 }
201 
202 
203 //====================================================================
205  int *recv_buf, int *send_buf,
206  int send_to, int recv_from, int tag)
207 {
208  return Communicator_impl::Base::send_1to1(sizeof(int) * count,
209  (void *)recv_buf, (void *)send_buf,
210  send_to, recv_from, tag);
211 }
212 
213 
214 //====================================================================
215 int Communicator::reduce_sum(int count, double *recv_buf,
216  double *send_buf, int pattern)
217 {
218  return Communicator_impl::Base::reduce(count,
219  (void *)recv_buf, (void *)send_buf,
220  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_ADD, pattern);
221 }
222 
223 
224 //====================================================================
225 int Communicator::reduce_sum(int count, int *recv_buf,
226  int *send_buf, int pattern)
227 {
228  return Communicator_impl::Base::reduce(count,
229  (void *)recv_buf, (void *)send_buf,
230  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_ADD, pattern);
231 }
232 
233 
234 //====================================================================
235 int Communicator::reduce_max(int count, double *recv_buf,
236  double *send_buf, int pattern)
237 {
238  return Communicator_impl::Base::reduce(count,
239  (void *)recv_buf, (void *)send_buf,
240  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_MAX, pattern);
241 }
242 
243 
244 //====================================================================
245 int Communicator::reduce_max(int count, int *recv_buf,
246  int *send_buf, int pattern)
247 {
248  return Communicator_impl::Base::reduce(count,
249  (void *)recv_buf, (void *)send_buf,
250  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_MAX, pattern);
251 }
252 
253 
254 //====================================================================
255 int Communicator::reduce_min(int count, double *recv_buf,
256  double *send_buf, int pattern)
257 {
258  return Communicator_impl::Base::reduce(count,
259  (void *)recv_buf, (void *)send_buf,
260  BGNET_COLLECTIVE_DOUBLE, BGNET_COLLECTIVE_MIN, pattern);
261 }
262 
263 
264 //====================================================================
265 int Communicator::reduce_min(int count, int *recv_buf,
266  int *send_buf, int pattern)
267 {
268  return Communicator_impl::Base::reduce(count,
269  (void *)recv_buf, (void *)send_buf,
270  BGNET_COLLECTIVE_INT32, BGNET_COLLECTIVE_MIN, pattern);
271 }
272 
273 
274 //====================================================================
275 double Communicator::reduce_sum(double a)
276 {
277  double ar = double();
278 
279  reduce_sum(1, &ar, &a, 0);
280 
281  return ar;
282 }
283 
284 
285 //====================================================================
286 double Communicator::reduce_max(double a)
287 {
288  double ar = double();
289 
290  reduce_max(1, &ar, &a, 0);
291  return ar;
292 }
293 
294 
295 //====================================================================
296 double Communicator::reduce_min(double a)
297 {
298  double ar = double();
299 
300  reduce_min(1, &ar, &a, 0);
301  return ar;
302 }
303 
304 
305 //====================================================================
307 {
309 }
310 
311 
312 //====================================================================
313 Channel *Communicator::send_init(int count, int idir, int ipm)
314 {
315  return Communicator_impl::send_init(count, idir, ipm);
316 }
317 
318 
319 //====================================================================
320 Channel *Communicator::recv_init(int count, int idir, int ipm)
321 {
322  return Communicator_impl::recv_init(count, idir, ipm);
323 }
324 
325 
326 //====================================================================
328 {
329  return Communicator_impl::status();
330 }
331 
332 
333 //====================================================================
334 //============================================================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 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:57
Channel class for asynchronous communication.
Definition: channel.h:24
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:64
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:50
static Channel * recv_init(int count, int idir, int ipm)
Definition: channel.cpp:98
static Channel * send_init(int count, int idir, int ipm)
async communication
Definition: channel.cpp:61
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)