0

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,

Armin
  • 134
  • 3
  • 16
  • Hmmmmm... Back in the days when I was doing this, I was required to simulate ring, tor and hypercube interconnection between nodes. Since MPI allows all nodes to communicate with each other, I used modulo N algebra to select which nodes get to communicate at a certain step. I remember that it was quite tricky to get it right for a hypercube. If you're interested, I can provide a link later to code which I used to perform matrix multiplication on a ring (I think). Just let me know. – Mihai Todor Jul 18 '12 at 16:20

2 Answers2

1

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();
Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
1

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.

  • Yep got it! We are developing the code so everything is possible! I just thought maybe there are built-in callback functions in MPI library.... apparently not. It would be extremely helpful though!!! thanks anyway :) – Armin Jul 18 '12 at 19:55