25 #include <hwi/include/bqc/A2_inlines.h>
26 #define CLOCKRATE 1.6e9;
42 static const char rcsid[] =
"$Id: communicator_bgnet.cpp 1145 2014-09-16 09:27:22Z namekawa $";
52 fprintf(stderr,
"abort() called. terminate.\n");
59 #ifdef ENABLE_MULTI_INSTANCE
60 int Communicator_impl::m_n_instance = 1;
61 int Communicator_impl::m_instance_id = 0;
64 int Communicator_impl::m_global_rank = 0;
65 int Communicator_impl::m_global_size = 1;
81 int required = MPI_THREAD_FUNNELED;
83 MPI_Init_thread(pargc, pargv, required, &provided);
84 if (provided < required) {
86 "MPI implementation provides insufficient threading support.\n"
87 "required = %d, provided = %d : (SINGLE, FUNNELED, SERIALIZED, MULT\
88 IPLE) = (%d, %d, %d, %d)\n",
92 MPI_THREAD_SERIALIZED,
96 MPI_Barrier(MPI_COMM_WORLD);
102 m_global_size = BGNET_Procs();
103 m_global_rank = BGNET_Rank();
131 #ifdef ENABLE_MULTI_INSTANCE
132 if ((ninstance == 0) || (m_global_size % ninstance != 0)) {
133 printf(
"%s: invalid number of instance: %d\n",
"Communicator::init", ninstance);
137 if (ninstance != 1) {
138 printf(
"%s: sorry, multi-instance is disabled.\n",
"Communicator::init");
142 m_n_instance = ninstance;
144 int gsize = m_global_size / ninstance;
145 m_instance_id = m_global_rank / gsize;
160 int N_send_buf = BGNET_GetNumInjBuffer();
161 int N_fifo = BGNET_GetNumInjFIFO();
162 int N_recv_buf = BGNET_GetNumRecBuffer();
163 int N_group = BGNET_GetNumGroup();
164 int N_counter = BGNET_GetNumRecCounter();
168 vout.
general(vl,
" Number of send buffer: %d\n", N_send_buf);
169 vout.
general(vl,
" Number of recv buffer: %d\n", N_recv_buf);
171 vout.
general(vl,
" Number of group: %d\n", N_group);
172 vout.
general(vl,
" Number of counter: %d\n", N_counter);
216 bool Communicator_impl::is_primary_master()
218 return m_global_rank == 0;
222 #ifdef ENABLE_MULTI_INSTANCE
224 int Communicator_impl::self_global()
226 return m_global_rank;
231 int Communicator_impl::world_id()
233 return m_instance_id;
244 BGNET_GlobalBarrier();
249 #ifdef ENABLE_MULTI_INSTANCE
251 int Communicator_impl::sync_global()
254 BGNET_GlobalBarrier();
267 BGNET_BCast(data, count, BGNET_COLLECTIVE_BYTE, sender,
276 void *recv_buf,
void *send_buf,
277 int idir,
int ipm,
int itag)
284 assert(ipm == 1 || ipm == -1);
287 memcpy(recv_buf, send_buf, size);
302 return BGNET_Sendrecv(0, send_buf, size, p_send, recv_buf, size, p_recv);
309 void *recv_buf,
void *send_buf,
310 int send_to,
int recv_from,
int tag)
332 if (send_to == recv_from) {
333 memcpy(recv_buf, send_buf, size);
335 if (
self() == recv_from)
336 BGNET_Send(0, send_buf, size, send_to);
338 if (
self() == send_to)
339 BGNET_Recv(0, recv_buf, size, recv_from);
351 void *recv_buf,
void *send_buf,
352 int type,
int op,
int pComm)
356 BGNET_AllReduce(send_buf, recv_buf, count, type, op, BGNET_COMM_WORLD);
369 BGNET_BCast(data, count, BGNET_COLLECTIVE_DOUBLE, sender,
381 BGNET_BCast(data, count, BGNET_COLLECTIVE_INT32, sender,
402 if (
sizeof(
size_t) == 4) {
403 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT32, sender,
405 }
else if (
sizeof(
size_t) == 8) {
406 BGNET_BCast(&size, 1, BGNET_COLLECTIVE_INT64, sender,
418 int size2 = (size + 1) / 4;
419 if ((size + 1) % 4 != 0) size2 += 1;
421 char *buf =
new char[size2];
422 memset(buf,
'\0', size2);
426 data.copy(buf, size, 0);
431 BGNET_BCast((
int *)buf, size2 / 4, BGNET_COLLECTIVE_INT32, sender,
436 data.assign(buf, size);
450 uint64_t clock = GetTimeBase();
462 #ifdef ENABLE_MULTI_INSTANCE
463 printf(
"global_rank=%2d/%2d: ngrid=%d, grid_id=%d: grid_rank=%2d/%2d\n",
464 m_global_rank, m_global_size,
465 m_n_instance, m_instance_id,
469 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 const char rcsid[]
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)