The Gaudi Framework  master (29688f1e)
Loading...
Searching...
No Matches
AlgResourcePool Class Reference

The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface. More...

#include <GaudiHive/AlgResourcePool.h>

Inheritance diagram for AlgResourcePool:
Collaboration diagram for AlgResourcePool:

Public Member Functions

 ~AlgResourcePool () override
StatusCode start () override
StatusCode initialize () override
StatusCode acquireAlgorithm (std::string_view name, IAlgorithm *&algo, bool blocking=false) override
 Acquire a certain algorithm using its name.
StatusCode releaseAlgorithm (std::string_view name, IAlgorithm *&algo) override
 Release a certain algorithm.
StatusCode acquireResource (std::string_view name, unsigned int value) override
 Acquire units of a certain resource.
StatusCode releaseResource (std::string_view name, unsigned int value) override
 Release a certain resource.
std::list< IAlgorithm * > getFlatAlgList () override
std::list< IAlgorithm * > getTopAlgList () override
StatusCode stop () override
StatusCode finalize () override
Public Member Functions inherited from extends< Service, IAlgResourcePool >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
StatusCode configure () override
StatusCode initialize () override
StatusCode start () override
StatusCode stop () override
StatusCode finalize () override
StatusCode terminate () override
Gaudi::StateMachine::State FSMState () const override
Gaudi::StateMachine::State targetFSMState () const override
StatusCode reinitialize () override
StatusCode restart () override
StatusCode sysInitialize () override
 Initialize Service.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolderoperator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream

Private Types

typedef tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr

Private Member Functions

StatusCode decodeTopAlgs ()
 Decode the top Algorithm list.
