Dana Vrajitoru
B424 Parallel and Distributed Programming

B424/B524 Homework 6

Due date: Thursday, October 8, 2020.

Ex. 1. Barrier and Broadcast

Download the following files.
barrier_bcast.cc
Makefile
hosts

This program is intended to implement the Barrier and Broadcast functions using the simple Send and Recv in MPI. In the initial state, the program showcases a full program using MPI and shows an example of successful send and receive calls.

a. Compile and run this program successfully on one of the lab machines or on your own computer.

Installation instructions:

If you need to install OpenMPI on your own computer, then the version we have in our labs is called OpenMPI. You will also need to install the development version of this library. For example, in Ubuntu you could do

sudo apt-get install libopenmpi-dev openmpi-bin libhdf5-openmpi-dev

Compilation instructions:

The Makefile should work on all the IUSB multi-core machines. On Carbonate you need to replace mpic++ with mpicxx.

Running instructions:

The executable is called barrier. To run this program in a parallel mode, it needs to be executed through a command called mpirun. This command takes one option np to specify the number of processes, for example, -np 4. So the command would be

mpirun -np 4 barrier

The command can also take an additional option to specify a list of hosts to run the program on (or nodes), that are stored in a file. The file linked above shows examples of such files. This part is still in experimental stage.

To be able to run a program with MPI on multiple machines, you need to set up your ssh keys so that once you connect to one of the lab machines, you can connect to any other without needing to enter the password again. Here are some instructions on how to do that:

https://source.ggy.bris.ac.uk/wiki/Configure_ssh_for_MPI

The complete command to run the program would be the following, assuming that the executable is in the current folder, and that the current folder is in your PATH environment variable, and that the path to the executable mpirun is also in your PATH:

mpirun -np 4 -hostfile hosts barrier

For convenience, a target called "run" in the Makefile stores this command. So you can run the program with one of these commands, depending on the system:

make run

The command in the Makefile contains a specific process number. To experiment with various numbers of processes, you can either edit the Makefile, or copy the command and run it in the terminal directly.

Environment variables

If you haven't done this before, it might be useful to add the current directory to your PATH variable, so that you don't have to type ./ to run local executables. For this, edit the file .bashrc in your home folder and add the line

PATH=.:$PATH

This will take effect the next time you log in. You can also make it take effect right away by doing

source ~/.bashrc

When working with MPI, to make things simpler, you can add the path to the executables mpirun, mpicc, and mpic++ in your environment variable PATH. In our labs, these executables are in the path /usr/lib64/openmpi/bin/. To add this to your path, you can edit the line above the following way:

PATH=.:/usr/lib64/openmpi/bin/:$PATH

It may also be useful to add the path to the library to another environment variable called LD_LIBRARY_PATH that allows the shell to find dynamically linked libraries needed to run executables. In our labs, these libraries are in /usr/lib64/openmpi/lib/. So you can add another line to the file .bashrc to set this variable:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/openmpi/lib/

b. Functions to Implement

Implement the functions Barrier and Broadcast using the simple MPI_Send and MPI_Recv in MPI. The function Barrier should make all the processes wait in this function until all of them are there. In the function Broadcast, the process with an id (or rank) equal to the value of the second parameter should send this value to all the others. The other processes should receive this value from the source process.

Homework Submission

Upload: to Canvas, Assignments, Homework 6, all the files that you modify, add, create. For this homework, you probably just need to add the file barrier_bcast.cc.