Bridge++  Version 1.6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
communicator.h
Go to the documentation of this file.
1 
14 #ifndef COMMUNICATOR_INCLUDED
15 #define COMMUNICATOR_INCLUDED
16 
17 #include "configure.h"
18 #include "bridge_complex.h"
19 #include "bridge_defs.h"
20 
21 #include <cstdio>
22 #include <cstdlib>
23 #include <cstddef>
24 #include <vector>
25 #include <string>
26 using std::string;
27 
28 class Channel;
29 
31 
47 // forward declaration
48 //class Channel;
49 
50 class Communicator {
51  public:
53 
62  static int init(int *pargc, char ***pargv);
63 
65 
70  static int finalize();
71 
73 
78  static void abort();
79 
81 
88  static int setup(int ninstance = 1);
89 
98  static int setup(const std::vector<int>& lattice_size,
99  std::vector<int>& grid_size,
100  int ninstance = 1);
101 
102 // info about rank
103  static bool is_primary();
104  static bool is_primary_master();
105 
106  static int self();
107 
108  static int nodeid() { return self(); }
109  static int size();
110 
111 #ifdef ENABLE_MULTI_INSTANCE
112  static int self_global();
113  static int world_id();
114 #endif
115 
116 // layout
117  static int ipe(const int dir);
118  static int npe(const int dir);
119 
120  static int grid_rank(int *rank, const int *grid_coord);
121  static int grid_coord(int *grid_coord, const int rank);
122  static int grid_dims(int *grid_dims);
123 
124 // synchronize
125  static int sync();
126 
127 // synchronize (w/o busy wait)
128  static int sync_usleep();
129 
130 #ifdef ENABLE_MULTI_INSTANCE
131  static int sync_global();
132 #endif
133 
134 // data transfer
135  static int broadcast(int count, dcomplex *data, int sender);
136  static int broadcast(int count, double *data, int sender);
137  static int broadcast(int count, float *data, int sender);
138  static int broadcast(int count, int *data, int sender);
139  static int broadcast(int count, string& data, int sender);
140 
141  static int exchange(int count, dcomplex *recv_buf, dcomplex *send_buf, int idir, int ipm, int tag);
142  static int exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag);
143  static int exchange(int count, float *recv_buf, float *send_buf, int idir, int ipm, int tag);
144  static int exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int tag);
145 
146  static int send_1to1(int count, dcomplex *recv_buf, dcomplex *send_buf, int p_to, int p_from, int tag);
147  static int send_1to1(int count, double *recv_buf, double *send_buf, int p_to, int p_from, int tag);
148  static int send_1to1(int count, float *recv_buf, float *send_buf, int p_to, int p_from, int tag);
149  static int send_1to1(int count, int *recv_buf, int *send_buf, int p_to, int p_from, int tag);
150 
151  static int reduce_sum(int count, dcomplex *recv_buf, dcomplex *send_buf, int pattern = 0);
152  static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern = 0);
153  static int reduce_sum(int count, float *recv_buf, float *send_buf, int pattern = 0);
154  static int reduce_sum(int count, int *recv_buf, int *send_buf, int pattern = 0);
155 
156  static int reduce_max(int count, double *recv_buf, double *send_buf, int pattern = 0);
157  static int reduce_max(int count, float *recv_buf, float *send_buf, int pattern = 0);
158  static int reduce_max(int count, int *recv_buf, int *send_buf, int pattern = 0);
159 
160  static int reduce_min(int count, double *recv_buf, double *send_buf, int pattern = 0);
161  static int reduce_min(int count, float *recv_buf, float *send_buf, int pattern = 0);
162  static int reduce_min(int count, int *recv_buf, int *send_buf, int pattern = 0);
163 
164  static dcomplex reduce_sum(dcomplex);
165 
166  //- NB. no reduce_{max,min} for dcomplex
167  // static dcomplex reduce_max(dcomplex);
168  // static dcomplex reduce_min(dcomplex);
169 
170  static double reduce_sum(double);
171  static double reduce_max(double);
172  static double reduce_min(double);
173 
174  static float reduce_sum(float);
175  static float reduce_max(float);
176  static float reduce_min(float);
177 
178  static double get_time();
179 
180  // async communication
181  static Channel *send_init(int count, int idir, int ipm);
182  static Channel *recv_init(int count, int idir, int ipm);
183 
184  // async communication with given buffer [2017.09.02 H.Matsufuru]
185  static Channel *send_init(int count, int idir, int ipm, void *buf);
186  static Channel *recv_init(int count, int idir, int ipm, void *buf);
187 
188 // debug
189  static int status();
190 
192 
197  class Base {
198  public:
199  static int broadcast(size_t size, void *data, int sender);
200  static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag);
201 
202  static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag);
203  };
204 
205  private:
206 
208 
217 
219 };
220 #endif /* COMMUNICATOR_INCLUDED */
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 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.
Communication library which wraps MPI.
Definition: communicator.h:50
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...
Communicator()
no instance at all
Definition: communicator.h:214
Communicator(const Communicator &)
Definition: communicator.h:215
static Channel * recv_init(int count, int idir, int ipm)
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 ...
Channel class for asynchronous communication.
Definition: channel.h:48
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 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 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 Channel * send_init(int count, int idir, int ipm)
static int sync()
synchronize within small world.
Communicator & operator=(const Communicator &)
static int nodeid()
alternative name for self().
Definition: communicator.h:108
static bool is_primary()
check if the present node is primary in small communicator.