Hands-On Session Messaging Fundamentals #2:
MPI Message Semantics

Objective: To better understand message passing semantics.
The code for this exercise can be found here. Instructions on how to log into the remote machine and how to download the source code to your working directory (using wget) can be found here.

Exercise 1

In mpiSwap.c, each process allocates an integer buffer of size BUFFLEN (= 128 integers). Each buffer is initialized to the rank of the process. Process 0 sends its buffer to process 1 and vice versa, i.e. process 0 sends a message of zeros and receives a message of 1s, while process 1 does the opposite.

  1. Compile and run the code interactively using two processes. Verify that it works as you expect.
  2. Now change the code so that BUFFLEN is 1024. Attempt to run the code. You should find that it fails to complete. Why?
  3. The message size can be controlled by passing the program an optional argument (i.e. mpirun -np 2 mpiSwap 512. Find the exact largest message size that the program can handle.
  4. Fix the code so that it completes for any value of BUFFLEN.

Exercise 2

  1. Modify the original (unfixed) version of mpiSwap.c to use MPI_Bsend() instead of MPI_Send(). Test this first on small message sizes, then on larger. Find the exact largest message size that the program can handle. Does it deadlock, or is there a different problem?
  2. Now replace the MPI_Bsend() with an MPI_Isend(); MPI_Wait() combination, adding the declarations
    MPI_Request sendReq; 
    MPI_Status sendStat;
    for this purpose. Test this. When working, see if there is any limit on the message size (make BUFFLEN 4096 or larger).
  3. Finally, modify the program so that rank 1 sends back a message of only half the size, and rank 0 determines this size using MPI_Get_count() and prints it out.