Skip to main content

parallel_reduce

Function parallel_reduce 

Source
pub fn parallel_reduce<T>(
    items: &[T],
    f: impl Fn(T, T) -> T + Send + Sync + 'static,
    identity: T,
) -> T
where T: Clone + Send + Sync + 'static,
Expand description

Reduce items to a single value using f with the given identity element.

Fans out the reduction into chunks (one per available hardware thread), reduces each chunk sequentially, then combines the chunk results.

§Type constraints

  • T: Clone + Send + Sync – items and identity must be cloneable and thread-safe.
  • f: Fn(T, T) -> T + Send + Sync – the combining function must be thread-safe.