13 #include "mpi_utils.h"
14 #include "Utilities.h"
26 MPI_Initialized(&mpi_init);
27 CAROM_VERIFY(mpi_init != 0);
29 int d_num_procs, d_rank;
30 MPI_Comm_rank(comm, &d_rank);
31 MPI_Comm_size(comm, &d_num_procs);
33 int local_dim = dim / d_num_procs;
34 if (dim % d_num_procs > d_rank)
45 MPI_Initialized(&mpi_init);
46 CAROM_VERIFY(mpi_init != 0);
48 int d_num_procs, d_rank;
49 MPI_Comm_rank(comm, &d_rank);
50 MPI_Comm_size(comm, &d_num_procs);
52 offsets.resize(d_num_procs + 1);
53 offsets[d_rank] = local_dim;
54 CAROM_VERIFY(MPI_Allgather(MPI_IN_PLACE, 1, MPI_INT,
55 &offsets[0], 1, MPI_INT,
56 comm) == MPI_SUCCESS);
59 for (
int i = 0; i < d_num_procs; i++)
61 offsets[d_num_procs] = dim;
63 for (
int i = d_num_procs - 1; i >= 0; i--)
64 offsets[i] = offsets[i + 1] - offsets[i];
66 CAROM_VERIFY(offsets[0] == 0);
74 MPI_Allreduce(MPI_IN_PLACE, p, 2, MPI_INT, MPI_MIN, comm);
75 return (p[0] == -p[1]);
int split_dimension(const int dim, const MPI_Comm &comm)
Distribute the global size dim into MPI processes as equally as possible.
bool is_same(int x, const MPI_Comm &comm)
Check if an integer is equal over all MPI processes.
int get_global_offsets(const int local_dim, std::vector< int > &offsets, const MPI_Comm &comm)
Save integer offsets for each MPI rank under MPI communicator comm, where each rank as the size of lo...