Bridge++  Version 1.5.4
 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_defs.h"
19 
20 #include <cstdio>
21 #include <cstdlib>
22 #include <cstddef>
23 #include <vector>
24 #include <string>
25 using std::string;
26 
27 class Channel;
28 
30 
44 // forward declaration
45 //class Channel;
46 
47 class Communicator {
48  public:
50 
59  static int init(int *pargc, char ***pargv);
60 
62 
67  static int finalize();
68 
70 
75  static void abort();
76 
78 
85  static int setup(int ninstance = 1);
86 
95  static int setup(const std::vector<int>& lattice_size,
96  std::vector<int>& grid_size,
97  int ninstance = 1);
98 
99 // info about rank
100  static bool is_primary();
101  static bool is_primary_master();
102 
103  static int self();
104 
105  static int nodeid() { return self(); }
106  static int size();
107 
108 #ifdef ENABLE_MULTI_INSTANCE
109  static int self_global();
110  static int world_id();
111 #endif
112 
113 // layout
114  static int ipe(const int dir);
115  static int npe(const int dir);
116 
117  static int grid_rank(int *rank, const int *grid_coord);
118  static int grid_coord(int *grid_coord, const int rank);
119  static int grid_dims(int *grid_dims);
120 
121 // synchronize
122  static int sync();
123 
124 // synchronize (w/o busy wait)
125  static int sync_usleep();
126 
127 #ifdef ENABLE_MULTI_INSTANCE
128  static int sync_global();
129 #endif
130 
131 // data transfer
132  static int broadcast(int count, double *data, int sender);
133  static int broadcast(int count, float *data, int sender);
134  static int broadcast(int count, int *data, int sender);
135  static int broadcast(int count, string& data, int sender);
136 
137  static int exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag);
138  static int exchange(int count, float *recv_buf, float *send_buf, int idir, int ipm, int tag);
139  static int exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int tag);
140 
141  static int send_1to1(int count, double *recv_buf, double *send_buf, int p_to, int p_from, int tag);
142  static int send_1to1(int count, float *recv_buf, float *send_buf, int p_to, int p_from, int tag);
143  static int send_1to1(int count, int *recv_buf, int *send_buf, int p_to, int p_from, int tag);
144 
145  static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern = 0);
146  static int reduce_sum(int count, float *recv_buf, float *send_buf, int pattern = 0);
147  static int reduce_sum(int count, int *recv_buf, int *send_buf, int pattern = 0);
148 
149  static int reduce_max(int count, double *recv_buf, double *send_buf, int pattern = 0);
150  static int reduce_max(int count, float *recv_buf, float *send_buf, int pattern = 0);
151  static int reduce_max(int count, int *recv_buf, int *send_buf, int pattern = 0);
152 
153  static int reduce_min(int count, double *recv_buf, double *send_buf, int pattern = 0);
154  static int reduce_min(int count, float *recv_buf, float *send_buf, int pattern = 0);
155  static int reduce_min(int count, int *recv_buf, int *send_buf, int pattern = 0);
156 
157  static double reduce_sum(double);
158  static double reduce_max(double);
159  static double reduce_min(double);
160 
161  static float reduce_sum(float);
162  static float reduce_max(float);
163  static float reduce_min(float);
164 
165  static double get_time();
166 
167  // async communication
168  static Channel *send_init(int count, int idir, int ipm);
169  static Channel *recv_init(int count, int idir, int ipm);
170 
171  // async communication with given buffer [2017.09.02 H.Matsufuru]
172  static Channel *send_init(int count, int idir, int ipm, void *buf);
173  static Channel *recv_init(int count, int idir, int ipm, void *buf);
174 
175 // debug
176  static int status();
177 
179 
184  class Base {
185  public:
186  static int broadcast(size_t size, void *data, int sender);
187  static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag);
188 
189  static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag);
190  };
191 
192  private:
193 
195 
204 
206 };
207 #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:47
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:201
Communicator(const Communicator &)
Definition: communicator.h:202
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.
Channel class for asynchronous communication.
Definition: channel.h:48
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 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 double get_time()
obtain a wall-clock time.
static Channel * send_init(int count, int idir, int ipm)
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.
Communicator & operator=(const Communicator &)
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
static int nodeid()
alternative name for self().
Definition: communicator.h:105
static bool is_primary()
check if the present node is primary in small communicator.