38 #ifndef _GLIBCXX_PARALLEL_NUMERIC_H
39 #define _GLIBCXX_PARALLEL_NUMERIC_H 1
49 namespace std _GLIBCXX_VISIBILITY(default)
54 template<
typename _IIter,
typename _Tp>
56 accumulate(_IIter __begin, _IIter __end, _Tp __init,
60 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
62 accumulate(_IIter __begin, _IIter __end, _Tp __init,
67 template<
typename _IIter,
typename _Tp,
typename _IteratorTag>
69 __accumulate_switch(_IIter __begin, _IIter __end,
70 _Tp __init, _IteratorTag)
74 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation,
75 typename _IteratorTag>
77 __accumulate_switch(_IIter __begin, _IIter __end, _Tp __init,
78 _BinaryOperation __binary_op, _IteratorTag)
79 {
return accumulate(__begin, __end, __init, __binary_op,
83 template<
typename __RAIter,
typename _Tp,
typename _BinaryOperation>
85 __accumulate_switch(__RAIter __begin, __RAIter __end,
86 _Tp __init, _BinaryOperation __binary_op,
87 random_access_iterator_tag,
91 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
93 && __gnu_parallel::__is_parallel(__parallelism_tag)))
103 __accumulate_binop_reduct
104 <_BinaryOperation>(__binary_op),
109 return accumulate(__begin, __end, __init, __binary_op,
114 template<
typename _IIter,
typename _Tp>
116 accumulate(_IIter __begin, _IIter __end, _Tp __init,
120 typedef typename _IteratorTraits::value_type _ValueType;
121 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
123 return __accumulate_switch(__begin, __end, __init,
125 _IteratorCategory(), __parallelism_tag);
128 template<
typename _IIter,
typename _Tp>
130 accumulate(_IIter __begin, _IIter __end, _Tp __init)
133 typedef typename _IteratorTraits::value_type _ValueType;
134 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
136 return __accumulate_switch(__begin, __end, __init,
138 _IteratorCategory());
141 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
143 accumulate(_IIter __begin, _IIter __end, _Tp __init,
144 _BinaryOperation __binary_op,
147 typedef iterator_traits<_IIter> _IteratorTraits;
148 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
149 return __accumulate_switch(__begin, __end, __init, __binary_op,
150 _IteratorCategory(), __parallelism_tag);
153 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
155 accumulate(_IIter __begin, _IIter __end, _Tp __init,
156 _BinaryOperation __binary_op)
158 typedef iterator_traits<_IIter> _IteratorTraits;
159 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
160 return __accumulate_switch(__begin, __end, __init, __binary_op,
161 _IteratorCategory());
166 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
169 _IIter2 __first2, _Tp __init,
172 __first1, __last1, __first2, __init); }
174 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
175 typename _BinaryFunction1,
typename _BinaryFunction2>
178 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
179 _BinaryFunction2 __binary_op2,
182 __binary_op1, __binary_op2); }
185 template<
typename _RAIter1,
typename _RAIter2,
186 typename _Tp,
typename _BinaryFunction1,
typename _BinaryFunction2>
188 __inner_product_switch(_RAIter1 __first1,
190 _RAIter2 __first2, _Tp __init,
191 _BinaryFunction1 __binary_op1,
192 _BinaryFunction2 __binary_op2,
193 random_access_iterator_tag,
194 random_access_iterator_tag,
201 __is_parallel(__parallelism_tag)))
206 _RAIter2, _Tp> __my_selector(__first1, __first2);
209 __first1, __last1, __binary_op2, __my_selector, __binary_op1,
219 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
220 typename _BinaryFunction1,
typename _BinaryFunction2,
221 typename _IteratorTag1,
typename _IteratorTag2>
223 __inner_product_switch(_IIter1 __first1, _IIter1 __last1,
224 _IIter2 __first2, _Tp __init,
225 _BinaryFunction1 __binary_op1,
226 _BinaryFunction2 __binary_op2,
227 _IteratorTag1, _IteratorTag2)
228 {
return inner_product(__first1, __last1, __first2, __init, __binary_op1,
231 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
232 typename _BinaryFunction1,
typename _BinaryFunction2>
235 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
236 _BinaryFunction2 __binary_op2,
239 typedef iterator_traits<_IIter1> _TraitsType1;
240 typedef typename _TraitsType1::iterator_category _IteratorCategory1;
242 typedef iterator_traits<_IIter2> _TraitsType2;
243 typedef typename _TraitsType2::iterator_category _IteratorCategory2;
245 return __inner_product_switch(__first1, __last1, __first2, __init,
246 __binary_op1, __binary_op2,
247 _IteratorCategory1(), _IteratorCategory2(),
251 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
252 typename _BinaryFunction1,
typename _BinaryFunction2>
255 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
256 _BinaryFunction2 __binary_op2)
258 typedef iterator_traits<_IIter1> _TraitsType1;
259 typedef typename _TraitsType1::iterator_category _IteratorCategory1;
261 typedef iterator_traits<_IIter2> _TraitsType2;
262 typedef typename _TraitsType2::iterator_category _IteratorCategory2;
264 return __inner_product_switch(__first1, __last1, __first2, __init,
265 __binary_op1, __binary_op2,
266 _IteratorCategory1(),
267 _IteratorCategory2());
270 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
273 _IIter2 __first2, _Tp __init,
276 typedef iterator_traits<_IIter1> _TraitsType1;
277 typedef typename _TraitsType1::value_type _ValueType1;
278 typedef iterator_traits<_IIter2> _TraitsType2;
279 typedef typename _TraitsType2::value_type _ValueType2;
283 _MultipliesResultType;
287 _Multiplies<_ValueType1, _ValueType2>(),
291 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
294 _IIter2 __first2, _Tp __init)
296 typedef iterator_traits<_IIter1> _TraitsType1;
297 typedef typename _TraitsType1::value_type _ValueType1;
298 typedef iterator_traits<_IIter2> _TraitsType2;
299 typedef typename _TraitsType2::value_type _ValueType2;
303 _MultipliesResultType;
307 _Multiplies<_ValueType1, _ValueType2>());
311 template<
typename _IIter,
typename _OutputIterator>
312 inline _OutputIterator
313 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
318 template<
typename _IIter,
typename _OutputIterator,
319 typename _BinaryOperation>
320 inline _OutputIterator
321 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
326 template<
typename _IIter,
typename _OutputIterator,
327 typename _BinaryOperation,
typename _IteratorTag1,
328 typename _IteratorTag2>
329 inline _OutputIterator
330 __partial_sum_switch(_IIter __begin, _IIter __end,
331 _OutputIterator __result, _BinaryOperation __bin_op,
332 _IteratorTag1, _IteratorTag2)
336 template<
typename _IIter,
typename _OutputIterator,
337 typename _BinaryOperation>
339 __partial_sum_switch(_IIter __begin, _IIter __end,
340 _OutputIterator __result, _BinaryOperation __bin_op,
341 random_access_iterator_tag,
342 random_access_iterator_tag)
345 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
350 return partial_sum(__begin, __end, __result, __bin_op,
355 template<
typename _IIter,
typename _OutputIterator>
356 inline _OutputIterator
357 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result)
359 typedef typename iterator_traits<_IIter>::value_type _ValueType;
365 template<
typename _IIter,
typename _OutputIterator,
366 typename _BinaryOperation>
367 inline _OutputIterator
368 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
369 _BinaryOperation __binary_op)
371 typedef iterator_traits<_IIter> _ITraitsType;
372 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
374 typedef iterator_traits<_OutputIterator> _OTraitsType;
375 typedef typename _OTraitsType::iterator_category _OIterCategory;
377 return __partial_sum_switch(__begin, __end, __result, __binary_op,
378 _IIteratorCategory(), _OIterCategory());
382 template<
typename _IIter,
typename _OutputIterator>
383 inline _OutputIterator
389 template<
typename _IIter,
typename _OutputIterator,
390 typename _BinaryOperation>
391 inline _OutputIterator
393 _OutputIterator __result, _BinaryOperation __bin_op,
396 __result, __bin_op); }
399 template<
typename _IIter,
typename _OutputIterator,
400 typename _BinaryOperation,
typename _IteratorTag1,
401 typename _IteratorTag2>
402 inline _OutputIterator
403 __adjacent_difference_switch(_IIter __begin, _IIter __end,
404 _OutputIterator __result,
405 _BinaryOperation __bin_op, _IteratorTag1,
411 template<
typename _IIter,
typename _OutputIterator,
412 typename _BinaryOperation>
414 __adjacent_difference_switch(_IIter __begin, _IIter __end,
415 _OutputIterator __result,
416 _BinaryOperation __bin_op,
417 random_access_iterator_tag,
418 random_access_iterator_tag,
423 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
425 && __gnu_parallel::__is_parallel(__parallelism_tag)))
429 random_access_iterator_tag> _ItTrip;
430 *__result = *__begin;
431 _ItTrip __begin_pair(__begin + 1, __result + 1),
432 __end_pair(__end, __result + (__end - __begin));
437 __begin_pair, __end_pair, __bin_op, __functionality,
447 template<
typename _IIter,
typename _OutputIterator>
448 inline _OutputIterator
450 _OutputIterator __result,
453 typedef iterator_traits<_IIter> _TraitsType;
454 typedef typename _TraitsType::value_type _ValueType;
460 template<
typename _IIter,
typename _OutputIterator>
461 inline _OutputIterator
463 _OutputIterator __result)
465 typedef iterator_traits<_IIter> _TraitsType;
466 typedef typename _TraitsType::value_type _ValueType;
471 template<
typename _IIter,
typename _OutputIterator,
472 typename _BinaryOperation>
473 inline _OutputIterator
475 _OutputIterator __result, _BinaryOperation __binary_op,
478 typedef iterator_traits<_IIter> _ITraitsType;
479 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
481 typedef iterator_traits<_OutputIterator> _OTraitsType;
482 typedef typename _OTraitsType::iterator_category _OIterCategory;
484 return __adjacent_difference_switch(__begin, __end, __result,
486 _IIteratorCategory(),
491 template<
typename _IIter,
typename _OutputIterator,
492 typename _BinaryOperation>
493 inline _OutputIterator
495 _OutputIterator __result, _BinaryOperation __binary_op)
497 typedef iterator_traits<_IIter> _ITraitsType;
498 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
500 typedef iterator_traits<_OutputIterator> _OTraitsType;
501 typedef typename _OTraitsType::iterator_category _OIterCategory;
503 return __adjacent_difference_switch(__begin, __end, __result,
505 _IIteratorCategory(),
static const _Settings & get()
Get the global settings.
_It _M_finish_iterator
_Iterator on last element processed; needed for some algorithms (e. g. std::transform()).
Functors representing different tasks to be plugged into the generic parallelization methods for emba...
#define _GLIBCXX_PARALLEL_CONDITION(__c)
Determine at compile(?)-time if the parallel variant of an algorithm should be called.
constexpr _Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
Compute inner product of two ranges.
constexpr _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
Similar to std::plus, but allows two different types.
Helper iterator classes for the std::transform() functions. This file is a GNU parallel extension to ...
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...
One of the math functors.
constexpr _Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
Parallel implementation of std::partial_sum(), i.e. prefix sums. This file is a GNU parallel extensio...
Main interface for embarrassingly parallel functions.
std::inner_product() selector.
Forces sequential execution at compile time.
One of the math functors.
_OutputIterator __parallel_partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op)
Parallel partial sum front-__end.
Reduction function doing nothing.
A pair of iterators. The usual iterator operations are applied to both child iterators.
Traits class for iterators.
_Result result_type
result_type is the return type
_Parallelism
Run-time equivalents for the compile-time tags.
_Op __for_each_template_random_access_ed(_RAIter __begin, _RAIter __end, _Op __o, _Fu &__f, _Red __r, _Result __base, _Result &__output, typename std::iterator_traits< _RAIter >::difference_type __bound)
Embarrassingly parallel algorithm for random access iterators, using hand-crafted parallelization by ...
Selector that returns the difference between two adjacent __elements.
std::accumulate() selector.
constexpr _OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return differences between adjacent values.