4 #include <sys/resource.h>
7 #include <tbb/tick_count.h>
21 GaudiAlgorithm(name, pSvc), m_avg_runtime(1.), m_var_runtime(.01), m_shortCalib(
24 declareProperty(
"inpKeys", m_inpKeys);
25 declareProperty(
"outKeys", m_outKeys);
28 declareProperty(
"avgRuntime", m_avg_runtime,
29 "Average runtime of the module.");
30 declareProperty(
"varRuntime", m_var_runtime,
31 "Variance of the runtime of the module.");
32 declareProperty(
"localRndm", m_local_rndm_gen =
true,
33 "Decide if the local random generator is to be used");
34 declareProperty(
"NIterationsVect", m_niters_vect,
35 "Number of iterations for the calibration.");
36 declareProperty(
"NTimesVect", m_times_vect,
37 "Number of seconds for the calibration.");
38 declareProperty(
"shortCalib", m_shortCalib =
false,
39 "Enable coarse grained calibration");
40 declareProperty(
"RwRepetitions", m_rwRepetitions = 1,
41 "Increase access to the WB");
42 declareProperty(
"SleepyExecution", m_sleepyExecution =
false,
43 "Sleep during execution instead of crunching");
47 CHM::accessor name_ninstances;
48 m_name_ncopies_map.insert(name_ninstances, name);
49 name_ninstances->second += 1;
142 unsigned int trials = 30;
144 auto start_cali=tbb::tick_count::now();
146 auto stop_cali=tbb::tick_count::now();
147 double deltat = (stop_cali-start_cali).seconds();
149 log <<
MSG::DEBUG <<
"Calibration: # iters = " << niters <<
" => " << deltat <<
endmsg;
158 unsigned int smaller_i=0;
181 const double m=(y1-y0)/(x1-x0);
182 const double q=y0-m*x0;
184 const unsigned long nCaliIters = m * runtime + q ;
200 unsigned int primes_size=1;
201 unsigned long* primes =
new unsigned long[primes_size];
207 for (
unsigned long int iiter=0;iiter<n_iterations;iiter++ ){
213 for (
unsigned long j=2;j<i && is_prime;++j){
220 unsigned int new_primes_size = 1 + primes_size;
221 unsigned long* new_primes =
new unsigned long[new_primes_size];
223 for (
unsigned int prime_index=0; prime_index<primes_size;prime_index++){
224 new_primes[prime_index]=primes[prime_index];
227 new_primes[primes_size]=
i;
232 primes_size=new_primes_size;
238 for (
unsigned int prime_index=0; prime_index<primes_size;prime_index++)
239 if (primes[prime_index] == 4)
240 log <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!"<<
endmsg ;
257 tbb::tick_count starttbb=tbb::tick_count::now();
259 tbb::tick_count endtbb=tbb::tick_count::now();
261 const double actualDreamTime=(endtbb-starttbb).seconds();
263 logstream <<
MSG::DEBUG <<
"Actual dreaming time was: "<< actualDreamTime <<
"s" <<
endmsg;
283 auto getGausRandom = [] (
double mean,
double sigma) ->
double {
287 auto getUnifRandom = [] (
unsigned int & seed) ->
double {
289 constexpr
unsigned int m = 232;
290 constexpr
unsigned int a = 1664525;
291 constexpr
unsigned int c = 1013904223;
292 seed = (a * seed +
c) % m;
293 const double unif = double(seed) /
m;
297 const double unif1 = getUnifRandom(seed);
298 const double unif2 = getUnifRandom(seed);
299 const double normal = sqrt(-2.*
log(unif1))*cos(2*M_PI*unif2);
300 return normal*sigma + mean;
310 tbb::tick_count starttbb=tbb::tick_count::now();
319 if(!inputHandle->isValid())
324 obj = inputHandle->get();
334 if(!outputHandle->isValid())
340 for (
auto & inputHandle: m_inputHandles){
341 if(!inputHandle->isValid())
349 tbb::tick_count endtbb=tbb::tick_count::now();
351 const double actualRuntime=(endtbb-starttbb).seconds();
356 <<
" in " << actualRuntime <<
" seconds" <<
endmsg;
358 logstream <<
MSG::DEBUG <<
"Timing: ExpectedRuntime= " << runtime
359 <<
" ActualRuntime= " << actualRuntime
360 <<
" Ratio= " << runtime/actualRuntime
361 <<
" Niters= " << n_iters <<
endmsg;
373 unsigned int ninstances;
376 CHM::const_accessor const_name_ninstances;
378 ninstances=const_name_ninstances->second;
381 constexpr
double s2ms=1000.;
386 <<
"\t n_clones= " << ninstances <<
endmsg;
388 CHM::accessor name_ninstances;
390 name_ninstances->second=0;
Definition of the MsgStream class used to transmit messages.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
virtual StatusCode initialize()
Its initialization.
virtual ~CPUCruncher()
virtual & protected desctrustor
void findPrimes(const unsigned long int)
The CPU intensive function.
Property * declareProperty(const std::string &name, DataObjectHandle< T > &hndl, const std::string &doc="none") const
Parameters for the Gauss random number generation.
EventContext * getContext() const
get the context
void calibrate()
Calibrate.
virtual StatusCode execute()
the execution of the algorithm
long unsigned int getNCaliIters(double)
#define DECLARE_COMPONENT(type)
const std::string & name() const override
The identifying name of the algorithm object.
virtual StatusCode finalize()
the finalization of the algorithm
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.
SmartIF< IRndmGenSvc > & randSvc() const
AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
static std::vector< double > m_times_vect
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
std::vector< std::string > m_outKeys
unsigned int m_rwRepetitions
std::vector< std::string > m_inpKeys
std::vector< DataObjectHandle< DataObject > * > m_outputHandles
A DataObject is the base class of any identifiable object on any data store.
tbb::concurrent_hash_map< std::string, unsigned int > CHM
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.