Hands-On Session PG-3: MPI One-sided Communications:
Three Synchronization Methods

Objective: To understand and compare the three synchronization methods, i) Fence Synchronization, ii) Post-Start-Complete-Wait, and iii) Lock-Unlock
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.

The following three exercises are extensions of material that is found at the Cornell Virtual Workshop on MPI One-Sided Communication.

Exercise 1: Fence Synchronization

The first exercise involves active synchronization of all processes within a communicator space. This is the easiest synchronization method to program, but also the most restrictive.

Open file ex1.c. The code is based on the Cornell code shown on the fence web page.

Compile and run this code, made sure you understand what is happening.

Task: Modify the code such that instead of processes rank!=0 using MPI_Get to access the data, process rank==0 uses MPI_Put to write the data into the memory of all other processes.

Exercise 2: Post-Start-Complete-Wait (PSCW) Synchronization

The second exercise involves active synchronization between a subset of processes within a communicator space. It is more complicated to program that the previous method, but is also slightly more flexible.

Open file ex2.c. The code is based on the Cornell code found on the pscw web page.

Compile and run the code, making sure you understand what is happening.

Task: Modify the code such that the processes in the subgroup write to the elements of the buf array held by process rank 0 in turn with rank 0 printing out the content of its array after each process has written to it.

Exercise 3: Lock-Unlock Synchronization

The final exercise involves use of passive synchronization to perform RMA operations between pairs of processes. This is the most complicated synchronization method to program but also the most flexible.

Open file ex3.c. The code is based on the Cornell code found on the lock-unlock web page.

Compile and run the code, making sure you understand what is happening.

Task: Modify the code such that process rank 0 writes the element of its buf arrary that is index by the rank of the process it is writing to into the corresponding element of buf on the remote process. That is:for (i=1; i < size; i++)buf_rank_i[i]=buf_rank_0[i]

Homework: Application to Stencil

Take the stencil code from previous exercises and implement the updates between adjacent cells using one-sided MPI communications.