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;
46 fatal() <<
"unable to acquire CPUCruncSvc" <<
endmsg;
83 VERBOSE_MSG <<
"found late-attributed output: " << outputHandle->objKey() <<
endmsg;
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
virtual std::chrono::milliseconds crunch_for(const std::chrono::milliseconds &) const =0
Definition of the MsgStream class used to transmit messages.
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
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
const std::string & name() const override
The identifying name of the algorithm object.
StatusCode initialize() override
standard initialization method
const DataObjIDColl & outputDataObjs() const override
virtual ~CPUCruncher()
virtual & protected desctrustor
void setFilterPassed(bool state) const
Set the filter passed flag to the specified state.
Gaudi::Property< unsigned int > m_rwRepetitions
constexpr static const auto SUCCESS
void initDataHandleHolder()
initializes all handles - called by the sysInitialize method of any descendant of this ...
const std::string & context() const
Returns the "context" string. Used to identify different processing states.
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
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static CHM m_name_ncopies_map
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
This class is used for returning status codes from appropriate routines.
void setIOBound(bool value)
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 SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void declareRuntimeRequestedOutputs()
The CPU intensive function.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< double > m_avg_runtime
StatusCode initialize() override
Its initialization.
bool isValid() const
Allow for check if smart pointer is valid.
CPUCruncher()
the default constructor is disabled
constexpr static const auto FAILURE
Gaudi::Property< unsigned int > m_failNEvents
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Gaudi::Property< std::vector< std::string > > m_outKeys
Gaudi::Property< std::vector< std::string > > m_inpKeys
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
A DataObject is the base class of any identifiable object on any data store.
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
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