Skip to main content

distributed_map

Function distributed_map 

Source
pub fn distributed_map<T, R, F>(
    data: Vec<T>,
    map_fn: F,
    n_workers: usize,
) -> Vec<R>
where T: Send + 'static, R: Send + 'static, F: Fn(T) -> R + Send + Clone + 'static,
Expand description

Parallel map over data, applying map_fn using n_workers threads.

Results are returned in input order (not completion order).

§Fallback

If n_workers == 0, it is silently clamped to 1.

§Example

use scirs2_core::distributed::primitives::distributed_map;

let data: Vec<i32> = (1..=8).collect();
let squares = distributed_map(data, |x| x * x, 4);
assert_eq!(squares, vec![1, 4, 9, 16, 25, 36, 49, 64]);