GrPPI  1.0
Generic and Reusable Parallel Pattern Interface
stencil.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_STENCIL_H
17 #define GRPPI_STENCIL_H
18 
19 #include <tuple>
20 #include <utility>
21 
23 #include "common/iterator_traits.h"
24 
25 namespace grppi {
26 
50 template <typename Execution, typename ...InputIterators, typename OutputIt,
51  typename StencilTransformer, typename Neighbourhood,
52  requires_iterators<InputIterators...> = 0,
53  requires_iterator<OutputIt> = 0>
54 void stencil(
55  const Execution & ex,
56  std::tuple<InputIterators...> firsts, std::size_t size, OutputIt out,
57  StencilTransformer && transform_op,
58  Neighbourhood && neighbour_op)
59 {
60  static_assert(supports_stencil<Execution>(),
61  "stencil not supported for execution type");
62  ex.stencil(firsts, out, size,
63  std::forward<StencilTransformer>(transform_op),
64  std::forward<Neighbourhood>(neighbour_op));
65 }
66 
83 template <typename Execution, typename ...InputIterators,
84  typename InputIt, typename OutputIt,
85  typename StencilTransformer, typename Neighbourhood,
86  requires_iterators<InputIterators...> = 0,
87  requires_iterator<InputIt> = 0,
88  requires_iterator<OutputIt> = 0>
89 void stencil(
90  const Execution & ex,
91  std::tuple<InputIterators...> firsts, InputIt last, OutputIt out,
92  StencilTransformer && transform_op,
93  Neighbourhood && neighbour_op)
94 {
95  static_assert(supports_stencil<Execution>(),
96  "stencil not supported for execution type");
97  ex.stencil(firsts, out,
98  std::distance(std::get<0>(firsts),last),
99  std::forward<StencilTransformer>(transform_op),
100  std::forward<Neighbourhood>(neighbour_op));
101 }
102 
118 template <typename Execution, typename InputIt, typename OutputIt,
119  typename StencilTransformer, typename Neighbourhood,
120  requires_iterator<InputIt> = 0,
121  requires_iterator<OutputIt> = 0>
122 void stencil(
123  const Execution & ex,
124  InputIt first, InputIt last, OutputIt out,
125  StencilTransformer && transform_op,
126  Neighbourhood && neighbour_op)
127 {
128  static_assert(supports_stencil<Execution>(),
129  "stencil not supported for execution type");
130  ex.stencil(std::make_tuple(first), out,
131  std::distance(first,last),
132  std::forward<StencilTransformer>(transform_op),
133  std::forward<Neighbourhood>(neighbour_op));
134 }
135 
153 template <typename Execution, typename InputIt, typename OutputIt,
154  typename StencilTransformer, typename Neighbourhood,
155  typename ... OtherInputIts,
156  requires_iterator<InputIt> = 0,
157  requires_iterator<OutputIt> = 0>
158 [[deprecated("This version of the interface is deprecated.\n"
159  "If you want to use multiple inputs, use a tuple instead.")]]
160 void stencil(
161  const Execution & ex,
162  InputIt first, InputIt last, OutputIt out,
163  StencilTransformer && transform_op,
164  Neighbourhood && neighbour_op,
165  OtherInputIts ... other_firsts)
166 {
167  static_assert(supports_stencil<Execution>(),
168  "stencil not supported for execution type");
169  ex.stencil(std::make_tuple(first,other_firsts...), out,
170  std::distance(first,last),
171  std::forward<StencilTransformer>(transform_op),
172  std::forward<Neighbourhood>(neighbour_op));
173 }
174 
180 }
181 
182 #endif
void stencil(const Execution &ex, std::tuple< InputIterators... > firsts, std::size_t size, OutputIt out, StencilTransformer &&transform_op, Neighbourhood &&neighbour_op)
Invoke Stencil pattern on a data sequence with sequential execution.
Definition: stencil.h:54
Definition: callable_traits.h:21
std::enable_if_t< are_iterators< T... >, int > requires_iterators
Definition: iterator_traits.h:59