Skip to main content

Module parallel

Module parallel 

Source
Expand description

Deterministic parallelism for the kernel’s embarrassingly parallel stages.

The rule that makes parallelism admissible here at all: the answer must be bit-identical at any thread count. map_ordered guarantees it structurally: each item is computed independently from shared read-only input, results are collected in item order, and nothing about scheduling can reach the output. A stage that cannot meet that bar stays sequential.

The thread count comes from threads: the machine’s parallelism by default, or the OGEOM_THREADS environment variable when it holds a positive count, and overridable process-wide with set_threads, including down to one, which is also what tiny workloads collapse to on their own. Worker threads re-install the caller’s progress watch, so cancellation reaches into the workers.

Workers are started with std::thread::scope. On a target whose standard library cannot start a thread, a host that has threads there (a browser’s web workers sharing the module’s memory) lends them with set_pool; once set, every stage runs its workers on that Pool.

Traits§

Pool
Threads a host lends the kernel, where std::thread cannot start one.

Functions§

map_ordered
Map f over items on up to threads workers, returning results in item order. f receives the item index and the item.
set_pool
Run parallel stages on pool from now on. The first call wins; later calls change nothing.
set_threads
Set the process-wide thread count for parallel stages. 0 restores the machine default. The answer never depends on this. Only the wall clock does.
threads
The thread count parallel stages will use.