StatusCode flattenSequencer (IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
 Recursively flatten an algList.
void dumpInstanceMisses () const
 Dump recorded Algorithm instance misses.

Private Attributes

std::mutex m_resource_mutex
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
std::map< size_t, size_t > m_n_of_allowed_instances
std::map< size_t, unsigned int > m_n_of_created_instances
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
 Counters for Algorithm instance misses.
Gaudi::Property< bool > m_lazyCreation { this, "CreateLazily", false, "" }
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Gaudi::Property< bool > m_overrideUnClonable
Gaudi::Property< bool > m_countAlgInstMisses
Gaudi::Property< IAlgorithm::AlgResources_tm_availableResources
Gaudi::Property< int > m_missingResourceMsgLevel
std::list< IAlgorithm * > m_algList
 The list of all algorithms created within the Pool which are not top.
std::list< IAlgorithm * > m_topAlgList
 The list of top algorithms.
std::list< IAlgorithm * > m_flatUniqueAlgList
 The flat list of algorithms w/o clones.

Additional Inherited Members

Public Types inherited from extends< Service, IAlgResourcePool >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.

Detailed Description

The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.

It either creates all instances up front or lazily. Internal bookkeeping is done via hashes of the algorithm names.

Author
Benedikt Hegner

Definition at line 35 of file AlgResourcePool.h.

Member Typedef Documentation

◆ concurrentQueueIAlgPtr

typedef tbb::concurrent_bounded_queue<IAlgorithm*> AlgResourcePool::concurrentQueueIAlgPtr
private

Definition at line 60 of file AlgResourcePool.h.

Constructor & Destructor Documentation

◆ ~AlgResourcePool()

AlgResourcePool::~AlgResourcePool ( )
override

Definition at line 27 of file AlgResourcePool.cpp.

27 {
28 for ( auto& algoId_algoQueue : m_algqueue_map ) {
29 auto* queue = algoId_algoQueue.second;
30 delete queue;
31 }
32}
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map

Member Function Documentation

◆ acquireAlgorithm()

StatusCode AlgResourcePool::acquireAlgorithm ( std::string_view name,
IAlgorithm *& algo,
bool blocking = false )
override

Acquire a certain algorithm using its name.

Definition at line 91 of file AlgResourcePool.cpp.

91 {
92
93 std::hash<std::string_view> hash_function;
94 size_t algo_id = hash_function( name );
95 auto itQueueIAlgPtr = m_algqueue_map.find( algo_id );
96
97 if ( itQueueIAlgPtr == m_algqueue_map.end() ) {
98 error() << "Algorithm " << name << " requested, but not recognised" << endmsg;
99 algo = nullptr;
100 return StatusCode::FAILURE;
101 }
102
103 StatusCode sc;
104 if ( blocking ) {
105 itQueueIAlgPtr->second->pop( algo );
106 } else {
107 if ( !itQueueIAlgPtr->second->try_pop( algo ) ) {
108 if ( m_countAlgInstMisses ) {
109 auto result = m_algInstanceMisses.find( name );
110 if ( result != m_algInstanceMisses.end() )
111 ++( result->second );
112 else
114 }
116 }
117 }
118
119 // Note that reentrant algorithms are not consumed so we put them
120 // back immediately in the queue at the end of this function.
121 // Now we may still be called again in between and get this
122 // error. In such a case, the Scheduler will retry later.
123 // This is of course not optimal, but should only happen very
124 // seldom and thud won't affect the global efficiency
125 if ( sc.isFailure() )
126 DEBUG_MSG << "No instance of algorithm " << name << " could be retrieved in non-blocking mode" << endmsg;
127
128 if ( sc.isSuccess() ) {
129 // Try to acquire all the resources the algorithm needs
130 if ( !algo->neededResources().empty() ) {
131 std::scoped_lock lock( m_resource_mutex );
132
133 auto tmpResources = m_availableResources; // backup resources
134 for ( const auto& [res_name, res_value] : algo->neededResources() ) {
135 auto res = m_availableResources.find( res_name );
136 if ( res != m_availableResources.end() && res->second >= res_value ) {
137 res->second -= res_value;
138 } else {
140 const auto lvl = static_cast<MSG::Level>( m_missingResourceMsgLevel.value() );
141 if ( msgLevel( lvl ) ) {
142 msgStream( lvl ) << "Failure to allocate resource '" << res_name << "' for algorithm " << name
143 << " (required: " << res_value << ", available: " << res->second << ")" << endmsg;
144 }
145 break;
146 }
147 }
148
149 // Could not acquire all resources
150 if ( sc.isFailure() ) {
151 // Restore resources
152 m_availableResources = std::move( tmpResources );
153
154 // in case of not reentrant, push it back. Reentrant ones are pushed back
155 // in all cases further down
156 if ( !algo->isReEntrant() ) { itQueueIAlgPtr->second->push( algo ); }
157 }
158 }
159
160 if ( algo->isReEntrant() ) {
161 // push back reentrant algorithms immediately as it can be reused
162 itQueueIAlgPtr->second->push( algo );
163 }
164 }
165 return sc;
166}
#define DEBUG_MSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
std::mutex m_resource_mutex
Gaudi::Property< bool > m_countAlgInstMisses
Gaudi::Property< int > m_missingResourceMsgLevel
Gaudi::Property< IAlgorithm::AlgResources_t > m_availableResources
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & msgStream() const
Return an uninitialized MsgStream.
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
virtual const AlgResources_t & neededResources() const =0
Named, non thread-safe resources used during event processing.
virtual bool isReEntrant() const =0
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
bool isFailure() const
Definition StatusCode.h:118
bool isSuccess() const
Definition StatusCode.h:302
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ acquireResource()

StatusCode AlgResourcePool::acquireResource ( std::string_view name,
unsigned int value )
override

Acquire units of a certain resource.

Definition at line 191 of file AlgResourcePool.cpp.

191 {
192 std::scoped_lock lock( m_resource_mutex );
193 auto res = m_availableResources.find( Gaudi::StringKey( name ) );
194 if ( res != m_availableResources.end() && res->second >= value ) {
195 res->second -= value;
196 return StatusCode::SUCCESS;
197 }
198
199 return StatusCode::FAILURE;
200}
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ decodeTopAlgs()

StatusCode AlgResourcePool::decodeTopAlgs ( )
private

Decode the top Algorithm list.

Definition at line 249 of file AlgResourcePool.cpp.

249 {
250
251 SmartIF<IAlgManager> algMan( serviceLocator() );
252 if ( !algMan.isValid() ) {
253 error() << "Algorithm manager could not be properly fetched." << endmsg;
254 return StatusCode::FAILURE;
255 }
256
257 StatusCode sc = StatusCode::SUCCESS;
258
259 // Fill the top algorithm list ----
260 for ( const std::string& typeName : m_topAlgNames ) {
261 IAlgorithm* algo = algMan->algorithm( typeName, /*createIf*/ true ).get();
262 sc = algo->sysInitialize();
263 if ( sc.isFailure() ) {
264 error() << "Unable to initialize Algorithm: " << algo->name() << endmsg;
265 return sc;
266 }
267 m_topAlgList.push_back( algo );
268 }
269 // Top algorithm list filled ----
270
271 // Now we unroll it ----
272 for ( IAlgorithm* ialgo : m_topAlgList ) { sc = flattenSequencer( ialgo, m_flatUniqueAlgList ); }
273 // stupid O(N^2) unique-ification..
274 for ( auto i = begin( m_flatUniqueAlgList ); i != end( m_flatUniqueAlgList ); ++i ) {
275 auto n = next( i );
276 while ( n != end( m_flatUniqueAlgList ) ) {
277 if ( *n == *i )
278 n = m_flatUniqueAlgList.erase( n );
279 else
280 ++n;
281 }
282 }
283 ON_DEBUG {
284 debug() << "List of algorithms is: " << endmsg;
285 for ( IAlgorithm* algo : m_flatUniqueAlgList )
286 debug() << " o " << algo->type() << "/" << algo->name() << " @ " << algo << endmsg;
287 }
288
289 // Unrolled ---
290
291 // Now let's manage the clones
292 std::hash<std::string> hash_function;
293 for ( IAlgorithm* ialgo : m_flatUniqueAlgList ) {
294
295 const std::string& item_name = ialgo->name();
296 const std::string& item_type = ialgo->type();
297 size_t algo_id = hash_function( item_name );
299 m_algqueue_map[algo_id] = queue;
300
301 if ( msgLevel( MSG::VERBOSE ) ) {
302 verbose() << "Treating resource management and clones of " << item_name << endmsg;
303 }
304
305 queue->push( ialgo );
306 m_algList.push_back( ialgo );
307 if ( ialgo->isReEntrant() ) {
308 if ( ialgo->cardinality() != 0 ) {
309 info() << "Algorithm " << ialgo->name() << " is ReEntrant, but Cardinality was set to " << ialgo->cardinality()
310 << ". Only creating 1 instance" << endmsg;
311 }
312 m_n_of_allowed_instances[algo_id] = 1;
313 } else if ( ialgo->isClonable() ) {
314 m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
315 } else {
316 if ( ialgo->cardinality() == 1 ) {
317 m_n_of_allowed_instances[algo_id] = 1;
318 } else {
319 if ( !m_overrideUnClonable ) {
320 info() << "Algorithm " << ialgo->name() << " is un-Clonable but Cardinality was set to "
321 << ialgo->cardinality() << ". Only creating 1 instance" << endmsg;
322 m_n_of_allowed_instances[algo_id] = 1;
323 } else {
324 warning() << "Overriding UnClonability of Algorithm " << ialgo->name() << ". Setting Cardinality to "
325 << ialgo->cardinality() << endmsg;
326 m_n_of_allowed_instances[algo_id] = ialgo->cardinality();
327 }
328 }
329 }
330 m_n_of_created_instances[algo_id] = 1;
331
332 // potentially create clones; if not lazy creation we have to do it now
333 if ( !m_lazyCreation ) {
334 for ( unsigned int i = 1, end = m_n_of_allowed_instances[algo_id]; i < end; ++i ) {
335 DEBUG_MSG << "type/name to create clone of: " << item_type << "/" << item_name << endmsg;
336 IAlgorithm* ialgoClone( nullptr );
337
338 if ( StatusCode createAlgSc = algMan->createAlgorithm( item_type, item_name, ialgoClone, /*managed*/ true,
339 /*checkIfExists*/ false );
340 createAlgSc.isFailure() ) {
341 return createAlgSc;
342 }
343 ialgoClone->setIndex( i );
344 queue->push( ialgoClone );
345 m_n_of_created_instances[algo_id] += 1;
346 }
347 }
348 }
349
350 return sc;
351}
#define ON_DEBUG
std::map< size_t, size_t > m_n_of_allowed_instances
Gaudi::Property< bool > m_lazyCreation
std::list< IAlgorithm * > m_algList
The list of all algorithms created within the Pool which are not top.
Gaudi::Property< std::vector< std::string > > m_topAlgNames
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
std::map< size_t, unsigned int > m_n_of_created_instances
Gaudi::Property< bool > m_overrideUnClonable
StatusCode flattenSequencer(IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
virtual const std::string & type() const =0
The type of the algorithm.
virtual StatusCode sysInitialize()=0
Initialization method invoked by the framework.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
AttribStringParser::Iterator begin(const AttribStringParser &parser)
@ VERBOSE
Definition IMessageSvc.h:22

◆ dumpInstanceMisses()

void AlgResourcePool::dumpInstanceMisses ( ) const
private

Dump recorded Algorithm instance misses.

Definition at line 362 of file AlgResourcePool.cpp.

362 {
363
364 std::multimap<unsigned int, std::string_view, std::greater<unsigned int>> sortedAlgInstanceMisses;
365
366 for ( auto& p : m_algInstanceMisses ) sortedAlgInstanceMisses.insert( { p.second, p.first } );
367
368 // determine optimal indentation
369 int indnt = std::to_string( sortedAlgInstanceMisses.cbegin()->first ).length();
370
371 std::ostringstream out;
372
373 out << "Hit parade of algorithm instance misses:\n"
374 << std::right << std::setfill( ' ' )
375 << " ===============================================================================\n"
376 << std::setw( indnt + 7 ) << "Misses "
377 << "| Algorithm (# of clones) \n"
378 << " ===============================================================================\n";
379
380 std::hash<std::string_view> hash_function;
381
382 out << std::right << std::setfill( ' ' );
383 for ( const auto& p : sortedAlgInstanceMisses ) {
384 out << std::setw( indnt + 7 ) << std::to_string( p.first ) + " "
385 << " " << p.second << " (" << m_n_of_allowed_instances.at( hash_function( p.second ) ) << ")\n";
386 }
387
388 info() << out.str() << endmsg;
389}

◆ finalize()

StatusCode AlgResourcePool::finalize ( )
override

Definition at line 411 of file AlgResourcePool.cpp.

411 {
412 m_topAlgList.clear();
413 m_algList.clear();
414 m_flatUniqueAlgList.clear();
415 return extends::finalize();
416}

◆ flattenSequencer()

StatusCode AlgResourcePool::flattenSequencer ( IAlgorithm * sequencer,
std::list< IAlgorithm * > & alglist,
unsigned int recursionDepth = 0 )
private

Recursively flatten an algList.

Definition at line 215 of file AlgResourcePool.cpp.

216 {
217
218 StatusCode sc = StatusCode::SUCCESS;
219
220 if ( algo->isSequence() ) {
221 auto seq = dynamic_cast<Gaudi::Sequence*>( algo );
222 if ( seq == 0 ) {
223 error() << "Unable to dcast Algorithm " << algo->name() << " to a Sequence, but it has isSequence==true"
224 << endmsg;
225 return StatusCode::FAILURE;
226 }
227
228 auto subAlgorithms = seq->subAlgorithms();
229
230 // Recursively unroll
231 ++recursionDepth;
232
233 for ( auto subalgo : *subAlgorithms ) {
234 sc = flattenSequencer( subalgo, alglist, recursionDepth );
235 if ( sc.isFailure() ) {
236 error() << "Algorithm " << subalgo->name() << " could not be flattened" << endmsg;
237 return sc;
238 }
239 }
240 } else {
241 alglist.emplace_back( algo );
242 return sc;
243 }
244 return sc;
245}

◆ getFlatAlgList()

std::list< IAlgorithm * > AlgResourcePool::getFlatAlgList ( )
override

Definition at line 355 of file AlgResourcePool.cpp.

355{ return m_flatUniqueAlgList; }

◆ getTopAlgList()

std::list< IAlgorithm * > AlgResourcePool::getTopAlgList ( )
override

Definition at line 359 of file AlgResourcePool.cpp.

359{ return m_topAlgList; }

◆ initialize()

StatusCode AlgResourcePool::initialize ( )
override

Definition at line 37 of file AlgResourcePool.cpp.

37 {
38
39 StatusCode sc( Service::initialize() );
40 if ( !sc.isSuccess() ) warning() << "Base class could not be started" << endmsg;
41
42 // Try to recover the topAlgList from the ApplicationManager for backward-compatibility
43 if ( m_topAlgNames.value().empty() ) {
44 info() << "TopAlg list empty. Recovering the one of Application Manager" << endmsg;
45 const Gaudi::Utils::TypeNameString appMgrName( "ApplicationMgr/ApplicationMgr" );
46 SmartIF<IProperty> appMgrProps( serviceLocator()->service( appMgrName ) );
47 m_topAlgNames.assign( appMgrProps->getProperty( "TopAlg" ) );
48 }
49
50 sc = decodeTopAlgs();
51 if ( sc.isFailure() ) warning() << "Algorithms could not be properly decoded." << endmsg;
52
54
55 // Check if an algorithm requests more of a resource than is available
56 for ( const IAlgorithm* algo : m_flatUniqueAlgList ) {
57 for ( const auto& [res_name, res_required] : algo->neededResources() ) {
58 auto res = m_availableResources.find( res_name );
59 auto res_available = ( res != m_availableResources.end() ) ? res->second : 0;
60 if ( res_required > res_available ) {
61 error() << "Cannot satisfy resource requirement '" << res_name << "' for algorithm '" << algo->name()
62 << " (required: " << res_required << ", available: " << res_available << ")" << endmsg;
64 }
65 }
66 }
67
69}
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
StatusCode initialize() override
Definition Service.cpp:118

◆ releaseAlgorithm()

StatusCode AlgResourcePool::releaseAlgorithm ( std::string_view name,
IAlgorithm *& algo )
override

Release a certain algorithm.

Definition at line 170 of file AlgResourcePool.cpp.

170 {
171
172 std::hash<std::string_view> hash_function;
173 size_t algo_id = hash_function( name );
174
175 // release resources used by the algorithm
176 {
177 std::scoped_lock lock( m_resource_mutex );
178 for ( const auto& [res_name, res_value] : algo->neededResources() ) {
179 auto res = m_availableResources.find( res_name );
180 if ( res != m_availableResources.end() ) { res->second += res_value; }
181 }
182 }
183
184 // release algorithm itself if not reentrant
185 if ( !algo->isReEntrant() ) { m_algqueue_map[algo_id]->push( algo ); }
186 return StatusCode::SUCCESS;
187}

◆ releaseResource()

StatusCode AlgResourcePool::releaseResource ( std::string_view name,
unsigned int value )
override

Release a certain resource.

Definition at line 204 of file AlgResourcePool.cpp.

204 {
205 std::scoped_lock lock( m_resource_mutex );
206 auto res = m_availableResources.find( Gaudi::StringKey( name ) );
207 if ( res == m_availableResources.end() ) { return StatusCode::FAILURE; }
208
209 res->second += value;
210 return StatusCode::SUCCESS;
211}

◆ start()

StatusCode AlgResourcePool::start ( )
override

Definition at line 73 of file AlgResourcePool.cpp.

73 {
74
75 StatusCode startSc = Service::start();
76 if ( !startSc.isSuccess() ) return startSc;
77
78 // sys-Start the algorithms
79 for ( IAlgorithm* ialgo : m_algList ) {
80 startSc = ialgo->sysStart();
81 if ( startSc.isFailure() ) {
82 error() << "Unable to start Algorithm: " << ialgo->name() << endmsg;
83 return startSc;
84 }
85 }
87}
StatusCode start() override
Definition Service.cpp:187

◆ stop()

StatusCode AlgResourcePool::stop ( )
override

Definition at line 393 of file AlgResourcePool.cpp.

393 {
394
395 StatusCode stopSc = Service::stop();
396 if ( !stopSc.isSuccess() ) return stopSc;
397
398 // sys-Stop the algorithm
399 for ( IAlgorithm* ialgo : m_algList ) {
400 stopSc = ialgo->sysStop();
401 if ( stopSc.isFailure() ) {
402 error() << "Unable to stop Algorithm: " << ialgo->name() << endmsg;
403 return stopSc;
404 }
405 }
407
408 return StatusCode::SUCCESS;
409}
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
StatusCode stop() override
Definition Service.cpp:181

Member Data Documentation

◆ m_algInstanceMisses

std::unordered_map<std::string_view, unsigned int> AlgResourcePool::m_algInstanceMisses
private

Counters for Algorithm instance misses.

Definition at line 78 of file AlgResourcePool.h.

◆ m_algList

std::list<IAlgorithm*> AlgResourcePool::m_algList
private

The list of all algorithms created within the Pool which are not top.

Definition at line 95 of file AlgResourcePool.h.

◆ m_algqueue_map

std::map<size_t, concurrentQueueIAlgPtr*> AlgResourcePool::m_algqueue_map
private

Definition at line 64 of file AlgResourcePool.h.

◆ m_availableResources

Gaudi::Property<IAlgorithm::AlgResources_t> AlgResourcePool::m_availableResources
private
Initial value:
{
this, "AvailableResources", {}, "Available named resources and their amounts" }

Definition at line 88 of file AlgResourcePool.h.

88 {
89 this, "AvailableResources", {}, "Available named resources and their amounts" };

◆ m_countAlgInstMisses

Gaudi::Property<bool> AlgResourcePool::m_countAlgInstMisses
private
Initial value:
{
this, "CountAlgorithmInstanceMisses", false,
"Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." }

Definition at line 85 of file AlgResourcePool.h.

85 {
86 this, "CountAlgorithmInstanceMisses", false,
87 "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };

◆ m_flatUniqueAlgList

std::list<IAlgorithm*> AlgResourcePool::m_flatUniqueAlgList
private

The flat list of algorithms w/o clones.

Definition at line 101 of file AlgResourcePool.h.

◆ m_lazyCreation

Gaudi::Property<bool> AlgResourcePool::m_lazyCreation { this, "CreateLazily", false, "" }
private

Definition at line 80 of file AlgResourcePool.h.

80{ this, "CreateLazily", false, "" };

◆ m_missingResourceMsgLevel

Gaudi::Property<int> AlgResourcePool::m_missingResourceMsgLevel
private
Initial value:
{
this, "MissingResourceMessageLevel", MSG::DEBUG,
"Message level in case an algorithm cannot be schedule due to a missing resource" }
@ DEBUG
Definition IMessageSvc.h:22

Definition at line 90 of file AlgResourcePool.h.

90 {
91 this, "MissingResourceMessageLevel", MSG::DEBUG,
92 "Message level in case an algorithm cannot be schedule due to a missing resource" };

◆ m_n_of_allowed_instances

std::map<size_t, size_t> AlgResourcePool::m_n_of_allowed_instances
private

Definition at line 65 of file AlgResourcePool.h.

◆ m_n_of_created_instances

std::map<size_t, unsigned int> AlgResourcePool::m_n_of_created_instances
private

Definition at line 66 of file AlgResourcePool.h.

◆ m_overrideUnClonable

Gaudi::Property<bool> AlgResourcePool::m_overrideUnClonable
private
Initial value:
{ this, "OverrideUnClonable", false,
"Override the un-clonability of algorithms. Use with caution!" }

Definition at line 83 of file AlgResourcePool.h.

83 { this, "OverrideUnClonable", false,
84 "Override the un-clonability of algorithms. Use with caution!" };

◆ m_resource_mutex

std::mutex AlgResourcePool::m_resource_mutex
private

Definition at line 62 of file AlgResourcePool.h.

◆ m_topAlgList

std::list<IAlgorithm*> AlgResourcePool::m_topAlgList
private

The list of top algorithms.

Definition at line 98 of file AlgResourcePool.h.

◆ m_topAlgNames

Gaudi::Property<std::vector<std::string> > AlgResourcePool::m_topAlgNames
private
Initial value:
{
this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" }

Definition at line 81 of file AlgResourcePool.h.

81 {
82 this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };

The documentation for this class was generated from the following files: