15 #include <sys/resource.h> 16 #include <sys/times.h> 18 #include <tbb/tick_count.h> 25 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 26 #define DEBUG_MSG ON_DEBUG debug() 28 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 29 #define VERBOSE_MSG ON_VERBOSE verbose() 39 CHM::accessor name_ninstances;
41 name_ninstances->second += 1;
54 m_crunchSvc = serviceLocator()->service(
"CPUCrunchSvc" );
56 fatal() <<
"unable to acquire CPUCruncSvc" <<
endmsg;
91 for (
const auto& k : outputDataObjs() ) {
93 VERBOSE_MSG <<
"found late-attributed output: " << outputHandle->objKey() <<
endmsg;
98 initDataHandleHolder();
125 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
128 auto getUnifRandom = [](
unsigned int& seed ) ->
double {
130 constexpr
unsigned int m = 232;
131 constexpr
unsigned int a = 1664525;
132 constexpr
unsigned int c = 1013904223;
133 seed = ( a * seed +
c ) %
m;
134 const double unif = double( seed ) /
m;
140 unif1 = getUnifRandom( seed );
141 unif2 = getUnifRandom( seed );
142 }
while ( unif1 == 0. );
144 const double normal =
sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
146 return normal * sigma +
mean;
156 unsigned int crunchtime_ms = 1000 * crunchtime;
163 tbb::tick_count startSleeptbb;
164 tbb::tick_count endSleeptbb;
167 tbb::tick_count starttbb = tbb::tick_count::now();
173 DEBUG_MSG <<
"Dreaming time will be: " << int( 1000 * dreamtime ) <<
" ms" <<
endmsg;
175 ON_DEBUG startSleeptbb = tbb::tick_count::now();
177 ON_DEBUG endSleeptbb = tbb::tick_count::now();
181 const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
182 debug() <<
"Actual dreaming time was: " << int( 1000 * actualDreamTime ) <<
"ms" <<
endmsg;
186 DEBUG_MSG <<
"Crunching time will be: " << crunchtime_ms <<
" ms" <<
endmsg;
193 if ( !inputHandle->isValid() )
continue;
197 for (
unsigned int i = 0; i <
m_rwRepetitions; ++i ) { obj = inputHandle->get(); }
198 if ( obj ==
nullptr ) error() <<
"A read object was a null pointer." <<
endmsg;
210 if ( !outputHandle->isValid() )
continue;
216 tbb::tick_count endtbb = tbb::tick_count::now();
217 const double actualRuntime = ( endtbb - starttbb ).seconds();
219 DEBUG_MSG <<
"Finish event " <<
context.evt() <<
" in " << int( 1000 * actualRuntime ) <<
" ms" <<
endmsg;
221 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime_ms <<
" ms. ExpectedDreamtime= " << int( 1000 * dreamtime )
222 <<
" ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
223 <<
" ms. Ratio= " << ( crunchtime + dreamtime ) / actualRuntime <<
endmsg;
236 unsigned int ninstances;
239 CHM::const_accessor const_name_ninstances;
241 ninstances = const_name_ninstances->second;
244 constexpr
double s2ms = 1000.;
246 if ( ninstances != 0 ) {
247 info() <<
"Summary: name= " <<
name() <<
"\t avg_runtime= " <<
m_avg_runtime * s2ms <<
"\t n_clones= " << ninstances
250 CHM::accessor name_ninstances;
252 name_ninstances->second = 0;
StatusCode execute() override
the execution of the algorithm
SmartIF< ICPUCrunchSvc > m_crunchSvc
Definition of the MsgStream class used to transmit messages.
virtual std::chrono::milliseconds crunch_for(const std::chrono::milliseconds &) const =0
Gaudi::Property< float > m_sleepFraction
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
A class that implements a search for prime numbers.
Gaudi::Property< bool > m_loader
StatusCode initialize() override
standard initialization method
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
virtual ~CPUCruncher()
virtual & protected desctrustor
bool isValid() const
Allow for check if smart pointer is valid.
Gaudi::Property< unsigned int > m_rwRepetitions
constexpr static const auto SUCCESS
Parameters for the Gauss random number generation.
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
This class represents an entry point to all the event specific data.
#define DECLARE_COMPONENT(type)
tbb::concurrent_hash_map< std::string, unsigned int > CHM
static CHM m_name_ncopies_map
This class is used for returning status codes from appropriate routines.
StatusCode finalize() override
standard finalization method
Gaudi::Property< bool > m_invertCFD
The useful base class for data processing algorithms.
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
GAUDI_API const EventContext & currentContext()
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
void declareRuntimeRequestedOutputs()
The CPU intensive function.
Gaudi::Property< double > m_avg_runtime
StatusCode initialize() override
Its initialization.
CPUCruncher()
the default constructor is disabled
constexpr static const auto FAILURE
Gaudi::Property< unsigned int > m_failNEvents
Gaudi::Property< std::vector< std::string > > m_outKeys
Gaudi::Property< std::vector< std::string > > m_inpKeys
A DataObject is the base class of any identifiable object on any data store.
StatusCode finalize() override
the finalization of the algorithm
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Gaudi::Property< bool > m_local_rndm_gen
Gaudi::Property< double > m_var_runtime