Intermediate Topic 34 of 51 Concurrency & Parallelism
Parallel Prefix Sum
Scan primitive computing running totals in parallel.
How it works
The prefix sum, or scan, computes for an array the running totals: output i is the sum of inputs up to i, inclusive or exclusive. Despite its apparently sequential dependency, it can be done in parallel in O(log n) steps: the Hillis-Steele algorithm does O(n log n) work with simple structure, while the Blelloch work-efficient algorithm uses an up-sweep reduction tree followed by a down-sweep to do O(n) work. Scans work for any associative operator.
Where it is used
Stream compaction, radix sort, histogram building, polynomial evaluation, allocation of output positions in parallel, lexical analysis, sparse matrix operations and many GPU algorithms use scans as primitives.
Common pitfall
Implementations must be careful about work efficiency versus steps, memory bank conflicts on GPUs and handling arrays larger than a block, requiring hierarchical scans. Inclusive and exclusive variants are easily confused. Floating-point scans differ from serial results. Use tuned libraries such as CUB, Thrust and parallel STL rather than writing your own.
Where it fits in the course
Parallel Prefix Sum is topic 34 of 51 in Concurrency & Parallelism, rated Intermediate. It follows Parallel Reduction. The next topic is OpenMP.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Concurrency & Parallelism quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Concurrency & Parallelism quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Parallel Prefix Sum?
Where do people use Parallel Prefix Sum?
What is the most common mistake with Parallel Prefix Sum?
What should I learn before this topic?
How can I practice it?
Is Parallel Prefix Sum hard to learn?
How long does it take to learn Parallel Prefix Sum?
Which topics are related to Parallel Prefix Sum?
What should I study after Parallel Prefix Sum?
Related topics
- Parallel Reduction (Concurrency & Parallelism)
- OpenMP (Concurrency & Parallelism)
- Fork-Join Model (Concurrency & Parallelism)
- MPI (Concurrency & Parallelism)