//CC G++
//G++-FLAGS -Xdebug -std=gnu++0x -I../3rdparty/tbb30_20110315oss/include -L../3rdparty/tbb30_20110315oss/build/windows_ia32_gcc_mingw4.6.0_debug -- -ltbb_debug
#include <stdlib.h>
#include <iostream>
#include <deque>
#include <tbb/tbb.h>
int main()
{
tbb::task_scheduler_init init(10);
std::deque<unsigned> data;
for(std::size_t i=1000000; i; --i)
data.push_back( rand() );
typedef tbb::blocked_range<decltype(data.cbegin())> range;
tbb::parallel_reduce(
range(data.cbegin(),data.cend()),
unsigned(),
[&data](range r, unsigned sum) {
std::cout << "Range from " << r.begin()-data.cbegin() << " to " << r.end()-data.cbegin() << std::endl;
for(unsigned v:r)
sum += v;
return sum;
},
[](unsigned a, unsigned b) {
std::cout << "Reduce " << a << " & " << b << std::endl;
return a+b;
}
);
}