33 #ifndef _GLIBCXX_PARALLEL_PAR_LOOP_H
34 #define _GLIBCXX_PARALLEL_PAR_LOOP_H 1
41 namespace __gnu_parallel
62 template<
typename RandomAccessIterator,
69 RandomAccessIterator end,
70 Op o, Fu& f, Red r, Result base,
73 <RandomAccessIterator>::
74 difference_type bound)
77 typedef typename traits_type::difference_type difference_type;
78 const difference_type length = end - begin;
79 Result *thread_results;
83 __gnu_parallel::min<difference_type>(get_max_threads(), length);
85 # pragma omp parallel num_threads(num_threads)
89 num_threads = omp_get_num_threads();
90 thread_results =
static_cast<Result*
>(
91 ::operator
new(num_threads *
sizeof(Result)));
92 constructed =
new bool[num_threads];
98 Result* reduct =
static_cast<Result*
>(::operator
new(
sizeof(Result)));
106 new(reduct) Result(f(o, begin + start));
108 constructed[iam] =
true;
111 constructed[iam] =
false;
113 for (; start < stop; ++start)
114 *reduct = r(*reduct, f(o, begin + start));
116 thread_results[iam] = *reduct;
121 output = r(output, thread_results[i]);
125 f.finish_iterator = begin + length;
127 delete[] thread_results;
128 delete[] constructed;