19#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 
   20#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 
   23  namespace Concurrency {
 
   47    error() << 
"Unable to retrieve ThreadInitTools Array" << 
endmsg;
 
   55    info() << 
"no thread init tools attached" << 
endmsg;
 
 
   65    warning() << 
"Looks like the ThreadPoolSvc was created, but thread pool " 
   66              << 
"was never initialized" << 
endmsg;
 
 
  100              << 
"-1 (use all available cores) and -100 (don't use a thread pool)" << 
endmsg;
 
  105                         << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) << 
endmsg;
 
  109    m_tbbgc = std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism,
 
  124    m_tbbgc = std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism, 0 );
 
  127  ON_DEBUG debug() << 
"Thread Pool initialization complete. Maximum allowed parallelism: " 
  128                   << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) << 
endmsg;
 
 
  143    error() << 
"Trying to terminate uninitialized thread pool!" << 
endmsg;
 
 
  160  const std::string taskType = 
terminate ? 
"termination" : 
"initialization";
 
  164  if ( tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) > 0 ) {
 
  169                << 
" threads were initialised" << 
endmsg;
 
  179      std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
 
  183    ON_DEBUG debug() << 
"waiting at barrier for all ThreadInitTool to finish executing" << 
endmsg;
 
  190      int numInit = t->nInit();
 
  193      if ( numInit != expectedNumInit ) {
 
  194        std::ostringstream ost;
 
  195        ost << 
"not all threads " << ( 
terminate ? 
"terminated" : 
"initialized" ) << 
" for tool " << t << 
" : " 
  196            << t->nInit() << 
" out of " << 
m_threadPoolSize << 
" are currently active.";
 
  213    ON_DEBUG debug() << 
"launching ThreadInitTask " << taskType << 
"in this thread." << 
endmsg;
 
  215    boost::barrier* noBarrier = 
nullptr;
 
  221    error() << 
"a ThreadInitTask failed to execute successfully" << 
endmsg;
 
 
  238    error() << 
"initThisThread triggered, but thread already initialized" << 
endmsg;
 
  243  boost::barrier* noBarrier = 
nullptr;
 
 
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
static GAUDI_API void setNumThreads(const std::size_t &nT)
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
const std::string & name() const override
Retrieve name of the service.
StatusCode terminate() override
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
StatusCode initialize() override
This class is used for returning status codes from appropriate routines.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.
A service which initializes a TBB thread pool.
virtual void initThisThread() override
StatusCode initPool(const int &poolSize, const int &maxParallelismExtra) override final
Initialize the thread pool and launch the ThreadInitTasks.
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
std::atomic< int > m_threadInitCount
Counter for all threads that are initialised.
bool m_init
Was the thread pool initialized?
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
int m_threadPoolSize
Size of the thread pool allocated.
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
int poolSize() const override final
tbb::task_arena m_arena
TBB task arena to run all algorithms.
StatusCode finalize() override final
Finalise.
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
StatusCode initialize() override final
Initialise.
ThreadPoolSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Base class used to extend a class implementing other interfaces.
thread_local bool ThreadInitDone
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...