Expand description
Parallel iterators over slices and owned Vecs.
All functions in this module use OS threads (no Rayon dependency) and fall back to sequential execution for small inputs or when only one CPU is available.
§Provided operations
| Function | Description |
|---|---|
parallel_map | Apply f to every element; preserves order. |
parallel_reduce | Reduce with a commutative binary op; associativity required. |
parallel_filter | Retain elements matching a predicate. |
parallel_scan | Inclusive/exclusive prefix scan. |
parallel_merge_sort | In-place parallel merge sort. |
parallel_for_each | Execute a closure for each element (side-effects). |
parallel_partition | Partition elements into two Vecs based on a predicate. |
parallel_prefix_sum | Specialised f64 prefix-sum using Blelloch’s algorithm. |
§Example
use scirs2_core::concurrent::parallel_iter::{parallel_map, parallel_reduce, parallel_scan, ScanMode};
let data: Vec<i64> = (1..=8).collect();
let doubled = parallel_map(&data, |&x| x * 2, 0).expect("map");
assert_eq!(doubled, vec![2, 4, 6, 8, 10, 12, 14, 16]);
let sum = parallel_reduce(&data, 0i64, |a, b| a + b, |a, b| a + b, 0).expect("reduce");
assert_eq!(sum, 36);
let prefix = parallel_scan(&data, 0i64, |a, b| a + b, ScanMode::Inclusive, 0).expect("scan");
assert_eq!(prefix, vec![1, 3, 6, 10, 15, 21, 28, 36]);Enums§
- Scan
Mode - Scan mode (inclusive or exclusive).
Functions§
- parallel_
filter - Retain elements matching
predin parallel. - parallel_
for_ each - Execute
ffor each element ofdatain parallel (fire-and-forget, side-effects only). Order of execution is not guaranteed. - parallel_
map - Apply
fto every element ofdatain parallel, returning results in the same order as the input. - parallel_
merge_ sort - Parallel merge sort.
- parallel_
partition - Partition
datainto(matching, non_matching)in parallel. - parallel_
prefix_ sum - Specialised parallel prefix sum for
f64slices. - parallel_
reduce - Parallel reduction using a chunk-local reduce followed by a sequential combine across chunks.
- parallel_
scan - Parallel prefix scan (generalised prefix sum) using Blelloch’s algorithm.
- resolve_
threads - Resolve
n_threadsto a concrete thread count (0 → hardware concurrency).