CS475 Lab 7 Getting Started with MPI

This lab is intended to introduce you to MPI. For your enjoyment, you are provided with a version of the SAT code discussed in class.

Also, you will edit skeleton code to pass messages around in a circle, and to exchange messages between consecutive processes. This exercise is not about speed up, it is just about learning to write message passing code. In the CS lab we use mpicc for compiling, and mpirun, both from openmpi, for running MPI programs.

Download and untar the provided mess.tar file. To be clear there are 3 distinct tasks:

  1. sat: run and report execution times on CS machines

    This is a complete code provided to you. It shows MPI initialization and collective communication.
  2. cycle: edit this code to complete the message passing

    This program sends messages of a certain size a certain number of times around a circle of processes. The message passing is initiated by process 0: it sends to process 1, and receives from process p-1. The other processes receive from their left neighbor and send to their right neighbor. Notice that (p-1)-s right neighbor is 0.
  3. exchange: edit this code to complete the message passing

    This program exchanges messages of a certain size a certain number of times between processes. Process 0 only communicates with process 1, process p-1 only communicates with process p-2. All other processes communicate with their right and left neighbor.

Running the Code

Make sure you have openmpi in your path and library load path, when running on CS (state-capital) machines:

echo $PATH
...  /usr/lib64/openmpi/bin .

echo $LD_LIBRARY_PATH
...:/usr/lib64/openmpi/lib

To update the environment variables for Bash terminals, edit the .bashrc file in your home directory and update PATH and LD_LIBRARY_PATH variables.
NOTE: Exporting these varibles only in the local machine terminal will not work when you run your program in multiple machines.

export PATH=/usr/lib64/openmpi/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib

You may also configure ssh to login without entering password each time. See SNA

Run your programs with mpirun in CS machines, example:

To run the program "sat" with 2 processes on the same machine
mpirun -np 2 sat
To run on multiple machines
mpirun -np 2 -hostfile host2 sat
Runs the sat program on two machines. Each host executes one process and the
-hostfile
arguments points to a file containing the list of hostnames.
cat host2
denver.cs.colostate.edu slots=1
augusta.cs.colostate.edu slots=1
slots
specify the number of processes to run on a host. You may have to change it as you want to increase the number of total processes.

Helpful Resources

MPI Tutorial
MPI Quick Reference in C