Go to the documentation of this file.
19 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
20 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
23 namespace Concurrency {
33 declareProperty(
"ThreadInitTools", m_threadInitTools,
"ToolHandleArray of IThreadInitTools" );
42 warning() <<
"Base class could not be initialized" <<
endmsg;
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;
99 fatal() <<
"Unexpected ThreadPoolSize \"" <<
m_threadPoolSize <<
"\". Allowed negative values are "
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;
151 ON_DEBUG debug() <<
"Thread pool termination complete!" <<
endmsg;
164 if ( tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) > 0 ) {
169 <<
" threads were initialised" <<
endmsg;
183 ON_DEBUG debug() <<
"waiting at barrier for all ThreadInitTool to finish executing" <<
endmsg;
190 int numInit =
t->nInit();
193 if ( numInit != expectedNumInit ) {
195 ost <<
"not all threads " << (
terminate ?
"terminated" :
"initialized" ) <<
" for tool " <<
t <<
" : "
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;
tbb::spin_mutex m_initMutex
Mutex used to protect the initPool and terminatePool methods.
int poolSize() const override final
std::atomic< int > m_threadInitCount
Counter for all threads that are initialised.
StatusCode initialize() override
StatusCode retrieve()
Retrieve all tools.
StatusCode launchTasks(bool finalize=false)
Launch tasks to execute the ThreadInitTools.
static GAUDI_API void setNumThreads(const std::size_t &nT)
StatusCode initialize() override final
Initialise.
thread_local bool ThreadInitDone
bool empty() const override
Return whether the list of tools is empty.
std::unique_ptr< tbb::global_control > m_tbbgc
TBB global control parameter.
ToolHandleArray< IThreadInitTool > m_threadInitTools
Handle array of thread init tools.
bool m_init
Was the thread pool initialized?
StatusCode initPool(const int &poolSize, const int &maxParallelismExtra) override final
Initialize the thread pool and launch the ThreadInitTasks.
const std::string & name() const override
Retrieve name of the service
int m_threadPoolSize
Size of the thread pool allocated.
T hardware_concurrency(T... args)
StatusCode finalize() override final
Finalise.
std::unique_ptr< boost::barrier > m_barrier
Barrier used to synchronization thread init tasks.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Base class used to extend a class implementing other interfaces.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Special TBB task used by ThreadPoolSvc to wrap execution of IThreadInitTools.
constexpr static const auto SUCCESS
tbb::task_arena m_arena
TBB task arena to run all algorithms.
#define DECLARE_COMPONENT(type)
StatusCode terminatePool() override final
Terminate the thread pool and launch thread termination tasks.
constexpr static const auto FAILURE
virtual void initThisThread() override
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
A service which initializes a TBB thread pool.
StatusCode terminate() override