15 #include <sys/times.h>
16 #include <tbb/tick_count.h>
20 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
21 #define DEBUG_MSG ON_DEBUG debug()
23 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
24 #define VERBOSE_MSG ON_VERBOSE verbose()
33 debug() <<
"initialize" <<
endmsg;
35 if ( base_class::initialize().isFailure() ) {
36 error() <<
"Error initializing base class" <<
endmsg;
53 m_niters_vect = { 0, 500, 600, 700, 800, 1000, 1300, 1600, 2000, 2300,
54 2600, 3000, 3300, 3500, 3900, 4200, 5000, 6000, 8000, 10000,
55 12000, 15000, 17000, 20000, 25000, 30000, 35000, 40000, 50000, 60000 };
65 warning() <<
"NIterationsVect[0]= " <<
m_niters_vect.
value().at( 0 ) <<
" but needs to be zero. resetting it."
80 debug() <<
"Starting calibration run " << irun + 1 <<
" ..." <<
endmsg;
83 unsigned int trials = 30;
85 auto start_cali = tbb::tick_count::now();
87 auto stop_cali = tbb::tick_count::now();
88 auto deltat = ( stop_cali - start_cali ).seconds();
90 debug() <<
" Calibration: # iters = " << niters <<
" => " <<
m_times_vect.
at( i ) <<
" us" <<
endmsg;
108 debug() <<
"Calibration finished!" <<
endmsg;
115 unsigned int smaller_i = 0;
118 double corrRuntime =
runtime.count();
122 if (
time > corrRuntime ) {
138 const double m = (double)( y1 - y0 ) / (double)( x1 - x0 );
139 const double q = y0 -
m * x0;
141 const unsigned int nCaliIters =
m * corrRuntime + q;
143 VERBOSE_MSG <<
"x0: " << x0 <<
" x1: " << x1 <<
" y0: " << y0 <<
" y1: " << y1 <<
" m: " <<
m <<
" q: " << q
144 <<
" itr: " << nCaliIters <<
endmsg;
156 unsigned int primes_size = 1;
157 unsigned long* primes =
new unsigned long[primes_size];
163 for (
unsigned long int iiter = 0; iiter < n_iterations; iiter++ ) {
169 for (
unsigned long j = 2;
j < i && is_prime; ++
j ) {
170 if ( i %
j == 0 ) is_prime =
false;
175 unsigned int new_primes_size = 1 + primes_size;
176 unsigned long* new_primes =
new unsigned long[new_primes_size];
178 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ ) {
179 new_primes[prime_index] = primes[prime_index];
182 new_primes[primes_size] = i;
187 primes_size = new_primes_size;
193 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ )
194 if ( primes[prime_index] == 4 )
195 debug() <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!" <<
endmsg;
207 auto start_cali = tbb::tick_count::now();
209 auto stop_cali = tbb::tick_count::now();
213 DEBUG_MSG <<
"crunch for " << crunchtime.
count() <<
" ms == " << niters <<
" iter. actual time: " << actual.
count()
214 <<
" ms. ratio: " << float( actual.
count() ) / crunchtime.
count() <<
endmsg;