Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more


In this article we discuss MPI communicators in more detail and show how to create user-defined communicators.
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science Ltd.

In MPI context, a communicator is a special object representing a group of processes that participate in communication. When a MPI routine is called, the communication will involve some or all of the processes in a communicator.

In C and Fortran, all MPI routines expect a communicator as one of the arguments. In Python, most MPI routines are implemented as methods of a communicator object.

A single process can belong to multiple communicators and will have an unique ID (rank) in each of the communicators.

MPI Communicator

User-defined communicators

All processes start in a global communicator called MPI_COMM_WORLD (or
MPI.COMM_WORLD in mpi4py), but the user can also define their own custom
communicators as needed.

  • By default a single, universal communicator exists to which all
    processes belong (MPI.COMM_WORLD)

A new communicator is created as a collective operation of an existing
communicator. For example, to split the processes in a communicator into
smaller sub-groups, one could do the following:

rank = comm.Get_rank()

color = rank % 4

local_comm = comm.Split(color)
local_rank = local_comm.Get_rank()

print("Global rank: %d Local rank: %d" % (rank, local_rank))

A distinct label (called color, which is actually just an integer number between 0-3) is assigned to each process based on its rank in the original communicator. New communicators are then created based on this value, so that all processes with the same “color” end up in the same communicator.

If effect, this splits the processes in the original communicator into 4 sub-groups that each share a new communicator within the sub-group.

Can you think of cases where multiple communicators can be useful?

© CC-BY-NC-SA 4.0 by CSC - IT Center for Science Ltd.
This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education