Module threads

Module threads 

Source
Expand description

The thread budget and the Rayon pool that runs every parallel region. treams-rs extension.

Parallel regions and parallel dense linear algebra run inside install, on a pool owned by this module, never on Rayon’s global pool. The global pool cannot be resized once started, and a process forked after it started inherits the pool without its worker threads, so its first parallel call would wait forever. The owned pool records the process that built it: a forked child builds its own pool on first use and never touches the parent’s pool, locks or threads.

Each worker clears the flushing bits of its floating-point control register when it starts (fpenv::keep_subnormals_on_worker), so the workers keep subnormal numbers whatever the mode of the thread that builds the pool; crate::fpenv explains why the kernels need them.

The thread budget comes from the first of set_num_threads, TREAMS_RS_NUM_THREADS, RAYON_NUM_THREADS and OMP_NUM_THREADS that holds a positive integer, and otherwise from the CPUs this process may use (affinity and cgroup quota). Environment variables are read once, on first use. Empty and zero values mean “not set”; other unparsable values are ignored and reported in Budget::diagnostics.

Calls already on a Rayon worker (a nested region, or a Rust caller’s own pool) run in place on that worker’s pool.

Structs§

Budget
A resolved thread budget.
Built 🔒
Info
Live state of the pool, for diagnostics.
Pools 🔒
Slot 🔒

Enums§

Source
Where the active thread budget came from.

Constants§

ENVIRONMENT
Environment variables consulted for the default budget, in precedence order.
GENERATIONS 🔒
SEQUENTIAL_PRODUCT 🔒
Faer multiplies complex128 matrices sequentially below this M·N·K (PAR_THRESHOLD_MNK times the scalar size). Require at least this much work per worker as well, so small matrices do not occupy the whole pool.

Statics§

DEFAULT 🔒
GENERATION 🔒
REQUESTED 🔒
Override from set_num_threads; zero means unset. Atomics stay readable after fork, unlike a lock another thread may have held.
SLOTS 🔒

Functions§

after_fork
Record that this process was just forked; call it only in the child.
budget
The active budget with its source and diagnostics. Never starts a pool.
build 🔒
Build a pool, halving the size while threads cannot be spawned.
current_num_threads
Workers available to the calling code: the current Rayon pool’s size on a worker, otherwise the treams-rs budget. Never starts a pool.
default_budget 🔒
dense 🔒
Run a dense operation with threads faer workers: inline when sequential, otherwise on the treams-rs pool.
faer 🔒
Faer parallelism for a dense operation that may use threads workers. The operation must run inside install unless this returns Par::Seq.
info
Budget and pool state. Never starts a pool or claims a slot.
install
Run op on the treams-rs pool, or in place when already on a Rayon worker.
join
[rayon::join] on the treams-rs pool.
num_threads
The budget parallel regions will use. Never starts a pool.
oversubscription 🔒
parse 🔒
A positive thread count, None for empty or zero, or a diagnostic.
pool 🔒
product 🔒
Run an m × k by k × n faer product with the treams-rs budget.
resolve 🔒
Resolve the default budget from lookup (an environment) and the CPUs available.
set_num_threads
Override the budget for this process.
slot 🔒
This process’s slot. A forked child moves to a fresh slot instead of using (or locking, or dropping) the parent’s.