Hands-on: Message exchange

In this exercise we study sending and receive data between two MPI process.

Source code for this exercise is located in mpi/message-exchange/

Communicating general Python objects

Write a simple program where two processes send and receive a message to/from each other using send and recv. The message content is a dictionary with a key {‘rank’ : myrank} where myrank is the rank of the sending process. After receiving a message, each process should print out the rank of the process and the value in the received dictionary.

Communicating NumPy arrays

In each process, construct a 100 000 element NumPy array which is initialized to the rank of process. Send and receive the array using Send and Recv and after receiving print out the rank of process together with the first element of the received array. Investigate what happens when reordering the send and receive calls in one of the processes.

Share this article:

This article is from the free online course:

Python in High Performance Computing

Partnership for Advanced Computing in Europe (PRACE)