Prerequisites
This lab follows the talk MPI Collective Communication. You should complete the Basics of MPI Programming module and lab exercise before starting this exercise.
Overview
This lab will familiarize you with the major collective communcation routines: broadcast, gather, and global reduction operations.
Exercise
Before You Begin
You can work either in Microsoft Visual Studio or at the command line. Although the instructions that follow refer specifically to the command line, the file references are the same for Visual Studio. To review how to compile MPI programs see Compiling Parallel Programs.
- Create an empty subdirectory to work in so that the files from this exercise do not get mixed up with your other files. In our example, we call this subdirectory "Lab".
H:
mkdir H:\users\your_userid\Lab
cd H:\users\your_userid\Lab
- Copy all lab files found in
- H:\VWlabs\MPI\Collective1\Lab1
to your home directory (or subdirectory) on H:, e.g.
- copy H:\VWlabs\MPI\Collective1\Lab1\* H:\Users\your_userid\Lab\
- Create and submit a two node batch script. For the remainder of this exercise, edit and compile your programs on one of the login nodes, and run them on the nodes you are allocated.
Instructions
Fortran lab file: ex1.f
Fortran lab file (solved): ex1_solved.f
Fortran solution file (for checking): ex1_f.data
Fortran input data file: f.seed
Fortran makefile: ex1_f.mak
C lab file: ex1.c
C lab file (solved): ex1_solved.c
C solution file (for checking): ex1_c.data
C input data file: c.seed
C makefile: ex1_c.mak
The structure of this program is as follows:
- Task zero reads in random number seed
- The seed is sent to all tasks (Lab project)
- Each task calculates one random number based on the seed and the rank
- The task with highest rank calculates the mean value of the random numbers (Lab project)
- 4 more random numbers are generated by each task
- The maximum value and the standard deviation of all generated random numbers are calculated, and the results are made available to all tasks (Lab project)
Solution
Please follow these steps in running the lab:
- Read through the program and identify which sections of code correspond to each of the elements of the program structure listed above. Note in particular the service routine GetStats which is to be used to calculate the maximum value and standard deviation of an array of numbers.
- Insert the appropriate calls to MPI collective communication routines at the points indicated.
- Compile the program using command line (mpicc ex1_solved.c) or appropriate makefile (For example: nmake /f ex1_c.mak ). Whichever method you choose, remember to run the appropriate setup script first (see Compiling and Porting Serial Applications ).
- Specify how many tasks you wish to use (1 through 8). If you plan to check your output against our sample output file, specify 4 tasks.
- Run the program. If you wish to compare your output with the solution file, change the value in the data file f.seed to 123456 for Fortran and c.seed to 123456 for C.
- Check the accuracy of your work by comparing the program output file f.data (c.data for C) with file ex1_f.data for Fortran (ex1_c.data for C). Note that the output file is created on one of the worker nodes. Copy it from T: to your directory on H:.
Cleanup
When you are done running programs, delete your subfolder on the T: drives. From a login node, return the nodes to the pool using the ccrm command. You may also wish to delete any files you copied into your \Lab\ folder on H:.