HPC - Ring communication with MPI

Moreno Marzolla moreno.marzolla@unibo.it

Last updated: 2022-10-22

Write an MPI program mpi-ring.c which implements a ring communication between the processes. In details, let \(P\) be the number of MPI processes (to be specified with the mpirun command); then, 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 (circles are MPI processes; arrows are messages whose content is the number shown above). There are \(K = 2\) "turns" of the ring; at the end, process 0 receives and prints the value 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