Expand description
Splittable CPU placement token for the tensor4all CPU stack.
threadteam is the single place that starts tasks. Kernels never see a
scheduler type: they take an Exec, a token for budget slots of a
Pool, and split it with Exec::fork, Exec::for_ranges,
Exec::broadcast or Exec::external.
- A
Poolis built once by its owner withPool::builder. Exec::newmints a token from a pool;Exec::serialneeds none.- A token is not
Clone/Copy; entries consume it; splits conserve slots. - Serial, budget-one and one-task entries run inline and never reach any scheduler, so the process-global Rayon pool is never started implicitly.
§Features
parallel(default): run on a private pool. Without it the same types exist, every pool has width 1 and every entry runs inline.ledger: test support, see theledgermodule (compiled only with this feature).
§Examples
use std::sync::atomic::{AtomicUsize, Ordering};
use threadteam::{Exec, Pool};
let pool = Pool::builder().threads(4).build()?;
let mut exec = Exec::new(&pool, 4)?;
// Phase 1: data-parallel loop.
let total = AtomicUsize::new(0);
exec.reborrow().for_ranges(1000, 64.try_into().unwrap(), |r| {
total.fetch_add(r.len(), Ordering::Relaxed);
});
assert_eq!(total.into_inner(), 1000);
// Phase 2: two independent parts, each with its share of the slots.
exec.fork(2, |_i, child| {
assert!(child.budget().get() <= 2);
});Re-exports§
pub use pool::Pool;pub use pool::PoolBuilder;
Structs§
- Cancelled
- A peer of a team section panicked: barriers return this so that the other participants can leave the section instead of waiting forever.
- Dispatch
Costs - Dispatch costs of a pool’s three kinds of token.
- Exec
budgetslots of aPool, or the calling thread alone.- Into
Team Error Pool::into_teamcould not reserve the members: the pool is handed back.- Participant
- The view one participant has of the section it runs.
- Pool
- A fixed set of worker threads that
Exectokens place work on. - Pool
Builder - Configuration of a
Pool. - Team
- Pool members reserved for as long as this value lives.
- Team
Exec - Exclusive authority over a set of reserved pool members, for one scope.
- Wait
Override - A partial
WaitPolicyfor one operation: unset fields are inherited. - Wait
Policy - How an idle member behaves after its reservation ended.
- Width
Costs - Dispatch cost of one kind of token, stored as the measured anchors.
Enums§
- Dispatch
Kind - Which kind of token a dispatch cost belongs to.
- Error
- Failure to build a
Poolor anExec. - Host
Class - The class of the machine, keyed by the kernel dispatch it will take, not by
the CPU model. Detected once per process by
HostClass::detect. - Qos
- Scheduling class of the pool’s worker threads (macOS quality of service).
- Refused
- A
broadcastthat cannot guarantee co-scheduling.
Constants§
- PAYS
- The one multiple of the stack: a region runs in parallel when its serial
estimate is at least
PAYS * sections * dispatch_cost.
Functions§
- pays_at
- The one rule: parallel exactly when
estimate >= PAYS * sections * dispatch_cost, compared in integer nanoseconds. - raise_
current_ thread_ qos - Raises the calling thread’s
Qosto at leastqos; never lowers it. - width_
for_ by - The width in
1..=budgetthat minimisessections * D(k) + estimate / k, whereDiscostand a width only counts when the regionpays_atit; 1 when no width does. Ties go to the smaller width. Allocation-free.