Reputation: 134
The question says it all. I have three communicators(Groups are also available). Now I want to call the a function just for one communication subset. That is mask the function for other subsets. Is this possible or should I explicitly right a loop and check for the existence of the current process in the group and then call the function.
Thanks,
Upvotes: 0
Views: 184
Reputation: 9311
Are you able to modify the code where the three communicators are created? In that case I recommend you add a variable (i.e. my_group
as Hristo suggested) that saves the group rank for the rest of the program's runtime. So whenever you need to call a group (or communicator)-specific function, you just check group_rank
.
Rationale
Most MPI programs tend to have some sort of global my_rank
variable anyways (which stores the process's rank), so adding a my_group
would be in line with this programming strategy.
Upvotes: 1
Reputation: 74355
There is no way to call a function over all members of a subcommunicator apart from abusing user-defined reduction operators in MPI_Allreduce()
. The cleanest thing to do is:
int group_rank;
// Test if current process belongs to "group"
MPI_Group_rank(group, &group_rank);
if (group_rank != MPI_UNDEFINED)
call_the_function();
Upvotes: 1