Skip to main content

shared_thread_pool

Function shared_thread_pool 

Source
pub fn shared_thread_pool() -> Arc<ThreadPool> 
Expand description

Returns the shared worker pool, building it on first use.

A SciRS2ParallelContext is constructed by every SciRS2Backend::new(), and thus by every StateVectorSimulator::new(). Building one rayon pool per context spawns num_threads OS threads each time, which dominates the runtime of any workload that creates a simulator in a loop (parameter-shift gradients create one per evaluation). One pool for the process keeps that cost at zero after the first call.