24 #include <hwi/include/bqc/A2_inlines.h>
25 #define CLOCKRATE 1.6e9;
43 fprintf(stderr,
"abort() called. terminate.\n");
50 #ifdef ENABLE_MULTI_INSTANCE
51 int Communicator_impl::m_n_instance = 1;
52 int Communicator_impl::m_instance_id = 0;
55 int Communicator_impl::m_global_rank = 0;
56 int Communicator_impl::m_global_size = 1;
72 int required = MPI_THREAD_FUNNELED;
74 MPI_Init_thread(pargc, pargv, required, &provided);
75 if (provided < required) {
77 "MPI implementation provides insufficient threading support.\n"
78 "required = %d, provided = %d : (SINGLE, FUNNELED, SERIALIZED, MULT\
79 IPLE) = (%d, %d, %d, %d)\n",
83 MPI_THREAD_SERIALIZED,
87 MPI_Barrier(MPI_COMM_WORLD);
93 m_global_size = BGNET_Procs();
94 m_global_rank = BGNET_Rank();
122 #ifdef ENABLE_MULTI_INSTANCE
123 if ((ninstance == 0) || (m_global_size % ninstance != 0)) {
124 printf(
"%s: invalid number of instance: %d\n",
"Communicator::init", ninstance);
128 if (ninstance != 1) {
129 printf(
"%s: sorry, multi-instance is disabled.\n",
"Communicator::init");
133 m_n_instance = ninstance;
135 int gsize = m_global_size / ninstance;
136 m_instance_id = m_global_rank / gsize;
151 int N_send_buf = BGNET_GetNumInjBuffer();
152 int N_fifo = BGNET_GetNumInjFIFO();
153 int N_recv_buf = BGNET_GetNumRecBuffer();
154 int N_group = BGNET_GetNumGroup();
155 int N_counter = BGNET_GetNumRecCounter();
159 vout.
general(vl,
" Number of send buffer: %d\n", N_send_buf);
160 vout.
general(vl,
" Number of recv buffer: %d\n", N_recv_buf);
162 vout.
general(vl,
" Number of group: %d\n", N_group);
163 vout.
general(vl,
" Number of counter: %d\n", N_counter);
175 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
207 bool Communicator_impl::is_primary_master()
209 return m_global_rank == 0;
213 #ifdef ENABLE_MULTI_INSTANCE
215 int Communicator_impl::self_global()
217 return m_global_rank;
222 int Communicator_impl::world_id()
224 return m_instance_id;
233 BGNET_GlobalBarrier();
238 #ifdef ENABLE_MULTI_INSTANCE
240 int Communicator_impl::sync_global()
243 BGNET_GlobalBarrier();
254 BGNET_BCast(data, count, BGNET_COLLECTIVE_BYTE, sender,
263 void *recv_buf,
void *send_buf,
264 int idir,
int ipm,
int itag)
271 assert(ipm == 1 || ipm == -1);
274 memcpy(recv_buf, send_buf, size);
289 return BGNET_Sendrecv(0, send_buf, size, p_send, recv_buf, size, p_recv);
296 void *recv_buf,
void *send_buf,
297 int send_to,
int recv_from,
int tag)
319 if (send_to == recv_from) {
320 memcpy(recv_buf, send_buf, size);
322 if (
self() == recv_from)
323 BGNET_Send(0, send_buf, size, send_to);
325 if (
self() == send_to)
326 BGNET_Recv(0, recv_buf, size, recv_from);
338 void *recv_buf,
void *send_buf,
339 int type,
int op,
int pComm)
343 BGNET_AllReduce(send_buf, recv_buf, count, type, op, BGNET_COMM_WORLD);
356 BGNET_BCast(data, count, BGNET_COLLECTIVE_DOUBLE, sender,
368 BGNET_BCast(data, count, BGNET_COLLECTIVE_INT32, sender,
389 if (
sizeof(
size_t) == 4) {
390 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT32, sender,
392 }
else if (
sizeof(
size_t) == 8) {
393 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT64, sender,
405 int size2 = (size + 1) / 4;
406 if ((size + 1) % 4 != 0) size2 += 1;
408 char *buf =
new char[size2];
409 memset(buf,
'\0', size2);
413 data.copy(buf, size, 0);
418 BGNET_BCast((
int *)buf, size2 / 4, BGNET_COLLECTIVE_INT32, sender,
423 data.assign(buf, size);
437 uint64_t clock = GetTimeBase();
449 #ifdef ENABLE_MULTI_INSTANCE
450 printf(
"global_rank=%2d/%2d: ngrid=%d, grid_id=%d: grid_rank=%2d/%2d\n",
451 m_global_rank, m_global_size,
452 m_n_instance, m_instance_id,
456 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)