References:

Groups and communicators are dynamic objects that can be created and destroyed during program execution. In terms of programming, groups and communicators are equivalent.

Identifying a group (MPI_Comm_group):

Identifies a group associated with a specific communicator. It is necessary to identify a group to create new ones.

Function prototype:

int MPI_Comm_group(
	MPI_Comm comm, //Communicator
	MPI_Group *group //MPI_Group address
);

Getting group size:

int MPI_Group_size(
	MPI_Group group, //Group
	int *size //Size address
);

Usage example:

#include <iostream>
#include <mpi.h>

using namespace std;

int main(int argc, char* argv[]) {
    int rank;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
    MPI_Group group;
    MPI_Comm_group(MPI_COMM_WORLD, &group);

    int size;
    MPI_Group_size(group, &size);

    if(rank == 0) {
      cout << "Group: " << group << endl;
      cout << "Size: " << size << endl;
    }
    
    MPI_Finalize();
    return 0;
}

Output:

Untitled

Creating a group:

Creating by Inclusion (MPI_Group_incl):

Create a new group from an existing group, including specified process ranks from the existing group.

Function prototype: