Beispiel #1
0
//! Test that two tick_count values recorded on different threads can be meaningfully subtracted.
void TestTickCountDifference( int n ) {
    const double tolerance = 3E-4;
    tick_count_array = new tbb::tick_count[n];

    int num_trials = 0;
    tbb::tick_count start_time = tbb::tick_count::now();
    do {
        NativeParallelFor( n, TickCountDifferenceBody( n ) );
        if ( barrier_time > tolerance )
            // The machine seems to be oversubscibed so skip the test.
            continue;
        for ( int i = 0; i < n; ++i ) {
            for ( int j = 0; j < i; ++j ) {
                double diff = (tick_count_array[i] - tick_count_array[j]).seconds();
                if ( diff < 0 ) diff = -diff;
                if ( diff > tolerance )
                    REPORT( "Warning: cross-thread tick_count difference = %g > %g = tolerance\n", diff, tolerance );
                ASSERT( diff < 3 * tolerance, "Too big difference." );
            }
        }
        // During 5 seconds we are trying to get 10 successful trials.
    } while ( ++num_trials < 10 && (tbb::tick_count::now() - start_time).seconds() < 5 );
    REMARK( "Difference test time: %g sec\n", (tbb::tick_count::now() - start_time).seconds() );
    ASSERT( num_trials == 10, "The machine seems to be heavily oversubscibed, difference test was skipped." );
    delete[] tick_count_array;
}
//! Test that two tick_count values recorded on different threads can be meaningfully subtracted.
void TestTickCountDifference( int n ) {
    double tolerance = 3E-4;
    for( int trial=0; trial<10; ++trial ) {
        Counter = n;
        Flag = false;
        NativeParallelFor( n, TickCountDifferenceBody() ); 
        ASSERT( Counter==0, NULL ); 
        for( int i=0; i<n; ++i )
            for( int j=0; j<i; ++j ) {
                double diff = (tick_count_array[i]-tick_count_array[j]).seconds();
                if( diff<0 ) diff = -diff;
                if( diff>tolerance ) {
                    REPORT("%s: cross-thread tick_count difference = %g > %g = tolerance\n",
                           diff>3*tolerance?"ERROR":"Warning",diff,tolerance);
                }
            }
    }
}