Computer Science Tutorial

Parallel Algorithms

Goal: This laboratory provides experience with two approaches for using parallel processing to solve a problem.

Problem: Compute the following sums:

Solution Using Result Parallelism: Program sum-result.sr solves this problem using result parallelism. A separate process is created for each desired result; each specific process makes its computation and reports its result.

  1. Obtain a paper copy of this program by typing
    
    print ~walker/parallel/sr/examples/sum-result.sr
    
  2. Test the program by running it using the following command:
    
    ~walker/parallel/sr/examples/sum-result
    
  3. Review this program and describe in a few sentences how it works.

    1. If the program is run several times, is the same output generated? Discuss briefly why you think this happens.

    2. Draw a diagram showing each processor and describing what each processor does. How does each processor know which line it should compute?

    3. How might the program change if one wanted to compute sums 1n + 2n + ... + maxn where max is larger than 10?

    4. How might the program change if one wanted to compute 1n + 2n + ... + 10n for a wider range of values of n?

  4. Explain in a few sentences how this program illustrates result parallelism.

Technical Note: You may work with the above program by copying it to your account, modifying the code, and recompiling. To recompile and run this program, follow these steps:


% sr -o sum-result sum-result.sr
% sum-result
Solution Using Specialist Parallelism:

Program sum-specialist.sr solves this problem using specialist parallelism. Each process is assigned the task of raising its number to various powers and adding those results to the appropriate sum.

  1. Obtain a paper copy of this program by typing
    
    print ~walker/parallel/sr/examples/sum-specialist.sr
    
  2. Test the program by running it using the following command:
    
    ~walker/parallel/sr/examples/sum-specialist
    
  3. Review this program and describe in a few sentences how it works.

    1. Draw a diagram showing each processor, describing what each processor does, and showing the communication lines from one processor to another.

      How does each processor know which line it should compute?
      What data do each processor receive and send?

    2. How might the program change if one wanted to compute sums 1n + 2n + ... + maxn where max is larger than 10?

    3. How might the program change if one wanted to compute 1n + 2n + ... + 10n for a wider range of values of n?

  4. Explain in a few sentences how this program illustrates specialist parallelism.

Challenge Questions: (optional)

  1. To cut down on communication overhead and the number of processes that must be created, each process in program sum-specialist.sr could compute more than one term in the sum. Revise sum-specialist.sr so that each process computes and adds two terms to the sum.

  2. Program sum-specialist.sr uses an array to store information for each process and to pass information about one process to the next. However, since the information for one process is needed only by one other, only one piece of this information must be stored at any one time. Rewrite sum-specialist.sr to replace array compute_proc by a single variable of the same name.

This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/tutorial/labs/lab-parallel.html

created November 12, 1997
last revised November 18, 1997