Expand description
Synchronous data-parallel primitives — Moirai’s rayon-replacement surface.
This crate is the parallel domain (throughput over data), distinct from
the concurrent domain (moirai-async, async tasks/IO). All operations
here are fully synchronous (no async, no .await), so they are safe inside
pure compute kernels without async contagion, and operate on borrowed slices
with in-place mutation (zero-copy).
§Selecting an execution strategy
Strategy is a zero-sized ExecutionPolicy type (Sequential,
Parallel, Adaptive) chosen at compile time, so every form below
monomorphizes with no dynamic dispatch:
- Extension traits (the surface) —
slice.par()/slice.par_mut()returnAdaptivehandles, thenfor_each/enumerate/map_collect/map_reduce:use moirai_parallel::{ParallelSlice, ParallelSliceMut}; let v: Vec<u64> = (0..1000).collect(); let sum = v.par().map_reduce(0, |&x| x, |a, b| a + b); // auto-routes let mut m = v.clone(); m.par_mut().for_each(|x| *x += 1); *_with::<P>free functions — a low-level override that pins the policy via turbofish (for_each_with::<Sequential>(&data, f)), for the rare case that needs to force sequential (determinism / nested regions) or parallel. Most code should just use.par().
Because Adaptive is itself a zero-sized policy, .par() is a fully
monomorphized, zero-cost abstraction that parallelizes only at or above
ADAPTIVE_PARALLEL_THRESHOLD and runs sequentially below it — the
parallel/sequential decision is automatic, with nothing to designate.
These data-parallel ops are synchronous (they return values, not futures),
but they run on the same unified hybrid scheduler as async work
(moirai_executor::global) — not a separate pool. A .par() worker task
can therefore spawn or drive async work (moirai::global().spawn_async/
block_on) on that same runtime, so parallel processing and asynchronous
tasks compose within one process. The sync return shape here is a property of
the operation, not an isolation boundary.
Re-exports§
pub use ops::ChunkBuffersError;pub use ops::Scope;pub use ops::UNIT_TASK_BYTES;pub use ops::enumerate_mut_with;pub use ops::enumerate_with;pub use ops::fold_reduce_with;pub use ops::for_each_chunk_buffers_mut_enumerated_with;pub use ops::for_each_chunk_mut_enumerated_with;pub use ops::for_each_chunk_mut_with;pub use ops::for_each_chunk_mut_with_state;pub use ops::for_each_chunk_pair_mut_enumerated_with;pub use ops::for_each_chunk_quad_mut_enumerated_with;pub use ops::for_each_chunk_triple_mut_enumerated_with;pub use ops::for_each_index_with;pub use ops::for_each_mut_with;pub use ops::for_each_unit_task_many_mut_with;pub use ops::for_each_unit_task_mut_with;pub use ops::for_each_unit_task_pair_mut_with;pub use ops::for_each_unit_task_range_with;pub use ops::for_each_unit_task_triple_mut_with;pub use ops::for_each_with;pub use ops::join;pub use ops::join_with;pub use ops::map_collect_index_with;pub use ops::map_collect_mut_with;pub use ops::map_collect_with;pub use ops::map_reduce_with;pub use ops::reduce_index_with;pub use ops::scope;pub use ops::units_per_task;
Modules§
- melinoe_
ext - Parallel partitioning drivers for branded Melinoe cell slices.
- ops
- Synchronous data-parallel operators and free functions. Synchronous data-parallel operators over the unified scheduler.
Structs§
- Adaptive
- Run in parallel only for inputs at or above
ADAPTIVE_PARALLEL_THRESHOLD. - Adaptive
With Threshold - Run in parallel only for inputs at or above the custom threshold
N. - ParMut
- A mutable parallel view of a slice bound to execution policy
P. - ParRef
- A read-only parallel view of a slice bound to execution policy
P. - Parallel
- Always run in parallel on the shared work-stealing pool.
- Sequential
- Always run sequentially (single thread, no scheduling).
- Work
Bytes - Run in parallel only for an operation that moves at least
Nbytes.
Constants§
- ADAPTIVE_
PARALLEL_ THRESHOLD - Element count at or above which
Adaptivechooses parallel execution.
Traits§
- Execution
Policy - Compile-time strategy selector for the data-parallel operations in this crate.
- Parallel
Slice - Extension trait providing an adaptive parallel view over
&[T]. - Parallel
Slice Mut - Extension trait providing an adaptive mutable parallel view over
&mut [T].