The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
AlgResourcePool.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
16#include <GaudiKernel/Service.h>
17#include <atomic>
18#include <bitset>
19#include <boost/dynamic_bitset.hpp>
20#include <list>
21#include <map>
22#include <mutex>
23#include <string>
24#include <string_view>
25#include <tbb/concurrent_queue.h>
26#include <unordered_map>
27#include <vector>
28
37class AlgResourcePool : public extends<Service, IAlgResourcePool> {
38public:
39 // Standard constructor
40 using extends::extends;
41 // Standard destructor
42 ~AlgResourcePool() override;
43
44 StatusCode start() override;
45 StatusCode initialize() override;
47 StatusCode acquireAlgorithm( std::string_view name, IAlgorithm*& algo, bool blocking = false ) override;
49 StatusCode releaseAlgorithm( std::string_view name, IAlgorithm*& algo ) override;
51 StatusCode acquireResource( std::string_view name ) override;
53 StatusCode releaseResource( std::string_view name ) override;
54
55 std::list<IAlgorithm*> getFlatAlgList() override;
56 std::list<IAlgorithm*> getTopAlgList() override;
57
58 StatusCode stop() override;
59 StatusCode finalize() override;
60
61private:
62 typedef tbb::concurrent_bounded_queue<IAlgorithm*> concurrentQueueIAlgPtr;
63 typedef boost::dynamic_bitset<> state_type;
64
65 std::mutex m_resource_mutex;
66
68 std::map<size_t, concurrentQueueIAlgPtr*> m_algqueue_map;
69 std::map<size_t, state_type> m_resource_requirements;
70 std::map<size_t, size_t> m_n_of_allowed_instances;
71 std::map<size_t, unsigned int> m_n_of_created_instances;
72 std::map<std::string_view, unsigned int> m_resource_indices;
73
76
78 StatusCode flattenSequencer( IAlgorithm* sequencer, std::list<IAlgorithm*>& alglist,
79 unsigned int recursionDepth = 0 );
80
82 void dumpInstanceMisses() const;
84 std::unordered_map<std::string_view, unsigned int> m_algInstanceMisses;
85
86 Gaudi::Property<bool> m_lazyCreation{ this, "CreateLazily", false, "" };
88 this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };
89 Gaudi::Property<bool> m_overrideUnClonable{ this, "OverrideUnClonable", false,
90 "Override the un-clonability of algorithms. Use with caution!" };
92 this, "CountAlgorithmInstanceMisses", false,
93 "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };
94
96 std::list<IAlgorithm*> m_algList;
97
99 std::list<IAlgorithm*> m_topAlgList;
100
102 std::list<IAlgorithm*> m_flatUniqueAlgList;
103};
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
std::list< IAlgorithm * > getFlatAlgList() override
std::map< size_t, size_t > m_n_of_allowed_instances
StatusCode acquireResource(std::string_view name) override
Acquire a certain resource.
Gaudi::Property< bool > m_lazyCreation
boost::dynamic_bitset state_type
std::list< IAlgorithm * > m_algList
The list of all algorithms created within the Pool which are not top.
std::map< size_t, concurrentQueueIAlgPtr * > m_algqueue_map
StatusCode initialize() override
std::mutex m_resource_mutex
StatusCode releaseAlgorithm(std::string_view name, IAlgorithm *&algo) override
Release a certain algorithm.
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Gaudi::Property< bool > m_countAlgInstMisses
~AlgResourcePool() override
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
std::list< IAlgorithm * > getTopAlgList() override
StatusCode finalize() override
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
StatusCode releaseResource(std::string_view name) override
Release a certain resource.
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
StatusCode stop() override
std::map< size_t, unsigned int > m_n_of_created_instances
state_type m_available_resources
StatusCode acquireAlgorithm(std::string_view name, IAlgorithm *&algo, bool blocking=false) override
Acquire a certain algorithm using its name.
std::unordered_map< std::string_view, unsigned int > m_algInstanceMisses
Counters for Algorithm instance misses.
std::map< size_t, state_type > m_resource_requirements
StatusCode start() override
StatusCode decodeTopAlgs()
Decode the top Algorithm list.
Gaudi::Property< bool > m_overrideUnClonable
StatusCode flattenSequencer(IAlgorithm *sequencer, std::list< IAlgorithm * > &alglist, unsigned int recursionDepth=0)
Recursively flatten an algList.
std::map< std::string_view, unsigned int > m_resource_indices
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition IAlgorithm.h:36
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
Base class used to extend a class implementing other interfaces.
Definition extends.h:19