The Gaudi Framework  master (37c0b60a)
CPUCruncher.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 
12 #include <GaudiKernel/Algorithm.h>
18 #include <tbb/concurrent_hash_map.h>
19 
20 //------------------------------------------------------------------------------
21 
29 class CPUCruncher : public Algorithm {
30 
31 public:
32  typedef tbb::concurrent_hash_map<std::string, unsigned int> CHM;
33 
34  bool isClonable() const override { return true; }
35 
37  StatusCode execute() override;
39  StatusCode initialize() override;
41  StatusCode finalize() override;
42 
43  double get_runtime() const { return m_avg_runtime; }
44 
45  CPUCruncher( const std::string& name, // the algorithm instance name
46  ISvcLocator* pSvc ); // the Service Locator
47 
49  virtual ~CPUCruncher(); // virtual & protected desctrustor
50 
51 private:
53  CPUCruncher(); // no default constructor
55  CPUCruncher( const CPUCruncher& ); // no copy constructor
57  CPUCruncher& operator=( const CPUCruncher& ); // no assignement
59 
62  bool m_declAugmented{ false };
63  Gaudi::Property<bool> m_loader{ this, "Loader", false, "Declare the algorithm to be a data loader" };
64 
67 
68  Gaudi::Property<double> m_avg_runtime{ this, "avgRuntime", 1., "Average runtime of the module." };
69  Gaudi::Property<double> m_var_runtime{ this, "varRuntime", 0.01, "Variance of the runtime of the module." };
70  Gaudi::Property<bool> m_local_rndm_gen{ this, "localRndm", true,
71  "Decide if the local random generator is to be used" };
72  Gaudi::Property<unsigned int> m_rwRepetitions{ this, "RwRepetitions", 1, "Increase access to the WB" };
74  this, "SleepFraction", 0.0,
75  "Fraction of time, between 0 and 1, when an algorithm is actually sleeping instead of crunching" };
76  Gaudi::Property<bool> m_invertCFD{ this, "InvertDecision", false, "Invert control flow decision." };
77  Gaudi::Property<unsigned int> m_failNEvents{ this, "FailNEvents", 0, "Return FAILURE on every Nth event" };
78  Gaudi::Property<int> m_nParallel{ this, "NParallel", -1, "Run N parallel crunching tasks" };
79 
80  // For the concurrency
81  const uint MAX_INPUTS = 40;
82  const uint MAX_OUTPUTS = 10;
83 
86 
88 
89  // CPUCrunchSvc
91 };
CPUCruncher::m_inpKeys
Gaudi::Property< std::vector< std::string > > m_inpKeys
Definition: CPUCruncher.h:65
CPUCruncher::m_rwRepetitions
Gaudi::Property< unsigned int > m_rwRepetitions
Definition: CPUCruncher.h:72
CPUCruncher
Definition: CPUCruncher.h:29
CPUCruncher::m_loader
Gaudi::Property< bool > m_loader
Definition: CPUCruncher.h:63
CPUCruncher::operator=
CPUCruncher & operator=(const CPUCruncher &)
the assignement operator is disabled
CPUCruncher::MAX_INPUTS
const uint MAX_INPUTS
Definition: CPUCruncher.h:81
std::string
STL class.
RndmGenerators.h
CPUCruncher::initialize
StatusCode initialize() override
Its initialization.
Definition: CPUCruncher.cpp:50
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:526
std::vector
STL class.
CPUCruncher::declareRuntimeRequestedOutputs
void declareRuntimeRequestedOutputs()
The CPU intensive function.
Definition: CPUCruncher.cpp:86
ISvcLocator
Definition: ISvcLocator.h:46
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
IRndmGenSvc.h
Algorithm.h
CPUCruncher::m_invertCFD
Gaudi::Property< bool > m_invertCFD
Definition: CPUCruncher.h:76
CPUCruncher::CPUCruncher
CPUCruncher(const CPUCruncher &)
the copy constructor is disabled
CPUCruncher::m_declAugmented
bool m_declAugmented
Definition: CPUCruncher.h:62
RegistryEntry.h
ICPUCrunchSvc.h
CPUCruncher::m_var_runtime
Gaudi::Property< double > m_var_runtime
Definition: CPUCruncher.h:69
CPUCruncher::CPUCruncher
CPUCruncher()
the default constructor is disabled
CPUCruncher::m_failNEvents
Gaudi::Property< unsigned int > m_failNEvents
Definition: CPUCruncher.h:77
CPUCruncher::m_outKeys
Gaudi::Property< std::vector< std::string > > m_outKeys
Definition: CPUCruncher.h:66
CPUCruncher::get_runtime
double get_runtime() const
Definition: CPUCruncher.h:43
StatusCode
Definition: StatusCode.h:65
CPUCruncher::execute
StatusCode execute() override
the execution of the algorithm
Definition: CPUCruncher.cpp:102
CPUCruncher::finalize
StatusCode finalize() override
the finalization of the algorithm
Definition: CPUCruncher.cpp:217
CPUCruncher::m_local_rndm_gen
Gaudi::Property< bool > m_local_rndm_gen
Definition: CPUCruncher.h:70
SmartIF< ICPUCrunchSvc >
CPUCruncher::CHM
tbb::concurrent_hash_map< std::string, unsigned int > CHM
Definition: CPUCruncher.h:32
CPUCruncher::m_inputHandles
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
Definition: CPUCruncher.h:84
CPUCruncher::isClonable
bool isClonable() const override
Definition: CPUCruncher.h:34
CPUCruncher::m_name_ncopies_map
static CHM m_name_ncopies_map
Definition: CPUCruncher.h:87
CPUCruncher::m_avg_runtime
Gaudi::Property< double > m_avg_runtime
Definition: CPUCruncher.h:68
CPUCruncher::~CPUCruncher
virtual ~CPUCruncher()
virtual & protected desctrustor
Definition: CPUCruncher.cpp:44
CPUCruncher::m_crunchSvc
SmartIF< ICPUCrunchSvc > m_crunchSvc
Definition: CPUCruncher.h:90
CPUCruncher::m_outputHandles
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Definition: CPUCruncher.h:85
CPUCruncher::m_sleepFraction
Gaudi::Property< double > m_sleepFraction
Definition: CPUCruncher.h:73
DataObjectHandle.h
Gaudi::Property< bool >
CPUCruncher::m_nParallel
Gaudi::Property< int > m_nParallel
Definition: CPUCruncher.h:78
CPUCruncher::MAX_OUTPUTS
const uint MAX_OUTPUTS
Definition: CPUCruncher.h:82