33#ifndef _GLIBCXX_PARALLEL_PARTIAL_SUM_H
34#define _GLIBCXX_PARALLEL_PARTIAL_SUM_H 1
54 template<
typename _IIter,
55 typename _OutputIterator,
56 typename _BinaryOperation>
59 _OutputIterator __result,
60 _BinaryOperation __bin_op,
61 typename std::iterator_traits <_IIter>::value_type __value)
66 while (__begin != __end)
68 __value = __bin_op(__value, *__begin);
85 template<
typename _IIter,
86 typename _OutputIterator,
87 typename _BinaryOperation>
90 _OutputIterator __result,
91 _BinaryOperation __bin_op,
95 typedef typename _TraitsType::value_type _ValueType;
96 typedef typename _TraitsType::difference_type _DifferenceType;
102 std::min<_DifferenceType>(__get_max_threads(), __n - 1);
104 if (__num_threads < 2)
106 *__result = *__begin;
108 __result + 1, __bin_op,
112 _DifferenceType* __borders;
117# pragma omp parallel num_threads(__num_threads)
121 __num_threads = omp_get_num_threads();
123 __borders =
new _DifferenceType[__num_threads + 2];
129 _DifferenceType __first_part_length =
130 std::max<_DifferenceType>(1,
132 _DifferenceType __chunk_length =
133 (__n - __first_part_length) / __num_threads;
134 _DifferenceType __borderstart =
135 __n - __num_threads * __chunk_length;
137 for (
_ThreadIndex __i = 1; __i < (__num_threads + 1); ++__i)
139 __borders[__i] = __borderstart;
140 __borderstart += __chunk_length;
142 __borders[__num_threads + 1] = __n;
145 __sums =
static_cast<_ValueType*
>(::operator
new(
sizeof(_ValueType)
147 _OutputIterator __target_end;
153 *__result = *__begin;
155 __begin + __borders[1],
158 ::new(&(__sums[__iam])) _ValueType(*(__result + __borders[1] - 1));
162 ::new(&(__sums[__iam]))
163 _ValueType(__gnu_parallel::accumulate(
164 __begin + __borders[__iam] + 1,
165 __begin + __borders[__iam + 1],
166 *(__begin + __borders[__iam]),
175 __sums + 1, __bin_op, __sums[0]);
181 __begin + __borders[__iam + 2],
182 __result + __borders[__iam + 1],
183 __bin_op, __sums[__iam]);
187 __sums[__i].~_ValueType();
188 ::operator
delete(__sums);
192 return __result + __n;
201 template<
typename _IIter,
202 typename _OutputIterator,
203 typename _BinaryOperation>
206 _OutputIterator __result, _BinaryOperation __bin_op)
211 typedef typename _TraitsType::value_type _ValueType;
212 typedef typename _TraitsType::difference_type _DifferenceType;
214 _DifferenceType __n = __end - __begin;
224 _GLIBCXX_PARALLEL_ASSERT(0);
225 return __result + __n;
End-user include file. Provides advanced settings and tuning options. This file is a GNU parallel ext...
#define _GLIBCXX_CALL(__n)
Macro to produce log message when entering a function.
GNU parallel code for public use.
uint16_t _ThreadIndex
Unsigned integer to index a thread number. The maximum thread number (for each processor) must fit in...
_OutputIterator __parallel_partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op)
Parallel partial sum front-__end.
_OutputIterator __parallel_partial_sum_linear(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op, typename std::iterator_traits< _IIter >::difference_type __n)
Parallel partial sum implementation, two-phase approach, no recursion.
_OutputIterator __equally_split(_DifferenceType __n, _ThreadIndex __num_threads, _OutputIterator __s)
function to split a sequence into parts of almost equal size.
_OutputIterator __parallel_partial_sum_basecase(_IIter __begin, _IIter __end, _OutputIterator __result, _BinaryOperation __bin_op, typename std::iterator_traits< _IIter >::value_type __value)
Base case prefix sum routine.
Traits class for iterators.
class _Settings Run-time settings for the parallel mode including all tunable parameters.
float partial_sum_dilation
Ratio for partial_sum. Assume "sum and write result" to be this factor slower than just "sum".
static const _Settings & get()
Get the global settings.
Forces sequential execution at compile time.