Expand description
Work-efficient parallel prefix sum (scan) operations
This module implements the Blelloch parallel scan algorithm, which computes prefix sums (and generalised prefix scans with arbitrary associative operators) in O(n) work and O(log n) span.
Two variants are provided:
- Exclusive scan (
parallel_prefix_sum_exclusive): elementiof the output is the sum of elements0..i(the first element isidentity). - Inclusive scan (
parallel_prefix_sum): elementiof the output is the sum of elements0..=i.
A generic parallel_scan function accepts any associative binary operator.
When the parallel feature is enabled, the up-sweep and down-sweep phases
use rayon for parallel execution. Without parallel, all operations
fall back to sequential execution.
§Example
use scirs2_core::distributed::parallel_scan::{parallel_prefix_sum, parallel_scan};
// Inclusive prefix sum: [1, 3, 6, 10, 15]
let data = vec![1, 2, 3, 4, 5];
let result = parallel_prefix_sum(&data);
assert_eq!(result, vec![1, 3, 6, 10, 15]);
// Generic scan with multiplication
let data = vec![1, 2, 3, 4];
let result = parallel_scan(&data, 1, |a, b| a * b);
assert_eq!(result, vec![1, 2, 6, 24]);Functions§
- parallel_
prefix_ max - Parallel prefix maximum —
result[i] = max(data[0..=i]). - parallel_
prefix_ min - Parallel prefix minimum —
result[i] = min(data[0..=i]). - parallel_
prefix_ sum - Inclusive prefix sum for a slice of values that support addition.
- parallel_
prefix_ sum_ exclusive - Exclusive prefix sum for a slice of values that support addition.
- parallel_
prefix_ sum_ f64 - Fast inclusive prefix sum for
f64slices. - parallel_
prefix_ sum_ i64 - Fast inclusive prefix sum for
i64slices. - parallel_
scan - Inclusive generalised parallel scan with an arbitrary associative operator.
- parallel_
scan_ exclusive - Exclusive generalised parallel scan.
- segmented_
prefix_ sum - Segmented prefix sum.
- try_
parallel_ prefix_ sum - Parallel prefix sum that returns a
CoreResult, for ergonomic error handling at call sites. - try_
parallel_ scan - Parallel scan that validates the input is non-empty.