8.3.2. Group Constructors

PreviousUpNext
Up: Group Management Next: Group Destructors Previous: Group Accessors

MPI provides two approaches to constructing groups. In the first approach, MPI procedures are provided to subset and superset existing groups. These constructors construct new groups from existing groups. In the second approach, a group is created using a session handle and associated process set. This second approach is available when using the Sessions Model. With both approaches, these are local operations, and distinct groups may be defined on different MPI processes; an MPI process may also define a group that does not include itself. Consistent definitions are required when groups are used as arguments in communicator creation functions. When using the World Model (Section The World Model) for MPI initialization, the base group, upon which all other groups are defined, is the group associated with the initial communicator MPI_COMM_WORLD (accessible through the function MPI_COMM_GROUP).


Rationale.

In what follows, there is no group duplication function analogous to MPI_COMM_DUP, defined later in this chapter. There is no need for a group duplicator. A group, once created, can have several references to it by making copies of the handle. The following constructors address the need for subsets and supersets of existing groups. ( End of rationale.)

Advice to implementors.

Each group constructor behaves as if it returned a new group object. When this new group is a copy of an existing group, then one can avoid creating such new objects, using a reference-count mechanism. ( End of advice to implementors.)

MPI_COMM_GROUP(comm, group)
IN commcommunicator (handle)
OUT groupgroup corresponding to comm (handle)
C binding
int MPI_Comm_group(MPI_Comm comm, MPI_Group *group)
Fortran 2008 binding
MPI_Comm_group(comm, group, ierror)

TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(MPI_Group), INTENT(OUT) :: group
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_COMM_GROUP(COMM, GROUP, IERROR)

INTEGER COMM, GROUP, IERROR

MPI_COMM_GROUP returns in group a handle to the group of comm.

