pub fn parallel_scan<T, F>(data: &[T], identity: T, op: F) -> Vec<T>Expand description
Inclusive generalised parallel scan with an arbitrary associative operator.
Given data = [a0, a1, a2, ...] and binary operator op, returns
[a0, op(a0, a1), op(op(a0, a1), a2), ...].
The identity element must satisfy op(identity, x) == x for all x.
ยงAlgorithm
For small inputs (< SEQUENTIAL_THRESHOLD elements), a simple sequential
scan is used. For larger inputs, the Blelloch three-phase algorithm
is used:
- Tile reduce: Divide the input into tiles, compute partial reductions
of each tile (in parallel when the
parallelfeature is enabled). - Prefix on reductions: Compute an exclusive prefix scan on the tile reductions (recursive, but the number of tiles is small).
- Tile scan: Each tile performs a local inclusive scan starting from
its tile prefix (in parallel when
parallelis enabled).