24#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
25#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
28 namespace Concurrency {
52 error() <<
"Unable to retrieve ThreadInitTools Array" <<
endmsg;
60 info() <<
"no thread init tools attached" <<
endmsg;
70 warning() <<
"Looks like the ThreadPoolSvc was created, but thread pool "
71 <<
"was never initialized" <<
endmsg;
105 <<
"-1 (use all available cores) and -100 (don't use a thread pool)" <<
endmsg;
110 << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) <<
endmsg;
114 m_tbbgc = std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism,
128 m_tbbgc = std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism, 0 );
131 ON_DEBUG debug() <<
"Thread Pool initialization complete. Maximum allowed parallelism: "
132 << tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) <<
endmsg;
147 error() <<
"Trying to terminate uninitialized thread pool!" <<
endmsg;
164 const std::string taskType =
terminate ?
"termination" :
"initialization";
168 if ( tbb::global_control::active_value( tbb::global_control::max_allowed_parallelism ) > 0 ) {
173 <<
" threads were initialised" <<
endmsg;
187 ON_DEBUG debug() <<
"waiting at barrier for all ThreadInitTool to finish executing" <<
endmsg;
194 int numInit = t->nInit();
197 if ( numInit != expectedNumInit ) {
198 std::ostringstream ost;
199 ost <<
"not all threads " << (
terminate ?
"terminated" :
"initialized" ) <<
" for tool " << t <<
" : "
200 << t->nInit() <<
" out of " <<
m_threadPoolSize <<
" are currently active.";
217 ON_DEBUG debug() <<
"launching ThreadInitTask " << taskType <<
"in this thread." <<
endmsg;
219 std::barrier<>* noBarrier =
nullptr;
225 error() <<
"a ThreadInitTask failed to execute successfully" <<
endmsg;
242 error() <<
"initThisThread triggered, but thread already initialized" <<
endmsg;
247 std::barrier<>* noBarrier =
nullptr;
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_COMPONENT(type)
duration< int64_t, milli > milliseconds
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
void sleep_for(const chrono::duration< _Rep, _Period > &__rtime)
__string_type str() const
constexpr pointer get() const noexcept
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 void setNumThreads(const std::size_t &nT)
Set the number of worker threads (for MT).
GaudiException(std::string Message, std::string Tag, StatusCode Code)
Constructor (1).
StatusCode retrieve() override
Retrieve all tools.
bool empty() const override
Return whether the list of tools is empty.
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
ThreadInitTask(ToolHandleArray< IThreadInitTool > &tools, std::barrier<> *b, ISvcLocator *svcLocator, bool terminate=false)
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< std::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.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...