Cornell Theory Center
MPI Example Programs: Concurrent Wave
Table of Contents
This program illustrates the sharing of endpoints for 1-dimensional data decomposition problems. There are two versions: one that uses sends and receives to share endpoints (wave_send) and one that uses collective communication (wave_shift).
This program calculates the amplitude of points along a vibrating string over a specified number of time steps. At each time step, each point is calculated as:
newval(i) = (2 * values(i)) - oldval(i) + (sqtau * (values(i-1) - (2 * values(i)) + values(i+1)))
i is the position of the point along the line; newval, oldval, and values are amplitudes for the next, previous, and current iteration; sqtau is a constant.
A full description of this problem is available in Fox et al., 1988, Solving Problems on Concurrent Processors, volume 1, chapter 5.
The code is SPMD, i.e., each tasks runs the same executable. The task with task ID 0 is the master task. It queries the user for input and collects and prints results. All tasks contribute to the calculation.
Since the amplitude of each point depends on its neighbors, a contiguous block of points is assigned to each task ("block" decomposition). Each task initializes its points based on a sine function.
Each task updates its block of points for the specified number of time steps. To update its endpoints at each timestep, each task must receive values for the points bordering the block from the tasks that "own" them. It must also send the values of its own endpoints to these tasks.
There are two versions of the concurrent wave code. Wave_send uses low-level sends and receives to achieve this communication. Wave_shift uses the collective communication shift routine. A call to shift receives from one "direction" (i.e. from either a higher or lower task ID), and sends in the opposite direction.
Finally, the master task collects the updated points from all the tasks and prints the amplitudes of the first 10 points.
- Copy the needed files to your working directory.
You may copy the files from within your browser, or use the
cp command. Some browsers add or replace characters when files are copied.
Tutorial directory: /usr/local/doc/www/Edu/Tutor/MPI/Templates/wave/
Fortran files:
C files:
- Compile using the make file:
For Fortran:
make -f make.wave.f wave_send
make -f make.wave.f wave_shift
For C:
make -f make.wave.c wave_send
make -f make.wave.c wave_shift
- Specify how many nodes to run on (choose n <= 4):
setenv MP_PROCS n
- Execute the master program:
wave_send
wave_shift
- When you run the wave codes you will be prompted for number of points along a vibrating string, and number of time steps. Currently, the limits for wave are:
maximum number of points = 1000
maximum number of steps = 10000
Some or all of the following files will be left in your directory, and should be removed to save space:
-
wave_send.f or wave_send.c
wave_shift.f or wave_shift.c
make.wave.f or make.wave.c
parameters.h
wave_send
wave_shift
Return to:
MPI Tutorial Page
CTC's MPI Home Page
URL http://www.tc.cornell.edu/Edu/Tutor/MPI/Templates/wave/
updated June 5, 1996