24 #include <hwi/include/bqc/A2_inlines.h>
25 #define CLOCKRATE 1.6e9;
39 #ifdef ENABLE_MULTI_INSTANCE
40 int Communicator_impl::m_n_instance = 1;
41 int Communicator_impl::m_instance_id = 0;
44 int Communicator_impl::m_global_rank = 0;
45 int Communicator_impl::m_global_size = 1;
61 int required = MPI_THREAD_FUNNELED;
63 MPI_Init_thread(pargc, pargv, required, &provided);
64 if (provided < required) {
66 "MPI implementation provides insufficient threading support.\n"
67 "required = %d, provided = %d : (SINGLE, FUNNELED, SERIALIZED, MULT\
68 IPLE) = (%d, %d, %d, %d)\n",
72 MPI_THREAD_SERIALIZED,
76 MPI_Barrier(MPI_COMM_WORLD);
82 m_global_size = BGNET_Procs();
83 m_global_rank = BGNET_Rank();
111 #ifdef ENABLE_MULTI_INSTANCE
112 if ((ninstance == 0) || (m_global_size % ninstance != 0)) {
113 printf(
"%s: invalid number of instance: %d\n",
"Communicator::init", ninstance);
117 if (ninstance != 1) {
118 printf(
"%s: sorry, multi-instance is disabled.\n",
"Communicator::init");
122 m_n_instance = ninstance;
124 int gsize = m_global_size / ninstance;
125 m_instance_id = m_global_rank / gsize;
139 int N_send_buf = BGNET_GetNumInjBuffer();
140 int N_fifo = BGNET_GetNumInjFIFO();
141 int N_recv_buf = BGNET_GetNumRecBuffer();
142 int N_group = BGNET_GetNumGroup();
143 int N_counter = BGNET_GetNumRecCounter();
147 vout.
general(vl,
" Number of send buffer: %d\n", N_send_buf);
148 vout.
general(vl,
" Number of recv buffer: %d\n", N_recv_buf);
150 vout.
general(vl,
" Number of group: %d\n", N_group);
151 vout.
general(vl,
" Number of counter: %d\n", N_counter);
163 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
195 bool Communicator_impl::is_primary_master()
197 return m_global_rank == 0;
201 #ifdef ENABLE_MULTI_INSTANCE
203 int Communicator_impl::self_global()
205 return m_global_rank;
210 int Communicator_impl::world_id()
212 return m_instance_id;
221 BGNET_GlobalBarrier();
226 #ifdef ENABLE_MULTI_INSTANCE
228 int Communicator_impl::sync_global()
231 BGNET_GlobalBarrier();
242 BGNET_BCast(data, count, BGNET_COLLECTIVE_BYTE, sender,
251 void *recv_buf,
void *send_buf,
252 int idir,
int ipm,
int itag)
259 assert(ipm == 1 || ipm == -1);
262 memcpy(recv_buf, send_buf, size);
277 return BGNET_Sendrecv(0, send_buf, size, p_send, recv_buf, size, p_recv);
284 void *recv_buf,
void *send_buf,
285 int send_to,
int recv_from,
int tag)
307 if (send_to == recv_from) {
308 memcpy(recv_buf, send_buf, size);
310 if (
self() == recv_from)
311 BGNET_Send(0, send_buf, size, send_to);
313 if (
self() == send_to)
314 BGNET_Recv(0, recv_buf, size, recv_from);
326 void *recv_buf,
void *send_buf,
327 int type,
int op,
int pComm)
331 BGNET_AllReduce(send_buf, recv_buf, count, type, op, BGNET_COMM_WORLD);
344 BGNET_BCast(data, count, BGNET_COLLECTIVE_DOUBLE, sender,
356 BGNET_BCast(data, count, BGNET_COLLECTIVE_INT32, sender,
377 if (
sizeof(
size_t) == 4) {
378 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT32, sender,
380 }
else if (
sizeof(
size_t) == 8) {
381 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT64, sender,
393 int size2 = (size + 1) / 4;
394 if ((size + 1) % 4 != 0) size2 += 1;
396 char *buf =
new char[size2];
397 memset(buf,
'\0', size2);
401 data.copy(buf, size, 0);
406 BGNET_BCast((
int *)buf, size2 / 4, BGNET_COLLECTIVE_INT32, sender,
411 data.assign(buf, size);
425 uint64_t clock = GetTimeBase();
437 #ifdef ENABLE_MULTI_INSTANCE
438 printf(
"global_rank=%2d/%2d: ngrid=%d, grid_id=%d: grid_rank=%2d/%2d\n",
439 m_global_rank, m_global_size,
440 m_n_instance, m_instance_id,
443 printf(
"grid_rank=%2d/%2d\n",
static int send_1to1(size_t size, void *recv_buf, void *send_buf, int send_to, int recv_from, int tag)
static int broadcast(size_t size, void *data, int sender)
static int layout_setup()
layout_setup() – setup logical layout
static void abort()
terminate communicator
static int self()
rank within small world.
static int broadcast_double(int count, double *data, int sender)
void general(const char *format,...)
static Bridge::VerboseLevel Vlevel()
static int sync()
synchronize within small world.
static int setup(int ninstance=1)
static int status()
for debug
static int broadcast_int(int count, int *data, int sender)
static bool is_primary()
info about rank
static int reduce(int count, void *recv_buf, void *send_buf, int type, int op, int pattern)
static int init(int *pargc, char ***pargv)
static int m_comm
instead of MPI_Comm m_comm;
static int * m_grid_dims
grid dimensions in directions.
static int broadcast_string(int count, string &data, int sender)
for specific datatypes
static std::terminate_handler default_handler
static double get_time()
for getting time interval using clock count.
static int * m_ipe_up
rank of upward neighbour in directions.
static int tag(int rank, int idir, int ipm)
static int * m_ipe_dn
rank of downward neighbour in directions.
static int exchange(size_t size, void *recv_buf, void *send_buf, int idir, int ipm, int tag)