pub unsafe fn mapreduce_threaded<S: AsRef<[isize]>, F>(
dims: &[usize],
blocks: &[usize],
strides_list: &[S],
offsets: &[isize],
costs: &[isize],
class: KernelClass,
exec: Exec<'_>,
f: &F,
) -> Result<()>Expand description
Prevalidated mapreduce threaded for kernel-family implementations.
class is the serial cost class of the leaf (see KernelClass); every node
of the split runs in parallel only when a fork of its region pays for that
class.
§Safety
All rank-indexed arrays must have matching lengths and a valid destination index (when present). Shape products, stride magnitudes, cost arithmetic, and every intermediate offset used by planning/iteration must be representable. Iteration blocks must be positive and offsets must correspond to the supplied layouts; threaded partitioning additionally requires positive costs. Callback memory accesses must be valid for each generated block, with disjoint mutable regions when partitions execute concurrently.
§Examples
use strided_basic::execution::*;
// SAFETY: the example supplies matching bounded layouts and disjoint storage.
use std::sync::atomic::{AtomicUsize, Ordering};
let count = AtomicUsize::new(0);
unsafe { mapreduce_threaded(&[4], &[4], &[vec![1]], &[0], &[2], KernelClass::Map, strided_basic::Exec::serial(), &|dims, _, _, _| { count.fetch_add(dims.iter().product::<usize>(), Ordering::Relaxed); Ok(()) }) }.unwrap();
assert_eq!(count.load(Ordering::Relaxed), 4);§Errors
Forwards errors from the owning kernel or callback; callers must still satisfy the safety contract before invoking this prevalidated entry.