What is a simple way to create a (sub)communicator containing consecutive ranks [rStart
, ..., last rank of MPI_COMM_WORLD
] of MPI_COMM_WORLD
?
rStart
is >= 0, i.e., first rStart
ranks need to be excluded.
The simplest code is to have
MPI_Comm_split(MPI_COMM_WORLD, rank < rStart, rank, &new_comm);
run on all ranks of MPI_COMM_WORLD
. It will create two communicators - all ranks starting with rStart
will get the one you desire, the others can just MPI_Comm_free
their communicator.
If you cannot easily have the excluded ranks run the same code, you can use MPI_Comm_create_group
, but then you have to also create the group first.