© Copyright 1994 Maui High Performance Computing Center.

Exercises and Examples

  1. Overview

  2. Exercises
    1. Simple Array Assignment
    2. Matrix Multiply
    3. pi Calculation
    4. Concurrent Wave Equation
    5. 2D Heat Equation Domain Decomposition

  3. Other Examples
    1. Image Rotation
    2. Mandelbrot Image and Display
    3. Timing Performance

  4. Acknowledgements and References





Overview

The Exercises and Examples section is a teaching aid to those learning the parallel programming tools available at the MHPCC.








The Exercises

This section contains a series of serial programs for the reader to parallelize. For each program there is a brief description followed by a list of associated files that, when clicked on, will bring up the code. There are five categories of files:

Each of these type of programs have the following files associated with them:

These files can be found in the following directories:


Exercises Simple Array Assignment

DESCRIPTION:

This is the "hello world" of parallel programming. It is a simple array assignment used to demonstrate the distribution of data among multiple tasks and the communications required to accomplish it. In the parallel version, the master task distributes an equal portion of the array to each worker task. Each worker task receives its portion of the array and performs a simple value assignment to each of its elements. Each worker then sends its portion of the array back to the master. As the master receives back each portion of the array selected elements are displayed.

There are serial, MPL, MPI, PVM3 and LINDA versions of this code.

SERIAL FILES: MPL FILES: MPI FILES: PVM3 FILES: LINDA FILES:

Exercises Matrix Multiply

DESCRIPTION:

This example is a simple matrix multiply program. There are serial, MPL, MPI, PVM3 and LINDA examples.

In the parallel version, the data is distributed among the worker tasks who perform the actual multiplication and send back their respective results to the master task.

Note that the C and FORTRAN versions of this code differ because of the way arrays are stored/passed. C arrays are row-major order but FORTRAN arrays are column-major order.

SERIAL FILES: MPL FILES: MPI FILES: PVM3 FILES: LINDA FILES:

Exercises pi Calculation

DESCRIPTION:

This program calculates pi using a "dartboard" algorithm. See Fox et al.(1988) Solving Problems on Concurrent Processors, vol.1 page 207. In the parallel version, all processes contribute to the calculation, with the master averaging the values for pi.

There are serial, MPL, MPI, PVM3 and LINDA versions of this program. The MPL and MPI version has two variations, one which demonstrates point-to-point communications (mpl_pi_send) and one that demonstrates collective communications (mpl_pi_reduce).

SERIAL FILES:

MPL FILES:

MPI FILES:

PVM3 FILES:

LINDA FILES:

Exercises Concurrent Wave Equation

DESCRIPTION:

This program implements the concurrent wave equation described in Chapter 5 of Fox et al., 1988, Solving Problems on Concurrent Processors, vol 1.

A vibrating string is decomposed into points. In the parallel version, each processor is responsible for updating the amplitude of a number of points over time. At each iteration, each processor exchanges boundary points with their nearest neighbors.

An X based display of the final wave is provided for the parallel versions of this code.

There are serial, MPL, MPI, PVM3 and LINDA versions of this program.

SERIAL FILES:

MPL FILES:

MPI FILES:

PVM3 FILES:

LINDA FILES:

Exercises 2D Heat Equation

DESCRIPTION:

This example is based on a simplified two-dimensional heat equation domain decomposition. The initial temperature is computed to be high in the middle of the domain and zero at the boundaries. The boundaries are held at zero throughout the simulation. During the time-stepping, an array containing two domains is used; these domains alternate between old data and new data.

There are serial, MPL, MPI, PVM3 and LINDA versions of this program. The PVM and MPL versions provide an X based display of the initial and final temperature distributions.

SERIAL FILES:

MPL FILES:

MPI FILES:

PVM3 FILES:

LINDA FILES:


Other Examples

This sections contains some advanced examples. Only the parallelized code is available and usually in only one language and one parallel tool. Currently, it contains some image processing examples using X-Windows.

Other Examples Image Rotation

DESCRIPTION:

This example is written in C using MPL and MPI. An image is read from disk and repeatedly rotated by one degree increments. After each image rotation the screen is updated.

A single processor reads the input image from disk and broadcasts to all the other processors in the system. Each processor allocates space for a contiguous swath of rows in the output image. Processors then calculate the coordinates of the source input image pixel for each pixel in this output image swath. Individual swaths of the output image are then collected at the destination processor. The destination processor then displays the image on the local X server.

Note: When running this program make sure that your DISPLAY environment variable is set and that the MP_PROCS environment variable is set to 4.

MPL FILES:

MPI FILES:


Other Examples Mandelbrot Image and Display

DESCRIPTION:

This program generates and Mandelbrot image and displays it using X Windows. It is written in C using MPL and MPI.

Each processor calculates the image pixels for a swath of rows in the output image. These swaths of rows are then collected at a single processor and displayed on the screen.

Press the small image to see a larger version.

MPL FILES:

MPI FILES:


Other Examples Timing Example

DESCRIPTION:

These examples are communication timing tests for MPL, MPI and PVM. There are C and FORTRAN versions.

A set number of messages are sent between the master and worker tasks. Before and after timings are made for each message and an average is calculated when completed.

MPL FILES:

MPI FILES:

PVM3 FILES:

Acknowledgements and References

IBM AIX Parallel Environment Parallel Programming Reference, Release 1.0. IBM Corporation.

"Message Passing Libraries on the SP1" Presentation materials from the Cornell Theory Center, Ithaca, New York

Man Pages - on the SP1. Use the C Language name for the routine if looking for the FORTRAN version.

We gratefully acknowledge David Turner of Scientific Computing Associates for the serial and linda versions of the Heat2D exercises and the Cornell Theory Center, Ithaca, New York for the use of their "Template Codes for the SP1".


© Copyright 1994, Maui High Performance Computing Center. All rights reserved.

Documents located on the Maui High Performance Computing Center's WWW server are copyrighted by the MHPCC. Educational institutions are encouraged to reproduce and distribute these materials for educational use as long as credit and notification are provided. Please retain this copyright notice and include this statement with any copies that you make. Also, the MHPCC requests that you send notification of their use to help@mail.mhpcc.edu.

Commercial use of these materials is prohibited without prior written permission.

Last revised: 5/17/95 George Gusciora