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,
92 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
94 && __gnu_parallel::__is_parallel(__parallelism_tag)))
104 __accumulate_binop_reduct
105 <_BinaryOperation>(__binary_op),
110 return accumulate(__begin, __end, __init, __binary_op,
115 template<
typename _IIter,
typename _Tp>
117 accumulate(_IIter __begin, _IIter __end, _Tp __init,
120 typedef std::iterator_traits<_IIter> _IteratorTraits;
121 typedef typename _IteratorTraits::value_type _ValueType;
122 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
124 return __accumulate_switch(__begin, __end, __init,
126 _IteratorCategory(), __parallelism_tag);
129 template<
typename _IIter,
typename _Tp>
131 accumulate(_IIter __begin, _IIter __end, _Tp __init)
133 typedef std::iterator_traits<_IIter> _IteratorTraits;
134 typedef typename _IteratorTraits::value_type _ValueType;
135 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
137 return __accumulate_switch(__begin, __end, __init,
139 _IteratorCategory());
142 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
144 accumulate(_IIter __begin, _IIter __end, _Tp __init,
145 _BinaryOperation __binary_op,
148 typedef iterator_traits<_IIter> _IteratorTraits;
149 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
150 return __accumulate_switch(__begin, __end, __init, __binary_op,
151 _IteratorCategory(), __parallelism_tag);
154 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
156 accumulate(_IIter __begin, _IIter __end, _Tp __init,
157 _BinaryOperation __binary_op)
159 typedef iterator_traits<_IIter> _IteratorTraits;
160 typedef typename _IteratorTraits::iterator_category _IteratorCategory;
161 return __accumulate_switch(__begin, __end, __init, __binary_op,
162 _IteratorCategory());
167 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
170 _IIter2 __first2, _Tp __init,
173 __first1, __last1, __first2, __init); }
175 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
176 typename _BinaryFunction1,
typename _BinaryFunction2>
179 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
180 _BinaryFunction2 __binary_op2,
183 __binary_op1, __binary_op2); }
186 template<
typename _RAIter1,
typename _RAIter2,
187 typename _Tp,
typename _BinaryFunction1,
typename _BinaryFunction2>
189 __inner_product_switch(_RAIter1 __first1,
191 _RAIter2 __first2, _Tp __init,
192 _BinaryFunction1 __binary_op1,
193 _BinaryFunction2 __binary_op2,
194 random_access_iterator_tag,
195 random_access_iterator_tag,
203 __is_parallel(__parallelism_tag)))
208 _RAIter2, _Tp> __my_selector(__first1, __first2);
211 __first1, __last1, __binary_op2, __my_selector, __binary_op1,
221 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
222 typename _BinaryFunction1,
typename _BinaryFunction2,
223 typename _IteratorTag1,
typename _IteratorTag2>
225 __inner_product_switch(_IIter1 __first1, _IIter1 __last1,
226 _IIter2 __first2, _Tp __init,
227 _BinaryFunction1 __binary_op1,
228 _BinaryFunction2 __binary_op2,
229 _IteratorTag1, _IteratorTag2)
230 {
return inner_product(__first1, __last1, __first2, __init, __binary_op1,
233 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
234 typename _BinaryFunction1,
typename _BinaryFunction2>
237 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
238 _BinaryFunction2 __binary_op2,
241 typedef iterator_traits<_IIter1> _TraitsType1;
242 typedef typename _TraitsType1::iterator_category _IteratorCategory1;
244 typedef iterator_traits<_IIter2> _TraitsType2;
245 typedef typename _TraitsType2::iterator_category _IteratorCategory2;
247 return __inner_product_switch(__first1, __last1, __first2, __init,
248 __binary_op1, __binary_op2,
249 _IteratorCategory1(), _IteratorCategory2(),
253 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
254 typename _BinaryFunction1,
typename _BinaryFunction2>
257 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
258 _BinaryFunction2 __binary_op2)
260 typedef iterator_traits<_IIter1> _TraitsType1;
261 typedef typename _TraitsType1::iterator_category _IteratorCategory1;
263 typedef iterator_traits<_IIter2> _TraitsType2;
264 typedef typename _TraitsType2::iterator_category _IteratorCategory2;
266 return __inner_product_switch(__first1, __last1, __first2, __init,
267 __binary_op1, __binary_op2,
268 _IteratorCategory1(),
269 _IteratorCategory2());
272 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
275 _IIter2 __first2, _Tp __init,
278 typedef iterator_traits<_IIter1> _TraitsType1;
279 typedef typename _TraitsType1::value_type _ValueType1;
280 typedef iterator_traits<_IIter2> _TraitsType2;
281 typedef typename _TraitsType2::value_type _ValueType2;
285 _MultipliesResultType;
289 _Multiplies<_ValueType1, _ValueType2>(),
293 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
296 _IIter2 __first2, _Tp __init)
298 typedef iterator_traits<_IIter1> _TraitsType1;
299 typedef typename _TraitsType1::value_type _ValueType1;
300 typedef iterator_traits<_IIter2> _TraitsType2;
301 typedef typename _TraitsType2::value_type _ValueType2;
305 _MultipliesResultType;
309 _Multiplies<_ValueType1, _ValueType2>());
313 template<
typename _IIter,
typename _OutputIterator>
314 inline _OutputIterator
315 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
320 template<
typename _IIter,
typename _OutputIterator,
321 typename _BinaryOperation>
322 inline _OutputIterator
323 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
328 template<
typename _IIter,
typename _OutputIterator,
329 typename _BinaryOperation,
typename _IteratorTag1,
330 typename _IteratorTag2>
331 inline _OutputIterator
332 __partial_sum_switch(_IIter __begin, _IIter __end,
333 _OutputIterator __result, _BinaryOperation __bin_op,
334 _IteratorTag1, _IteratorTag2)
338 template<
typename _IIter,
typename _OutputIterator,
339 typename _BinaryOperation>
341 __partial_sum_switch(_IIter __begin, _IIter __end,
342 _OutputIterator __result, _BinaryOperation __bin_op,
343 random_access_iterator_tag,
344 random_access_iterator_tag)
347 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
352 return partial_sum(__begin, __end, __result, __bin_op,
357 template<
typename _IIter,
typename _OutputIterator>
358 inline _OutputIterator
359 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result)
361 typedef typename iterator_traits<_IIter>::value_type _ValueType;
367 template<
typename _IIter,
typename _OutputIterator,
368 typename _BinaryOperation>
369 inline _OutputIterator
370 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
371 _BinaryOperation __binary_op)
373 typedef iterator_traits<_IIter> _ITraitsType;
374 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
376 typedef iterator_traits<_OutputIterator> _OTraitsType;
377 typedef typename _OTraitsType::iterator_category _OIterCategory;
379 return __partial_sum_switch(__begin, __end, __result, __binary_op,
380 _IIteratorCategory(), _OIterCategory());
384 template<
typename _IIter,
typename _OutputIterator>
385 inline _OutputIterator
391 template<
typename _IIter,
typename _OutputIterator,
392 typename _BinaryOperation>
393 inline _OutputIterator
395 _OutputIterator __result, _BinaryOperation __bin_op,
398 __result, __bin_op); }
401 template<
typename _IIter,
typename _OutputIterator,
402 typename _BinaryOperation,
typename _IteratorTag1,
403 typename _IteratorTag2>
404 inline _OutputIterator
405 __adjacent_difference_switch(_IIter __begin, _IIter __end,
406 _OutputIterator __result,
407 _BinaryOperation __bin_op, _IteratorTag1,
413 template<
typename _IIter,
typename _OutputIterator,
414 typename _BinaryOperation>
416 __adjacent_difference_switch(_IIter __begin, _IIter __end,
417 _OutputIterator __result,
418 _BinaryOperation __bin_op,
419 random_access_iterator_tag,
420 random_access_iterator_tag,
426 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
428 && __gnu_parallel::__is_parallel(__parallelism_tag)))
432 random_access_iterator_tag> _ItTrip;
433 *__result = *__begin;
434 _ItTrip __begin_pair(__begin + 1, __result + 1),
435 __end_pair(__end, __result + (__end - __begin));
440 __begin_pair, __end_pair, __bin_op, __functionality,
450 template<
typename _IIter,
typename _OutputIterator>
451 inline _OutputIterator
453 _OutputIterator __result,
456 typedef iterator_traits<_IIter> _TraitsType;
457 typedef typename _TraitsType::value_type _ValueType;
463 template<
typename _IIter,
typename _OutputIterator>
464 inline _OutputIterator
466 _OutputIterator __result)
468 typedef iterator_traits<_IIter> _TraitsType;
469 typedef typename _TraitsType::value_type _ValueType;
474 template<
typename _IIter,
typename _OutputIterator,
475 typename _BinaryOperation>
476 inline _OutputIterator
478 _OutputIterator __result, _BinaryOperation __binary_op,
481 typedef iterator_traits<_IIter> _ITraitsType;
482 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
484 typedef iterator_traits<_OutputIterator> _OTraitsType;
485 typedef typename _OTraitsType::iterator_category _OIterCategory;
487 return __adjacent_difference_switch(__begin, __end, __result,
489 _IIteratorCategory(),
494 template<
typename _IIter,
typename _OutputIterator,
495 typename _BinaryOperation>
496 inline _OutputIterator
498 _OutputIterator __result, _BinaryOperation __binary_op)
500 typedef iterator_traits<_IIter> _ITraitsType;
501 typedef typename _ITraitsType::iterator_category _IIteratorCategory;
503 typedef iterator_traits<_OutputIterator> _OTraitsType;
504 typedef typename _OTraitsType::iterator_category _OIterCategory;
506 return __adjacent_difference_switch(__begin, __end, __result,
508 _IIteratorCategory(),
static const _Settings & get()
Get the global settings.
std::inner_product() selector.
Reduction function doing nothing.
_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 ...
Main interface for embarrassingly parallel functions.
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...
One of the math functors.
Parallel implementation of std::partial_sum(), i.e. prefix sums. This file is a GNU parallel extensio...
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
Selector that returns the difference between two adjacent __elements.
Forces sequential execution at compile time.
Similar to std::plus, but allows two different types.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
#define _GLIBCXX_PARALLEL_CONDITION(__c)
Determine at compile(?)-time if the parallel variant of an algorithm should be called.
_It _M_finish_iterator
_Iterator on last element processed; needed for some algorithms (e. g. std::transform()).
_Result result_type
result_type is the return type
One of the math functors.
_Parallelism
Run-time equivalents for the compile-time tags.
Helper iterator classes for the std::transform() functions. This file is a GNU parallel extension to ...
std::accumulate() selector.
_OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return differences between adjacent values.
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
Compute inner product of two ranges.
_OutputIterator __parallel_partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op)
Parallel partial sum front-__end.
A pair of iterators. The usual iterator operations are applied to both child iterators.
Parallel balanced (work-stealing).
Parallel unbalanced (equal-sized chunks).
Functors representing different tasks to be plugged into the generic parallelization methods for emba...