Skip to main content

parallel_scan

Function parallel_scan 

Source
pub fn parallel_scan<T, F>(data: &[T], identity: T, op: F) -> Vec<T>
where T: Clone + Send + Sync, F: Fn(T, T) -> T + Send + Sync + Clone,
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:

  1. Tile reduce: Divide the input into tiles, compute partial reductions of each tile (in parallel when the parallel feature is enabled).
  2. Prefix on reductions: Compute an exclusive prefix scan on the tile reductions (recursive, but the number of tiles is small).
  3. Tile scan: Each tile performs a local inclusive scan starting from its tile prefix (in parallel when parallel is enabled).