GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
reduce.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_REDUCE_H
17 #define GRPPI_REDUCE_H
18 
19 #include <utility>
20 
21 #include "common/iterator_traits.h"
23 
24 namespace grppi {
25 
48 template <typename Execution, typename InputIt, typename Result, typename Combiner,
49  requires_iterator<InputIt> = 0>
50 auto reduce(const Execution & ex,
51  InputIt first, std::size_t size,
52  Result && identity,
53  Combiner && combine_op)
54 {
55  static_assert(supports_reduce<Execution>(),
56  "reduce not supported on execution type");
57 // static_assert(std::is_same<Result,typename std::result_of<Combiner(Result,Result)>::type>::value,
58 // "reduce combiner should be homogeneous:T = op(T,T)");
59  return ex.reduce(first, size,
60  std::forward<Result>(identity), std::forward<Combiner>(combine_op));
61 }
62 
77 template <typename Execution, typename InputIt, typename Result, typename Combiner,
78  requires_iterator<InputIt> = 0>
79 auto reduce(const Execution & ex,
80  InputIt first, InputIt last,
81  Result && identity,
82  Combiner && combine_op)
83 {
84  static_assert(supports_reduce<Execution>(),
85  "reduce not supported on execution type");
86 // static_assert(std::is_same<Result,typename std::result_of<Combiner(Result,Result)>::type>::value,
87 // "reduce combiner should be homogeneous:T = op(T,T)");
88  return ex.reduce(first, std::distance(first,last),
89  std::forward<Result>(identity), std::forward<Combiner>(combine_op));
90 }
91 
96 }
97 
98 #endif
auto reduce(const Execution &ex, InputIt first, std::size_t size, Result &&identity, Combiner &&combine_op)
Invoke Reduce pattern with identity value on a data sequence with sequential execution.
Definition: reduce.h:50
Definition: callable_traits.h:21