64 MyMPI(
const MPI_Comm& comm_world,
int nplanes){
66 MPI_Comm_size( comm_world, &
nranks );
72 printf(
"\nERROR: Invalid number of MPI ranks: must be divisible by sml_nphi_total\n");
73 printf(
"#MPI ranks=%d",
nranks);
74 printf(
"#sml_nphi_total=%d", nplanes);
80 int ranks_per_plane =
nranks/nplanes;
88 std::vector<int> new_sml_comm_ranks(
nranks);
90 for(
int j=0; j<ranks_per_plane; j++){
91 for(
int i=0; i<nplanes; i++){
92 new_sml_comm_ranks[ranks_per_plane*i + j] = k;
99 MPI_Group mpi_comm_world_group;
100 MPI_Comm_group(comm_world, &mpi_comm_world_group);
103 MPI_Group_incl(mpi_comm_world_group,
nranks, new_sml_comm_ranks.data(), &
group);
106 MPI_Comm_create(comm_world,
group, &
comm);
112 int plane_0_pe=int(
my_rank/ranks_per_plane)*ranks_per_plane;
113 std::vector<int> plane_ranks(ranks_per_plane);
114 for(
int j=0; j<ranks_per_plane; j++){
115 plane_ranks[j]=plane_0_pe + j;
119 MPI_Group plane_group;
120 MPI_Group_incl(
group, ranks_per_plane, plane_ranks.data(), &plane_group);
131 std::vector<int> intpl_ranks(nplanes);
132 for(
int i=0; i<nplanes; i++){
137 MPI_Group intpl_group;
138 MPI_Group_incl(
group, nplanes, intpl_ranks.data(), &intpl_group);
178 template <
typename F>
182 MPI_Comm_rank( comm, &my_rank );
183 MPI_Comm_size( comm, &n_ranks );
190 for(
int i=0; i<n_ranks; i++){
191 if(my_rank==i) func(i);
MPI_Comm SML_COMM_WORLD
Definition: my_mpi.cpp:4
MPI_Comm plane_comm
Definition: my_mpi.hpp:38
MyMPI(const MPI_Comm &comm_world, int nplanes)
Definition: my_mpi.hpp:64
int my_intpl_rank
Definition: my_mpi.hpp:49
int my_rank
Definition: my_mpi.hpp:24
Definition: my_mpi.hpp:19
void create_comm_world(int color)
Definition: my_mpi.cpp:13
int SML_COMM_SIZE
Definition: my_mpi.cpp:6
MPI_Comm comm
Definition: my_mpi.hpp:21
int my_plane_rank
Definition: my_mpi.hpp:39
int n_plane_ranks
Definition: my_mpi.hpp:40
int SML_COMM_RANK
Definition: my_mpi.cpp:5
void execute_in_rank_order(const MPI_Comm &comm, F func)
Definition: my_mpi.hpp:179
MyMPI()
Definition: my_mpi.hpp:57
MPI_Comm intpl_comm
Definition: my_mpi.hpp:48
void destroy_comm_world()
Definition: my_mpi.cpp:28
MPI_Group group
Definition: my_mpi.hpp:22
int nranks
Definition: my_mpi.hpp:23
int n_intpl_ranks
Definition: my_mpi.hpp:50
MyMPI(int nranks_in)
Definition: my_mpi.hpp:60