Bridge++  Version 1.4.4
 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 //#include "Field/field.h"
25 
26 //namespace Communicator {
28 //}
29 
30 //====================================================================
31 int Communicator::init(int *pargc, char ***pargv)
32 {
33  return EXIT_SUCCESS;
34 }
35 
36 
37 //====================================================================
39 {
40  return EXIT_SUCCESS;
41 }
42 
43 
44 //====================================================================
46 {
47  ::abort(); // call system function.
48 }
49 
50 
51 //====================================================================
52 int Communicator::setup(int ninstance)
53 {
55  return EXIT_SUCCESS;
56 }
57 
58 
59 //====================================================================
61 {
62  return true;
63 }
64 
65 
66 //====================================================================
68 {
69  return true;
70 }
71 
72 
73 //====================================================================
75 {
76  return 0;
77 }
78 
79 
80 //====================================================================
82 {
83  return 1;
84 }
85 
86 
87 //====================================================================
88 int Communicator::self_global()
89 {
90  return 0;
91 }
92 
93 
94 //====================================================================
95 int Communicator::ipe(const int dir)
96 {
97  return 0;
98 }
99 
100 
101 //====================================================================
102 int Communicator::npe(const int dir)
103 {
104  return 1;
105 }
106 
107 
108 //====================================================================
109 int Communicator::grid_rank(int *rank, const int *gcoord)
110 {
111  *rank = 0;
112  return EXIT_SUCCESS;
113 }
114 
115 
116 //====================================================================
117 int Communicator::grid_coord(int *gcoord, const int rank)
118 {
119  for (int i = 0; i < m_Ndim; ++i) {
120  gcoord[i] = 0;
121  }
122  return EXIT_SUCCESS;
123 }
124 
125 
126 //====================================================================
127 int Communicator::grid_dims(int *gdims)
128 {
129  for (int i = 0; i < m_Ndim; ++i) {
130  gdims[i] = 1;
131  }
132  return EXIT_SUCCESS;
133 }
134 
135 
136 //====================================================================
137 int Communicator::sync()
138 {
139  return EXIT_SUCCESS;
140 }
141 
142 
143 //====================================================================
144 int Communicator::sync_global()
145 {
146  return EXIT_SUCCESS;
147 }
148 
149 
150 //====================================================================
151 int Communicator::Base::broadcast(size_t size, void *data, int sender)
152 {
153  // stay intact
154  return EXIT_SUCCESS;
155 }
156 
157 
158 int Communicator::broadcast(int count, double *data, int sender)
159 {
160  // stay intact
161  return EXIT_SUCCESS;
162 }
163 
164 
165 int Communicator::broadcast(int count, int *data, int sender)
166 {
167  // stay intact
168  return EXIT_SUCCESS;
169 }
170 
171 
172 int Communicator::broadcast(int count, string& data, int sender)
173 {
174  // stay intact
175  return EXIT_SUCCESS;
176 }
177 
178 
179 //====================================================================
180 int Communicator::Base::exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)
181 {
182  memcpy(recv_buf, send_buf, size);
183  return EXIT_SUCCESS;
184 }
185 
186 
187 int Communicator::exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag)
188 {
189  memcpy(recv_buf, send_buf, sizeof(double) * count);
190  return EXIT_SUCCESS;
191 }
192 
193 
194 int Communicator::exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int tag)
195 {
196  memcpy(recv_buf, send_buf, sizeof(int) * count);
197  return EXIT_SUCCESS;
198 }
199 
200 
201 //====================================================================
202 int Communicator::Base::send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
203 {
204  memcpy(recv_buf, send_buf, size);
205  return EXIT_SUCCESS;
206 }
207 
208 
209 int Communicator::send_1to1(int count, double *recv_buf, double *send_buf, int send_to, int recv_from, int tag)
210 {
211  memcpy(recv_buf, send_buf, sizeof(double) * count);
212  return EXIT_SUCCESS;
213 }
214 
215 
216 int Communicator::send_1to1(int count, int *recv_buf, int *send_buf, int send_to, int recv_from, int tag)
217 {
218  memcpy(recv_buf, send_buf, sizeof(int) * count);
219  return EXIT_SUCCESS;
220 }
221 
222 
223 //====================================================================
224 int Communicator::reduce_sum(int count, double *recv_buf, double *send_buf, int pattern)
225 {
226  memcpy(recv_buf, send_buf, sizeof(double) * count);
227  return EXIT_SUCCESS;
228 }
229 
230 
231 int Communicator::reduce_sum(int count, int *recv_buf, int *send_buf, int pattern)
232 {
233  memcpy(recv_buf, send_buf, sizeof(int) * count);
234  return EXIT_SUCCESS;
235 }
236 
237 
238 double Communicator::reduce_sum(double v)
239 {
240  return v;
241 }
242 
243 
244 //====================================================================
245 double Communicator::reduce_max(double v)
246 {
247  return v;
248 }
249 
250 
251 //====================================================================
252 double Communicator::reduce_min(double v)
253 {
254  return v;
255 }
256 
257 
258 //====================================================================
260 {
261 #ifdef DEBUG
262  printf("Communicator Single\n");
263 #endif
264  return EXIT_SUCCESS;
265 }
266 
267 
268 //====================================================================
269 double Communicator::get_time()
270 {
271  struct timeval now;
272 
273  if (gettimeofday(&now, (struct timezone *)0) != 0) {
274  return double();
275  }
276 
277  double sec = (double)now.tv_sec + ((double)now.tv_usec) * 1.0e-6;
278 
279  return sec;
280 }
281 
282 
283 //====================================================================
284 //============================================================END=====
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 *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 m_Ndim
static int broadcast(size_t size, void *data, int sender)
static int ipe(const int dir)
logical coordinate of current proc.
static int finalize()
finalize communicator
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 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 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 send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static int size()
size of small world.
static double get_time()
obtain a wall-clock time.
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.