Skip to main content

Module ops

Module ops 

Source
Expand description

Synchronous data-parallel operators and free functions. Synchronous data-parallel operators over the unified scheduler.

§Safety

The mutable operators split a buffer across worker tasks through Melinoe’s WriterShard / ParChunks, which own the disjoint-partition contract and the range math once; each operator brands the caller’s slice in place (MelinoeCell::from_mut_slice) and vends one partition per task. One executor contract makes every such access sound, and each per-site SAFETY comment appeals to it:

  • Disjoint partition. global().for_each_indexed(count, f) invokes f with each index in 0..count exactly once — the same guarantee ParChunks::get_unchecked_chunk requires of its caller. The operators map that index (or a chunk_size-strided range derived from it) to a disjoint slice of the buffer, so no two concurrent tasks ever form &mut to the same element. Multi-buffer operators additionally rely on the caller’s distinct &mut [_] arguments being non-aliasing (guaranteed by the borrow checker at the call site).
  • All-or-error collect. The map_collect_* helpers build a Vec<MaybeUninit<R>>, set_len it (sound — MaybeUninit needs no initialization), fill every slot through the disjoint-partition contract, then reinterpret it as Vec<R>. for_each_indexed returns Ok only after writing every index, so the reinterpretation is reached only when all slots are initialized; a task panic instead surfaces as Err, which .expect() turns into a propagating panic that unwinds with the buffer still typed MaybeUninit<R> (its contents are not dropped — a leak of the written values on panic, never a use of uninitialized memory).

Structs§

Scope
Borrowing scope for spawning parallel sub-tasks that may capture non-'static references.

Enums§

ChunkBuffersError
Failure to partition a fixed set of mutable buffers into matching chunks.

Constants§

UNIT_TASK_BYTES
Bytes of work one scheduled task carries.

Functions§

enumerate_mut_with
Apply f(index, &mut element) to every element of data in place, scheduled by policy P.
enumerate_with
Apply f(index, &element) to every element of data, scheduled by policy P.
fold_reduce_with
Parallel fold-reduce over the index domain 0..len, scheduled by policy P.
for_each_chunk_buffers_mut_enumerated_with
Apply f(index, chunks) to matching chunks from a fixed set of distinct mutable buffers, scheduled by policy P.
for_each_chunk_mut_enumerated_with
Like for_each_chunk_mut_with but also passes the zero-based chunk index to f (synchronous equivalent of data.par_chunks_mut(chunk_size).enumerate().for_each(f)).
for_each_chunk_mut_with
Apply f to each consecutive chunk_size-element mutable chunk of data in parallel, scheduled by policy P. The final chunk may be shorter.
for_each_chunk_mut_with_state
Apply f(state, chunk) to each consecutive mutable chunk, creating one reusable state value per scheduled worker shard.
for_each_chunk_pair_mut_enumerated_with
Apply f(index, a_chunk, b_chunk) to paired chunk_size-element mutable chunks of two distinct buffers in parallel, scheduled by policy P.
for_each_chunk_quad_mut_enumerated_with
Apply f(index, a_chunk, b_chunk, c_chunk, d_chunk) to four distinct mutable buffers chunked identically, scheduled by policy P.
for_each_chunk_triple_mut_enumerated_with
Apply f(index, a_chunk, b_chunk, c_chunk) to three distinct mutable buffers chunked identically, scheduled by policy P.
for_each_index_with
Apply f to every index in 0..len in parallel, scheduled by policy P.
for_each_mut_with
Apply f to every element of data in place, scheduled by policy P.
for_each_unit_task_many_mut_with
crate::for_each_unit_task_mut_with over K buffers of one type, split in lockstep.
for_each_unit_task_mut_with
Apply f(state, first_unit, units) to consecutive runs of whole units of data, each run sized to about crate::UNIT_TASK_BYTES of work.
for_each_unit_task_pair_mut_with
Apply f(state, first_unit, a_units, b_units) to aligned runs of whole units of two mutable buffers, each run sized to about crate::UNIT_TASK_BYTES of work.
for_each_unit_task_range_with
Apply f(state, first_unit, units) to consecutive runs of whole units of a pass that addresses its own data, each run sized to about crate::UNIT_TASK_BYTES of work.
for_each_unit_task_triple_mut_with
Apply f(state, first_unit, a_units, b_units, c_units) to aligned runs of whole units of three mutable buffers, each run sized to about crate::UNIT_TASK_BYTES of work.
for_each_with
Apply f to every element of data, scheduled by policy P.
join
Adaptive Rayon-style two-closure join.
join_with
Run two closures to completion and return both results.
map_collect_index_with
Parallel map over the index domain 0..len, collecting into a Vec<R> in order, scheduled by policy P.
map_collect_mut_with
Map each element of data in place with f(index, &mut element), collecting each returned value into a Vec<R> in order, scheduled by policy P.
map_collect_with
Map each element of data with f, collecting into a Vec<R> in order, scheduled by policy P.
map_reduce_with
Map-reduce over data, scheduled by policy P.
reduce_index_with
Parallel reduction over the index domain 0..len, scheduled by policy P.
scope
Create a borrowing scope for parallel sub-tasks.
units_per_task
Units one task carries when each unit moves unit_bytes, never fewer than one: a unit at or above UNIT_TASK_BYTES is a task on its own.