MPI_Group_incl
MPI_Group_incl
MPI_Group_incl creates new group from existing group and specifies member processes.
Fortran Syntax
Subroutine MPI_Group_incl(group, count, members, new_group, ierr)
C Syntax
int MPI_Group_incl(MPI_Group group, int count, int *members,
MPI_Group *new_group)
Example in Fortran
include "mpif.h"
implicit none
integer group_world, odd_group, even_group
integer i, p, Neven, Nodd, members(0:7), ierr
call MPI_Comm_size(MPI_COMM_WORLD, p, ierr)
call MPI_Comm_group(MPI_COMM_WORLD,group_world,ierr)
Neven = (p + 1)/2 ! processes of MPI_COMM_WORLD are divided
Nodd = p - Neven ! into odd- and even-numbered groups
do i=0,Neven - 1 ! "members" determines members of even_group
members(i) = 2*i
enddo
call MPI_Group_incl(group_world, Neven, members, even_group, ierr)
|
Example in C
#include "mpi.h";
MPI_Group group_world, odd_group, even_group;;
int i, p, Neven, Nodd, members[8], ierr;
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_group(MPI_COMM_WORLD, &group_world);
Neven = (p+1)/2; /* processes of MPI_COMM_WORLD are divided */
Nodd = p - Neven; /* into odd- and even-numbered groups */
for (i=0; i<Neven; i++) { /* "members" determines members of even_group */
members[i] = 2*i;
};
MPI_Group_incl(group_world, Neven, members, &even_group);
|
In the above example, we create a new group whose members are the even-numbered processes of the communicator MPI_COMM_WORLD. These group members are ranked in ascending order (0, 1, 2, …, Neven-1) corresponding to the process ranks as defined by (members(0), members(1), …, members(Neven-1)) in the original group (i.e., MPI_COMM_WORLD). In this example, members(0) = 0, members(1) = 2, members(2) = 4, and so on. The same task could also be accomplished by a similar routine, MPI_Group_excl.