Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 dcomplex Communicator::reduce_sum(dcomplex v)
343 {
344  return v;
345 }
346 
347 
348 //- NB. no reduce_{max,min} for dcomplex
349 // dcomplex Communicator::reduce_max(dcomplex v);
350 // dcomplex Communicator::reduce_min(dcomplex v);
351 
352 
353 //====================================================================
354 double Communicator::reduce_sum(double v)
355 {
356  return v;
357 }
358 
359 
360 double Communicator::reduce_max(double v)
361 {
362  return v;
363 }
364 
365 
366 double Communicator::reduce_min(double v)
367 {
368  return v;
369 }
370 
371 
372 //====================================================================
373 float Communicator::reduce_sum(float v)
374 {
375  return v;
376 }
377 
378 
379 float Communicator::reduce_max(float v)
380 {
381  return v;
382 }
383 
384 
385 float Communicator::reduce_min(float v)
386 {
387  return v;
388 }
389 
390 
391 //====================================================================
393 {
394 #ifdef DEBUG
395  printf("Communicator Single\n");
396 #endif
397  return EXIT_SUCCESS;
398 }
399 
400 
401 //====================================================================
402 double Communicator::get_time()
403 {
404  struct timeval now;
405 
406  if (gettimeofday(&now, (struct timezone *)0) != 0) {
407  return double();
408  }
409 
410  double sec = (double)now.tv_sec + ((double)now.tv_usec) * 1.0e-6;
411 
412  return sec;
413 }
414 
415 
416 //====================================================================
417 //============================================================END=====
static int npe(const int dir)
logical grid extent
static int NPEy()
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 *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 broadcast(size_t size, void *data, int sender)
static int ipe(const int dir)
logical coordinate of current proc.
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 ...
static int finalize()
finalize communicator
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 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...
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 NPEx()
static int sync_usleep()
synchronize within small world. (slow but no busy wait)
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static int NPEz()
static int size()
size of small world.
static int broadcast(int count, dcomplex *data, int sender)
broadcast array of dcomplex from sender.
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...
static double get_time()
obtain a wall-clock time.
static int sync()
synchronize within small world.
static bool is_primary()
check if the present node is primary in small communicator.