Rookie HPC

About

Docs

Tools

Tests

MPI_Group_incl

Definition

MPI_Group_incl creates a group from a list of process ranks taken from an existing group. If the number of processes to include in the group is 0, the group created is MPI_GROUP_EMPTY.

Copy

Feedback

int MPI_Group_incl(MPI_Group old_group,
                   int rank_number,
                   int* ranks,
                   MPI_Group* new_group);

Parameters

old_group
The group to which the process ranks listed belong.
rank_number
The number of process ranks contained in the list.
ranks
An array containing the ranks of the processes in the old group to include in the new group.
new_group
The variable in which store the groupe created. If the number of processes to include in the group is 0, the group created is MPI_GROUP_EMPTY.

Returned value

MPI_SUCCESS
The routine successfully completed.

Example

Copy

Feedback

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

/**
 * @brief Illustrates how to create a group from a list of process ranks.
 * @details This code obtains the group of processes in the default
 * communicator, then it prints the rank of each process in that group and the
 * total number of processes in that group.
 **/
int main(int argc, char* argv[])
{
    MPI_Init(&argc, &argv);

    // 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 group
    int my_rank;
    MPI_Group_rank(world_group, &my_rank);

    // Get the size of the group
    int size;
    MPI_Group_size(world_group, &size);

    // Print my rank in that group as well as the number of processes in it.
    printf("I am process %d, we are %d processes.\n", my_rank, size);

    MPI_Finalize();

    return EXIT_SUCCESS;
}