Ejemplo n.º 1
0
void TestDeterministicReduction () {
    typedef typename Op::Type Type;
    const tbb::blocked_range<int> range(0, N);
    ReduceBody<Op> body;
    tbb::parallel_deterministic_reduce( range,body );
    Type R = body.my_value;
    for ( int i=0; i<100; ++i ) {
        ReduceBody<Op> body2;
        tbb::parallel_deterministic_reduce( range,body2 );
        ASSERT( body2.my_value == R, NULL );
#if __TBB_LAMBDAS_PRESENT
        Type r = tbb::parallel_deterministic_reduce( range, Type(), 
            [](const tbb::blocked_range<int>& br, Type value) -> Type {
                Harness::ConcurrencyTracker ct;
                for ( int ii = br.begin(); ii != br.end(); ++ii ) {
                    Op op;
                    value = op(value, ii);
                }
                return value;
        },
            [](const Type& v1, const Type& v2) -> Type {
                Op op;
                return op.join(v1,v2);
        }
            );
        ASSERT( r == R, NULL );
#endif /* LAMBDAS */
    }
    ASSERT_WARNING((Harness::ConcurrencyTracker::PeakParallelism() > 1), "no parallel execution\n");
}
Ejemplo n.º 2
0
 void join( const ReduceBody& y ) {
     Op op;
     my_value = op.join(my_value, y.my_value);
 }