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,
58 {
return _GLIBCXX_STD_A::accumulate(__begin, __end, __init); }
60 template<
typename _IIter,
typename _Tp,
typename _BinaryOperation>
62 accumulate(_IIter __begin, _IIter __end, _Tp __init,
64 {
return _GLIBCXX_STD_A::accumulate(__begin, __end, __init, __binary_op); }
67 template<
typename _IIter,
typename _Tp,
typename _IteratorTag>
69 __accumulate_switch(_IIter __begin, _IIter __end,
70 _Tp __init, _IteratorTag)
71 {
return accumulate(__begin, __end, __init,
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,
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>
169 inner_product(_IIter1 __first1, _IIter1 __last1,
170 _IIter2 __first2, _Tp __init,
172 {
return _GLIBCXX_STD_A::inner_product(
173 __first1, __last1, __first2, __init); }
175 template<
typename _IIter1,
typename _IIter2,
typename _Tp,
176 typename _BinaryFunction1,
typename _BinaryFunction2>
178 inner_product(_IIter1 __first1, _IIter1 __last1,
179 _IIter2 __first2, _Tp __init, _BinaryFunction1 __binary_op1,
180 _BinaryFunction2 __binary_op2,
182 {
return _GLIBCXX_STD_A::inner_product(__first1, __last1, __first2, __init,
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,
203 __is_parallel(__parallelism_tag)))
208 _RAIter2, _Tp> __my_selector(__first1, __first2);
211 __first1, __last1, __binary_op2, __my_selector, __binary_op1,
216 return inner_product(__first1, __last1, __first2, __init,
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>
236 inner_product(_IIter1 __first1, _IIter1 __last1,
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>
256 inner_product(_IIter1 __first1, _IIter1 __last1,
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>
274 inner_product(_IIter1 __first1, _IIter1 __last1,
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;
286 return __gnu_parallel::inner_product(__first1, __last1, __first2, __init,
289 _Multiplies<_ValueType1, _ValueType2>(),
293 template<
typename _IIter1,
typename _IIter2,
typename _Tp>
295 inner_product(_IIter1 __first1, _IIter1 __last1,
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;
306 return __gnu_parallel::inner_product(__first1, __last1, __first2, __init,
309 _Multiplies<_ValueType1, _ValueType2>());
313 template<
typename _IIter,
typename _OutputIterator>
314 inline _OutputIterator
315 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
317 {
return _GLIBCXX_STD_A::partial_sum(__begin, __end, __result); }
320 template<
typename _IIter,
typename _OutputIterator,
321 typename _BinaryOperation>
322 inline _OutputIterator
323 partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result,
325 {
return _GLIBCXX_STD_A::partial_sum(__begin, __end, __result, __bin_op); }
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)
335 {
return _GLIBCXX_STD_A::partial_sum(__begin, __end, __result, __bin_op); }
338 template<
typename _IIter,
typename _OutputIterator,
339 typename _BinaryOperation>
341 __partial_sum_switch(_IIter __begin, _IIter __end,
342 _OutputIterator __result, _BinaryOperation __bin_op,
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;
362 return __gnu_parallel::partial_sum(__begin, __end,
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
386 adjacent_difference(_IIter __begin, _IIter __end, _OutputIterator __result,
388 {
return _GLIBCXX_STD_A::adjacent_difference(__begin, __end, __result); }
391 template<
typename _IIter,
typename _OutputIterator,
392 typename _BinaryOperation>
393 inline _OutputIterator
394 adjacent_difference(_IIter __begin, _IIter __end,
395 _OutputIterator __result, _BinaryOperation __bin_op,
397 {
return _GLIBCXX_STD_A::adjacent_difference(__begin, __end,
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,
409 {
return adjacent_difference(__begin, __end, __result, __bin_op,
413 template<
typename _IIter,
typename _OutputIterator,
414 typename _BinaryOperation>
416 __adjacent_difference_switch(_IIter __begin, _IIter __end,
417 _OutputIterator __result,
418 _BinaryOperation __bin_op,
426 static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
428 && __gnu_parallel::__is_parallel(__parallelism_tag)))
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,
445 return adjacent_difference(__begin, __end, __result, __bin_op,
450 template<
typename _IIter,
typename _OutputIterator>
451 inline _OutputIterator
452 adjacent_difference(_IIter __begin, _IIter __end,
453 _OutputIterator __result,
456 typedef iterator_traits<_IIter> _TraitsType;
457 typedef typename _TraitsType::value_type _ValueType;
458 return adjacent_difference(__begin, __end, __result,
463 template<
typename _IIter,
typename _OutputIterator>
464 inline _OutputIterator
465 adjacent_difference(_IIter __begin, _IIter __end,
466 _OutputIterator __result)
468 typedef iterator_traits<_IIter> _TraitsType;
469 typedef typename _TraitsType::value_type _ValueType;
470 return adjacent_difference(__begin, __end, __result,
474 template<
typename _IIter,
typename _OutputIterator,
475 typename _BinaryOperation>
476 inline _OutputIterator
477 adjacent_difference(_IIter __begin, _IIter __end,
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
497 adjacent_difference(_IIter __begin, _IIter __end,
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(),
_Parallelism
Run-time equivalents for the compile-time tags.
static const _Settings & get()
Get the global settings.
Reduction function doing nothing.
Selector that returns the difference between two adjacent __elements.
_OutputIterator __parallel_partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op)
Parallel partial sum front-__end.
Similar to std::plus, but allows two different types.
Forces sequential execution at compile time.
One of the math functors.
Functors representing different tasks to be plugged into the generic parallelization methods for emba...
std::accumulate() selector.
A pair of iterators. The usual iterator operations are applied to both child iterators.
Helper iterator classes for the std::transform() functions. This file is a GNU parallel extension to ...
std::inner_product() selector.
_It _M_finish_iterator
_Iterator on last element processed; needed for some algorithms (e. g. std::transform()).
#define _GLIBCXX_PARALLEL_CONDITION(__c)
Determine at compile(?)-time if the parallel variant of an algorithm should be called.
_Result result_type
result_type is the return type
One of the math functors.
Main interface for embarrassingly parallel functions.
Parallel STL function calls corresponding to stl_numeric.h. The functions defined here mainly do case...
Parallel unbalanced (equal-sized chunks).
Parallel balanced (work-stealing).
Random-access iterators support a superset of bidirectional iterator operations.
Parallel implementation of std::partial_sum(), i.e. prefix sums. This file is a GNU parallel extensio...
_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 ...