This material is part of the course Practical Introduction to Parallel Programming and meant for educational purposes only.
Task
Implement an MPI program in which a single integer is passed around all processes using blocking point-to-point communication.
That is, the process with rank zero assigns the initial value to the integer. It then passes the integer to the process with rank one.
This process, in turn, passes the integer to the process with rank two.
This continues until the process with rank \((p - 1)\), with \(p\) the number of processes. This last process passes the integer back to the process with rank zero.
Finally, the process with rank zero prints the integer to the terminal and the program ends.
Test the program with one and more processes.
Hints
Use the functions MPI_Send
and MPI_Recv
to pass the integer from one process to the next.
Use the function MPI_Comm_rank
to determine from which process the integer is to be received, and to which process the integer is to be sent.
Use the function MPI_Comm_size
to determine the total number of processes.