Bridge++  Ver. 2.0.2
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  //- NB. no reduce_{max,min} for dcomplex
166  // static dcomplex reduce_max(dcomplex);
167  // static dcomplex reduce_min(dcomplex);
168 
169  static double reduce_sum(double);
170  static double reduce_max(double);
171  static double reduce_min(double);
172 
173  static float reduce_sum(float);
174  static float reduce_max(float);
175  static float reduce_min(float);
176 
177  static double get_time();
178 
179  // async communication
180  static Channel *send_init(int count, int idir, int ipm);
181  static Channel *recv_init(int count, int idir, int ipm);
182 
183  // async communication with given buffer [2017.09.02 H.Matsufuru]
184  static Channel *send_init(int count, int idir, int ipm, void *buf);
185  static Channel *recv_init(int count, int idir, int ipm, void *buf);
186 
187 // debug
188  static int status();
189 
191 
196  class Base {
197  public:
198  static int broadcast(size_t size, void *data, int sender);
199  static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag);
200 
201  static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag);
202  };
203 
204  private:
205 
207 
216 
218 };
219 #endif /* COMMUNICATOR_INCLUDED */
Communicator::sync
static int sync()
synchronize within small world.
Definition: communicator.cpp:140
Communicator::recv_init
static Channel * recv_init(int count, int idir, int ipm)
Communicator::get_time
static double get_time()
obtain a wall-clock time.
Definition: communicator.cpp:401
Communicator::Base
base case
Definition: communicator.h:196
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::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::operator=
Communicator & operator=(const Communicator &)
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
bridge_complex.h
Communicator::send_init
static Channel * send_init(int count, int idir, int ipm)
Communicator::npe
static int npe(const int dir)
logical grid extent
Definition: communicator.cpp:112
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
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
Communicator::is_primary
static bool is_primary()
check if the present node is primary in small communicator.
Definition: communicator.cpp:60
Communicator
Communication library which wraps MPI.
Definition: communicator.h:50
Communicator::Communicator
Communicator()
no instance at all
Definition: communicator.h:213
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
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::grid_rank
static int grid_rank(int *rank, const int *grid_coord)
find rank number from grid coordinate.
Definition: communicator.cpp:119
Communicator::Communicator
Communicator(const Communicator &)
Definition: communicator.h:214
bridge_defs.h
configure.h
Communicator::~Communicator
~Communicator()
Definition: communicator.h:217