O'Reilly logo

Python Parallel Programming Cookbook by Giancarlo Zaccone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collective communication using gather

The gather function performs the inverse of the scatter functionality. In this case, all processes send data to a root process that collects the data received. The gather function implemented in mpi4py is, as follows:

recvbuf  = comm.gather(sendbuf, rank_of_root_process)

Here, sendbuf is the data that is sent and rank_of_root_process represents the process receiver of all the data:

Collective communication using gather

Gathering data from processes 1, 2, 3, 4

How to do it…

In the following example, we wanted to represent just the condition shown in the preceding figure. Each process builds its own data that is to be sent to the root processes that are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required