33 #ifndef _GLIBCXX_PARALLEL_PAR_LOOP_H
34 #define _GLIBCXX_PARALLEL_PAR_LOOP_H 1
41 namespace __gnu_parallel
61 template<
typename _RAIter,
68 _Op __o, _Fu& __f, _Red __r,
69 _Result
__base, _Result& __output,
70 typename std::iterator_traits<_RAIter>::difference_type __bound)
72 typedef std::iterator_traits<_RAIter> _TraitsType;
73 typedef typename _TraitsType::difference_type _DifferenceType;
74 const _DifferenceType __length = __end - __begin;
75 _Result *__thread_results;
78 _ThreadIndex __num_threads = __gnu_parallel::min<_DifferenceType>
79 (__get_max_threads(), __length);
81 # pragma omp parallel num_threads(__num_threads)
85 __num_threads = omp_get_num_threads();
86 __thread_results =
static_cast<_Result*
>
87 (::operator
new(__num_threads *
sizeof(_Result)));
88 __constructed =
new bool[__num_threads];
100 if (__start < __stop)
102 __reduct =
new _Result(__f(__o, __begin + __start));
104 __constructed[__iam] =
true;
107 __constructed[__iam] =
false;
109 for (; __start < __stop; ++__start)
110 *__reduct = __r(*__reduct, __f(__o, __begin + __start));
112 if (__constructed[__iam])
114 ::new(&__thread_results[__iam]) _Result(*__reduct);
120 if (__constructed[__i])
122 __output = __r(__output, __thread_results[__i]);
123 __thread_results[__i].~_Result();
128 __f._M_finish_iterator = __begin + __length;
130 ::operator
delete(__thread_results);
132 delete[] __constructed;