Communication in a Ring
Table of contents
Introduction
In this exercise, we will perform straightforward communication using MPI. Communication in a ring involves sending to the next process rank, and receiving from the previous process rank.
Problem Description
You will implement a program that performs sending and receiving in a ring. You will use MPI_Send and MPI_Recv. Figure 2 shows an example of communication between \(p=6\) total process ranks.

Figure 2: example of ring communication, where there are \(p=6\) total ranks.
Programming Activity #2
Program the ring communication exercise described above. Note the following guidelines below.
- Use and modify the starter file:
ring_comm_starter.c. - Only use the
MPI_SendandMPI_Recvprimitives. - The program will take as input a variable number of process ranks. The program should work with \(p>1\) process ranks.
- Each time a rank sends to its neighboring rank, the data should contain the sender’s process rank. E.g., rank 2 sends the integer value 2 to rank 3. And rank 3 sends integer value 3 to rank 4.
- Each time you receive from your neighboring rank, add the value to a local counter. For instance, rank 2 will add 1 to its local counter once it receives the messsage from rank 1.
- Each process rank should send and receive 10 times in total.
- After each process has sent and received 10 times, the rank should output its value stored in the counter and exit gracefully.
Communication should begin with rank 0 sending to rank 1.
- Q3: What does process rank 5’s counter store at the end of the computation?
Programming Activity #3
Program the ring communication exercise described above. Note the following guidelines below.
- Instead of using
MPI_Send, useMPI_Isend.
You must rewrite your program, not simply find/replace MPI_Isend with MPI_send from programming activity #2.
- Q4: Comparing Programming Activities #2 and #3, which was easier to implement? Explain.