Skip main navigation

What is point-to-point communication in MPI?

MPI processes communicate by explicitly sending and receiving messages. In point-to-point, messages are sent between two processes
© CC-BY-NC-SA 4.0 by CSC - IT Center for Science Ltd.

Since MPI processes are independent, in order to coordinate work, they need to communicate by explicitly sending and receiving messages. There are two types of communication in MPI: point-to-point communication and collective communication.

In point-to-point communication messages are sent between two processes, whereas a collective communication involves a number of processes at the same time.

What is point-to-point communication?

In a nutshell, in point-to-point communication one process sends a message (some data) to another process that receives it. The important thing to remember is that the sends and receives in a programme have to match: one receive per one send.

In addition to matching each send call with a corresponding receive call, one needs to pay particular attention to match also the destination and source ranks for the communication. A message is always sent to given process (destination rank) and, similarly, received from a given process (source rank).

One can think of the destination and source ranks as the addresses for the messages, for example: “please send the message to this address” and “is there a message coming from this address?”.

What is an example of sending and receiving a dictionary?

from mpi4py import MPI

comm = MPI.COMM_WORLD
rank = comm.Get_rank()

if rank == 0:
 data = {'a': 7, 'b': 3.14}
 comm.send(data, dest=1)
elif rank == 1:
 data = comm.recv(source=0)

How can I send and receive data?

Python objects can be communicated with the send() and recv() methods of a communicator. It works for any Python object that can be serialised into a byte stream, that is any object that can be pickled.

This includes all standard Python objects and most derived ones as well. The basic interfaces (check mpi4py documentation for optional arguments) of the methods are:

.send(data, dest)

  • data: Python object to send
  • dest: destination rank

.recv(source)

  • source: source rank
  • note: data is provided as return value

What are typical point-to-point communication patterns?

The normal send and receive routines are blocking, meaning the functions exit only once it is safe to use the data (memory) involved in the communication. This means that the completion depends on the other process and that there is
a risk of a deadlock. For example, if both processes call recv() first there is no-one left to call a corresponding send() and the program is stuck forever.

Typical point-to-point communication patterns are shown below. Incorrect ordering of sends and receives may result in a deadlock:

© 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

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now