1

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.

user2052436
  • 4,321
  • 1
  • 25
  • 46

1 Answers1

2

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.

Zulan
  • 21,896
  • 6
  • 49
  • 109
  • 2
    After reading about `MPI_Comm_split`, I realized that `(rank < rStart ? MPI_UNDEFINED : 0)` is even better for second argument: it will produce `MPI_COMM_NULL` on first ranks. – user2052436 Mar 06 '19 at 19:21