GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
mapreduce.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Universidad Carlos III de Madrid
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef GRPPI_MAPREDUCE_H
17 #define GRPPI_MAPREDUCE_H
18 
19 #include <utility>
20 
22 #include "common/iterator_traits.h"
23 
24 namespace grppi {
25 
49 template <typename Execution, typename ...InputIterators,
50  typename Identity, typename Transformer, typename Combiner,
51  requires_iterators<InputIterators...> = 0>
52 auto map_reduce(const Execution & ex,
53  std::tuple<InputIterators...> firsts, std::size_t size,
54  Identity && identity,
55  Transformer && transform_op, Combiner && combine_op)
56 {
57  static_assert(supports_map_reduce<Execution>(),
58  "map/reduce not supported on execution type");
59  return ex.map_reduce(firsts, size,
60  std::forward<Identity>(identity),
61  std::forward<Transformer>(transform_op),
62  std::forward<Combiner>(combine_op));
63 }
64 
81 template <typename Execution, typename ...InputIterators, typename InputIt,
82  typename Identity, typename Transformer, typename Combiner,
83  requires_iterators<InputIterators...> = 0,
84  requires_iterator<InputIt> = 0>
85 auto map_reduce(const Execution & ex,
86  std::tuple<InputIterators...> firsts, InputIt last,
87  Identity && identity,
88  Transformer && transform_op, Combiner && combine_op)
89 {
90  static_assert(supports_map_reduce<Execution>(),
91  "map/reduce not supported on execution type");
92  return ex.map_reduce(firsts,
93  std::distance(std::get<0>(firsts),last),
94  std::forward<Identity>(identity),
95  std::forward<Transformer>(transform_op),
96  std::forward<Combiner>(combine_op));
97 }
98 
114 template <typename Execution, typename InputIterator, typename Identity,
115  typename Transformer, typename Combiner,
116  requires_iterator<InputIterator> = 0>
117 auto map_reduce(const Execution & ex,
118  InputIterator first, InputIterator last,
119  Identity && identity,
120  Transformer && transform_op, Combiner && combine_op)
121 {
122  static_assert(supports_map_reduce<Execution>(),
123  "map/reduce not supported on execution type");
124  return ex.map_reduce(make_tuple(first), std::distance(first,last),
125  std::forward<Identity>(identity),
126  std::forward<Transformer>(transform_op),
127  std::forward<Combiner>(combine_op));
128 }
129 
145 template <typename Execution, typename InputIterator, typename Identity,
146  typename Transformer, typename Combiner,
147  typename ... OtherInputIterators,
148  requires_iterator<InputIterator> = 0>
149 [[deprecated("This version of the interface is deprecated.\n"
150  "If you want to use multiple inputs, use a tuple instead.")]]
151 auto map_reduce(const Execution & ex,
152  InputIterator first, InputIterator last,
153  Identity && identity,
154  Transformer && transform_op, Combiner && combine_op,
155  OtherInputIterators ... other_firsts)
156 {
157  static_assert(supports_map_reduce<Execution>(),
158  "map/reduce not supported on execution type");
159  return ex.map_reduce(make_tuple(first, other_firsts...),
160  std::distance(first,last),
161  std::forward<Identity>(identity),
162  std::forward<Transformer>(transform_op),
163  std::forward<Combiner>(combine_op));
164 }
165 
171 }
172 
173 #endif
auto map_reduce(const Execution &ex, std::tuple< InputIterators... > firsts, std::size_t size, Identity &&identity, Transformer &&transform_op, Combiner &&combine_op)
Invoke md_map-reduce on a data sequence.
Definition: mapreduce.h:52
Definition: callable_traits.h:21
std::enable_if_t< are_iterators< T... >, int > requires_iterators
Definition: iterator_traits.h:59