CSC 213:  Operation Systems and Parallel Algorithms

Laboratory Exercise on Parallel Searching

Goals:

This laboratory exercise illustrates a common approach for parallel processing:

Definitions

Suppose we are given an [unordered] array a of size MAX, a number value, and an index i. We want to compute three values:

Example:

Suppose a = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]. then

Specific Tasks and Initial Discussion

This lab seeks to compute the rank, truncated rank, and indexed count using multiple processes that are organized in a hierarchy.

While a single-process approach likely would be much simpler (and faster) for these specific tasks, much of the purpose of the lab is to illustrate a common strategy within parallel algorithms.

Suppose we have 2N - 1 processors available to us. We arrange them within a full tree structure, as illustrated below (where N is 5).

tree of processors

Notes:

  1. Within this structure, finding the parent or child of a process node involves simple computations. For example, the right child of processor Pi is P2*(i+1)
  2. If we have 2N - 1 processors altogether, then the tree has N levels, and the last row has 2(N-1) processors.
  3. The index of the first processor of the last row is 2N-1 - 1.
  4. Processor Pi is above the last row if i <= 2N-1 - 2, and processor Pi is in the last row if i >= 2N-1 - 1
Computational Exercises (not to be turned in, but to be used shortly in programming):
  1. Find a formula for the left child of processor Pi.
  2. Find a formula for the parent of processor Pi.
  3. In counting the processors on the last row (first processor, second processor, etc.), find the index of the jth processor.

A Divide-and-Conquer Search Strategy

For simplicity, suppose MAX is R*2N-1 for known integers R and N.

We want to compute the rank, truncated rank, and indexed count for a given value and index i

Strategy: Part A -- Searching the Array

We assign the bottom row of processors in the above tree to compute the desired values for blocks of the tree. The first processor will examine a[0..R-1], the second processor will examine a[R..2R-1], the third processor will examine a[2R..3R-1], and so forth. Thus, the jth processor in the last row will a[R*(j-1)..R*j-1].

Within this array segment, the jth processor of the last row computes rank, truncated rank, and indexed count using a simple linear search.

Strategy: Part B -- Reporting up the Hierarchy

From part A, the processes at the bottom of the processor tree know the desired results for various array segments. These values can percolate up through the tree as follows:

Each processor (not in the bottom row):

At the top of the hierarchy, process 0 prints the final results on the keyboard.

Some Technical Details

For simplicity, suppose that MAX, R, and N, are given as program constants. (If you wish, 2N-1 and 2N - 1 also may defined as program constants.)

Also, for simplicity, suppose that the array a[0..MAX-1] is stored in shared memory.

Conceptually, connections between processors would be made via pipes or sockets, although sockets are to be used in this laboratory exercise. (In a more practical setting, the sockets would allow communication among multiple machines, but work on multiple machines is not part of this exercise.)

Number the sockets from 0 through 2N - 1, starting at the top of the tree and moving downward from left to right.

Use the numbering scheme for processor children and parents to determine the number of the pipe or socket going to a processors parent and to determine the number of the pipe coming in from each child.

Programming Assignment

Code the above algorithm in C, using sockets.


Work to be turned in:


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/213.fa04/lab-par-search.shtml

created November 6, 2004
last revised November 14, 2004
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at (walker@cs.grinnell.edu)