HPC - Ring communication with MPI

Moreno Marzolla

Last updated: 2023-11-06

Write a MPI program mpi-ring.c that implements a message exchange along a ring. Let \(P\) be the number of MPI processes; the program should behave according to the following specification:

For example, if \(K = 2\) and there are \(P = 4\) processes, the communication should be as shown in Figure 1 (arrows are messages whose content is the number reported above them). There are \(K = 2\) turns of the ring; at the end, process 0 receives and prints 8.

Figure 1: Ring communication
Figure 1: Ring communication

To compile:

    mpicc -std=c99 -Wall -Wpedantic mpi-ring.c -o mpi-ring

To execute:

    mpirun -n 4 ./mpi-ring

Files