Go to the documentation of this file.
15 #include <sys/resource.h>
16 #include <sys/times.h>
17 #include <tbb/blocked_range.h>
18 #include <tbb/parallel_for.h>
19 #include <tbb/tick_count.h>
26 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
27 #define DEBUG_MSG ON_DEBUG debug()
29 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
30 #define VERBOSE_MSG ON_VERBOSE verbose()
40 CHM::accessor name_ninstances;
42 name_ninstances->second += 1;
57 fatal() <<
"unable to acquire CPUCruncSvc" <<
endmsg;
94 VERBOSE_MSG <<
"found late-attributed output: " << outputHandle->objKey() <<
endmsg;
126 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
129 auto getUnifRandom = [](
unsigned int&
seed ) ->
double {
131 constexpr
unsigned int m = 232;
132 constexpr
unsigned int a = 1664525;
133 constexpr
unsigned int c = 1013904223;
135 const double unif = double(
seed ) /
m;
141 unif1 = getUnifRandom(
seed );
142 unif2 = getUnifRandom(
seed );
145 const double normal =
sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
147 return normal * sigma +
mean;
155 crunchtime =
std::abs( rndmgaus() );
157 unsigned int crunchtime_ms = 1000 * crunchtime;
164 tbb::tick_count startSleeptbb;
165 tbb::tick_count endSleeptbb;
168 tbb::tick_count starttbb = tbb::tick_count::now();
174 DEBUG_MSG <<
"Dreaming time will be: " << int( 1000 * dreamtime ) <<
" ms" <<
endmsg;
176 ON_DEBUG startSleeptbb = tbb::tick_count::now();
178 ON_DEBUG endSleeptbb = tbb::tick_count::now();
182 const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
183 debug() <<
"Actual dreaming time was: " << int( 1000 * actualDreamTime ) <<
"ms" <<
endmsg;
187 DEBUG_MSG <<
"Crunching time will be: " << crunchtime_ms <<
" ms" <<
endmsg;
194 if ( !inputHandle->isValid() )
continue;
198 for (
unsigned int i = 0; i <
m_rwRepetitions; ++i ) { obj = inputHandle->get(); }
199 if ( obj ==
nullptr ) error() <<
"A read object was a null pointer." <<
endmsg;
203 tbb::parallel_for( tbb::blocked_range<size_t>( 0,
m_nParallel ), [&]( tbb::blocked_range<size_t> r ) {
205 debug() <<
"CPUCrunch complete in TBB parallel for block " << r.begin() <<
" to " << r.end() <<
endmsg;
218 if ( !outputHandle->isValid() )
continue;
221 outputHandle->put( std::make_unique<DataObject>() );
224 tbb::tick_count endtbb = tbb::tick_count::now();
225 const double actualRuntime = ( endtbb - starttbb ).seconds();
227 DEBUG_MSG <<
"Finish event " << context.
evt() <<
" in " << int( 1000 * actualRuntime ) <<
" ms" <<
endmsg;
229 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime_ms <<
" ms. ExpectedDreamtime= " << int( 1000 * dreamtime )
230 <<
" ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
231 <<
" ms. Ratio= " << ( crunchtime + dreamtime ) / actualRuntime <<
endmsg;
244 unsigned int ninstances;
247 CHM::const_accessor const_name_ninstances;
249 ninstances = const_name_ninstances->second;
252 constexpr
double s2ms = 1000.;
254 if ( ninstances != 0 ) {
255 info() <<
"Summary: name= " <<
name() <<
"\t avg_runtime= " <<
m_avg_runtime * s2ms <<
"\t n_clones= " << ninstances
258 CHM::accessor name_ninstances;
260 name_ninstances->second = 0;
Gaudi::Property< std::vector< std::string > > m_inpKeys
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
Gaudi::Property< unsigned int > m_rwRepetitions
Gaudi::Property< bool > m_loader
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
StatusCode initialize() override
Its initialization.
GAUDI_API const EventContext & currentContext()
const std::string & name() const override
The identifying name of the algorithm object.
void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
void declareRuntimeRequestedOutputs()
The CPU intensive function.
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Alias for backward compatibility.
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Gaudi::Property< bool > m_invertCFD
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.
Gaudi::Property< double > m_var_runtime
CPUCruncher()
the default constructor is disabled
Gaudi::Property< unsigned int > m_failNEvents
bool isValid() const
Allow for check if smart pointer is valid.
Gaudi::Property< std::vector< std::string > > m_outKeys
void initDataHandleHolder()
initializes all handles - called by the sysInitialize method of any descendant of this
Parameters for the Gauss random number generation.
StatusCode execute() override
the execution of the algorithm
void setBlocking(bool value)
StatusCode finalize() override
the finalization of the algorithm
Gaudi::Property< bool > m_local_rndm_gen
tbb::concurrent_hash_map< std::string, unsigned int > CHM
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
static CHM m_name_ncopies_map
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
constexpr static const auto SUCCESS
Gaudi::Property< double > m_avg_runtime
const DataObjIDColl & outputDataObjs() const override
#define DECLARE_COMPONENT(type)
Gaudi::Property< float > m_sleepFraction
virtual ~CPUCruncher()
virtual & protected desctrustor
SmartIF< ICPUCrunchSvc > m_crunchSvc
constexpr static const auto FAILURE
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
Gaudi::Property< int > m_nParallel