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§
- Grid
Writer - 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
wavefrontpass 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)fori in 0..nin parallel when enabled. - for_
each_ row_ chunk - Run
f(first_row, rows_chunk)overdatasplit into chunks ofrows_per_chunkrows ofrow_lenelements each. - for_
each_ row_ chunk_ bounded - Like
for_each_row_chunkbut split into at mostmax_workerstasks (used for memory-bound kernels where more threads only add contention). - map
- Map
foveritemsin 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
fon the calling thread with every parallel helper sequential: insidef,threadsreturns 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.
boundsare(start, end)pairs that must not overlap and be sorted. ReturnsNoneif they are not valid fordata. - 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 rowrand on columns<= xof thehalorows above it. Rows are cut into bands (one per thread) and columns into blocks; blockjof a band runs once blockj - 1of the same band and blockjof the band above are done, so the bands advance as a wavefront without waiting for each other row by row.