CS322: Concurrent Processes and Programming

Discovering the potential for parallelism inherent in existing sequential algorithms

  1. Most traditional algorithms have been developed on the assumption that they will be executed by a single process. With the growing availability of multiprocessors, it is important that we be able to modify these algorithms to take advantage of the parallelism available.

    Example: sorting. (It was estimated that at one point in time 50% of all CPU power was used for sorting.)

  2. Another example: searching. (processing queries against a database)

  3. One of the most important areas of research in concurrent algorithms was in numerical linear algebra operations. Many (if not most) scientific problems that can be solved using a computer involve solving linear systems.

    Two of the most important operations on vectors of data are the linear combination of two vectors (also called a SAXPY operation due to the name of the FORTRAN subroutine in the LINPACK library that performed this operation) and the inner (or dot) product of two vectors.

  4. While potential parallelism in some algorithms is easily discovered, in others it is not. There is much research to be done in this area.

  5. We can formulate some general rules to help us locate portions of a sequential program that can be done in parallel.

    1. Given: a sequential program S1; S2; S3; S4 ... Sn.

      • the Sk may be compound statements, procedure calls or what have you.

      • if the program contains loops, we may wish to unwind them first - e.g.

        	for i := 1 to n do
        		Si
        

        becomes S1; S2 .. Sn.

    2. We wish to determine whether any given pair of statements Si and Sj can be done in parallel. The condition turns out to be that if i < j then Si and Sj can be executed in parallel if:

      • { variables written by Si } ^ { variables read by Sj } = {}

        rationale: in the sequential form, Sj assumes the values of all variables written by Si; but in the parallel form Sj might access a value before Si writes it.

      • { variables read by Si } ^ { variables written by Sj } = {}

        rationale: if Si and Sj are done in parallel, and Sj changes a variable Si is going to read before Si reads it, then the result of Si will differ.

      • { variables written by Si } ^ { variables written by Sj } = {}

        rationale: in the sequential form, the effect of Sj replaces what Si does. But in the parallel form, Si might change a variable after Sj writes it.

  6. Applying these rules to a sequential program allows us to construct a precedence graph in which an arrow from Si -> Sj means that Si must complete execution before Sj can begin.

    b := d;		S1
    a := b + c;	S2
    d := e + f;	S3
    e := a;		S4
    f := b;		S5
    g := e + f;	S6
    
    R(S1) = {d}	W(S1) = {b}
    R(S2) = {b,c}	W(S2) = {a}	S1 must precede S2 since
    				  W(S1) ^ R(S2) = {b}
    R(S3) = {e,f}	W(S3) = {d)	S1 must precede S3 since       
    				  R(S1) ^ W(S3) = {d}
    R(S4) = {a}	W(S4) = {e}	S2 must precede S4 since
    				  W(S2) ^ R(S4) = {a}
    				S3 must precede S4 since
    				  R(S3) ^ W(S4) = {e}
    R(S5) = {b}	W(S5) = {f}	S1 must precede S5 since
    				  W(S1) ^ R(S5) = {b}
    				S3 must precede S5 since
    				  R(S3) ^ W(S5) = {f}
    R(S6) = {e,f}	W(S6) = {g}	S4 must precede S6 since
    				  W(S4) ^ R(S6) = {e}
    				S5 must precede S6 since
    				  W(S5) ^ R(S6) = {f}
    
    S1      (arc from S1 to S5 not needed since S1 precedes S3 and
    | \     S3 precedes S5)
    S2 S3
    |  / \
    S4    S5
      \  /
       S6
    

    S2 can be done in parallel with S3 and also with S5; S4 can be done in parallel with S5.


$Id: concurrency2.html,v 1.3 1998/03/03 23:42:04 senning Exp $

These notes were written by Prof. R. Bjork of Gordon College. In February 1998 they were edited, converted into HTML and augmented by J. Senning of Gordon College.