33 #ifndef _GLIBCXX_PARALLEL_PAR_LOOP_H 34 #define _GLIBCXX_PARALLEL_PAR_LOOP_H 1 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;
_DifferenceType __equally_split_point(_DifferenceType __n, _ThreadIndex __num_threads, _ThreadIndex __thread_no)
function to split a sequence into parts of almost equal size.
Runtime settings and tuning parameters, heuristics to decide whether to use parallelized algorithms....
Sequential helper functions. This file is a GNU parallel extension to the Standard C++ Library.
GNU parallel code for public use.
_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 ...
uint16_t _ThreadIndex
Unsigned integer to index a thread number. The maximum thread number (for each processor) must fit in...