0

I am trying to set an MPI_Barrier for a subset of the processes in MPI_COMM_WORLD, as follows:

//Get MPI rank
MPI_Comm_rank(MPI_COMM_WORLD, &current_rank);

//Get group of processes in MPI_COMM_WORLD
MPI_Comm_group(MPI_COMM_WORLD, &world_group);

//Create group with specified ranks 
MPI_Group_incl(world_group, num, ranks, &my_group);

//Create a new communicator based on my_group   
MPI_Comm_create(MPI_COMM_WORLD, my_group, &MY_COMM);

MPI_Barrier(MY_COMM);

(where ranks is an array of the required ranks, and num is the size of this array) The above code results in a NULL communicator error at the MPI_Barrier.

I have also tried the following:

MPI_Comm_split(MPI_COMM_WORLD, color, current_rank, &MY_COMM);

MPI_Barrier(MY_COMM);

(where color is set to 1 if the current rank is in the required subset, and 0 otherwise) The above code has no effect, the barrier doesn't seem to be working at all.

Any help would be greatly appreciated, thanks :)

Gabyazz
  • 1
  • 4
  • 2
    Please post the actual error message and a [mcve]. What does "has no effect" mean? What is the expected and actual behaviour? Which processes are calling above code sequences? Always check the return value of MPI functions for errors. `MY_COM` is not valid to use on ranks that are not part of `my_group `! – Zulan May 30 '16 at 16:49
  • As noted by @Zulan, `MPI_Comm_create` and `MPI_Comm_split` (when called with `color` set to `MPI_UNDEFINED`) return `MPI_COMM_NULL` in ranks that are not members of the new communicator. You must add a check for that before calling `MPI_Barrier`. – Hristo Iliev May 30 '16 at 18:19

0 Answers0