C | Fortran-2008 | Fortran-90



MPI_Group_incl_range creates a group by selecting ranks from an existing group based on the list of rank ranges passed. If the number of processes to include in the group is 0, the group created is MPI_GROUP_EMPTY. MPI_Group_incl_range is a variant of MPI_Group_incl.



int MPI_Group_range_incl(MPI_Group group, 
                         int n,
                         int ranges[][3],
                         MPI_Group* new_group);



The group to which the process ranks listed belong.


The number of triplets in the array of rank ranges given, not the total number of integers in that array.


The list of n triplets containing each, in the following order:

  • the first rank
  • the last rank
  • the stride

For each range represented by a triplet, the corresponding ranks are computed by selecting every <stride> ranks starting at the first rank, until it is strictly beyond <last>.
Note: the first rank may be strictly greater than the last rank and the stride may be negative. However, the stride cannot be zero.


The variable in which store the group created. If the number of processes to include in the group is 0, the group created is MPI_GROUP_EMPTY.

Return value

The error code returned from the group inclusion.




#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

 * @brief Illustrates how to create a group by including ranges of processes
 * from another group.
 * @details This application is meant to be run with 4 processes. It begins with
 * the default group made of all processes and then creates another group from
 * it, keeping only odd process ranks.
int main(int argc, char* argv[])
    MPI_Init(&argc, &argv);

    // Check that 4 processes are used
    int comm_size;
    MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
    if(comm_size != 4)
        printf("This application is meant to be run with 4 processes.\n");

    // Get the group or processes of the default communicator
    MPI_Group world_group;
    MPI_Comm_group(MPI_COMM_WORLD, &world_group);

    // Get my rank in the world group
    int my_world_group_rank;
    MPI_Group_rank(world_group, &my_world_group_rank);

    // Selecting odd ranks means selecting every 2 ranks starting from 1, until the max rank <comm_size - 1>.
    int rank_ranges[1][3] = {1, comm_size-1, 2};
    MPI_Group odd_group;
    MPI_Group_range_incl(world_group, 1, rank_ranges, &odd_group);

    // Get my rank in the odd group
    int my_odd_group_rank;
    MPI_Group_rank(odd_group, &my_odd_group_rank);

    // Continue only if we are part of the odd group
    if(my_odd_group_rank != MPI_UNDEFINED)
        printf("I am process %d in world group and %d in the odd group.\n", my_world_group_rank, my_odd_group_rank);
        printf("I am process %d in world group but I am not part of the odd group.\n", my_world_group_rank);


    return EXIT_SUCCESS;