MPI_Barrier with custom MPI Communicator

425 Views Asked by At

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 :)

0

There are 0 best solutions below