8. Parallel Prefix
Feb 8, 2021
Parallel Prefix
- Given
, is approximately 16 and
Phase 1: perform summation then store result in leaves
Phase 2: do prefix sum: add left sibling
Phase 3: do uniprocessor prefix on chunks:
Phase 1 gives optimality, phase 2 gives speed, and phase 3 preserves optimality.
Bounds | |
---|---|
phase I | |
phase II | |
phase III | |
time | |
work |
Work is optimal when
Alternative strategy: do prefix sum in phase I. In phase III add left neighbor (not sibling) to each value.
Compaction
Applications of prefix sum include: 1. processor enumeration 2. compaction: "filter a subset from a larger set" or compacts a distributed array over large range to a compact array
Example 1: Find students
Given array
Step 1. process
Step 2. run parallel prefix
Step 3. run compaction. If eligible then B[e] = student_id
.
1 2 3 4 5 6 7 |
|
5 eligible students remain in array
Example 2: Categorization
Categorize students by letter grade:
Step | Explanation | Time |
---|---|---|
1 | Compact A | |
2 | Compact B | |
3 | Compact C | |
4 | Compact D | |
5 | Compact F |
Overall time:
You can make this faster by looking only at 0 indices after each pass. Everything with 1 has already been processed previously (local optimization).
Notes on sorting
- Lower bound of comparison sort is
: for an array of N items, there are permutations - Upper bound is
When does
If
(Are we using comparison sort here? No.)
Radix sort has different bounds: use it when
Zero Before Use
In PRAM world we have shared memory where memory is initialized to 0s. Now enumerate the processors:
- Processors that are present set their leaves to 1 then sum up the tree
- Only processors
are preset and tree is dirty — how to do this?
Zero before use: assume neighbor is dead. Zero the parent of the neighbor. Then each processor sets themselves to 1. The cost of zeroing is constant: 1 operation / leaf / processor.
Memory Bootstrapping technique
Assume
Step 1. all processors clear 1 location
Step 2. use 1 processor to clear
Step 3. use
... continue until everything is clear,