GrPPI  0.3.1
Generic and Reusable Parallel Pattern Interface
mapreduce.h
Go to the documentation of this file.
1 
21 #ifndef GRPPI_MAPREDUCE_H
22 #define GRPPI_MAPREDUCE_H
23 
24 #include <utility>
25 
27 #include "common/iterator_traits.h"
28 
29 namespace grppi {
30 
54 template <typename Execution, typename ...InputIterators,
55  typename Identity, typename Transformer, typename Combiner,
56  requires_iterators<InputIterators...> = 0>
57 auto map_reduce(const Execution & ex,
58  std::tuple<InputIterators...> firsts, std::size_t size,
59  Identity && identity,
60  Transformer && transform_op, Combiner && combine_op)
61 {
62  static_assert(supports_map_reduce<Execution>(),
63  "map/reduce not supported on execution type");
64  return ex.map_reduce(firsts, size,
65  std::forward<Identity>(identity),
66  std::forward<Transformer>(transform_op),
67  std::forward<Combiner>(combine_op));
68 }
69 
86 template <typename Execution, typename ...InputIterators, typename InputIt,
87  typename Identity, typename Transformer, typename Combiner,
88  requires_iterators<InputIterators...> = 0,
90 auto map_reduce(const Execution & ex,
91  std::tuple<InputIterators...> firsts, InputIt last,
92  Identity && identity,
93  Transformer && transform_op, Combiner && combine_op)
94 {
95  static_assert(supports_map_reduce<Execution>(),
96  "map/reduce not supported on execution type");
97  return ex.map_reduce(firsts,
98  std::distance(std::get<0>(firsts),last),
99  std::forward<Identity>(identity),
100  std::forward<Transformer>(transform_op),
101  std::forward<Combiner>(combine_op));
102 }
103 
119 template <typename Execution, typename InputIterator, typename Identity,
120  typename Transformer, typename Combiner,
122 auto map_reduce(const Execution & ex,
123  InputIterator first, InputIterator last,
124  Identity && identity,
125  Transformer && transform_op, Combiner && combine_op)
126 {
127  static_assert(supports_map_reduce<Execution>(),
128  "map/reduce not supported on execution type");
129  return ex.map_reduce(make_tuple(first), std::distance(first,last),
130  std::forward<Identity>(identity),
131  std::forward<Transformer>(transform_op),
132  std::forward<Combiner>(combine_op));
133 }
134 
150 template <typename Execution, typename InputIterator, typename Identity,
151  typename Transformer, typename Combiner,
152  typename ... OtherInputIterators,
153  requires_iterator<InputIterator> = 0>
154 [[deprecated("This version of the interface is deprecated.\n"
155  "If you want to use multiple inputs, use a tuple instead.")]]
156 auto map_reduce(const Execution & ex,
157  InputIterator first, InputIterator last,
158  Identity && identity,
159  Transformer && transform_op, Combiner && combine_op,
160  OtherInputIterators ... other_firsts)
161 {
162  static_assert(supports_map_reduce<Execution>(),
163  "map/reduce not supported on execution type");
164  return ex.map_reduce(make_tuple(first, other_firsts...),
165  std::distance(first,last),
166  std::forward<Identity>(identity),
167  std::forward<Transformer>(transform_op),
168  std::forward<Combiner>(combine_op));
169 }
170 
176 }
177 
178 #endif
Definition: callable_traits.h:26
std::enable_if_t< are_iterators< T... >, int > requires_iterators
Definition: iterator_traits.h:64
auto map_reduce(const Execution &ex, std::tuple< InputIterators... > firsts, std::size_t size, Identity &&identity, Transformer &&transform_op, Combiner &&combine_op)
Invoke Map/reduce pattern on a data sequence.
Definition: mapreduce.h:57
std::enable_if_t< is_iterator< T >, int > requires_iterator
Definition: iterator_traits.h:58