Foundations, Sorting on a Linear Array, Algorithm Assessment
Tom Kelliher, CS 315
Jan. 25, 1999
Read Section 1.1.1--1.1.3.
Foundations: asymptotic analysis, mathematical induction.
- Foundations: loop invariants.
- Sorting on a linear array: linear arrays, sorting, time analysis.
- Algorithm assessment.
Using fewer processors, the bit model, lower bounds.
Four characteristics:
- Must be true upon entry into the loop
- Execution of the loop body must preserve the invariant
- Invariant must capture the correctness and the meaning of the
loop
- Loop must terminate
Consider the following sorting algorithm which sorts the n elements
of data (the elements are indexed ):
for i := n downto 2 do
largest := i;
for j := i-1 downto 1 do
if data[j] > data[largest]
largest := j;
swap(data[largest], data[i]);
Prove that the algorithm sorts the elements of the array data into
ascending order.
First, demonstrate the algorithm on the array
int data[] = { 12, 19, 6, 15 };
A linear array:
Cell properties:
- Local program: a ``few'' operations.
- Local storage: a ``few'' words of data.
- Operation sequence:
- Receive inputs from neighbors.
- Read local storage.
- Perform computation indicated by local program.
- Generate output for neighbors.
- Update local storage.
- Synchronized to a global clock.
- Must all the programs be identical? Elegance?
Communication properties:
- Bidirectional links between cells.
- Left, right neighbors.
- Fixed connection network.
- Data pulsing through network: systolic computation.
- Phase 1: sorting program.
- Accept input from left neighbor.
- Compare to stored value.
- Output larger value to right neighbor.
- Store smaller value.
- Phase 2: output. Begin passing left when no more input is received
from the left neighbor.
Example: sort 12, 19, 6, 15.
How many steps to sort? How many steps to output?
How can we measure a parallel algorithm? Apply following to sorting on the
linear array.
- Run time: T.
- Number of processors: N.
- Speedup: Let be the running time of the fastest sequential
algorithm. Then:
What is linear speedup?
Say you have P processors. Speedup is at most P. Why? (Hint: a
parallel algorithm that runs in T steps on P processors can be
simulated on a sequential machine in how many steps?)
- Work: W = TP.
Measures algorithm inefficiencies due to idle processors.
- Efficiency of processor utilization:
- Is it always possible to minimize T and E?
Example: consider two algorithms for solving a problem of size M:
- M steps on an M processor machine.
- steps on an processor machine.
If we have an processor machine and need to run the algorithm X
times, which algorithm should we use? Assume the processor machine
may be split in M M processor machines.
(Recall: .)
Thomas P. Kelliher
Mon Jan 25 09:49:26 EST 1999
Tom Kelliher