Skip to main content

Module parallel_iter

Module parallel_iter 

Source
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

FunctionDescription
parallel_mapApply f to every element; preserves order.
parallel_reduceReduce with a commutative binary op; associativity required.
parallel_filterRetain elements matching a predicate.
parallel_scanInclusive/exclusive prefix scan.
parallel_merge_sortIn-place parallel merge sort.
parallel_for_eachExecute a closure for each element (side-effects).
parallel_partitionPartition elements into two Vecs based on a predicate.
parallel_prefix_sumSpecialised 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§

ScanMode
Scan mode (inclusive or exclusive).

Functions§

parallel_filter
Retain elements matching pred in parallel.
parallel_for_each
Execute f for each element of data in parallel (fire-and-forget, side-effects only). Order of execution is not guaranteed.
parallel_map
Apply f to every element of data in parallel, returning results in the same order as the input.
parallel_merge_sort
Parallel merge sort.
parallel_partition
Partition data into (matching, non_matching) in parallel.
parallel_prefix_sum
Specialised parallel prefix sum for f64 slices.
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_threads to a concrete thread count (0 → hardware concurrency).