bridgestan icon indicating copy to clipboard operation
bridgestan copied to clipboard

Control over the internal threading of a model

Open WardBrian opened this issue 2 years ago • 0 comments

If a model is compiled with STAN_THREADS and uses a function such as map_rect or reduce_sum, this will lead to the model spawning multiple threads during each call to the log density.

Currently, the model is allowed to spawn up to the hardware number of threads, which means if it is done in a loop which is also parallel on the "outside" you get oversubscription.

The Stan Math library lets you set the maximum number of threads by using init_threadpool_tbb. We could just expose this, but it has some issues, most notably that calling it multiple times has no effect. Similar to the print callback, this will also globally apply to all instances from the same shared library.

WardBrian avatar Dec 07 '23 21:12 WardBrian