Embedded Multicore Building Blocks V1.0.0
scan.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_SCAN_H_
28 #define EMBB_ALGORITHMS_SCAN_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 
45 #ifdef DOXYGEN
46 
89 template<typename RAIIn, typename RAIOut, typename ReturnType,
90  typename ScanFunction, typename TransformationFunction>
91 void Scan(
92  RAIIn first,
95  RAIIn last,
98  RAIOut output_first,
101  ReturnType neutral,
103  ScanFunction scan,
105  TransformationFunction transformation = Identity(),
110  size_t block_size = 0
117  );
118 
119 #else // DOXYGEN
120 
124 template<typename RAIIn, typename RAIOut, typename ReturnType>
125 void Scan(
126  RAIIn first,
127  RAIIn last,
128  RAIOut output_iterator,
129  ReturnType neutral,
130  embb::mtapi::Job scan,
131  embb::mtapi::Job transformation,
132  const embb::mtapi::ExecutionPolicy& policy,
133  size_t block_size
134  );
135 
139 template<typename RAIIn, typename RAIOut, typename ReturnType,
140  typename ScanFunction>
141 void Scan(
142  RAIIn first,
143  RAIIn last,
144  RAIOut output_iterator,
145  ReturnType neutral,
146  ScanFunction scan,
147  embb::mtapi::Job transformation,
148  const embb::mtapi::ExecutionPolicy& policy,
149  size_t block_size
150  );
151 
155 template<typename RAIIn, typename RAIOut, typename ReturnType,
156  typename TransformationFunction>
157 void Scan(
158  RAIIn first,
159  RAIIn last,
160  RAIOut output_iterator,
161  ReturnType neutral,
162  embb::mtapi::Job scan,
163  TransformationFunction transformation,
164  const embb::mtapi::ExecutionPolicy& policy,
165  size_t block_size
166  );
167 
171 template<typename RAIIn, typename RAIOut, typename ReturnType,
172  typename ScanFunction, typename TransformationFunction>
173 void Scan(
174  RAIIn first,
175  RAIIn last,
176  RAIOut output_iterator,
177  ReturnType neutral,
178  ScanFunction scan,
179  TransformationFunction transformation,
180  const embb::mtapi::ExecutionPolicy& policy,
181  size_t block_size
182  );
183 
187 template<typename RAIIn, typename RAIOut, typename ReturnType,
188  typename ScanFunction>
189 void Scan(
190  RAIIn first,
191  RAIIn last,
192  RAIOut output_iterator,
193  ReturnType neutral,
194  ScanFunction scan
195  ) {
196  Scan(first, last, output_iterator, neutral, scan, Identity(),
198 }
199 
203 template<typename RAIIn, typename RAIOut, typename ReturnType,
204  typename ScanFunction, typename TransformationFunction>
205 void Scan(
206  RAIIn first,
207  RAIIn last,
208  RAIOut output_iterator,
209  ReturnType neutral,
210  ScanFunction scan,
211  TransformationFunction transformation
212  ) {
213  Scan(first, last, output_iterator, neutral, scan, transformation,
215 }
216 
220 template<typename RAIIn, typename RAIOut, typename ReturnType,
221  typename ScanFunction, typename TransformationFunction>
222 void Scan(
223  RAIIn first,
224  RAIIn last,
225  RAIOut output_iterator,
226  ReturnType neutral,
227  ScanFunction scan,
228  TransformationFunction transformation,
229  const embb::mtapi::ExecutionPolicy& policy
230  ) {
231  Scan(first, last, output_iterator, neutral, scan, transformation, policy, 0);
232 }
233 
234 #endif // else DOXYGEN
235 
240 } // namespace algorithms
241 } // namespace embb
242 
243 #include <embb/algorithms/internal/scan-inl.h>
244 
245 #endif // EMBB_ALGORITHMS_SCAN_H_
Definition: lock_free_mpmc_queue.h:40
void Scan(RAIIn first, RAIIn last, RAIOut output_first, ReturnType neutral, ScanFunction scan, TransformationFunction transformation=Identity(), const embb::mtapi::ExecutionPolicy &policy=embb::mtapi::ExecutionPolicy(), size_t block_size=0)
Performs a parallel scan (or prefix) computation 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