32#ifndef _GLIBCXX_PARALLEL_QUICKSORT_H
33#define _GLIBCXX_PARALLEL_QUICKSORT_H 1
49 template<
typename _RAIter,
typename _Compare>
50 typename std::iterator_traits<_RAIter>::difference_type
53 <_RAIter>::difference_type __pivot_rank,
55 <_RAIter>::difference_type
59 typedef typename _TraitsType::value_type _ValueType;
60 typedef typename _TraitsType::difference_type _DifferenceType;
62 _DifferenceType __n = __end - __begin;
63 __num_samples =
std::min(__num_samples, __n);
66 _ValueType* __samples =
static_cast<_ValueType*
>
67 (::operator
new(__num_samples *
sizeof(_ValueType)));
69#pragma GCC diagnostic push
70#pragma GCC diagnostic ignored "-Wlong-long"
71 for (_DifferenceType __s = 0; __s < __num_samples; ++__s)
73 const unsigned long long __index =
static_cast<unsigned long long>
74 (__s) * __n / __num_samples;
75 ::new(&(__samples[__s])) _ValueType(__begin[__index]);
77#pragma GCC diagnostic pop
79 __gnu_sequential::sort(__samples, __samples + __num_samples, __comp);
81 _ValueType& __pivot = __samples[__pivot_rank * __num_samples / __n];
84 __pred(__comp, __pivot);
86 __pred, __num_threads);
88 for (_DifferenceType __s = 0; __s < __num_samples; ++__s)
89 __samples[__s].~_ValueType();
90 ::operator
delete(__samples);
102 template<
typename _RAIter,
typename _Compare>
109 typedef typename _TraitsType::value_type _ValueType;
110 typedef typename _TraitsType::difference_type _DifferenceType;
112 if (__num_threads <= 1)
114 __gnu_sequential::sort(__begin, __end, __comp);
118 _DifferenceType __n = __end - __begin, __pivot_rank;
125 if ((__num_threads % 2) == 1)
126 __num_threads_left = __num_threads / 2 + 1;
128 __num_threads_left = __num_threads / 2;
130 __pivot_rank = __n * __num_threads_left / __num_threads;
133 (__begin, __end, __comp, __pivot_rank,
136#pragma omp parallel sections num_threads(2)
140 __comp, __num_threads_left);
143 __comp, __num_threads - __num_threads_left);
155 template<
typename _RAIter,
typename _Compare>
164 typedef typename _TraitsType::value_type _ValueType;
165 typedef typename _TraitsType::difference_type _DifferenceType;
167 _DifferenceType __n = __end - __begin;
170 if (__num_threads > __n)
174 __begin, __begin + __n, __comp, __num_threads);
#define _GLIBCXX_CALL(__n)
Macro to produce log message when entering a function.
End-user include file. Provides advanced settings and tuning options. This file is a GNU parallel ext...
Parallel implementation of std::partition(), std::nth_element(), and std::partial_sort()....
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
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...
void __parallel_sort_qs_conquer(_RAIter __begin, _RAIter __end, _Compare __comp, _ThreadIndex __num_threads)
Unbalanced quicksort conquer step.
std::iterator_traits< _RAIter >::difference_type __parallel_sort_qs_divide(_RAIter __begin, _RAIter __end, _Compare __comp, typename std::iterator_traits< _RAIter >::difference_type __pivot_rank, typename std::iterator_traits< _RAIter >::difference_type __num_samples, _ThreadIndex __num_threads)
Unbalanced quicksort divide step.
void __parallel_sort_qs(_RAIter __begin, _RAIter __end, _Compare __comp, _ThreadIndex __num_threads)
Unbalanced quicksort main call.
std::iterator_traits< _RAIter >::difference_type __parallel_partition(_RAIter __begin, _RAIter __end, _Predicate __pred, _ThreadIndex __num_threads)
Parallel implementation of std::partition.
Traits class for iterators.
Similar to std::binder2nd, but giving the argument types explicitly.
static const _Settings & get()
Get the global settings.