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.
-
Obtain a paper copy of this program by typing
print ~walker/parallel/sr/examples/sum-result.sr
-
Test the program by running it using the following command:
~walker/parallel/sr/examples/sum-result
-
Review this program and describe in a few sentences how it works.
-
If the program is run several times, is the same output generated?
Discuss briefly why you think this happens.
-
Draw a diagram showing each processor and describing what each processor
does. How does each processor know which line it should compute?
-
How might the program change if one wanted to compute sums
where max is larger than 10?
-
How might the program change if one wanted to compute
for a wider range of values of n?
-
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.
-
Obtain a paper copy of this program by typing
print ~walker/parallel/sr/examples/sum-specialist.sr
-
Test the program by running it using the following command:
~walker/parallel/sr/examples/sum-specialist
-
Review this program and describe in a few sentences how it works.
-
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?
-
How might the program change if one wanted to compute sums
where max is larger than 10?
-
How might the program change if one wanted to compute
for a wider range of values of n?
-
Explain in a few sentences how this program illustrates specialist parallelism.
Challenge Questions: (optional)
-
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.
-
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