MPI_GROUP_UNION(group1, group2, newgroup)
IN group1first group (handle)
IN group2second group (handle)
OUT newgroupunion group (handle)
C binding
int MPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_union(group1, group2, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group1, group2
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_UNION(GROUP1, GROUP2, NEWGROUP, IERROR)

INTEGER GROUP1, GROUP2, NEWGROUP, IERROR

MPI_GROUP_INTERSECTION(group1, group2, newgroup)
IN group1first group (handle)
IN group2second group (handle)
OUT newgroupintersection group (handle)
C binding
int MPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_intersection(group1, group2, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group1, group2
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_INTERSECTION(GROUP1, GROUP2, NEWGROUP, IERROR)

INTEGER GROUP1, GROUP2, NEWGROUP, IERROR

MPI_GROUP_DIFFERENCE(group1, group2, newgroup)
IN group1first group (handle)
IN group2second group (handle)
OUT newgroupdifference group (handle)
C binding
int MPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_difference(group1, group2, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group1, group2
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_DIFFERENCE(GROUP1, GROUP2, NEWGROUP, IERROR)

INTEGER GROUP1, GROUP2, NEWGROUP, IERROR

The set-like operations are defined as follows:

union:
All elements of the first group ( group1), followed by all elements of second group ( group2) not in the first group.
intersect:
All elements of the first group that are also in the second group, ordered as in the first group.
difference
All elements of the first group that are not in the second group, ordered as in the first group.

Note that for these operations the order of MPI processes in the output group is determined primarily by order in the first group (if possible) and then, if necessary, by order in the second group. Neither union nor intersection are commutative, but both are associative. The new group can be empty, that is, equal to MPI_GROUP_EMPTY.

MPI_GROUP_INCL(group, n, ranks, newgroup)
IN groupgroup (handle)
IN nnumber of elements in array ranks (and size of newgroup) (integer)
IN ranksranks of processes in group to appear in newgroup (array of integers)
OUT newgroupnew group derived from above, in the order defined by ranks (handle)
C binding
int MPI_Group_incl(MPI_Group group, int n, const int ranks[], MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_incl(group, n, ranks, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group
INTEGER, INTENT(IN) :: n, ranks(n)
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_INCL(GROUP, N, RANKS, NEWGROUP, IERROR)

INTEGER GROUP, N, RANKS(*), NEWGROUP, IERROR

The function MPI_GROUP_INCL creates a group newgroup that consists of the n MPI processes in group with ranks ranks[0],..., ranks[n-1]; the MPI process with rank i in newgroup is the MPI process with rank ranks[i] in group. Each of the n elements of ranks must be a valid rank in group and all elements must be distinct, or else the program is erroneous. If n~=~0, then newgroup is MPI_GROUP_EMPTY. This function can, for instance, be used to reorder the elements of a group. See also MPI_GROUP_COMPARE.

MPI_GROUP_EXCL(group, n, ranks, newgroup)
IN groupgroup (handle)
IN nnumber of elements in array ranks (integer)
IN ranksarray of integer ranks of MPI processes in group not to appear in newgroup
OUT newgroupnew group derived from above, preserving the order defined by group (handle)
C binding
int MPI_Group_excl(MPI_Group group, int n, const int ranks[], MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_excl(group, n, ranks, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group
INTEGER, INTENT(IN) :: n, ranks(n)
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_EXCL(GROUP, N, RANKS, NEWGROUP, IERROR)

INTEGER GROUP, N, RANKS(*), NEWGROUP, IERROR

The function MPI_GROUP_EXCL creates a group of MPI processes newgroup that is obtained by deleting from group those MPI processes with ranks ranks[0],..., ranks[n-1]. The ordering of MPI processes in newgroup is identical to the ordering in group. Each of the n elements of ranks must be a valid rank in group and all elements must be distinct; otherwise, the program is erroneous. If n~=~0, then newgroup is identical to group.

MPI_GROUP_RANGE_INCL(group, n, ranges, newgroup)
IN groupgroup (handle)
IN nnumber of triplets in array ranges (integer)
IN rangesa one-dimensional array of integer triplets, of the form (first rank, last rank, stride) indicating ranks in group of MPI processes to be included in newgroup
OUT newgroupnew group derived from above, in the order defined by ranges (handle)
C binding
int MPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_range_incl(group, n, ranges, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group
INTEGER, INTENT(IN) :: n, ranges(3, n)
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_RANGE_INCL(GROUP, N, RANGES, NEWGROUP, IERROR)

INTEGER GROUP, N, RANGES(3, *), NEWGROUP, IERROR

If ranges consists of the triplets

(first1 , last1, stride1) , ... , (firstn, lastn, striden)

then newgroup consists of the sequence of MPI processes in group with ranks

Image file

Image file

Each computed rank must be a valid rank in group and all computed ranks must be distinct, or else the program is erroneous. Note that we may have firsti > lasti, and stridei may be negative, but cannot be zero.

The functionality of this routine is specified to be equivalent to expanding the array of ranges to an array of the included ranks and passing the resulting array of ranks and other arguments to MPI_GROUP_INCL. A call to MPI_GROUP_INCL is equivalent to a call to MPI_GROUP_RANGE_INCL with each rank i in ranks replaced by the triplet (i,i,1) in the argument ranges.

MPI_GROUP_RANGE_EXCL(group, n, ranges, newgroup)
IN groupgroup (handle)
IN nnumber of triplets in array ranges (integer)
IN rangesa one-dimensional array of integer triplets, of the form (first rank, last rank, stride) indicating ranks in group of MPI processes to be excluded from the output group newgroup (array of integers)
OUT newgroupnew group derived from above, preserving the order in group (handle)
C binding
int MPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_range_excl(group, n, ranges, newgroup, ierror)

TYPE(MPI_Group), INTENT(IN) :: group
INTEGER, INTENT(IN) :: n, ranges(3, n)
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_RANGE_EXCL(GROUP, N, RANGES, NEWGROUP, IERROR)

INTEGER GROUP, N, RANGES(3, *), NEWGROUP, IERROR

Each computed rank must be a valid rank in group and all computed ranks must be distinct, or else the program is erroneous.

The functionality of this routine is specified to be equivalent to expanding the array of ranges to an array of the excluded ranks and passing the resulting array of ranks and other arguments to MPI_GROUP_EXCL. A call to MPI_GROUP_EXCL is equivalent to a call to MPI_GROUP_RANGE_EXCL with each rank i in ranks replaced by the triplet (i,i,1) in the argument ranges.


Advice to users.

The range operations do not explicitly enumerate ranks, and therefore are more scalable if implemented efficiently. Hence, we recommend MPI programmers to use them whenenever possible, as high-quality implementations will take advantage of this fact. ( End of advice to users.)

Advice to implementors.

The range operations should be implemented, if possible, without enumerating the group members, in order to obtain better scalability (time and space). ( End of advice to implementors.)

MPI_GROUP_FROM_SESSION_PSET(session, pset_name, newgroup)
IN sessionsession (handle)
IN pset_namename of process set to use to create the new group (string)
OUT newgroupnew group derived from supplied session and process set (handle)
C binding
int MPI_Group_from_session_pset(MPI_Session session, const char *pset_name, MPI_Group *newgroup)
Fortran 2008 binding
MPI_Group_from_session_pset(session, pset_name, newgroup, ierror)

TYPE(MPI_Session), INTENT(IN) :: session
CHARACTER(LEN=*), INTENT(IN) :: pset_name
TYPE(MPI_Group), INTENT(OUT) :: newgroup
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_GROUP_FROM_SESSION_PSET(SESSION, PSET_NAME, NEWGROUP, IERROR)

INTEGER SESSION, NEWGROUP, IERROR
CHARACTER*(*) PSET_NAME

The function MPI_GROUP_FROM_SESSION_PSET creates a group newgroup using the provided session handle and process set. The process set name must be one returned from an invocation of MPI_SESSION_GET_NTH_PSET using the supplied session handle. If the pset_name does not exist, MPI_GROUP_NULL will be returned in the newgroup argument. As with other group constructors, MPI_GROUP_FROM_SESSION_PSET is a local function. See Section The Sessions Model for more information on sessions and process sets.


PreviousUpNext
Up: Group Management Next: Group Destructors Previous: Group Accessors


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023