4. Analysing
Jan 25, 2021
Analysing parallel algorithms
Alarm Example
Consider the following algorithm:
1 2 3 4 |
|
It may cause multiple alarms to sound at once.
Then compare to this version:
1 2 3 4 5 |
|
Will only alarm once, but the algorithm is linear — not good.
Logical-OR on PRAM
Given array
Sequential version
1 2 3 4 5 |
|
Analysis of sequential version time:
- lower bound
Parallel version
1 2 3 4 5 6 |
|
Parallel version analysis:
-
describes time and number of machine instructions (effort)- Work =
- processors time product - time on a single processor- superlinear speedup may occur due to caches but not realistic otherwise, because
it would imply there is some
and we should always use
Parallel Sum
This example is for summation but can be done with any associative operation
e.g.
Setup have
- Create a summation tree
- this is a binary tree with
leaves and - initialize leaves with values of
- sum children bottom to top; store value at parent
- this is a binary tree with
In code map the tree to an array then sum with neighbor:
Bounds |
---|
- algorithm is log-efficient when
- work is polylog efficient when
where is some constant - work is optimal when
optimal work implies linear speedup
Example when
x speedup