Embedded Multicore Building Blocks V1.0.0
reduce.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_ALGORITHMS_REDUCE_H_
28 #define EMBB_ALGORITHMS_REDUCE_H_
29 
30 #include <embb/mtapi/job.h>
31 #include <embb/mtapi/execution_policy.h>
32 #include <embb/algorithms/identity.h>
33 
34 namespace embb {
35 namespace algorithms {
36 
44 #ifdef DOXYGEN
45 
86 template<typename RAI, typename ReturnType, typename ReductionFunction,
87  typename TransformationFunction>
88 ReturnType Reduce(
89  RAI first,
91  RAI last,
94  ReturnType neutral,
96  ReductionFunction reduction,
98  TransformationFunction transformation = Identity(),
103  size_t block_size = 0
110  );
111 
112 #else // DOXYGEN
113 
117 template<typename RAI, typename ReturnType>
118 ReturnType Reduce(
119  RAI first,
120  RAI last,
121  ReturnType neutral,
122  embb::mtapi::Job reduction,
123  embb::mtapi::Job transformation,
124  const embb::mtapi::ExecutionPolicy& policy,
125  size_t block_size
126  );
127 
131 template<typename RAI, typename ReturnType, typename ReductionFunction>
132 ReturnType Reduce(
133  RAI first,
134  RAI last,
135  ReturnType neutral,
136  ReductionFunction reduction,
137  embb::mtapi::Job transformation,
138  const embb::mtapi::ExecutionPolicy& policy,
139  size_t block_size
140  );
141 
145 template<typename RAI, typename ReturnType, typename TransformationFunction>
146 ReturnType Reduce(
147  RAI first,
148  RAI last,
149  ReturnType neutral,
150  embb::mtapi::Job reduction,
151  TransformationFunction transformation,
152  const embb::mtapi::ExecutionPolicy& policy,
153  size_t block_size
154  );
155 
159 template<typename RAI, typename ReturnType, typename ReductionFunction,
160  typename TransformationFunction>
161 ReturnType Reduce(
162  RAI first,
163  RAI last,
164  ReturnType neutral,
165  ReductionFunction reduction,
166  TransformationFunction transformation,
167  const embb::mtapi::ExecutionPolicy& policy,
168  size_t block_size
169  );
170 
174 template<typename RAI, typename ReturnType, typename ReductionFunction>
175 ReturnType Reduce(
176  RAI first,
177  RAI last,
178  ReturnType neutral,
179  ReductionFunction reduction
180  ) {
181  return Reduce(first, last, neutral, reduction, Identity(),
183 }
184 
188 template<typename RAI, typename ReturnType, typename ReductionFunction,
189  typename TransformationFunction>
190 ReturnType Reduce(
191  RAI first,
192  RAI last,
193  ReturnType neutral,
194  ReductionFunction reduction,
195  TransformationFunction transformation
196  ) {
197  return Reduce(first, last, neutral, reduction, transformation,
199 }
200 
204 template<typename RAI, typename ReturnType, typename ReductionFunction,
205  typename TransformationFunction>
206 ReturnType Reduce(
207  RAI first,
208  RAI last,
209  ReturnType neutral,
210  ReductionFunction reduction,
211  TransformationFunction transformation,
212  const embb::mtapi::ExecutionPolicy& policy
213  ) {
214  return Reduce(first, last, neutral, reduction, transformation, policy, 0);
215 }
216 
217 #endif // else DOXYGEN
218 
223 } // namespace algorithms
224 } // namespace embb
225 
226 #include <embb/algorithms/internal/reduce-inl.h>
227 
228 #endif // EMBB_ALGORITHMS_REDUCE_H_
Definition: lock_free_mpmc_queue.h:40
ReturnType Reduce(RAI first, RAI last, ReturnType neutral, ReductionFunction reduction, TransformationFunction transformation=Identity(), const embb::mtapi::ExecutionPolicy &policy=embb::mtapi::ExecutionPolicy(), size_t block_size=0)
Performs a parallel reduction operation on a range of elements.
Represents a collection of Actions.
Definition: job.h:41
Describes the execution policy of a parallel algorithm.
Definition: execution_policy.h:48