34 fprintf(stderr,
"abort() called. terminate.\n");
41 #ifdef ENABLE_MULTI_INSTANCE
42 int Communicator_impl::m_n_instance = 1;
43 int Communicator_impl::m_instance_id = 0;
46 int Communicator_impl::m_global_rank = 0;
47 int Communicator_impl::m_global_size = 1;
61 MPI_Init(pargc, pargv);
63 MPI_Comm_size(MPI_COMM_WORLD, &m_global_size);
64 MPI_Comm_rank(MPI_COMM_WORLD, &m_global_rank);
71 MPI_Comm_dup(MPI_COMM_WORLD, &
m_comm);
80 return MPI_Finalize();
88 #ifdef ENABLE_MULTI_INSTANCE
89 if ((ninstance == 0) || (m_global_size % ninstance != 0)) {
90 printf(
"%s: invalid number of instance: %d\n",
"Communicator::init", ninstance);
94 m_n_instance = ninstance;
96 int gsize = m_global_size / ninstance;
97 m_instance_id = m_global_rank / gsize;
99 MPI_Comm_split(MPI_COMM_WORLD, m_instance_id, 0 , &
m_comm);
105 MPI_Comm_dup(MPI_COMM_WORLD, &
m_comm);
122 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
149 bool Communicator_impl::is_primary_master()
151 return m_global_rank == 0;
155 #ifdef ENABLE_MULTI_INSTANCE
157 int Communicator_impl::self_global()
159 return m_global_rank;
163 int Communicator_impl::world_id()
165 return m_instance_id;
178 return MPI_Barrier(
m_comm);
182 #ifdef ENABLE_MULTI_INSTANCE
184 int Communicator_impl::sync_global()
187 return MPI_Barrier(MPI_COMM_WORLD);
200 return MPI_Bcast(data, size, MPI_BYTE, sender,
m_comm);
211 assert(ipm == 1 || ipm == -1);
214 memcpy(recv_buf, send_buf, size);
230 send_buf, size, MPI_BYTE, p_send, tag_send,
231 recv_buf, size, MPI_BYTE, p_recv, tag_recv,
242 if (send_to == recv_from) {
243 memcpy(recv_buf, send_buf, size);
245 if (
self() == recv_from)
246 MPI_Send(send_buf, size, MPI_BYTE, send_to, tag,
m_comm);
248 if (
self() == send_to)
249 MPI_Recv(recv_buf, size, MPI_BYTE, recv_from, tag,
m_comm, &status);
261 return MPI_Allreduce((
void *)send_buf, (
void *)recv_buf, count, type, op,
Layout::m_sub_comm[pattern]);
279 MPI_Bcast((
void *)&size,
sizeof(
size_t), MPI_BYTE, sender,
m_comm);
282 char *buf =
new char[size + 1];
283 memset(buf,
'\0', size + 1);
286 data.copy(buf, size, 0);
290 int retv = MPI_Bcast((
void *)buf, size, MPI_BYTE, sender,
m_comm);
317 #ifdef ENABLE_MULTI_INSTANCE
318 printf(
"global_rank=%2d/%2d: ngrid=%d, grid_id=%d: grid_rank=%2d/%2d\n",
319 m_global_rank, m_global_size,
320 m_n_instance, m_instance_id,
324 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 sync()
synchronize within small world.
static int setup(int ninstance=1)
static int status()
for debug
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 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)
static std::terminate_handler default_handler