Bridge++  Ver. 2.0.2
communicator_single.cpp
Go to the documentation of this file.
1 
15 
16 #include <cstdarg>
17 #include <cstring>
18 #include <cassert>
19 
20 #include <sys/time.h>
21 #include <time.h>
22 
24 
25 //====================================================================
26 int Communicator::init(int *pargc, char ***pargv)
27 {
28  return EXIT_SUCCESS;
29 }
30 
31 
32 //====================================================================
34 {
35  return EXIT_SUCCESS;
36 }
37 
38 
39 //====================================================================
41 {
42  ::abort(); // call system function.
43 }
44 
45 
46 //====================================================================
47 int Communicator::setup(int Ninstance)
48 {
49  assert(Ninstance == 1);
50 
51  // check consistency
52  if (!((CommonParameters::NPE() == 1) &&
53  (CommonParameters::NPEx() == 1) &&
54  (CommonParameters::NPEy() == 1) &&
55  (CommonParameters::NPEz() == 1) &&
56  (CommonParameters::NPEt() == 1)))
57  {
58  fprintf(stderr, "Error at Communicator::setup(): inappropriate grid_size.\n");
59  exit(EXIT_FAILURE);
60  }
61 
62  return EXIT_SUCCESS;
63 }
64 
65 
66 //====================================================================
68  const std::vector<int>& lattice_size,
69  std::vector<int>& grid_size,
70  int Ninstance)
71 {
72  int Ndim = lattice_size.size();
73 
74  if (grid_size.size() != Ndim) {
75  grid_size.resize(Ndim, 1);
76  }
77 
78  int err = 0;
79  for (int i = 0; i < Ndim; ++i) {
80  if (grid_size[i] != 1) {
81  ++err;
82  }
83  }
84 
85  if (err > 0) {
86  printf("Error at Communicator: %s: unexpected grid_size.\n", __func__);
87  exit(EXIT_FAILURE);
88  }
89 
90  return EXIT_SUCCESS;
91 }
92 
93 
94 //====================================================================
96 {
97  return true;
98 }
99 
100 
101 //====================================================================
103 {
104  return true;
105 }
106 
107 
108 //====================================================================
109 int Communicator::self()
110 {
111  return 0;
112 }
113 
114 
115 //====================================================================
116 int Communicator::size()
117 {
118  return 1;
119 }
120 
121 
122 //====================================================================
123 int Communicator::self_global()
124 {
125  return 0;
126 }
127 
128 
129 //====================================================================
130 int Communicator::ipe(const int dir)
131 {
132  return 0;
133 }
134 
135 
136 //====================================================================
137 int Communicator::npe(const int dir)
138 {
139  return 1;
140 }
141 
142 
143 //====================================================================
144 int Communicator::grid_rank(int *rank, const int *g_coord)
145 {
146  *rank = 0;
147  return EXIT_SUCCESS;
148 }
149 
150 
151 //====================================================================
152 int Communicator::grid_coord(int *g_coord, const int rank)
153 {
154  int Ndim = CommonParameters::Ndim();
155 
156  for (int i = 0; i < Ndim; ++i) {
157  g_coord[i] = 0;
158  }
159  return EXIT_SUCCESS;
160 }
161 
162 
163 //====================================================================
164 int Communicator::grid_dims(int *g_dims)
165 {
166  int Ndim = CommonParameters::Ndim();
167 
168  for (int i = 0; i < Ndim; ++i) {
169  g_dims[i] = 1;
170  }
171  return EXIT_SUCCESS;
172 }
173 
174 
175 //====================================================================
176 int Communicator::sync()
177 {
178  return EXIT_SUCCESS;
179 }
180 
181 
182 //====================================================================
183 // sync w/o (possible) busy wait
185 {
186  return EXIT_SUCCESS;
187 }
188 
189 
190 //====================================================================
191 int Communicator::sync_global()
192 {
193  return EXIT_SUCCESS;
194 }
195 
196 
197 //====================================================================
198 int Communicator::Base::broadcast(size_t size, void *data, int sender)
199 {
200  // stay intact
201  return EXIT_SUCCESS;
202 }
203 
204 
205 int Communicator::broadcast(int count, dcomplex *data, int sender)
206 {
207  // stay intact
208  return EXIT_SUCCESS;
209 }
210 
211 
212 int Communicator::broadcast(int count, double *data, int sender)
213 {
214  // stay intact
215  return EXIT_SUCCESS;
216 }
217 
218 
219 int Communicator::broadcast(int count, float *data, int sender)
220 {
221  // stay intact
222  return EXIT_SUCCESS;
223 }
224 
225 
226 int Communicator::broadcast(int count, int *data, int sender)
227 {
228  // stay intact
229  return EXIT_SUCCESS;
230 }
231 
232 
233 int Communicator::broadcast(int count, string& data, int sender)
234 {
235  // stay intact
236  return EXIT_SUCCESS;
237 }
238 
239 
240 //====================================================================
241 int Communicator::Base::exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
242 {
243  memcpy(recv_buf, send_buf, size);
244  return EXIT_SUCCESS;
245 }
246 
247 
248 int Communicator::exchange(int count, dcomplex *recv_buf, dcomplex *send_buf, int idir, int ipm, int tag)
249 {
250  memcpy(recv_buf, send_buf, sizeof(dcomplex) * count);
251  return EXIT_SUCCESS;
252 }
253 
254 
255 int Communicator::exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag)
256 {
257  memcpy(recv_buf, send_buf, sizeof(double) * count);
258  return EXIT_SUCCESS;
259 }
260 
261 
262 int Communicator::exchange(int count, float *recv_buf, float *send_buf, int idir, int ipm, int tag)
263 {
264  memcpy(recv_buf, send_buf, sizeof(float) * count);
265  return EXIT_SUCCESS;
266 }
267 
268 
269 int Communicator::exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int tag)
270 {
271  memcpy(recv_buf, send_buf, sizeof(int) * count);
272  return EXIT_SUCCESS;
273 }
274 
275 
276 //====================================================================
277 int Communicator::Base::send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
278 {
279  memcpy(recv_buf, send_buf, size);
280  return EXIT_SUCCESS;
281 }
282 
283 
284 int Communicator::send_1to1(int count, dcomplex *recv_buf, dcomplex *send_buf, int send_to, int recv_from, int tag)
285 {
286  memcpy(recv_buf, send_buf, sizeof(dcomplex) * count);
287  return EXIT_SUCCESS;
288 }
289 
290 
291 int Communicator::send_1to1(int count, double *recv_buf, double *send_buf, int send_to, int recv_from, int tag)
292 {
293  memcpy(recv_buf, send_buf, sizeof(double) * count);
294  return EXIT_SUCCESS;
295 }
296 
297 
298 int Communicator::send_1to1(int count, float *recv_buf, float *send_buf, int send_to, int recv_from, int tag)
299 {
300  memcpy(recv_buf, send_buf, sizeof(float) * count);
301  return EXIT_SUCCESS;
302 }
303 
304 
305 int Communicator::send_1to1(int count, int *recv_buf, int *send_buf, int send_to, int recv_from, int tag)
306 {
307  memcpy(recv_buf, send_buf, sizeof(int) * count);
308  return EXIT_SUCCESS;
309 }
310 
311 
312 //====================================================================
313 int Communicator::reduce_sum(int count, dcomplex *recv_buf, dcomplex *send_buf, int pattern)
314 {
315  memcpy(recv_buf, send_buf, sizeof(dcomplex) * count);
316  return EXIT_SUCCESS;
317 }
318 
319 
320 int Communicator::reduce_sum(int count, double *recv_buf, double *send_buf, int pattern)
321 {
322  memcpy(recv_buf, send_buf, sizeof(double) * count);
323  return EXIT_SUCCESS;
324 }
325 
326 
327 int Communicator::reduce_sum(int count, float *recv_buf, float *send_buf, int pattern)
328 {
329  memcpy(recv_buf, send_buf, sizeof(float) * count);
330  return EXIT_SUCCESS;
331 }
332 
333 
334 int Communicator::reduce_sum(int count, int *recv_buf, int *send_buf, int pattern)
335 {
336  memcpy(recv_buf, send_buf, sizeof(int) * count);
337  return EXIT_SUCCESS;
338 }
339 
340 
341 //====================================================================
342 int Communicator::reduce_max(int count, double *recv_buf, double *send_buf, int pattern)
343 {
344  memcpy(recv_buf, send_buf, sizeof(double) * count);
345  return EXIT_SUCCESS;
346 }
347 
348 
349 int Communicator::reduce_max(int count, float *recv_buf, float *send_buf, int pattern)
350 {
351  memcpy(recv_buf, send_buf, sizeof(float) * count);
352  return EXIT_SUCCESS;
353 }
354 
355 
356 int Communicator::reduce_max(int count, int *recv_buf, int *send_buf, int pattern)
357 {
358  memcpy(recv_buf, send_buf, sizeof(int) * count);
359  return EXIT_SUCCESS;
360 }
361 
362 
363 //====================================================================
364 dcomplex Communicator::reduce_sum(dcomplex v)
365 {
366  return v;
367 }
368 
369 
370 //- NB. no reduce_{max,min} for dcomplex
371 // dcomplex Communicator::reduce_max(dcomplex v);
372 // dcomplex Communicator::reduce_min(dcomplex v);
373 
374 
375 //====================================================================
376 double Communicator::reduce_sum(double v)
377 {
378  return v;
379 }
380 
381 
382 double Communicator::reduce_max(double v)
383 {
384  return v;
385 }
386 
387 
388 double Communicator::reduce_min(double v)
389 {
390  return v;
391 }
392 
393 
394 //====================================================================
395 float Communicator::reduce_sum(float v)
396 {
397  return v;
398 }
399 
400 
401 float Communicator::reduce_max(float v)
402 {
403  return v;
404 }
405 
406 
407 float Communicator::reduce_min(float v)
408 {
409  return v;
410 }
411 
412 
413 //====================================================================
415 {
416 #ifdef DEBUG
417  printf("Communicator Single\n");
418 #endif
419  return EXIT_SUCCESS;
420 }
421 
422 
423 //====================================================================
424 double Communicator::get_time()
425 {
426  struct timeval now;
427 
428  if (gettimeofday(&now, (struct timezone *)0) != 0) {
429  return double();
430  }
431 
432  double sec = (double)now.tv_sec + ((double)now.tv_usec) * 1.0e-6;
433 
434  return sec;
435 }
436 
437 
438 //====================================================================
439 //============================================================END=====
Communicator::sync
static int sync()
synchronize within small world.
Definition: communicator.cpp:140
Communicator::get_time
static double get_time()
obtain a wall-clock time.
Definition: communicator.cpp:401
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
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::size
static int size()
size of small world.
Definition: communicator.cpp:81
Communicator::grid_dims
static int grid_dims(int *grid_dims)
find grid dimensions.
Definition: communicator.cpp:133
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::is_primary_master
static bool is_primary_master()
check if the present node is primary in global communicator.
Definition: communicator.cpp:67
Communicator::status
static int status()
Definition: communicator.cpp:408
Communicator::sync_usleep
static int sync_usleep()
synchronize within small world. (slow but no busy wait)
Definition: communicator.cpp:147
Communicator::setup
static int setup(int ninstance=1)
setup communicator
Definition: communicator.cpp:43
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
CommonParameters::NPEz
static int NPEz()
Definition: commonParameters.h:99
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
CommonParameters::NPE
static int NPE()
Definition: commonParameters.h:101
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::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
CommonParameters::NPEy
static int NPEy()
Definition: commonParameters.h:98
Communicator::is_primary
static bool is_primary()
check if the present node is primary in small communicator.
Definition: communicator.cpp:60
CommonParameters::NPEx
static int NPEx()
Definition: commonParameters.h:97
Communicator::finalize
static int finalize()
finalize communicator
Definition: communicator.cpp:29
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
CommonParameters::NPEt
static int NPEt()
Definition: commonParameters.h:100
commonParameters.h
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.h
Communicator::grid_rank
static int grid_rank(int *rank, const int *grid_coord)
find rank number from grid coordinate.
Definition: communicator.cpp:119