Rookie HPC

MPI exercises

You want to practice your MPI skills? This page is made for you. Here is a list of exercises, help yourself and have fun!

Hello worldProducing a hello world is the first test in any language / library / framework you learn. The MPI version of the good old hello world is an application where each MPI process prints its MPI rank and the total number of MPI processes in the global communicator.
Send a messageThis test is for you to practice the fundamental feature of MPI: sending a message. The application you must develop is made of 2 MPI processes, the first one sends a message and the second one receives it. The message to send is just an integer with the value 12345. The receiver must print the value received. You are free to pick the tag value you want.
Shout it to the whole worldThis test is an easy way to use a collective operation. This application is made of 4 MPI processes and consists of the MPI process 1 sending the value 12345 to all other MPI processes. To achieve this, you are not allowed to use individual sends, instead you must use a collective operation.
An incorrect hello worldEven a hello world can be incorrect; this code demonstrates it. Find the bug and fix it.
Distributed sumA classic collective: the reduction. This exercise consists in writing an application where each process declares a variable containing a value equal to its MPI rank times 100. Then, all processes participate to a collective operation calculating the sum of all these variables and store the sum in a variable held on MPI process 0, which then prints it.
Wait for everybodyThe application to write here is a simple one, designed around 2 phases. First, every MPI process prints a message, only then does MPI process 0 alone prints a second message.
Switch to non-blockingIn this test, you are provided with a working code: 2 MPI processes, one sends a message and the other receives it. The objective is simple: make this program use non-blocking operations instead of blocking ones.
Take as much as you needThis code makes for a simple application; 2 MPI processes, one sends a message, the other receives it. Yet, it crashes, find why and fix the bug without changing the sending mode used.
Ordered hello worldThe Hello World is the easiest program you can write in MPI. However, one cannot know in which order MPI processes will print their message. The objective here is to write a program that does guarantee that MPI process 0 will write the hello world first, then MPI process 1, then MPI process 2 and so on, for any number of MPI processes.
Odd-even scatterThis application is made of 3 MPI processes: MPI process 0 holds a 2D array that contains an even number of consecutive integers starting from 0. You must write a program that scatters this array such that MPI process 0 receives nothing, MPI process 1 receives all odd numbers and MPI process 2 all even ones.