Skip to main content

Module par

Module par 

Source
Expand description

Parallel execution helpers that degrade to sequential execution when the rayon feature is disabled (e.g. single-threaded WASM) or parallelism is off.

Structs§

GridWriter
Concurrent writer for a buffer partitioned into a regular tile grid.
TileMut
Exclusive access to one claimed tile’s area within the buffer.
Wavefront
Geometry of a wavefront pass over a row-major buffer.

Constants§

PAR_MIN_SAMPLES
Minimum number of samples before splitting work across threads pays off.

Functions§

for_each_index
Run f(i) for i in 0..n in parallel when enabled.
for_each_row_chunk
Run f(first_row, rows_chunk) over data split into chunks of rows_per_chunk rows of row_len elements each.
for_each_row_chunk_bounded
Like for_each_row_chunk but split into at most max_workers tasks (used for memory-bound kernels where more threads only add contention).
map
Map f over items in parallel (when enabled), preserving order.
memory_bound_workers
Workers worth using for memory-bound kernels (copies, byte swaps, packed unpack, lookup curves). Measured on a 16-thread x86 server: such loops peak at ~4 threads and get 1.7-1.9x slower at 16 from memory-controller and page-fault contention. Machines with more bandwidth per core scale further, so the cap grows with the thread count.
sequential
Run f on the calling thread with every parallel helper sequential: inside f, threads returns 1 and no work is handed to a thread pool. This is how a single-threaded decode runs, so it stays on the caller’s thread (and on the CPU core class the operating system picked for it) instead of moving to a pool worker.
split_disjoint
Split a mutable slice into disjoint sub-slices at the given ascending offsets. bounds are (start, end) pairs that must not overlap and be sorted. Returns None if they are not valid for data.
threads
Number of worker threads available to parallel helpers (1 inside sequential).
wavefront
Process a buffer whose sample (r, x) depends only on samples left of it in row r and on columns <= x of the halo rows above it. Rows are cut into bands (one per thread) and columns into blocks; block j of a band runs once block j - 1 of the same band and block j of the band above are done, so the bands advance as a wavefront without waiting for each other row by row.