iMSTK
Interactive Medical Simulation Toolkit
imstkThreadManager.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkThreadManager.h"
8 #include "imstkLogger.h"
9 
10 namespace imstk
11 {
12 namespace ParallelUtils
13 {
14 std::unique_ptr<tbb::global_control> ThreadManager::s_tbbGlobalControl;
15 
16 void
17 ThreadManager::setThreadPoolSize(const size_t nThreads)
18 {
19  LOG_IF(FATAL, (nThreads == 0)) << "Invalid number of threads";
20  LOG(INFO) << "Set number of worker threads to " << nThreads;
21 
22  if (s_tbbGlobalControl)
23  {
24  s_tbbGlobalControl.reset();
25  }
26 
27  s_tbbGlobalControl = std::unique_ptr<tbb::global_control>(
28  new tbb::global_control(tbb::global_control::max_allowed_parallelism,
29  nThreads));
30 }
31 
32 void
34 {
35  setThreadPoolSize(static_cast<size_t>(tbb::info::default_concurrency()));
36 }
37 
38 size_t
40 {
41  return s_tbbGlobalControl->active_value(tbb::global_control::max_allowed_parallelism);
42 }
43 } // end namespace ParallelUtils
44 } // end namespace imstk
static void setThreadPoolSize(const size_t nThreads)
Set system-wide thread pool size for parallel computation.
Compound Geometry.
static size_t getThreadPoolSize()
Returns the size of the thread pool.
static void setOptimalParallelism()
Set system-wide thread pool size to the optimal value (use all logical cores)