The Gaudi Framework  master (bb95dfce)
Loading...
Searching...
No Matches
AlgResourcePool.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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 <list>
19#include <map>
20#include <mutex>
21#include <string>
22#include <string_view>
23#include <tbb/concurrent_queue.h>
24#include <unordered_map>
25#include <vector>
26
35class AlgResourcePool : public extends<Service, IAlgResourcePool> {
36public:
37 // Standard constructor
38 using extends::extends;
39 // Standard destructor
40 ~AlgResourcePool() override;
41
42 StatusCode start() override;
43 StatusCode initialize() override;
45 StatusCode acquireAlgorithm( std::string_view name, IAlgorithm*& algo, bool blocking = false ) override;
47 StatusCode releaseAlgorithm( std::string_view name, IAlgorithm*& algo ) override;
49 StatusCode acquireResource( std::string_view name, unsigned int value ) override;
51 StatusCode releaseResource( std::string_view name, unsigned int value ) override;
52
53 std::list<IAlgorithm*> getFlatAlgList() override;
54 std::list<IAlgorithm*> getTopAlgList() override;
55
56 StatusCode stop() override;
57 StatusCode finalize() override;
58
59private:
60 typedef tbb::concurrent_bounded_queue<IAlgorithm*> concurrentQueueIAlgPtr;
61
62 std::mutex m_resource_mutex;
63
64 std::map<size_t, concurrentQueueIAlgPtr*> m_algqueue_map;
65 std::map<size_t, size_t> m_n_of_allowed_instances;
66 std::map<size_t, unsigned int> m_n_of_created_instances;
67
70
72 StatusCode flattenSequencer( IAlgorithm* sequencer, std::list<IAlgorithm*>& alglist,
73 unsigned int recursionDepth = 0 );
74
76 void dumpInstanceMisses() const;
78 std::unordered_map<std::string_view, unsigned int> m_algInstanceMisses;
79
80 Gaudi::Property<bool> m_lazyCreation{ this, "CreateLazily", false, "" };
82 this, "TopAlg", {}, "Names of the algorithms to be passed to the algorithm manager" };
83 Gaudi::Property<bool> m_overrideUnClonable{ this, "OverrideUnClonable", false,
84 "Override the un-clonability of algorithms. Use with caution!" };
86 this, "CountAlgorithmInstanceMisses", false,
87 "Count and print out algorithm instance misses. Useful for finding ways to improve throughput scalability." };
89 this, "AvailableResources", {}, "Available named resources and their amounts" };
91 this, "MissingResourceMessageLevel", MSG::DEBUG,
92 "Message level in case an algorithm cannot be schedule due to a missing resource" };
93
95 std::list<IAlgorithm*> m_algList;
96
98 std::list<IAlgorithm*> m_topAlgList;
99
101 std::list<IAlgorithm*> m_flatUniqueAlgList;
102};
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
Gaudi::Property< bool > m_lazyCreation
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
StatusCode acquireResource(std::string_view name, unsigned int value) override
Acquire units of a certain resource.
std::list< IAlgorithm * > m_flatUniqueAlgList
The flat list of algorithms w/o clones.
void dumpInstanceMisses() const
Dump recorded Algorithm instance misses.
Gaudi::Property< int > m_missingResourceMsgLevel
StatusCode releaseResource(std::string_view name, unsigned int value) override
Release a certain resource.
std::list< IAlgorithm * > getTopAlgList() override
StatusCode finalize() override
tbb::concurrent_bounded_queue< IAlgorithm * > concurrentQueueIAlgPtr
Gaudi::Property< IAlgorithm::AlgResources_t > m_availableResources
std::list< IAlgorithm * > m_topAlgList
The list of top algorithms.
StatusCode stop() override
std::map< size_t, unsigned int > m_n_of_created_instances
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.
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.
Implementation of property with value of concrete type.
Definition Property.h:35
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition IAlgorithm.h:37
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
@ DEBUG
Definition IMessageSvc.h:22