32 fprintf(stderr,
"abort() called. terminate.\n");
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;
58 MPI_Init(pargc, pargv);
60 MPI_Comm_size(MPI_COMM_WORLD, &m_global_size);
61 MPI_Comm_rank(MPI_COMM_WORLD, &m_global_rank);
68 MPI_Comm_dup(MPI_COMM_WORLD, &
m_comm);
78 return MPI_Finalize();
87 #ifdef ENABLE_MULTI_INSTANCE
88 if ((ninstance == 0) || (m_global_size % ninstance != 0)) {
89 printf(
"%s: invalid number of instance: %d\n",
"Communicator::init", ninstance);
93 m_n_instance = ninstance;
95 int gsize = m_global_size / ninstance;
96 m_instance_id = m_global_rank / gsize;
98 MPI_Comm_split(MPI_COMM_WORLD, m_instance_id, 0 , &
m_comm);
104 MPI_Comm_dup(MPI_COMM_WORLD, &
m_comm);
122 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
150 bool Communicator_impl::is_primary_master()
152 return m_global_rank == 0;
157 #ifdef ENABLE_MULTI_INSTANCE
159 int Communicator_impl::self_global()
161 return m_global_rank;
166 int Communicator_impl::world_id()
168 return m_instance_id;
177 return MPI_Barrier(
m_comm);
182 #ifdef ENABLE_MULTI_INSTANCE
184 int Communicator_impl::sync_global()
187 return MPI_Barrier(MPI_COMM_WORLD);
196 return MPI_Bcast(data, size, MPI_BYTE, sender,
m_comm);
208 assert(ipm == 1 || ipm == -1);
211 memcpy(recv_buf, send_buf, size);
227 send_buf, size, MPI_BYTE, p_send, tag_send,
228 recv_buf, size, MPI_BYTE, p_recv, tag_recv,
240 if (send_to == recv_from) {
241 memcpy(recv_buf, send_buf, size);
243 if (
self() == recv_from)
244 MPI_Send(send_buf, size, MPI_BYTE, send_to, tag,
m_comm);
246 if (
self() == send_to)
247 MPI_Recv(recv_buf, size, MPI_BYTE, recv_from, tag,
m_comm, &status);
260 return MPI_Allreduce((
void *)send_buf, (
void *)recv_buf, count, type, op,
Layout::m_sub_comm[pattern]);
277 MPI_Bcast((
void *)&size,
sizeof(
size_t), MPI_BYTE, sender,
m_comm);
280 char *buf =
new char[size + 1];
281 memset(buf,
'\0', size + 1);
284 data.copy(buf, size, 0);
288 int retv = MPI_Bcast((
void *)buf, size, MPI_BYTE, sender,
m_comm);
313 #ifdef ENABLE_MULTI_INSTANCE
314 printf(
"global_rank=%2d/%2d: ngrid=%d, grid_id=%d: grid_rank=%2d/%2d\n",
315 m_global_rank, m_global_size,
316 m_n_instance, m_instance_id,
320 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