Begin by making a new directory for this course, containing a subdirectory for this exercise, and save a copy of the C program greetings.c in that subdirectory. This program is a parallel version of a "hello world" style program, using the Message Passing Interface (MPI).
To compile the program, use the command:
mpicc greetings.cmpicc compiles a C program in the usual way (i.e., using gcc), except that it correctly processes the MPI commands the program uses, which would generate errors if a regular C compiler were used. The resulting binary is stored in a file named a.out.
(If you get an error message like:
bash: mpicc: file not foundthen you will need to add MPI's bin directory to your PATH variable. For example, if MPI's bin directory were in /opt/openmpi/bin/, you would add:
PATH=/opt/openmpi/bin/:$PATH
export PATH
in the file .bash_profile in your home directory.)
To run an MPI program in parallel on multiple machines, we will use the mpirun command. In the Unix lab, we will invoke the mpirun command using two switches:
mpirun -np numProcesses -machinefile hostNameFile binaryFileNamewill run numProcesses instances of the program in binaryFileName, starting the first instance on our local machine, and then starting the remaining numProcesses-1 instances on the machines whose names are listed in hostNameFile.
Your first task in the Unix lab is to set up your own personal file of host names. To make this easy, download and run either Tim Brom's Perl script, or John VanEnk's shell script. These scripts generate a randomized list of all the ulab machines that are currently running Linux. (Note: Neither of these scripts generate host files for multicore hosts. Feel free to hack them so that they do so.) Change the permissions on the script file to allow execution; then run it and redirect its output to a file (e.g., hosts).
The mpirun command will start up remote processes on the machines according to their order in this file, so you may want to ensure that the machine on which you are working occurs first in this file. (Note: You will not need to use the -machinefile switch on the cluster.)
Once you have your own "randomized" personal machines file, we are nearly ready to run our program in the Unix lab. To run the program in a.out on the first four machines listed in hosts, use the command
mpirun -np 4 -machinefile hosts ./a.outThe argument to the -np switch must be an integer specifying how many processes you want to use (generally, more than 1).
One annoying thing is that mpirun uses ssh to launch the remmote processes, and if you have not yet set up SSH key authentication for each remote node, you will have to enter your password. To avoid having to enter your password each time, follow Kevin DeGraaf's instructions on SSH Key Authentication.
Run the program with different arguments for this switch (e.g., 4, 8, 12, 16) and compare its behavior against its source code, until you understand how it is generating the behavior you observe.
When you understand how greetings.c is working, continue on to today's homework assignment, which is given below.
Today's assignment has these parts:
scp ringCircler.c adams@dahl.calvin.edu:/home/adams/374/proj1
On dahl, repeat the timing experiments you did in the Unix lab by measuring the average time per trip using 3 trips around the "ring". Note that you need not prepare a machine file, and you should need not use the -machinefile switch on the cluster.
Record the timing data when using rings of 4, 8, 16, 32, and 64 processes.
| Up to the HPC Homework Project Page | Up to the Calvin HPC Course Page |