The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgResourcePool.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #ifndef GAUDIHIVE_ALGRESOURCEPOOL_H
12 #define GAUDIHIVE_ALGRESOURCEPOOL_H
13 
16 #include "GaudiKernel/IAlgorithm.h"
17 #include "GaudiKernel/Service.h"
18 #include <Gaudi/Algorithm.h>
19 
20 #include <atomic>
21 #include <bitset>
22 #include <list>
23 #include <map>
24 #include <mutex>
25 #include <string>
26 #include <string_view>
27 #include <unordered_map>
28 #include <vector>
29 
30 // External libs
31 #include "boost/dynamic_bitset.hpp"
32 #include "tbb/concurrent_queue.h"
33 
42 class AlgResourcePool : public extends<Service, IAlgResourcePool> {
43 public:
44  // Standard constructor
45  using extends::extends;
46  // Standard destructor
47  ~AlgResourcePool() override;
48 
49  StatusCode start() override;
50  StatusCode initialize() override;
52  StatusCode acquireAlgorithm( std::string_view name, IAlgorithm*& algo, bool blocking = false ) override;
54  StatusCode releaseAlgorithm( std::string_view name, IAlgorithm*& algo ) override;
56  StatusCode acquireResource( std::string_view name ) override;
58  StatusCode releaseResource( std::string_view name ) override;
59 
62 
63  StatusCode stop() override;
64  StatusCode finalize() override;
65 
66 private:
67  typedef tbb::concurrent_bounded_queue<IAlgorithm*> concurrentQueueIAlgPtr;
69  typedef boost::dynamic_bitset<> state_type;
70 
72 
79 
82 
84  StatusCode flattenSequencer( Gaudi::Algorithm* sequencer, ListAlg& alglist, unsigned int recursionDepth = 0 );
85 
87  void dumpInstanceMisses() const;
90 
91  Gaudi::Property<bool> m_lazyCreation{ this, "CreateLazily", false, "" };
93  this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };
94  Gaudi::Property<bool> m_overrideUnClonable{ this, "OverrideUnClonable", false,
95  "Override the un-clonability of algorithms. Use with caution!" };
97  this, "CountAlgorithmInstanceMisses", false,
98  "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };
99 
102 
105 
108 
111 
114 };
115 
116 #endif // GAUDIHIVE_ALGRESOURCEPOOL_H
AlgResourcePool::~AlgResourcePool
~AlgResourcePool() override
Definition: AlgResourcePool.cpp:31
AlgResourcePool::initialize
StatusCode initialize() override
Definition: AlgResourcePool.cpp:41
AtlasMCRecoFullPrecedenceDump.sequencer
sequencer
Definition: AtlasMCRecoFullPrecedenceDump.py:52
IAlgManager.h
IAlgResourcePool.h
AlgResourcePool::ListAlg
std::list< SmartIF< IAlgorithm > > ListAlg
Definition: AlgResourcePool.h:68
AlgResourcePool::m_countAlgInstMisses
Gaudi::Property< bool > m_countAlgInstMisses
Definition: AlgResourcePool.h:96
AlgResourcePool::m_available_resources
state_type m_available_resources
Definition: AlgResourcePool.h:73
std::list< IAlgorithm * >
AlgResourcePool::releaseResource
StatusCode releaseResource(std::string_view name) override
Release a certain resource.
Definition: AlgResourcePool.cpp:171
AlgResourcePool::m_algList
ListAlg m_algList
The list of all algorithms created within the Pool which are not top.
Definition: AlgResourcePool.h:101
AlgResourcePool::m_flatUniqueAlgList
ListAlg m_flatUniqueAlgList
The flat list of algorithms w/o clones.
Definition: AlgResourcePool.h:107
AlgResourcePool::state_type
boost::dynamic_bitset state_type
Definition: AlgResourcePool.h:69
AlgResourcePool::m_flatUniqueAlgPtrList
std::list< IAlgorithm * > m_flatUniqueAlgPtrList
The flat list of algorithms w/o clones which is returned.
Definition: AlgResourcePool.h:110
AlgResourcePool::m_n_of_created_instances
std::map< size_t, unsigned int > m_n_of_created_instances
Definition: AlgResourcePool.h:77
AlgResourcePool::finalize
StatusCode finalize() override
Definition: AlgResourcePool.cpp:437
AlgResourcePool
Definition: AlgResourcePool.h:42
AlgResourcePool::m_resource_requirements
std::map< size_t, state_type > m_resource_requirements
Definition: AlgResourcePool.h:75
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:78
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:419
Algorithm.h
AlgResourcePool::dumpInstanceMisses
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
Definition: AlgResourcePool.cpp:388
AlgResourcePool::decodeTopAlgs
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
Definition: AlgResourcePool.cpp:213
AlgResourcePool::concurrentQueueIAlgPtr
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Definition: AlgResourcePool.h:67
AlgResourcePool::m_overrideUnClonable
Gaudi::Property< bool > m_overrideUnClonable
Definition: AlgResourcePool.h:94
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:76
AlgResourcePool::start
StatusCode start() override
Definition: AlgResourcePool.cpp:64
Service.h
AlgResourcePool::m_algInstanceMisses
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
Definition: AlgResourcePool.h:89
AlgResourcePool::m_lazyCreation
Gaudi::Property< bool > m_lazyCreation
Definition: AlgResourcePool.h:91
AlgResourcePool::acquireResource
StatusCode acquireResource(std::string_view name) override
Acquire a certain resource.
Definition: AlgResourcePool.cpp:162
AlgResourcePool::m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Definition: AlgResourcePool.h:92
AlgResourcePool::flattenSequencer
StatusCode flattenSequencer(Gaudi::Algorithm *sequencer, ListAlg &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
Definition: AlgResourcePool.cpp:180
AlgResourcePool::m_algqueue_map
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
Definition: AlgResourcePool.h:74
AlgResourcePool::acquireAlgorithm
StatusCode acquireAlgorithm(std::string_view name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
Definition: AlgResourcePool.cpp:82
AlgResourcePool::getFlatAlgList
std::list< IAlgorithm * > getFlatAlgList() override
Definition: AlgResourcePool.cpp:373
AlgResourcePool::m_resource_mutex
std::mutex m_resource_mutex
Definition: AlgResourcePool.h:71
std::mutex
STL class.
IAlgorithm.h
AlgResourcePool::releaseAlgorithm
StatusCode releaseAlgorithm(std::string_view name, IAlgorithm *&algo) override
Release a certain algorithm.
Definition: AlgResourcePool.cpp:145
std::unordered_map< std::string_view, unsigned int >
AlgResourcePool::m_topAlgPtrList
std::list< IAlgorithm * > m_topAlgPtrList
The top list of algorithms.
Definition: AlgResourcePool.h:113
Gaudi::Property< bool >
AlgResourcePool::m_topAlgList
ListAlg m_topAlgList
The list of top algorithms.
Definition: AlgResourcePool.h:104
AlgResourcePool::getTopAlgList
std::list< IAlgorithm * > getTopAlgList() override
Definition: AlgResourcePool.cpp:381