What is Parallel reduction?
Computing a sum or similar over many values in parallel with a tree that repeatedly combines neighbors, finishing n values in log2 n stages, rounded up.
Japanese name: 並列リダクション
Computing a sum or similar over many values in parallel with a tree that repeatedly combines neighbors, finishing n values in log2 n stages, rounded up.
Japanese name: 並列リダクション
A reduction combines many values into one. Besides sums, it includes finding a maximum or a minimum. A single thread adding in order needs n - 1 steps for n values. A tree repeatedly adds neighbors at the same time, halving the number of values. Eight values finish in 3 stages: 8 → 4 → 2 → 1. The additions total 4 + 2 + 1 = 7, the same as adding in order.
A tree changes the order of the additions compared with sequential code. The operation must therefore give the same result when the grouping changes. This property is called associativity: (a + b) + c = a + (b + c). NVIDIA's Thrust library requires an associative operation for its parallel reduction and also assumes it is commutative. Floating-point addition involves rounding, so it is not strictly associative. The last digits can therefore differ from a sum taken in order.
In CUDA, a common form has the threads of a block advance the stages of the tree in shared memory. A barrier between stages makes sure the writes of one stage are finished before the next stage reads them. Each block thus produces one partial result. Synchronization across blocks is available only in limited cases. The partial results are therefore combined further, for example in a later kernel launch. Some libraries and standards, such as Thrust and SYCL, provide reduction as a ready-made building block.
Answer: B. Many threads add simultaneously at each stage, summing n values in log2 n stages
Summing sequentially in one thread takes n - 1 steps, but with a tree, n/2 threads add neighboring pairs in the first stage, n/4 in the second and so on, finishing in log2 n stages (rounded up when n is not a power of 2). The total number of additions is the same, but far fewer stages make it fast in parallel. Within a block the stages proceed in shared memory, and per-block results are combined at the end.
Answer: A. 10
Each stage halves the number of values, 1024 → 512 → 256 → ... → 1, which takes 10 halvings, so the number of stages is log2 1024 = 10. The total number of additions is 512 + 256 + ... + 1 = 1023, the same as one thread summing in sequence, but with only 10 stages it finishes very quickly given enough threads.
No. Combining n values takes n - 1 additions either way. What shrinks is the number of stages, and the additions within a stage run at the same time, which makes it fast.
Not as it is, because subtraction is not associative. For example, (8 - 4) - 2 = 2, but 8 - (4 - 2) = 6.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.