21 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 22 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 25 namespace Concurrency {
35 declareProperty(
"ThreadInitTools", m_threadInitTools,
"ToolHandleArray of IThreadInitTools" );
49 error() <<
"Unable to retrieve ThreadInitTools Array" <<
endmsg;
57 info() <<
"no thread init tools attached" <<
endmsg;
67 warning() <<
"Looks like the ThreadPoolSvc was created, but thread pool " 68 <<
"was never initialized" <<
endmsg;
102 <<
"-1 (use all available cores) and -100 (don't use a thread pool)" <<
endmsg;
106 #if TBB_INTERFACE_VERSION_MAJOR < 12 108 #endif // TBB_INTERFACE_VERSION_MAJOR < 12 111 << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) <<
endmsg;
116 std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism,
m_threadPoolSize + 1 );
127 m_tbbgc = std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism, 0 );
130 ON_DEBUG debug() <<
"Thread Pool initialization complete. Maximum allowed parallelism: " 131 << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) <<
endmsg;
146 error() <<
"Trying to terminate uninitialized thread pool!" <<
endmsg;
167 if ( tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) > 0 ) {
173 tbb::task* t =
new ( tbb::task::allocate_root() )
177 tbb::task::enqueue( *t );
182 ON_DEBUG debug() <<
"waiting at barrier for all ThreadInitTool to finish executing" <<
endmsg;
189 int numInit = t->nInit();
192 if ( numInit != expectedNumInit ) {
194 ost <<
"not all threads " << (
terminate ?
"terminated" :
"initialized" ) <<
" for tool " << t <<
" : " 195 << t->nInit() <<
" out of " <<
m_threadPoolSize <<
" are currently active.";
212 ON_DEBUG debug() <<
"launching ThreadInitTask " << taskType <<
"in this thread." <<
endmsg;
214 boost::barrier* noBarrier =
nullptr;
221 error() <<
"a ThreadInitTask failed to execute successfully" <<
endmsg;
248 error() <<
"initThisThread triggered, but thread already initialized" <<
endmsg;
252 boost::barrier* noBarrier =
nullptr;
StatusCode finalize() override final
Finalise.
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
static GAUDI_API void setNumThreads(const std::size_t &nT)
StatusCode initialize() override
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
tbb::task * execute() override
Execute the task.
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.
constexpr static const auto SUCCESS
virtual void initThisThread() override
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
T hardware_concurrency(T... args)
int m_threadPoolSize
Size of the thread pool allocated.
#define GAUDI_NO_SANITIZE_ADDRESS
#define DECLARE_COMPONENT(type)
const std::string & name() const override
Retrieve name of the service.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
bool m_init
Was the thread pool initialized?
StatusCode retrieve()
Retrieve all tools.
This class is used for returning status codes from appropriate routines.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
StatusCode initialize() override final
Initialise.
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
thread_local bool ThreadInitDone
Base class used to extend a class implementing other interfaces.
A service which initializes a TBB thread pool.
StatusCode terminate() override
constexpr static const auto FAILURE
std::unique_ptr< tbb::task_scheduler_init > m_tbbSchedInit
TBB task scheduler initializer.
StatusCode initPool(const int &poolSize) override final
Initialize the thread pool and launch the ThreadInitTasks.
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
int poolSize() const override final
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Header file for std:chrono::duration-based Counters.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.