15#if defined(__parallel)
22 const int error = (CMD); \
23 if (MPI_SUCCESS != error) { \
24 fprintf(stderr, "MPI error #%i in %s:%i\n", error, __FILE__, __LINE__); \
25 MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); \
35#if defined(__parallel)
36 CHECK(MPI_Init(argc, argv));
48#if defined(__parallel)
49 CHECK(MPI_Finalize());
58#if defined(__parallel)
59 return MPI_COMM_WORLD;
70#if defined(__parallel)
72 return 0 != fortran_comm ? MPI_Comm_f2c(fortran_comm) : MPI_COMM_NULL;
84#if defined(__parallel)
85 return MPI_Comm_c2f(comm);
97#if defined(__parallel)
99 if (MPI_COMM_NULL != comm) {
100 CHECK(MPI_Comm_rank(comm, &rank));
114#if defined(__parallel)
116 if (MPI_COMM_NULL != comm) {
117 CHECK(MPI_Comm_size(comm, &nranks));
131#if defined(__parallel)
132 CHECK(MPI_Dims_create(nnodes, ndims, dims));
135 for (
int i = 1;
i < ndims;
i++) {
146 const int dims[],
const int periods[],
148#if defined(__parallel)
150 CHECK(MPI_Cart_create(comm_old, ndims, dims, periods, reorder, &comm_cart));
167 int periods[],
int coords[]) {
168#if defined(__parallel)
169 CHECK(MPI_Cart_get(comm, maxdims, dims, periods, coords));
172 for (
int i = 0;
i < maxdims;
i++) {
185#if defined(__parallel)
187 CHECK(MPI_Cart_rank(comm, coords, &rank));
201 const int remain_dims[]) {
202#if defined(__parallel)
204 CHECK(MPI_Cart_sub(comm, remain_dims, &newcomm));
218#if defined(__parallel)
219 CHECK(MPI_Comm_free(comm));
231#if defined(__parallel)
233 CHECK(MPI_Comm_compare(comm1, comm2, &res));
234 return res == MPI_IDENT || res == MPI_CONGRUENT || res == MPI_SIMILAR;
247#if defined(__parallel)
248 if (MPI_COMM_NULL != comm) {
252 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_INT, MPI_MAX, comm));
253 memcpy(values, recvbuf, count *
sizeof(
int));
271#if defined(__parallel)
272 if (MPI_COMM_NULL != comm) {
276 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_UINT64_T, MPI_MAX, comm));
277 memcpy(values, recvbuf, count *
sizeof(uint64_t));
295#if defined(__parallel)
296 if (MPI_COMM_NULL != comm) {
300 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_DOUBLE, MPI_MAX, comm));
301 memcpy(values, recvbuf, count *
sizeof(
double));
318#if defined(__parallel)
319 if (MPI_COMM_NULL != comm) {
323 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_INT, MPI_SUM, comm));
324 memcpy(values, recvbuf, count *
sizeof(
int));
341#if defined(__parallel)
342 if (MPI_COMM_NULL != comm) {
346 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_LONG, MPI_SUM, comm));
347 memcpy(values, recvbuf, count *
sizeof(
long));
365#if defined(__parallel)
366 if (MPI_COMM_NULL != comm) {
370 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_INT64_T, MPI_SUM, comm));
371 memcpy(values, recvbuf, count *
sizeof(int64_t));
389#if defined(__parallel)
390 if (MPI_COMM_NULL != comm) {
394 CHECK(MPI_Allreduce(values, recvbuf, count, MPI_DOUBLE, MPI_SUM, comm));
395 memcpy(values, recvbuf, count *
sizeof(
double));
412 const int dest,
const int sendtag,
void *recvbuf,
413 const int recvcount,
const int source,
415#if defined(__parallel)
417 CHECK(MPI_Sendrecv(sendbuf, sendcount, MPI_BYTE, dest, sendtag, recvbuf,
418 recvcount, MPI_BYTE, source, recvtag, comm, &status));
419 int count_received = 0;
420 CHECK(MPI_Get_count(&status, MPI_BYTE, &count_received));
421 return count_received;
432 fprintf(stderr,
"Error: cp_mpi_sendrecv_byte not available without MPI\n");
442 const int dest,
const int sendtag,
double *recvbuf,
443 const int recvcount,
const int source,
445#if defined(__parallel)
447 CHECK(MPI_Sendrecv(sendbuf, sendcount, MPI_DOUBLE, dest, sendtag, recvbuf,
448 recvcount, MPI_DOUBLE, source, recvtag, comm, &status));
450 CHECK(MPI_Get_count(&status, MPI_DOUBLE, &count_received));
451 return count_received;
462 fprintf(stderr,
"Error: cp_mpi_sendrecv_double not available without MPI\n");
473#if defined(__parallel)
474 CHECK(MPI_Alltoall(sendbuf, sendcount, MPI_INT, recvbuf, recvcount, MPI_INT,
478 assert(sendcount == recvcount);
479 memcpy(recvbuf, sendbuf, sendcount *
sizeof(
int));
488 const int *sdispls,
void *recvbuf,
489 const int *recvcounts,
const int *rdispls,
491#if defined(__parallel)
492 CHECK(MPI_Alltoallv(sendbuf, sendcounts, sdispls, MPI_BYTE, recvbuf,
493 recvcounts, rdispls, MPI_BYTE, comm));
496 assert(sendcounts[0] == recvcounts[0]);
497 assert(sdispls[0] == 0 && rdispls[0] == 0);
498 memcpy(recvbuf, sendbuf, sendcounts[0]);
507 const int *sdispls,
double *recvbuf,
508 const int *recvcounts,
const int *rdispls,
510#if defined(__parallel)
511 CHECK(MPI_Alltoallv(sendbuf, sendcounts, sdispls, MPI_DOUBLE, recvbuf,
512 recvcounts, rdispls, MPI_DOUBLE, comm));
515 assert(sendcounts[0] == recvcounts[0]);
516 assert(sdispls[0] == 0 && rdispls[0] == 0);
517 memcpy(recvbuf, sendbuf, sendcounts[0] *
sizeof(
double));
527#if DBM_ALLOC_MPI && defined(__parallel)
528 CHECK(MPI_Alloc_mem((MPI_Aint)size, MPI_INFO_NULL, &result));
529#elif DBM_ALLOC_OPENMP && (201811 <= _OPENMP)
530 result = omp_alloc(size, omp_null_allocator);
532 result = malloc(size);
542#if DBM_ALLOC_MPI && defined(__parallel)
543 CHECK(MPI_Free_mem(mem));
544#elif DBM_ALLOC_OPENMP && (201811 <= _OPENMP)
545 omp_free(mem, omp_null_allocator);
int cp_mpi_comm_size(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_size.
void cp_mpi_free_mem(void *mem)
Wrapper around MPI_Free_mem.
void cp_mpi_max_int(int *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_INT.
void cp_mpi_sum_double(double *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_DOUBLE.
cp_mpi_comm_t cp_mpi_cart_create(const cp_mpi_comm_t comm_old, const int ndims, const int dims[], const int periods[], const int reorder)
Wrapper around MPI_Cart_create.
int cp_mpi_sendrecv_byte(const void *sendbuf, const int sendcount, const int dest, const int sendtag, void *recvbuf, const int recvcount, const int source, const int recvtag, const cp_mpi_comm_t comm)
Wrapper around MPI_Sendrecv for datatype MPI_BYTE.
void cp_mpi_alltoallv_double(const double *sendbuf, const int *sendcounts, const int *sdispls, double *recvbuf, const int *recvcounts, const int *rdispls, const cp_mpi_comm_t comm)
Wrapper around MPI_Alltoallv for datatype MPI_DOUBLE.
int cp_mpi_cart_rank(const cp_mpi_comm_t comm, const int coords[])
Wrapper around MPI_Cart_rank.
void cp_mpi_init(int *argc, char ***argv)
Wrapper around MPI_Init.
int cp_mpi_comm_c2f(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_c2f.
void * cp_mpi_alloc_mem(size_t size)
Wrapper around MPI_Alloc_mem.
void cp_mpi_max_uint64(uint64_t *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_UINT64_T.
cp_mpi_comm_t cp_mpi_get_comm_world(void)
Returns MPI_COMM_WORLD.
void cp_mpi_cart_get(const cp_mpi_comm_t comm, int maxdims, int dims[], int periods[], int coords[])
Wrapper around MPI_Cart_get.
void cp_mpi_max_double(double *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_MAX and datatype MPI_DOUBLE.
void cp_mpi_sum_int64(int64_t *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT64_T.
void cp_mpi_comm_free(cp_mpi_comm_t *comm)
Wrapper around MPI_Comm_free.
void cp_mpi_alltoall_int(const int *sendbuf, const int sendcount, int *recvbuf, const int recvcount, const cp_mpi_comm_t comm)
Wrapper around MPI_Alltoall for datatype MPI_INT.
void cp_mpi_dims_create(const int nnodes, const int ndims, int dims[])
Wrapper around MPI_Dims_create.
bool cp_mpi_comms_are_similar(const cp_mpi_comm_t comm1, const cp_mpi_comm_t comm2)
Wrapper around MPI_Comm_compare.
void cp_mpi_sum_int(int *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_INT.
void cp_mpi_sum_long(long *values, const int count, const cp_mpi_comm_t comm)
Wrapper around MPI_Allreduce for op MPI_SUM and datatype MPI_LONG.
void cp_mpi_alltoallv_byte(const void *sendbuf, const int *sendcounts, const int *sdispls, void *recvbuf, const int *recvcounts, const int *rdispls, const cp_mpi_comm_t comm)
Wrapper around MPI_Alltoallv for datatype MPI_BYTE.
void cp_mpi_finalize(void)
Wrapper around MPI_Finalize.
cp_mpi_comm_t cp_mpi_comm_f2c(const int fortran_comm)
Wrapper around MPI_Comm_f2c.
cp_mpi_comm_t cp_mpi_cart_sub(const cp_mpi_comm_t comm, const int remain_dims[])
Wrapper around MPI_Cart_sub.
int cp_mpi_sendrecv_double(const double *sendbuf, const int sendcount, const int dest, const int sendtag, double *recvbuf, const int recvcount, const int source, const int recvtag, const cp_mpi_comm_t comm)
Wrapper around MPI_Sendrecv for datatype MPI_DOUBLE.
int cp_mpi_comm_rank(const cp_mpi_comm_t comm)
Wrapper around MPI_Comm_rank.
static void const int const int i