GrPPI  0.2
Generic and Reusable Parallel Pattern Interface
tbb/reduce.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_TBB_REDUCE_H
22 #define GRPPI_TBB_REDUCE_H
23 
24 #ifdef GRPPI_TBB
25 
26 #include "parallel_execution_tbb.h"
27 
28 #include <tbb/tbb.h>
29 
30 namespace grppi {
31 
52 template < typename InputIt, typename Identity, typename Combiner>
54  InputIt first, InputIt last,
55  Identity identity,
56  Combiner && combine_op)
57 {
58  auto identityVal = identity;
59  return tbb::parallel_reduce(tbb::blocked_range<InputIt>( first, last ), identityVal,
60  [&](const tbb::blocked_range<InputIt> &r,typename std::iterator_traits<InputIt>::value_type temp){
61  for(InputIt i=r.begin(); i!= r.end(); ++i){
62  temp = combine_op( temp, *i);
63  }
64  return temp;
65  },
66  [&](typename std::iterator_traits<InputIt>::value_type a, typename std::iterator_traits<InputIt>::value_type b) -> typename std::iterator_traits<InputIt>::value_type
67  {
68  a = combine_op(a,b);
69  return a;
70  }
71  );
72 
73 }
74 
80 }
81 
82 #endif
83 
84 #endif
Definition: callable_traits.h:24
TBB parallel execution policy.
Definition: parallel_execution_tbb.h:37
auto reduce(parallel_execution_native &ex, InputIt first, InputIt last, Identity identity, Combiner &&combine_op)
Invoke Reduce pattern with identity value on a data sequence with parallel native execution...
Definition: native/reduce.h:51