Bridge++  Version 1.4.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 "defs.h"
19 
20 #include <cstdio>
21 #include <cstdlib>
22 #include <cstddef>
23 #include <string>
24 using std::string;
25 
26 class Channel;
27 
29 
43 // forward declaration
44 //class Channel;
45 
46 class Communicator {
47  public:
49 
58  static int init(int *pargc, char ***pargv);
59 
61 
66  static int finalize();
67 
69 
74  static void abort();
75 
77 
84  static int setup(int ninstance = 1);
85 
86 // info about rank
87  static bool is_primary();
88  static bool is_primary_master();
89 
90  static int self();
91 
92  static int nodeid() { return self(); }
93  static int size();
94 
95 #ifdef ENABLE_MULTI_INSTANCE
96  static int self_global();
97  static int world_id();
98 #endif
99 
100 // layout
101  static int ipe(const int dir);
102  static int npe(const int dir);
103 
104  static int grid_rank(int *rank, const int *grid_coord);
105  static int grid_coord(int *grid_coord, const int rank);
106  static int grid_dims(int *grid_dims);
107 
108 // synchronize
109  static int sync();
110 
111 #ifdef ENABLE_MULTI_INSTANCE
112  static int sync_global();
113 #endif
114 
115 // data transfer
116  static int broadcast(int count, double *data, int sender);
117  static int broadcast(int count, int *data, int sender);
118  static int broadcast(int count, string& data, int sender);
119 
120  static int exchange(int count, double *recv_buf, double *send_buf, int idir, int ipm, int tag);
121  static int exchange(int count, int *recv_buf, int *send_buf, int idir, int ipm, int tag);
122 
123  static int send_1to1(int count, double *recv_buf, double *send_buf, int p_to, int p_from, int tag);
124  static int send_1to1(int count, int *recv_buf, int *send_buf, int p_to, int p_from, int tag);
125 
126  static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern = 0);
127  static int reduce_sum(int count, int *recv_buf, int *send_buf, int pattern = 0);
128 
129  static int reduce_max(int count, double *recv_buf, double *send_buf, int pattern = 0);
130  static int reduce_max(int count, int *recv_buf, int *send_buf, int pattern = 0);
131 
132  static int reduce_min(int count, double *recv_buf, double *send_buf, int pattern = 0);
133  static int reduce_min(int count, int *recv_buf, int *send_buf, int pattern = 0);
134 
135  static double reduce_sum(double);
136  static double reduce_max(double);
137  static double reduce_min(double);
138 
139  static double get_time();
140 
141  // async communication
142  static Channel *send_init(int count, int idir, int ipm);
143  static Channel *recv_init(int count, int idir, int ipm);
144 
145  // async communication with given buffer [2017.09.02 H.Matsufuru]
146  static Channel *send_init(int count, int idir, int ipm, void* buf);
147  static Channel *recv_init(int count, int idir, int ipm, void* buf);
148 
149 // debug
150  static int status();
151 
153 
158  class Base {
159  public:
160  static int broadcast(size_t size, void *data, int sender);
161  static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag);
162 
163  static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag);
164  };
165 
166  private:
167 
169 
178 
180 };
181 #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:46
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:175
Communicator(const Communicator &)
Definition: communicator.h:176
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:24
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 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:92
static bool is_primary()
check if the present node is primary in small communicator.