43inline T 
reduce(RangeT range, 
const T& identity, 
const FuncT &func, 
const JoinT &join)
 
   45    if (range.empty()) 
return identity;
 
   47    return tbb::parallel_reduce(range, identity, func, join);
 
   49    if (
const size_t threadCount = std::thread::hardware_concurrency()>>1) {
 
   50        std::vector<RangeT> rangePool{ range };
 
   51        while(rangePool.size() < threadCount) {
 
   52            const size_t oldSize = rangePool.size();
 
   53            for (
size_t i = 0; i < oldSize && rangePool.size() < threadCount; ++i) {
 
   54                auto &r = rangePool[i];
 
   55                if (r.is_divisible()) rangePool.push_back(RangeT(r, 
Split()));
 
   57            if (rangePool.size() == oldSize) 
break;
 
   59        std::vector< std::future<T> > futurePool;
 
   60        for (
auto &r : rangePool) {
 
   61            auto task = std::async(std::launch::async, [&](){
return func(r, identity);});
 
   62            futurePool.push_back( std::move(task) );
 
   65        for (
auto &f : futurePool) {
 
   66            result = join(result, f.get());
 
   70        return static_cast<T
>(func(range, identity));
 
 
T reduce(size_t begin, size_t end, size_t grainSize, const T &identity, const FuncT &func, const JoinT &join)
Simple wrapper to the function defined above.
Definition Reduce.h:106