4 #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;
91 3000, 3300, 3500, 3900,
92 4200, 5000, 6000, 8000,
93 10000, 12000, 15000, 17000,
105 info() <<
"Starting calibration..." <<
endmsg;
108 unsigned int trials = 30;
110 auto start_cali = tbb::tick_count::now();
112 auto stop_cali = tbb::tick_count::now();
113 double deltat = ( stop_cali - start_cali ).seconds();
115 DEBUG_MSG <<
"Calibration: # iters = " << niters <<
" => " << deltat <<
endmsg;
125 unsigned int smaller_i = 0;
131 if ( time > runtime ) {
147 const double m = ( y1 - y0 ) / ( x1 - x0 );
148 const double q = y0 - m * x0;
150 const unsigned long nCaliIters = m * runtime + q;
162 unsigned int primes_size = 1;
163 unsigned long* primes =
new unsigned long[primes_size];
169 for (
unsigned long int iiter = 0; iiter < n_iterations; iiter++ ) {
175 for (
unsigned long j = 2; j < i && is_prime; ++j ) {
176 if ( i % j == 0 ) is_prime =
false;
181 unsigned int new_primes_size = 1 + primes_size;
182 unsigned long* new_primes =
new unsigned long[new_primes_size];
184 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ ) {
185 new_primes[prime_index] = primes[prime_index];
188 new_primes[primes_size] = i;
193 primes_size = new_primes_size;
199 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ )
200 if ( primes[prime_index] == 4 )
201 debug() <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!" <<
endmsg;
225 auto getGausRandom = [](
double mean,
double sigma ) ->
double {
229 auto getUnifRandom = [](
unsigned int& seed ) ->
double {
231 constexpr
unsigned int m = 232;
232 constexpr
unsigned int a = 1664525;
233 constexpr
unsigned int c = 1013904223;
234 seed = ( a * seed +
c ) % m;
235 const double unif = double( seed ) /
m;
239 const double unif1 = getUnifRandom( seed );
240 const double unif2 = getUnifRandom( seed );
241 const double normal = sqrt( -2. *
log( unif1 ) ) * cos( 2 * M_PI * unif2 );
242 return normal * sigma +
mean;
257 tbb::tick_count startSleeptbb;
258 tbb::tick_count endSleeptbb;
261 tbb::tick_count starttbb = tbb::tick_count::now();
269 ON_DEBUG startSleeptbb = tbb::tick_count::now();
271 ON_DEBUG endSleeptbb = tbb::tick_count::now();
275 const double actualDreamTime = ( endSleeptbb - startSleeptbb ).seconds();
276 debug() <<
"Actual dreaming time was: " << actualDreamTime <<
"s" <<
endmsg;
282 DEBUG_MSG <<
"Start event " << context.
evt() <<
" in slot " << context.
slot()
287 if ( !inputHandle->isValid() )
continue;
292 obj = inputHandle->get();
294 if ( obj ==
nullptr )
error() <<
"A read object was a null pointer." <<
endmsg;
302 if ( !outputHandle->isValid() )
continue;
308 tbb::tick_count endtbb = tbb::tick_count::now();
310 const double actualRuntime = ( endtbb - starttbb ).seconds();
314 <<
" in " << actualRuntime <<
" seconds" <<
endmsg;
316 DEBUG_MSG <<
"Timing: ExpectedCrunchtime= " << crunchtime <<
" ExpectedDreamtime= " << dreamtime
317 <<
" ActualTotalRuntime= " << actualRuntime <<
" Ratio= " << ( crunchtime + dreamtime ) / actualRuntime
318 <<
" Niters= " << n_iters << endmsg;
329 unsigned int ninstances;
332 CHM::const_accessor const_name_ninstances;
334 ninstances = const_name_ninstances->second;
337 constexpr
double s2ms = 1000.;
339 if ( ninstances != 0 ) {
341 <<
"\t n_clones= " << ninstances <<
endmsg;
343 CHM::accessor name_ninstances;
345 name_ninstances->second = 0;
StatusCode execute() override
the execution of the algorithm
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.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
void setIOBound(bool value)
StatusCode initialize() override
standard initialization method
virtual ~CPUCruncher()
virtual & protected desctrustor
void findPrimes(const unsigned long int)
The CPU intensive function.
Gaudi::Property< unsigned int > m_rwRepetitions
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
The useful base class for data processing algorithms.
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
GAUDI_API const EventContext & currentContext()
static std::vector< double > m_times_vect
Gaudi::Property< bool > m_shortCalib
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
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
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