3#include <BS_thread_pool.hpp>
23 const std::size_t hw = std::thread::hardware_concurrency();
24 return hw == 0 ? std::size_t{1} : hw;
44 std::size_t minOpsPerWorker = std::size_t{1} << 15)
noexcept {
48 return (totalOps / nJobs) >= minOpsPerWorker;
65 BS::light_thread_pool *
pool =
nullptr;
73 return (
pool !=
nullptr) ?
pool->get_thread_count() : std::size_t{1};
83 return BS::this_thread::get_index().value_or(std::size_t{0});
99 std::size_t minTasksPerWorker = 2) const noexcept {
100 if (
pool ==
nullptr || minChunk == 0) {
103 return (totalWork / minChunk) >= (
workerCount() * minTasksPerWorker);
119 std::size_t minOpsPerWorker = std::size_t{1}
120 << 15)
const noexcept {
121 if (
pool ==
nullptr) {
124 return (totalOps /
workerCount()) >= minOpsPerWorker;
std::size_t clampedJobCount(std::size_t nJobs) noexcept
Clamp a caller-supplied nJobs to a valid BS::light_thread_pool worker count.
bool shouldSpawnPool(std::size_t totalOps, std::size_t nJobs, std::size_t minOpsPerWorker=std::size_t{1}<< 15) noexcept
Decide whether spawning a pool with nJobs workers is worth it for totalOps of arithmetic work.
Thin injection wrapper around a BS::light_thread_pool.
static std::size_t workerIndex() noexcept
Stable index of the calling worker thread within the owning pool.
std::size_t workerCount() const noexcept
Number of worker threads available, or 1 in serial mode.
BS::light_thread_pool * pool
Underlying pool, or nullptr to force serial execution.
bool shouldParallelize(std::size_t totalWork, std::size_t minChunk, std::size_t minTasksPerWorker=2) const noexcept
Decide whether totalWork warrants parallel dispatch.
bool shouldParallelizeWork(std::size_t totalOps, std::size_t minOpsPerWorker=std::size_t{1}<< 15) const noexcept
Decide whether totalOps warrants parallel dispatch, based on work volume.