References:

Like the communicator routines, the group routines are methods of the objects, but they can also be called statically (MPI.Group) by passing the object as a parameter.

Identifying a group (Comm.group):

A communicator's group can be easily accessed through the group attribute, as shown below:

from mpi4py import MPI

comm = MPI.COMM_WORLD
worldGroup = comm.group

But it can also be accessed through the Get_group method:

from mpi4py import MPI

comm = MPI.COMM_WORLD
worldGroup = comm.Get_group()

Getting group size:

The group size can be accessed through the size attribute, as shown below:

from mpi4py import MPI

comm = MPI.COMM_WORLD

worldGroup = comm.group
groupSize = worldGroup.size

print(groupSize)

But it can also be accessed through the Get_size method:

from mpi4py import MPI

comm = MPI.COMM_WORLD

worldGroup = comm.group
groupSize = worldGroup.Get_size()

print(groupSize)

Output (for both cases):

Untitled

Creating a group:

Creating by Inclusion (Group.Incl):

It works the same way as standard MPI.