4 #include <sys/resource.h>
7 #include <tbb/tick_count.h>
20 GaudiAlgorithm(name, pSvc), m_avg_runtime(1.), m_var_runtime(.01), m_shortCalib(
24 m_inputHandles.resize(MAX_INPUTS);
25 for (uint
i = 0;
i < MAX_INPUTS; ++
i){
30 m_outputHandles.resize(MAX_OUTPUTS);
31 for (uint
i = 0;
i < MAX_OUTPUTS; ++
i){
36 declareProperty(
"avgRuntime", m_avg_runtime,
37 "Average runtime of the module.");
38 declareProperty(
"varRuntime", m_var_runtime,
39 "Variance of the runtime of the module.");
40 declareProperty(
"localRndm", m_local_rndm_gen =
true,
41 "Decide if the local random generator is to be used");
42 declareProperty(
"NIterationsVect", m_niters_vect,
43 "Number of iterations for the calibration.");
44 declareProperty(
"NTimesVect", m_times_vect,
45 "Number of seconds for the calibration.");
46 declareProperty(
"shortCalib", m_shortCalib =
false,
47 "Enable coarse grained calibration");
48 declareProperty(
"RwRepetitions", m_rwRepetitions = 1,
49 "Increase access to the WB");
50 declareProperty(
"SleepyExecution", m_sleepyExecution =
false,
51 "Sleep during execution instead of crunching");
55 CHM::accessor name_ninstances;
56 m_name_ncopies_map.insert(name_ninstances, name);
57 name_ninstances->second += 1;
128 unsigned int trials = 30;
130 auto start_cali=tbb::tick_count::now();
132 auto stop_cali=tbb::tick_count::now();
133 double deltat = (stop_cali-start_cali).seconds();
135 log <<
MSG::DEBUG <<
"Calibration: # iters = " << niters <<
" => " << deltat <<
endmsg;
144 unsigned int smaller_i=0;
167 const double m=(y1-y0)/(x1-x0);
168 const double q=y0-m*x0;
170 const unsigned long nCaliIters = m * runtime + q ;
186 unsigned int primes_size=1;
187 unsigned long* primes =
new unsigned long[primes_size];
193 for (
unsigned long int iiter=0;iiter<n_iterations;iiter++ ){
199 for (
unsigned long j=2;j<i && is_prime;++j){
206 unsigned int new_primes_size = 1 + primes_size;
207 unsigned long* new_primes =
new unsigned long[new_primes_size];
209 for (
unsigned int prime_index=0; prime_index<primes_size;prime_index++){
210 new_primes[prime_index]=primes[prime_index];
213 new_primes[primes_size]=
i;
218 primes_size=new_primes_size;
224 for (
unsigned int prime_index=0; prime_index<primes_size;prime_index++)
225 if (primes[prime_index] == 4)
226 log <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!"<<
endmsg ;
243 tbb::tick_count starttbb=tbb::tick_count::now();
244 std::this_thread::sleep_for(dreamtime);
245 tbb::tick_count endtbb=tbb::tick_count::now();
247 const double actualDreamTime=(endtbb-starttbb).seconds();
249 logstream <<
MSG::DEBUG <<
"Actual dreaming time was: "<< actualDreamTime <<
"s" <<
endmsg;
269 auto getGausRandom = [] (
double mean,
double sigma) ->
double {
271 unsigned int seed = std::clock();
273 auto getUnifRandom = [] (
unsigned int & seed) ->
double {
275 constexpr
unsigned int m = 232;
276 constexpr
unsigned int a = 1664525;
277 constexpr
unsigned int c = 1013904223;
278 seed = (a * seed +
c) % m;
279 const double unif = double(seed) /
m;
283 const double unif1 = getUnifRandom(seed);
284 const double unif2 = getUnifRandom(seed);
285 const double normal = sqrt(-2.*
log(unif1))*cos(2*M_PI*unif2);
286 return normal*sigma + mean;
293 runtime = std::fabs(rndmgaus());
296 tbb::tick_count starttbb=tbb::tick_count::now();
299 logstream <<
MSG::DEBUG <<
"Start event " << getContext()->evt()
300 <<
" in slot " << getContext()->slot()
301 <<
" on pthreadID " << std::hex << pthread_self() << std::dec
305 if(!inputHandle->isValid())
310 obj = inputHandle->get();
320 if(!outputHandle->isValid())
326 for (
auto & inputHandle: m_inputHandles){
327 if(!inputHandle->isValid())
335 tbb::tick_count endtbb=tbb::tick_count::now();
337 const double actualRuntime=(endtbb-starttbb).seconds();
340 logstream <<
MSG::DEBUG <<
"Finish event " << getContext()->evt()
342 <<
" in " << actualRuntime <<
" seconds" <<
endmsg;
344 logstream <<
MSG::DEBUG <<
"Timing: ExpectedRuntime= " << runtime
345 <<
" ActualRuntime= " << actualRuntime
346 <<
" Ratio= " << runtime/actualRuntime
347 <<
" Niters= " << n_iters <<
endmsg;
359 unsigned int ninstances;
362 CHM::const_accessor const_name_ninstances;
364 ninstances=const_name_ninstances->second;
367 constexpr
double s2ms=1000.;
372 <<
"\t n_clones= " << ninstances <<
endmsg;
374 CHM::accessor name_ninstances;
376 name_ninstances->second=0;
384 const std::vector<std::string>
387 std::vector<std::string> di;
390 di.push_back(
h->dataProductName());
398 const std::vector<std::string>
401 std::vector<std::string> di;
404 di.push_back(
h->dataProductName());
Definition of the MsgStream class used to transmit messages.
string to_string(const T &value)
#define DECLARE_ALGORITHM_FACTORY(x)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
virtual StatusCode initialize()
Its initialization.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual ~CPUCruncher()
virtual & protected desctrustor
void findPrimes(const unsigned long int)
The CPU intensive function.
Parameters for the Gauss random number generation.
void calibrate()
Calibrate.
virtual const std::vector< std::string > get_inputs()
Get the inputs.
virtual StatusCode execute()
the execution of the algorithm
long unsigned int getNCaliIters(double)
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.
static std::vector< double > m_times_vect
std::vector< DataObjectHandle< DataObject > * > m_inputHandles
unsigned int m_rwRepetitions
virtual const std::vector< std::string > get_outputs()
Get the outputs.
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