5 #include <sys/resource.h> 8 #include <tbb/tick_count.h> 15 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 16 #define DEBUG_MSG ON_DEBUG debug() 18 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 19 #define VERBOSE_MSG ON_VERBOSE verbose() 29 CHM::accessor name_ninstances;
31 name_ninstances->second += 1;
44 m_crunchSvc = serviceLocator()->service(
"CPUCrunchSvc" );
46 fatal() <<
"unable to acquire CPUCruncSvc" <<
endmsg;
81 for (
const auto& k : outputDataObjs() ) {
83 VERBOSE_MSG <<
"found late-attributed output: " << outputHandle->objKey() <<
endmsg;
88 initDataHandleHolder();
115 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
118 auto getUnifRandom = [](
unsigned int& seed ) ->
double {
120 constexpr
unsigned int m = 232;
121 constexpr
unsigned int a = 1664525;
122 constexpr
unsigned int c = 1013904223;
123 seed = ( a * seed +
c ) %
m;
124 const double unif = double( seed ) /
m;
130 unif1 = getUnifRandom( seed );
131 unif2 = getUnifRandom( seed );
132 }
while ( unif1 == 0. );
134 const double normal =
sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
136 return normal * sigma +
mean;
146 unsigned int crunchtime_ms = 1000 * crunchtime;
153 tbb::tick_count startSleeptbb;
154 tbb::tick_count endSleeptbb;
157 tbb::tick_count starttbb = tbb::tick_count::now();
163 DEBUG_MSG <<
"Dreaming time will be: " << int( 1000 * dreamtime ) <<
" ms" <<
endmsg;
165 ON_DEBUG startSleeptbb = tbb::tick_count::now();
167 ON_DEBUG endSleeptbb = tbb::tick_count::now();
171 const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
172 debug() <<
"Actual dreaming time was: " << int( 1000 * actualDreamTime ) <<
"ms" <<
endmsg;
176 DEBUG_MSG <<
"Crunching time will be: " << crunchtime_ms <<
" ms" <<
endmsg;
183 if ( !inputHandle->isValid() )
continue;
187 for (
unsigned int i = 0; i <
m_rwRepetitions; ++i ) { obj = inputHandle->get(); }
188 if ( obj ==
nullptr ) error() <<
"A read object was a null pointer." <<
endmsg;
200 if ( !outputHandle->isValid() )
continue;
206 tbb::tick_count endtbb = tbb::tick_count::now();
207 const double actualRuntime = ( endtbb - starttbb ).seconds();
209 DEBUG_MSG <<
"Finish event " <<
context.evt() <<
" in " << int( 1000 * actualRuntime ) <<
" ms" <<
endmsg;
211 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime_ms <<
" ms. ExpectedDreamtime= " << int( 1000 * dreamtime )
212 <<
" ms. ActualTotalRuntime= " << int( 1000 * actualRuntime )
213 <<
" ms. Ratio= " << ( crunchtime + dreamtime ) / actualRuntime <<
endmsg;
226 unsigned int ninstances;
229 CHM::const_accessor const_name_ninstances;
231 ninstances = const_name_ninstances->second;
234 constexpr
double s2ms = 1000.;
236 if ( ninstances != 0 ) {
237 info() <<
"Summary: name= " <<
name() <<
"\t avg_runtime= " <<
m_avg_runtime * s2ms <<
"\t n_clones= " << ninstances
240 CHM::accessor name_ninstances;
242 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
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.
auto sqrt(std::chrono::duration< Rep, Period > d)
sqrt for std::chrono::duration
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