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()
28 constexpr
bool essentiallyEqual(
double const a,
double const b ) {
40 debug() <<
"initialize" <<
endmsg;
42 if ( base_class::initialize().isFailure() ) {
43 error() <<
"Error initializing base class" <<
endmsg;
60 m_niters_vect = { 0, 500, 600, 700, 800, 1000, 1300, 1600, 2000, 2300,
61 2600, 3000, 3300, 3500, 3900, 4200, 5000, 6000, 8000, 10000,
62 12000, 15000, 17000, 20000, 25000, 30000, 35000, 40000, 50000, 60000 };
72 warning() <<
"NIterationsVect[0]= " <<
m_niters_vect.
value().at( 0 ) <<
" but needs to be zero. resetting it."
87 debug() <<
"Starting calibration run " << irun + 1 <<
" ..." <<
endmsg;
90 unsigned int trials = 30;
92 auto start_cali = tbb::tick_count::now();
94 auto stop_cali = tbb::tick_count::now();
95 auto deltat = ( stop_cali - start_cali ).seconds();
97 debug() <<
" Calibration: # iters = " << niters <<
" => " <<
m_times_vect.
at( i ) <<
" us" <<
endmsg;
103 debug() <<
" increasing calib vect with " << int(
m_niters_vect.
value().back() * 1.2 )
115 debug() <<
"Calibration finished!" <<
endmsg;
122 unsigned int smaller_i = 0;
125 double corrRuntime = runtime.
count();
129 if (
time > corrRuntime ) {
145 const double m = (double)( y1 - y0 ) / (double)( x1 - x0 );
146 const double q = y0 -
m * x0;
148 const unsigned int nCaliIters =
m * corrRuntime + q;
150 VERBOSE_MSG <<
"x0: " << x0 <<
" x1: " << x1 <<
" y0: " << y0 <<
" y1: " << y1 <<
" m: " <<
m <<
" q: " << q
151 <<
" itr: " << nCaliIters <<
endmsg;
163 unsigned int primes_size = 1;
164 unsigned long* primes =
new unsigned long[primes_size];
170 for (
unsigned long int iiter = 0; iiter < n_iterations; iiter++ ) {
176 for (
unsigned long j = 2;
j < i && is_prime; ++
j ) {
177 if ( i %
j == 0 ) is_prime =
false;
182 unsigned int new_primes_size = 1 + primes_size;
183 unsigned long* new_primes =
new unsigned long[new_primes_size];
185 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ ) {
186 new_primes[prime_index] = primes[prime_index];
189 new_primes[primes_size] = i;
194 primes_size = new_primes_size;
200 for (
unsigned int prime_index = 0; prime_index < primes_size; prime_index++ )
201 if ( primes[prime_index] == 4 )
202 debug() <<
"This does never happen, but it's necessary too fool aggressive compiler optimisations!" <<
endmsg;
214 auto start_cali = tbb::tick_count::now();
216 auto stop_cali = tbb::tick_count::now();
220 DEBUG_MSG <<
"crunch for " << crunchtime.
count() <<
" ms == " << niters <<
" iter. actual time: " << actual.
count()
221 <<
" ms. ratio: " << float( actual.
count() ) / crunchtime.
count() <<
endmsg;