5 #include <sys/resource.h> 8 #include <tbb/tick_count.h> 17 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 18 #define DEBUG_MSG ON_DEBUG debug() 20 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 21 #define VERBOSE_MSG ON_VERBOSE verbose() 35 CHM::accessor name_ninstances;
37 name_ninstances->second += 1;
88 m_niters_vect = {0, 500, 600, 700, 800, 1000, 1300, 1600, 2000, 2300, 2600, 3000, 3300, 3500, 3900,
89 4200, 5000, 6000, 8000, 10000, 12000, 15000, 17000, 20000, 25000, 30000, 35000, 40000, 60000};
101 unsigned int trials = 30;
103 auto start_cali = tbb::tick_count::now();
105 auto stop_cali = tbb::tick_count::now();
106 double deltat = ( stop_cali - start_cali ).seconds();
108 DEBUG_MSG <<
"Calibration: # iters = " << niters <<
" => " << deltat <<
endmsg;
118 unsigned int smaller_i = 0;
124 if ( time > runtime ) {
140 const double m = ( y1 - y0 ) / ( x1 - x0 );
141 const double q = y0 - m * x0;
143 const unsigned long nCaliIters = m * runtime + q;
155 unsigned int primes_size = 1;
156 unsigned long* primes =
new unsigned long[primes_size];
162 for (
unsigned long int iiter = 0; iiter < n_iterations; iiter++ ) {
168 for (
unsigned long j = 2; j < i && is_prime; ++j ) {
169 if ( i % j == 0 ) is_prime =
false;
174 unsigned int new_primes_size = 1 + primes_size;
175 unsigned long* new_primes =
new unsigned long[new_primes_size];
177 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ ) {
178 new_primes[prime_index] = primes[prime_index];
181 new_primes[primes_size] = i;
186 primes_size = new_primes_size;
192 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ )
193 if ( primes[prime_index] == 4 )
194 debug() <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!" <<
endmsg;
205 VERBOSE_MSG <<
"found late-attributed output: " << outputHandle->objKey() <<
endmsg;
237 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
241 auto getUnifRandom = [](
unsigned int& seed ) ->
double {
243 constexpr
unsigned int m = 232;
244 constexpr
unsigned int a = 1664525;
245 constexpr
unsigned int c = 1013904223;
246 seed = ( a * seed +
c ) % m;
247 const double unif = double( seed ) /
m;
253 unif1 = getUnifRandom( seed );
254 unif2 = getUnifRandom( seed );
255 }
while ( unif1 == 0. );
257 const double normal = sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
259 return normal * sigma +
mean;
275 tbb::tick_count startSleeptbb;
276 tbb::tick_count endSleeptbb;
279 tbb::tick_count starttbb = tbb::tick_count::now();
287 ON_DEBUG startSleeptbb = tbb::tick_count::now();
289 ON_DEBUG endSleeptbb = tbb::tick_count::now();
294 const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
295 debug() <<
"Actual dreaming time was: " << actualDreamTime <<
"s" <<
endmsg;
306 if ( !inputHandle->isValid() )
continue;
311 obj = inputHandle->get();
313 if ( obj ==
nullptr )
error() <<
"A read object was a null pointer." <<
endmsg;
326 if ( !outputHandle->isValid() )
continue;
332 tbb::tick_count endtbb = tbb::tick_count::now();
334 const double actualRuntime = ( endtbb - starttbb ).seconds();
338 <<
" in " << actualRuntime <<
" seconds" <<
endmsg;
340 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime <<
" ExpectedDreamtime= " << dreamtime
341 <<
" ActualTotalRuntime= " << actualRuntime <<
" Ratio= " << ( crunchtime + dreamtime ) / actualRuntime
342 <<
" Niters= " << n_iters << endmsg;
355 unsigned int ninstances;
358 CHM::const_accessor const_name_ninstances;
360 ninstances = const_name_ninstances->second;
363 constexpr
double s2ms = 1000.;
365 if ( ninstances != 0 ) {
366 info() <<
"Summary: name= " <<
name() <<
"\t avg_runtime= " <<
m_avg_runtime * s2ms <<
"\t n_clones= " << ninstances
369 CHM::accessor name_ninstances;
371 name_ninstances->second = 0;
StatusCode execute() override
the execution of the algorithm
constexpr static const auto FAILURE
Definition of the MsgStream class used to transmit messages.
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Gaudi::Property< float > m_sleepFraction
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & name() const override
The identifying name of the algorithm object.
A class that implements a search for prime numbers.
void setFilterPassed(bool state) const override
Set the filter passed flag to the specified state.
Gaudi::Property< bool > m_loader
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
void setIOBound(bool value)
StatusCode initialize() override
standard initialization method
const DataObjIDColl & outputDataObjs() const override
virtual ~CPUCruncher()
virtual & protected desctrustor
void findPrimes(const unsigned long int)
The CPU intensive function.
Gaudi::Property< unsigned int > m_rwRepetitions
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
void calibrate()
Calibrate.
This class represents an entry point to all the event specific data.
long unsigned int getNCaliIters(double)
#define DECLARE_COMPONENT(type)
tbb::concurrent_hash_map< std::string, unsigned int > CHM
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
static std::vector< unsigned int > m_niters_vect
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 SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
constexpr static const auto SUCCESS
static std::vector< double > m_times_vect
Gaudi::Property< bool > m_shortCalib
void declareRuntimeRequestedOutputs()
Pick up late-attributed data outputs.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< double > m_avg_runtime
StatusCode initialize() override
Its initialization.
CPUCruncher()
the default constructor is disabled
Gaudi::Property< unsigned int > m_failNEvents
Gaudi::Property< std::vector< std::string > > m_outKeys
Gaudi::Details::PropertyBase * declareProperty(const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
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