10#if defined(POLYFEM_WITH_TBB) || defined(POLYFEM_WITH_CPP_THREADS)
11#include <tbb/global_control.h>
32 inline static thread_local size_t limit_ = std::numeric_limits<size_t>::max();
49 const unsigned int tmp = max_threads <= 0 ? std::numeric_limits<int>::max() : max_threads;
50 const unsigned int num_threads = std::min(tmp, std::thread::hardware_concurrency());
53#if defined(POLYFEM_WITH_TBB) || defined(POLYFEM_WITH_CPP_THREADS)
54 thread_limiter = std::make_shared<tbb::global_control>(tbb::global_control::max_allowed_parallelism,
num_threads);
64#if defined(POLYFEM_WITH_TBB) || defined(POLYFEM_WITH_CPP_THREADS)
66 std::shared_ptr<tbb::global_control> thread_limiter;
70 void par_for(
const int size,
const std::function<
void(
int,
int,
int)> &func);
size_t num_threads() const
void set_num_threads(const int max_threads)
Restrict parallel work on the current thread and its CPP worker calls.
ScopedThreadLimit(const size_t limit)
ScopedThreadLimit & operator=(const ScopedThreadLimit &)=delete
ScopedThreadLimit(const ScopedThreadLimit &)=delete
static thread_local size_t limit_
void par_for(const int size, const std::function< void(int, int, int)> &func)