The Gaudi Framework  master (37c0b60a)
AlgResourcePool.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <Gaudi/Algorithm.h>
16 #include <GaudiKernel/IAlgorithm.h>
17 #include <GaudiKernel/Service.h>
18 #include <atomic>
19 #include <bitset>
20 #include <boost/dynamic_bitset.hpp>
21 #include <list>
22 #include <map>
23 #include <mutex>
24 #include <string>
25 #include <string_view>
26 #include <tbb/concurrent_queue.h>
27 #include <unordered_map>
28 #include <vector>
29 
38 class AlgResourcePool : public extends<Service, IAlgResourcePool> {
39 public:
40  // Standard constructor
41  using extends::extends;
42  // Standard destructor
43  ~AlgResourcePool() override;
44 
45  StatusCode start() override;
46  StatusCode initialize() override;
48  StatusCode acquireAlgorithm( std::string_view name, IAlgorithm*& algo, bool blocking = false ) override;
50  StatusCode releaseAlgorithm( std::string_view name, IAlgorithm*& algo ) override;
52  StatusCode acquireResource( std::string_view name ) override;
54  StatusCode releaseResource( std::string_view name ) override;
55 
58 
59  StatusCode stop() override;
60  StatusCode finalize() override;
61 
62 private:
63  typedef tbb::concurrent_bounded_queue<IAlgorithm*> concurrentQueueIAlgPtr;
65  typedef boost::dynamic_bitset<> state_type;
66 
68 
75 
78 
80  StatusCode flattenSequencer( Gaudi::Algorithm* sequencer, ListAlg& alglist, unsigned int recursionDepth = 0 );
81 
83  void dumpInstanceMisses() const;
86 
87  Gaudi::Property<bool> m_lazyCreation{ this, "CreateLazily", false, "" };
89  this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };
90  Gaudi::Property<bool> m_overrideUnClonable{ this, "OverrideUnClonable", false,
91  "Override the un-clonability of algorithms. Use with caution!" };
93  this, "CountAlgorithmInstanceMisses", false,
94  "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };
95 
98 
101 
104 
107 
110 };
AlgResourcePool::~AlgResourcePool
~AlgResourcePool() override
Definition: AlgResourcePool.cpp:29
AlgResourcePool::initialize
StatusCode initialize() override
Definition: AlgResourcePool.cpp:39
AtlasMCRecoFullPrecedenceDump.sequencer
sequencer
Definition: AtlasMCRecoFullPrecedenceDump.py:52
IAlgManager.h
IAlgResourcePool.h
AlgResourcePool::ListAlg
std::list< SmartIF< IAlgorithm > > ListAlg
Definition: AlgResourcePool.h:64
AlgResourcePool::m_countAlgInstMisses
Gaudi::Property< bool > m_countAlgInstMisses
Definition: AlgResourcePool.h:92
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:69
std::list< IAlgorithm * >
AlgResourcePool::releaseResource
StatusCode releaseResource(std::string_view name) override
Release a certain resource.
Definition: AlgResourcePool.cpp:169
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created within the Pool which are not top.
Definition: AlgResourcePool.h:97
AlgResourcePool::m_flatUniqueAlgList
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
Definition: AlgResourcePool.h:103
AlgResourcePool::state_type
boost::dynamic_bitset state_type
Definition: AlgResourcePool.h:65
AlgResourcePool::m_flatUniqueAlgPtrList
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
Definition: AlgResourcePool.h:106
AlgResourcePool::m_n_of_created_instances
std::map< size_t, unsigned int > m_n_of_created_instances
Definition: AlgResourcePool.h:73
AlgResourcePool::finalize
StatusCode finalize() override
Definition: AlgResourcePool.cpp:435
AlgResourcePool
Definition: AlgResourcePool.h:38
AlgResourcePool::m_resource_requirements
std::map< size_t, state_type > m_resource_requirements
Definition: AlgResourcePool.h:71
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
IAlgorithm
Definition: IAlgorithm.h:38
AlgResourcePool::m_resource_indices
std::map< std::string_view, unsigned int > m_resource_indices
Definition: AlgResourcePool.h:74
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
AlgResourcePool::stop
StatusCode stop() override
Definition: AlgResourcePool.cpp:417
Algorithm.h
AlgResourcePool::dumpInstanceMisses
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
Definition: AlgResourcePool.cpp:386
AlgResourcePool::decodeTopAlgs
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
Definition: AlgResourcePool.cpp:211
AlgResourcePool::concurrentQueueIAlgPtr
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Definition: AlgResourcePool.h:63
AlgResourcePool::m_overrideUnClonable
Gaudi::Property< bool > m_overrideUnClonable
Definition: AlgResourcePool.h:90
std::map< size_t, concurrentQueueIAlgPtr * >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
AlgResourcePool::m_n_of_allowed_instances
std::map< size_t, size_t > m_n_of_allowed_instances
Definition: AlgResourcePool.h:72
AlgResourcePool::start
StatusCode start() override
Definition: AlgResourcePool.cpp:62
Service.h
AlgResourcePool::m_algInstanceMisses
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
Definition: AlgResourcePool.h:85
AlgResourcePool::m_lazyCreation
Gaudi::Property< bool > m_lazyCreation
Definition: AlgResourcePool.h:87
AlgResourcePool::acquireResource
StatusCode acquireResource(std::string_view name) override
Acquire a certain resource.
Definition: AlgResourcePool.cpp:160
AlgResourcePool::m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Definition: AlgResourcePool.h:88
AlgResourcePool::flattenSequencer
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Definition: AlgResourcePool.cpp:178
AlgResourcePool::m_algqueue_map
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
Definition: AlgResourcePool.h:70
AlgResourcePool::acquireAlgorithm
StatusCode acquireAlgorithm(std::string_view name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
Definition: AlgResourcePool.cpp:80
AlgResourcePool::getFlatAlgList
std::list< IAlgorithm * > getFlatAlgList() override
Definition: AlgResourcePool.cpp:371
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:67
std::mutex
STL class.
IAlgorithm.h
AlgResourcePool::releaseAlgorithm
StatusCode releaseAlgorithm(std::string_view name, IAlgorithm *&algo) override
Release a certain algorithm.
Definition: AlgResourcePool.cpp:143
std::unordered_map< std::string_view, unsigned int >
AlgResourcePool::m_topAlgPtrList
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
Definition: AlgResourcePool.h:109
Gaudi::Property< bool >
AlgResourcePool::m_topAlgList
ListAlg m_topAlgList
The list of top algorithms.
Definition: AlgResourcePool.h:100
AlgResourcePool::getTopAlgList
std::list< IAlgorithm * > getTopAlgList() override
Definition: AlgResourcePool.cpp:379