mirror of git://gcc.gnu.org/git/gcc.git
algobase.h: Replace tabs by spaces; correct line breaks.
2009-09-17 Johannes Singler <singler@ira.uka.de>
* include/parallel/algobase.h: Replace tabs by spaces;
correct line breaks.
* include/parallel/algorithmfwd.h: Likewise.
* include/parallel/balanced_quicksort.h: Likewise.
* include/parallel/base.h: Likewise.
* include/parallel/checkers.h: Likewise.
* include/parallel/compatibility.h: Likewise.
* include/parallel/equally_split.h: Likewise.
* include/parallel/find.h: Likewise.
* include/parallel/for_each.h: Likewise.
* include/parallel/for_each_selectors.h: Likewise.
* include/parallel/iterator.h: Likewise.
* include/parallel/list_partition.h: Likewise.
* include/parallel/losertree.h: Likewise.
* include/parallel/merge.h: Likewise.
* include/parallel/multiseq_selection.h: Likewise.
* include/parallel/multiway_merge.h: Likewise.
* include/parallel/multiway_mergesort.h: Likewise.
* include/parallel/numeric: Likewise.
* include/parallel/numericfwd.h: Likewise.
* include/parallel/omp_loop.h: Likewise.
* include/parallel/omp_loop_static.h: Likewise.
* include/parallel/par_loop.h: Likewise.
* include/parallel/partial_sum.h: Likewise.
* include/parallel/partition.h: Likewise.
* include/parallel/queue.h: Likewise.
* include/parallel/quicksort.h: Likewise.
* include/parallel/random_number.h: Likewise.
* include/parallel/random_shuffle.h: Likewise.
* include/parallel/search.h: Likewise.
* include/parallel/set_operations.h: Likewise.
* include/parallel/settings.h: Likewise.
* include/parallel/sort.h: Likewise.
* include/parallel/types.h: Likewise.
* include/parallel/unique_copy.h: Likewise.
* include/parallel/workstealing.h: Likewise.
* include/parallel/algo.h: Likewise;
shorten _ForwardIterator to _FIterator.
* include/parallel/find_selectors.h: Likewise.
From-SVN: r151791
This commit is contained in:
parent
10e154dfd7
commit
15ac3c72db
|
|
@ -1,3 +1,45 @@
|
|||
2009-09-17 Johannes Singler <singler@ira.uka.de>
|
||||
|
||||
* include/parallel/algobase.h: Replace tabs by spaces;
|
||||
correct line breaks.
|
||||
* include/parallel/algorithmfwd.h: Likewise.
|
||||
* include/parallel/balanced_quicksort.h: Likewise.
|
||||
* include/parallel/base.h: Likewise.
|
||||
* include/parallel/checkers.h: Likewise.
|
||||
* include/parallel/compatibility.h: Likewise.
|
||||
* include/parallel/equally_split.h: Likewise.
|
||||
* include/parallel/find.h: Likewise.
|
||||
* include/parallel/for_each.h: Likewise.
|
||||
* include/parallel/for_each_selectors.h: Likewise.
|
||||
* include/parallel/iterator.h: Likewise.
|
||||
* include/parallel/list_partition.h: Likewise.
|
||||
* include/parallel/losertree.h: Likewise.
|
||||
* include/parallel/merge.h: Likewise.
|
||||
* include/parallel/multiseq_selection.h: Likewise.
|
||||
* include/parallel/multiway_merge.h: Likewise.
|
||||
* include/parallel/multiway_mergesort.h: Likewise.
|
||||
* include/parallel/numeric: Likewise.
|
||||
* include/parallel/numericfwd.h: Likewise.
|
||||
* include/parallel/omp_loop.h: Likewise.
|
||||
* include/parallel/omp_loop_static.h: Likewise.
|
||||
* include/parallel/par_loop.h: Likewise.
|
||||
* include/parallel/partial_sum.h: Likewise.
|
||||
* include/parallel/partition.h: Likewise.
|
||||
* include/parallel/queue.h: Likewise.
|
||||
* include/parallel/quicksort.h: Likewise.
|
||||
* include/parallel/random_number.h: Likewise.
|
||||
* include/parallel/random_shuffle.h: Likewise.
|
||||
* include/parallel/search.h: Likewise.
|
||||
* include/parallel/set_operations.h: Likewise.
|
||||
* include/parallel/settings.h: Likewise.
|
||||
* include/parallel/sort.h: Likewise.
|
||||
* include/parallel/types.h: Likewise.
|
||||
* include/parallel/unique_copy.h: Likewise.
|
||||
* include/parallel/workstealing.h: Likewise.
|
||||
* include/parallel/algo.h: Likewise;
|
||||
shorten _ForwardIterator to _FIterator.
|
||||
* include/parallel/find_selectors.h: Likewise.
|
||||
|
||||
2009-09-16 Johannes Singler <singler@ira.uka.de>
|
||||
|
||||
* include/parallel/base.h: Correct some comments accidentally changed
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -57,8 +57,7 @@ namespace __parallel
|
|||
{ return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2); }
|
||||
|
||||
// Sequential fallback
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline pair<_IIter1, _IIter2>
|
||||
mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
|
||||
_Predicate __pred, __gnu_parallel::sequential_tag)
|
||||
|
|
@ -68,14 +67,12 @@ namespace __parallel
|
|||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate, typename _IteratorTag1, typename _IteratorTag2>
|
||||
inline pair<_IIter1, _IIter2>
|
||||
__mismatch_switch(_IIter1 __begin1, _IIter1 __end1,
|
||||
_IIter2 __begin2, _Predicate __pred, _IteratorTag1,
|
||||
_IteratorTag2)
|
||||
__mismatch_switch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
|
||||
_Predicate __pred, _IteratorTag1, _IteratorTag2)
|
||||
{ return _GLIBCXX_STD_P::mismatch(__begin1, __end1, __begin2, __pred); }
|
||||
|
||||
// Parallel mismatch for random access iterators
|
||||
template<typename _RAIter1, typename _RAIter2,
|
||||
typename _Predicate>
|
||||
template<typename _RAIter1, typename _RAIter2, typename _Predicate>
|
||||
pair<_RAIter1, _RAIter2>
|
||||
__mismatch_switch(_RAIter1 __begin1, _RAIter1 __end1,
|
||||
_RAIter2 __begin2, _Predicate __pred,
|
||||
|
|
@ -112,8 +109,7 @@ namespace __parallel
|
|||
}
|
||||
|
||||
// Public interface
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline pair<_IIter1, _IIter2>
|
||||
mismatch(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
|
||||
_Predicate __pred)
|
||||
|
|
@ -123,8 +119,8 @@ namespace __parallel
|
|||
typedef typename iterator1_traits::iterator_category _IteratorCategory1;
|
||||
typedef typename iterator2_traits::iterator_category _IteratorCategory2;
|
||||
|
||||
return __mismatch_switch(__begin1, __end1, __begin2, __pred, _IteratorCategory1(),
|
||||
_IteratorCategory2());
|
||||
return __mismatch_switch(__begin1, __end1, __begin2, __pred,
|
||||
_IteratorCategory1(), _IteratorCategory2());
|
||||
}
|
||||
|
||||
// Sequential fallback
|
||||
|
|
@ -135,8 +131,7 @@ namespace __parallel
|
|||
{ return _GLIBCXX_STD_P::equal(__begin1, __end1, __begin2); }
|
||||
|
||||
// Sequential fallback
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline bool
|
||||
equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
|
||||
_Predicate __pred, __gnu_parallel::sequential_tag)
|
||||
|
|
@ -149,8 +144,7 @@ namespace __parallel
|
|||
{ return mismatch(__begin1, __end1, __begin2).first == __end1; }
|
||||
|
||||
// Public interface
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline bool
|
||||
equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2,
|
||||
_Predicate __pred)
|
||||
|
|
@ -166,14 +160,13 @@ namespace __parallel
|
|||
__begin2, __end2); }
|
||||
|
||||
// Sequential fallback
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline bool
|
||||
lexicographical_compare(_IIter1 __begin1, _IIter1 __end1,
|
||||
_IIter2 __begin2, _IIter2 __end2,
|
||||
_Predicate __pred, __gnu_parallel::sequential_tag)
|
||||
{ return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1,
|
||||
__begin2, __end2, __pred); }
|
||||
{ return _GLIBCXX_STD_P::lexicographical_compare(
|
||||
__begin1, __end1, __begin2, __end2, __pred); }
|
||||
|
||||
// Sequential fallback for input iterator case
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
|
|
@ -181,19 +174,18 @@ namespace __parallel
|
|||
inline bool
|
||||
__lexicographical_compare_switch(_IIter1 __begin1, _IIter1 __end1,
|
||||
_IIter2 __begin2, _IIter2 __end2,
|
||||
_Predicate __pred, _IteratorTag1, _IteratorTag2)
|
||||
{ return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1,
|
||||
__begin2, __end2, __pred); }
|
||||
_Predicate __pred,
|
||||
_IteratorTag1, _IteratorTag2)
|
||||
{ return _GLIBCXX_STD_P::lexicographical_compare(
|
||||
__begin1, __end1, __begin2, __end2, __pred); }
|
||||
|
||||
// Parallel lexicographical_compare for random access iterators
|
||||
// Limitation: Both valuetypes must be the same
|
||||
template<typename _RAIter1, typename _RAIter2,
|
||||
typename _Predicate>
|
||||
template<typename _RAIter1, typename _RAIter2, typename _Predicate>
|
||||
bool
|
||||
__lexicographical_compare_switch(_RAIter1 __begin1,
|
||||
_RAIter1 __end1,
|
||||
_RAIter2 __begin2,
|
||||
_RAIter2 __end2, _Predicate __pred,
|
||||
__lexicographical_compare_switch(_RAIter1 __begin1, _RAIter1 __end1,
|
||||
_RAIter2 __begin2, _RAIter2 __end2,
|
||||
_Predicate __pred,
|
||||
random_access_iterator_tag,
|
||||
random_access_iterator_tag)
|
||||
{
|
||||
|
|
@ -205,36 +197,37 @@ namespace __parallel
|
|||
typedef iterator_traits<_RAIter2> _TraitsType2;
|
||||
typedef typename _TraitsType2::value_type _ValueType2;
|
||||
|
||||
typedef __gnu_parallel::_EqualFromLess<_Predicate, _ValueType1,
|
||||
_ValueType2> _EqualFromLessCompare;
|
||||
typedef __gnu_parallel::
|
||||
_EqualFromLess<_Predicate, _ValueType1, _ValueType2>
|
||||
_EqualFromLessCompare;
|
||||
|
||||
// Longer sequence in first place.
|
||||
if ((__end1 - __begin1) < (__end2 - __begin2))
|
||||
{
|
||||
typedef pair<_RAIter1, _RAIter2>
|
||||
_SpotType;
|
||||
typedef pair<_RAIter1, _RAIter2> _SpotType;
|
||||
_SpotType __mm = __mismatch_switch(__begin1, __end1, __begin2,
|
||||
_EqualFromLessCompare(__pred),
|
||||
random_access_iterator_tag(),
|
||||
random_access_iterator_tag());
|
||||
|
||||
return (__mm.first == __end1) || bool(__pred(*__mm.first, *__mm.second));
|
||||
return (__mm.first == __end1)
|
||||
|| bool(__pred(*__mm.first, *__mm.second));
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef pair<_RAIter2, _RAIter1>
|
||||
_SpotType;
|
||||
typedef pair<_RAIter2, _RAIter1> _SpotType;
|
||||
_SpotType __mm = __mismatch_switch(__begin2, __end2, __begin1,
|
||||
_EqualFromLessCompare(__pred),
|
||||
random_access_iterator_tag(),
|
||||
random_access_iterator_tag());
|
||||
|
||||
return (__mm.first != __end2) && bool(__pred(*__mm.second, *__mm.first));
|
||||
return (__mm.first != __end2)
|
||||
&& bool(__pred(*__mm.second, *__mm.first));
|
||||
}
|
||||
}
|
||||
else
|
||||
return _GLIBCXX_STD_P::lexicographical_compare(__begin1, __end1,
|
||||
__begin2, __end2, __pred);
|
||||
return _GLIBCXX_STD_P::lexicographical_compare(
|
||||
__begin1, __end1, __begin2, __end2, __pred);
|
||||
}
|
||||
|
||||
// Public interface
|
||||
|
|
@ -252,14 +245,13 @@ namespace __parallel
|
|||
typedef typename _TraitsType2::iterator_category _IteratorCategory2;
|
||||
typedef __gnu_parallel::_Less<_ValueType1, _ValueType2> _LessType;
|
||||
|
||||
return __lexicographical_compare_switch(__begin1, __end1, __begin2, __end2,
|
||||
_LessType(), _IteratorCategory1(),
|
||||
_IteratorCategory2());
|
||||
return __lexicographical_compare_switch(
|
||||
__begin1, __end1, __begin2, __end2, _LessType(),
|
||||
_IteratorCategory1(), _IteratorCategory2());
|
||||
}
|
||||
|
||||
// Public interface
|
||||
template<typename _IIter1, typename _IIter2,
|
||||
typename _Predicate>
|
||||
template<typename _IIter1, typename _IIter2, typename _Predicate>
|
||||
inline bool
|
||||
lexicographical_compare(_IIter1 __begin1, _IIter1 __end1,
|
||||
_IIter2 __begin2, _IIter2 __end2,
|
||||
|
|
@ -271,9 +263,9 @@ namespace __parallel
|
|||
typedef iterator_traits<_IIter2> _TraitsType2;
|
||||
typedef typename _TraitsType2::iterator_category _IteratorCategory2;
|
||||
|
||||
return __lexicographical_compare_switch(__begin1, __end1, __begin2, __end2, __pred,
|
||||
_IteratorCategory1(),
|
||||
_IteratorCategory2());
|
||||
return __lexicographical_compare_switch(
|
||||
__begin1, __end1, __begin2, __end2, __pred,
|
||||
_IteratorCategory1(), _IteratorCategory2());
|
||||
}
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
|
|
|||
|
|
@ -190,7 +190,8 @@ namespace __parallel
|
|||
template<typename _IIter, typename _FIter,
|
||||
typename _IterTag1, typename _IterTag2>
|
||||
_IIter
|
||||
__find_first_of_switch(_IIter, _IIter, _FIter, _FIter, _IterTag1, _IterTag2);
|
||||
__find_first_of_switch(
|
||||
_IIter, _IIter, _FIter, _FIter, _IterTag1, _IterTag2);
|
||||
|
||||
template<typename _RAIter, typename _FIter, typename _BiPredicate,
|
||||
typename _IterTag>
|
||||
|
|
@ -546,7 +547,8 @@ namespace __parallel
|
|||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
_RAIter
|
||||
__max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
|
||||
__max_element_switch(
|
||||
_RAIter, _RAIter, _Compare, random_access_iterator_tag,
|
||||
__gnu_parallel::_Parallelism __parallelism
|
||||
= __gnu_parallel::parallel_balanced);
|
||||
|
||||
|
|
@ -596,7 +598,8 @@ namespace __parallel
|
|||
|
||||
template<typename _FIter>
|
||||
_FIter
|
||||
min_element(_FIter, _FIter, __gnu_parallel::_Parallelism __parallelism_tag);
|
||||
min_element(_FIter, _FIter,
|
||||
__gnu_parallel::_Parallelism __parallelism_tag);
|
||||
|
||||
template<typename _FIter, typename _Compare>
|
||||
_FIter
|
||||
|
|
@ -616,7 +619,8 @@ namespace __parallel
|
|||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
_RAIter
|
||||
__min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
|
||||
__min_element_switch(
|
||||
_RAIter, _RAIter, _Compare, random_access_iterator_tag,
|
||||
__gnu_parallel::_Parallelism __parallelism
|
||||
= __gnu_parallel::parallel_balanced);
|
||||
|
||||
|
|
@ -668,7 +672,8 @@ namespace __parallel
|
|||
|
||||
template<typename _RAIter, typename _Predicate>
|
||||
_RAIter
|
||||
__partition_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag);
|
||||
__partition_switch(
|
||||
_RAIter, _RAIter, _Predicate, random_access_iterator_tag);
|
||||
|
||||
template<typename _RAIter>
|
||||
void
|
||||
|
|
|
|||
|
|
@ -115,12 +115,18 @@ template<typename _RAIter, typename _Compare>
|
|||
_DifferenceType __n = __end - __begin;
|
||||
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
(!__comp(*__pivot_pos, *__begin) && !__comp(*(__begin + __n / 2), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *__begin) && !__comp(*(__end - 1), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__begin + __n / 2)) && !__comp(*__begin, *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__begin + __n / 2)) && !__comp(*(__end - 1), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__end - 1)) && !__comp(*__begin, *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__end - 1)) && !__comp(*(__begin + __n / 2), *__pivot_pos)));
|
||||
(!__comp(*__pivot_pos, *__begin) &&
|
||||
!__comp(*(__begin + __n / 2), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *__begin) &&
|
||||
!__comp(*(__end - 1), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__begin + __n / 2)) &&
|
||||
!__comp(*__begin, *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__begin + __n / 2)) &&
|
||||
!__comp(*(__end - 1), *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__end - 1)) &&
|
||||
!__comp(*__begin, *__pivot_pos))
|
||||
|| (!__comp(*__pivot_pos, *(__end - 1)) &&
|
||||
!__comp(*(__begin + __n / 2), *__pivot_pos)));
|
||||
#endif
|
||||
|
||||
// Swap pivot value to end.
|
||||
|
|
@ -183,10 +189,12 @@ template<typename _RAIter, typename _Compare>
|
|||
}
|
||||
|
||||
// Divide step.
|
||||
_DifferenceType __split_pos = __qsb_divide(__begin, __end, __comp, __num_threads);
|
||||
_DifferenceType __split_pos =
|
||||
__qsb_divide(__begin, __end, __comp, __num_threads);
|
||||
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
_GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos && __split_pos < (__end - __begin));
|
||||
_GLIBCXX_PARALLEL_ASSERT(0 <= __split_pos &&
|
||||
__split_pos < (__end - __begin));
|
||||
#endif
|
||||
|
||||
_ThreadIndex __num_threads_leftside =
|
||||
|
|
@ -284,11 +292,13 @@ template<typename _RAIter, typename _Compare>
|
|||
|
||||
// Divide, leave pivot unchanged in last place.
|
||||
_RAIter __split_pos1, __split_pos2;
|
||||
__split_pos1 = __gnu_sequential::partition(__begin, __end - 1, __pred);
|
||||
__split_pos1 =
|
||||
__gnu_sequential::partition(__begin, __end - 1, __pred);
|
||||
|
||||
// Left side: < __pivot_pos; __right side: >= __pivot_pos.
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
_GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1 && __split_pos1 < __end);
|
||||
_GLIBCXX_PARALLEL_ASSERT(__begin <= __split_pos1
|
||||
&& __split_pos1 < __end);
|
||||
#endif
|
||||
// Swap pivot back to middle.
|
||||
if (__split_pos1 != __pivot_pos)
|
||||
|
|
@ -304,8 +314,8 @@ template<typename _RAIter, typename _Compare>
|
|||
__gnu_parallel::__unary_negate<__gnu_parallel::__binder1st
|
||||
<_Compare, _ValueType, _ValueType, bool>, _ValueType>
|
||||
__pred(__gnu_parallel::__binder1st
|
||||
<_Compare, _ValueType, _ValueType, bool>(__comp,
|
||||
*__pivot_pos));
|
||||
<_Compare, _ValueType, _ValueType, bool>(
|
||||
__comp, *__pivot_pos));
|
||||
|
||||
// Find other end of pivot-equal range.
|
||||
__split_pos2 = __gnu_sequential::partition(__split_pos1 + 1,
|
||||
|
|
@ -325,8 +335,8 @@ template<typename _RAIter, typename _Compare>
|
|||
{
|
||||
// Right side larger.
|
||||
if ((__split_pos2) != __end)
|
||||
__tl._M_leftover_parts.push_front(std::make_pair(__split_pos2,
|
||||
__end));
|
||||
__tl._M_leftover_parts.push_front(
|
||||
std::make_pair(__split_pos2, __end));
|
||||
|
||||
//__current.first = __begin; //already set anyway
|
||||
__current.second = __split_pos1;
|
||||
|
|
@ -367,7 +377,8 @@ template<typename _RAIter, typename _Compare>
|
|||
|
||||
// Look for new work.
|
||||
bool __successfully_stolen = false;
|
||||
while (__wait && *__tl._M_elements_leftover > 0 && !__successfully_stolen
|
||||
while (__wait && *__tl._M_elements_leftover > 0
|
||||
&& !__successfully_stolen
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
// Possible dead-lock.
|
||||
&& (omp_get_wtime() < (__search_start + 1.0))
|
||||
|
|
@ -439,11 +450,13 @@ template<typename _RAIter, typename _Compare>
|
|||
|
||||
// Initialize thread local storage
|
||||
_TLSType** __tls = new _TLSType*[__num_threads];
|
||||
_DifferenceType __queue_size = __num_threads * (_ThreadIndex)(log2(__n) + 1);
|
||||
_DifferenceType __queue_size =
|
||||
__num_threads * (_ThreadIndex)(log2(__n) + 1);
|
||||
for (_ThreadIndex __t = 0; __t < __num_threads; ++__t)
|
||||
__tls[__t] = new _QSBThreadLocal<_RAIter>(__queue_size);
|
||||
|
||||
// There can never be more than ceil(log2(__n)) ranges on the stack, because
|
||||
// There can never be more than ceil(log2(__n)) ranges on the stack,
|
||||
// because
|
||||
// 1. Only one processor pushes onto the stack
|
||||
// 2. The largest range has at most length __n
|
||||
// 3. Each range is larger than half of the range remaining
|
||||
|
|
@ -459,13 +472,15 @@ template<typename _RAIter, typename _Compare>
|
|||
}
|
||||
|
||||
// Main recursion call.
|
||||
__qsb_conquer(__tls, __begin, __begin + __n, __comp, 0, __num_threads, true);
|
||||
__qsb_conquer(
|
||||
__tls, __begin, __begin + __n, __comp, 0, __num_threads, true);
|
||||
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
// All stack must be empty.
|
||||
_Piece __dummy;
|
||||
for (int __i = 1; __i < __num_threads; ++__i)
|
||||
_GLIBCXX_PARALLEL_ASSERT(!__tls[__i]->_M_leftover_parts.pop_back(__dummy));
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
!__tls[__i]->_M_leftover_parts.pop_back(__dummy));
|
||||
#endif
|
||||
|
||||
for (int __i = 0; __i < __num_threads; ++__i)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@
|
|||
namespace __gnu_parallel
|
||||
{
|
||||
/**
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp.
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according
|
||||
* to @__c __comp.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param __end End iterator of sequence.
|
||||
* @param __comp Comparator.
|
||||
|
|
@ -75,7 +76,8 @@ namespace __gnu_parallel
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp.
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according to
|
||||
* @__c __comp.
|
||||
* Prints the position in case an unordered pair is found.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param __end End iterator of sequence.
|
||||
|
|
@ -116,7 +118,8 @@ namespace __gnu_parallel
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according to @__c __comp.
|
||||
* @brief Check whether @__c [__begin, @__c __end) is sorted according to
|
||||
* @__c __comp.
|
||||
* Prints all unordered pair, including the surrounding two elements.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param __end End iterator of sequence.
|
||||
|
|
|
|||
|
|
@ -202,7 +202,8 @@ namespace __gnu_parallel
|
|||
int32 __before;
|
||||
__asm__ __volatile__("lock; cmpxchgl %1,%2"
|
||||
: "=a"(__before)
|
||||
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)), "0"(__old)
|
||||
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)),
|
||||
"0"(__old)
|
||||
: "memory");
|
||||
return __before;
|
||||
}
|
||||
|
|
@ -215,7 +216,8 @@ namespace __gnu_parallel
|
|||
int64 __before;
|
||||
__asm__ __volatile__("lock; cmpxchgq %1,%2"
|
||||
: "=a"(__before)
|
||||
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)), "0"(__old)
|
||||
: "q"(__nw), "__m"(*(volatile long long*)(__ptr)),
|
||||
"0"(__old)
|
||||
: "memory");
|
||||
return __before;
|
||||
}
|
||||
|
|
@ -232,7 +234,8 @@ namespace __gnu_parallel
|
|||
* @param __replacement Replacement value.
|
||||
*/
|
||||
inline bool
|
||||
__compare_and_swap_32(volatile int32* __ptr, int32 __comparand, int32 __replacement)
|
||||
__compare_and_swap_32(volatile int32* __ptr, int32 __comparand,
|
||||
int32 __replacement)
|
||||
{
|
||||
#if defined(__ICC) //x86 version
|
||||
return _InterlockedCompareExchange((void*)__ptr, __replacement,
|
||||
|
|
@ -241,8 +244,10 @@ namespace __gnu_parallel
|
|||
return _InterlockedCompareExchange((void*)__ptr, __replacement,
|
||||
__comparand) == __comparand;
|
||||
#elif defined(__ICL) || defined(_MSC_VER)
|
||||
return _InterlockedCompareExchange(reinterpret_cast<volatile long*>(__ptr),
|
||||
__replacement, __comparand) == __comparand;
|
||||
return _InterlockedCompareExchange(
|
||||
reinterpret_cast<volatile long*>(__ptr),
|
||||
__replacement, __comparand)
|
||||
== __comparand;
|
||||
#elif defined(__GNUC__)
|
||||
return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement);
|
||||
#elif defined(__SUNPRO_CC) && defined(__sparc)
|
||||
|
|
@ -272,7 +277,8 @@ namespace __gnu_parallel
|
|||
* @param __replacement Replacement value.
|
||||
*/
|
||||
inline bool
|
||||
__compare_and_swap_64(volatile int64* __ptr, int64 __comparand, int64 __replacement)
|
||||
__compare_and_swap_64(volatile int64* __ptr, int64 __comparand,
|
||||
int64 __replacement)
|
||||
{
|
||||
#if defined(__ICC) && defined(__x86_64) //x86 version
|
||||
return __cas64<int>(__ptr, __comparand, __replacement) == __comparand;
|
||||
|
|
@ -327,9 +333,11 @@ namespace __gnu_parallel
|
|||
__compare_and_swap(volatile _Tp* __ptr, _Tp __comparand, _Tp __replacement)
|
||||
{
|
||||
if (sizeof(_Tp) == sizeof(int32))
|
||||
return __compare_and_swap_32((volatile int32*) __ptr, (int32)__comparand, (int32)__replacement);
|
||||
return __compare_and_swap_32((volatile int32*) __ptr, (int32)__comparand,
|
||||
(int32)__replacement);
|
||||
else if (sizeof(_Tp) == sizeof(int64))
|
||||
return __compare_and_swap_64((volatile int64*) __ptr, (int64)__comparand, (int64)__replacement);
|
||||
return __compare_and_swap_64((volatile int64*) __ptr, (int64)__comparand,
|
||||
(int64)__replacement);
|
||||
else
|
||||
_GLIBCXX_PARALLEL_ASSERT(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ namespace __gnu_parallel
|
|||
* @returns End of splitter sequence, i.e. @__c __s+__num_threads+1 */
|
||||
template<typename _DifferenceType, typename _OutputIterator>
|
||||
_OutputIterator
|
||||
equally_split(_DifferenceType __n, _ThreadIndex __num_threads, _OutputIterator __s)
|
||||
equally_split(_DifferenceType __n, _ThreadIndex __num_threads,
|
||||
_OutputIterator __s)
|
||||
{
|
||||
_DifferenceType __chunk_length = __n / __num_threads;
|
||||
_DifferenceType __num_longer_chunks = __n % __num_threads;
|
||||
|
|
@ -53,7 +54,8 @@ template<typename _DifferenceType, typename _OutputIterator>
|
|||
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
|
||||
{
|
||||
*__s++ = __pos;
|
||||
__pos += (__i < __num_longer_chunks) ? (__chunk_length + 1) : __chunk_length;
|
||||
__pos += (__i < __num_longer_chunks) ?
|
||||
(__chunk_length + 1) : __chunk_length;
|
||||
}
|
||||
*__s++ = __n;
|
||||
return __s;
|
||||
|
|
|
|||
|
|
@ -125,7 +125,8 @@ template<typename _RAIter1,
|
|||
} //single
|
||||
|
||||
_ThreadIndex __iam = omp_get_thread_num();
|
||||
_DifferenceType __start = __borders[__iam], __stop = __borders[__iam + 1];
|
||||
_DifferenceType __start = __borders[__iam],
|
||||
__stop = __borders[__iam + 1];
|
||||
|
||||
_RAIter1 __i1 = __begin1 + __start;
|
||||
_RAIter2 __i2 = __begin2 + __start;
|
||||
|
|
@ -153,8 +154,7 @@ template<typename _RAIter1,
|
|||
delete[] __borders;
|
||||
|
||||
return
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result,
|
||||
__begin2 + __result);
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -178,7 +178,6 @@ template<typename _RAIter1,
|
|||
* There are two main differences between the growing blocks and
|
||||
* the constant-size blocks variants.
|
||||
* 1. For GB, the block size grows; for CSB, the block size is fixed.
|
||||
|
||||
* 2. For GB, the blocks are allocated dynamically;
|
||||
* for CSB, the blocks are allocated in a predetermined manner,
|
||||
* namely spacial round-robin.
|
||||
|
|
@ -250,7 +249,8 @@ template<typename _RAIter1,
|
|||
}
|
||||
|
||||
__local_result = __selector._M_sequential_algorithm(
|
||||
__begin1 + __start, __begin1 + __stop, __begin2 + __start, __pred);
|
||||
__begin1 + __start, __begin1 + __stop,
|
||||
__begin2 + __start, __pred);
|
||||
if (__local_result.first != (__begin1 + __stop))
|
||||
{
|
||||
omp_set_lock(&__result_lock);
|
||||
|
|
@ -259,18 +259,20 @@ template<typename _RAIter1,
|
|||
__result = __local_result.first - __begin1;
|
||||
|
||||
// Result cannot be in future blocks, stop algorithm.
|
||||
__fetch_and_add<_DifferenceType>(&__next_block_start, __length);
|
||||
__fetch_and_add<_DifferenceType>(
|
||||
&__next_block_start, __length);
|
||||
}
|
||||
omp_unset_lock(&__result_lock);
|
||||
}
|
||||
|
||||
__block_size =
|
||||
std::min<_DifferenceType>(__block_size * __s.find_increasing_factor,
|
||||
__block_size = std::min<_DifferenceType>(
|
||||
__block_size * __s.find_increasing_factor,
|
||||
__s.find_maximum_block_size);
|
||||
|
||||
// Get new block, update pointer to next block.
|
||||
__start =
|
||||
__fetch_and_add<_DifferenceType>(&__next_block_start, __block_size);
|
||||
__fetch_and_add<_DifferenceType>(
|
||||
&__next_block_start, __block_size);
|
||||
__stop = ((__length < (__start + __block_size))
|
||||
? __length : (__start + __block_size));
|
||||
}
|
||||
|
|
@ -280,8 +282,7 @@ template<typename _RAIter1,
|
|||
|
||||
// Return iterator on found element.
|
||||
return
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result,
|
||||
__begin2 + __result);
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -329,8 +330,8 @@ template<typename _RAIter1,
|
|||
|
||||
// Try it sequentially first.
|
||||
std::pair<_RAIter1, _RAIter2> __find_seq_result =
|
||||
__selector._M_sequential_algorithm(__begin1, __begin1 + __sequential_search_size,
|
||||
__begin2, __pred);
|
||||
__selector._M_sequential_algorithm(
|
||||
__begin1, __begin1 + __sequential_search_size, __begin2, __pred);
|
||||
|
||||
if (__find_seq_result.first != (__begin1 + __sequential_search_size))
|
||||
return __find_seq_result;
|
||||
|
|
@ -384,7 +385,8 @@ template<typename _RAIter1,
|
|||
|
||||
// Where to work.
|
||||
__start = __iteration_start + __iam * __block_size;
|
||||
__stop = std::min<_DifferenceType>(__length, __start + __block_size);
|
||||
__stop = std::min<_DifferenceType>(
|
||||
__length, __start + __block_size);
|
||||
}
|
||||
} //parallel
|
||||
|
||||
|
|
@ -392,8 +394,7 @@ template<typename _RAIter1,
|
|||
|
||||
// Return iterator on found element.
|
||||
return
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result,
|
||||
__begin2 + __result);
|
||||
std::pair<_RAIter1, _RAIter2>(__begin1 + __result, __begin2 + __result);
|
||||
}
|
||||
#endif
|
||||
} // end namespace
|
||||
|
|
|
|||
|
|
@ -143,18 +143,19 @@ namespace __gnu_parallel
|
|||
_M_sequential_algorithm(_RAIter1 __begin1,
|
||||
_RAIter1 __end1,
|
||||
_RAIter2 __begin2, _Pred __pred)
|
||||
{ return mismatch(__begin1, __end1, __begin2, __pred, sequential_tag()); }
|
||||
{ return mismatch(__begin1, __end1, __begin2, __pred, sequential_tag());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** @brief Test predicate on several elements. */
|
||||
template<typename _ForwardIterator>
|
||||
template<typename _FIterator>
|
||||
struct __find_first_of_selector : public __generic_find_selector
|
||||
{
|
||||
_ForwardIterator _M_begin;
|
||||
_ForwardIterator _M_end;
|
||||
_FIterator _M_begin;
|
||||
_FIterator _M_end;
|
||||
|
||||
explicit __find_first_of_selector(_ForwardIterator __begin, _ForwardIterator __end)
|
||||
explicit __find_first_of_selector(_FIterator __begin, _FIterator __end)
|
||||
: _M_begin(__begin), _M_end(__end) { }
|
||||
|
||||
/** @brief Test on one position.
|
||||
|
|
@ -166,7 +167,7 @@ namespace __gnu_parallel
|
|||
bool
|
||||
operator()(_RAIter1 __i1, _RAIter2 __i2, _Pred __pred)
|
||||
{
|
||||
for (_ForwardIterator __pos_in_candidates = _M_begin;
|
||||
for (_FIterator __pos_in_candidates = _M_begin;
|
||||
__pos_in_candidates != _M_end; ++__pos_in_candidates)
|
||||
if (__pred(*__i1, *__pos_in_candidates))
|
||||
return true;
|
||||
|
|
@ -184,8 +185,11 @@ namespace __gnu_parallel
|
|||
_M_sequential_algorithm(_RAIter1 __begin1,
|
||||
_RAIter1 __end1,
|
||||
_RAIter2 __begin2, _Pred __pred)
|
||||
{ return std::make_pair(find_first_of(__begin1, __end1, _M_begin, _M_end, __pred,
|
||||
sequential_tag()), __begin2); }
|
||||
{
|
||||
return std::make_pair(
|
||||
find_first_of(__begin1, __end1, _M_begin, _M_end, __pred,
|
||||
sequential_tag()), __begin2);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ namespace __gnu_parallel
|
|||
__for_each_template_random_access(_IIter __begin, _IIter __end,
|
||||
_UserOp __user_op,
|
||||
_Functionality& __functionality,
|
||||
_Red __reduction, _Result __reduction_start,
|
||||
_Red __reduction,
|
||||
_Result __reduction_start,
|
||||
_Result& __output, typename
|
||||
std::iterator_traits<_IIter>::
|
||||
difference_type __bound,
|
||||
|
|
@ -73,13 +74,15 @@ namespace __gnu_parallel
|
|||
__reduction_start,
|
||||
__output, __bound);
|
||||
else if (__parallelism_tag == parallel_omp_loop)
|
||||
return for_each_template_random_access_omp_loop(__begin, __end, __user_op,
|
||||
return for_each_template_random_access_omp_loop(
|
||||
__begin, __end, __user_op,
|
||||
__functionality,
|
||||
__reduction,
|
||||
__reduction_start,
|
||||
__output, __bound);
|
||||
else if (__parallelism_tag == parallel_omp_loop_static)
|
||||
return for_each_template_random_access_omp_loop(__begin, __end, __user_op,
|
||||
return for_each_template_random_access_omp_loop(
|
||||
__begin, __end, __user_op,
|
||||
__functionality,
|
||||
__reduction,
|
||||
__reduction_start,
|
||||
|
|
|
|||
|
|
@ -214,7 +214,8 @@ namespace __gnu_parallel
|
|||
* @param __i iterator referencing object.
|
||||
* @return The current value. */
|
||||
template<typename _Op>
|
||||
typename std::iterator_traits<_It>::value_type operator()(_Op __o, _It __i)
|
||||
typename std::iterator_traits<_It>::value_type
|
||||
operator()(_Op __o, _It __i)
|
||||
{ return *__i; }
|
||||
};
|
||||
|
||||
|
|
@ -267,7 +268,8 @@ namespace __gnu_parallel
|
|||
* __elements.
|
||||
*/
|
||||
template<typename _It>
|
||||
struct __adjacent_difference_selector : public __generic_for_each_selector<_It>
|
||||
struct __adjacent_difference_selector :
|
||||
public __generic_for_each_selector<_It>
|
||||
{
|
||||
template<typename _Op>
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ namespace __gnu_parallel
|
|||
/** @brief A pair of iterators. The usual iterator operations are
|
||||
* applied to both child iterators.
|
||||
*/
|
||||
template<typename _Iterator1, typename _Iterator2, typename _IteratorCategory>
|
||||
template<typename _Iterator1, typename _Iterator2,
|
||||
typename _IteratorCategory>
|
||||
class _IteratorPair : public std::pair<_Iterator1, _Iterator2>
|
||||
{
|
||||
private:
|
||||
|
|
@ -102,7 +103,8 @@ namespace __gnu_parallel
|
|||
|
||||
_IteratorPair
|
||||
operator+(difference_type __delta) const
|
||||
{ return _IteratorPair(_Base::first + __delta, _Base::second + __delta); }
|
||||
{ return _IteratorPair(_Base::first + __delta, _Base::second + __delta);
|
||||
}
|
||||
|
||||
difference_type
|
||||
operator-(const _IteratorPair& __other) const
|
||||
|
|
@ -184,7 +186,8 @@ namespace __gnu_parallel
|
|||
|
||||
_IteratorTriple
|
||||
operator+(difference_type __delta) const
|
||||
{ return _IteratorTriple(_M_first + __delta, _M_second + __delta, _M_third + __delta); }
|
||||
{ return _IteratorTriple(_M_first + __delta, _M_second + __delta,
|
||||
_M_third + __delta); }
|
||||
|
||||
difference_type
|
||||
operator-(const _IteratorTriple& __other) const
|
||||
|
|
|
|||
|
|
@ -137,7 +137,8 @@ namespace __gnu_parallel
|
|||
if (__it == __end)
|
||||
break;
|
||||
|
||||
__shrink_and_double(__os_starts, __count_to_two, __range_length, __make_twice);
|
||||
__shrink_and_double(__os_starts, __count_to_two, __range_length,
|
||||
__make_twice);
|
||||
__next = __os_starts.size() / 2 + 1;
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +160,8 @@ namespace __gnu_parallel
|
|||
}
|
||||
|
||||
// Biggest partitions.
|
||||
for (int __i = __num_parts + 1 - __size_greater; __i <= __num_parts; ++__i)
|
||||
for (int __i = __num_parts + 1 - __size_greater; __i <= __num_parts;
|
||||
++__i)
|
||||
{
|
||||
__lengths[__i - 1] = (__size_part+1) * __range_length;
|
||||
__index += (__size_part+1);
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ public:
|
|||
_M_offset = _M_k;
|
||||
|
||||
// Avoid default-constructing _M_losers[]._M_key
|
||||
_M_losers = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
|
||||
_M_losers
|
||||
= static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
|
||||
for (unsigned int __i = _M_ik - 1; __i < _M_k; ++__i)
|
||||
_M_losers[__i + _M_k]._M_sup = true;
|
||||
|
||||
|
|
@ -223,7 +224,8 @@ public:
|
|||
for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
|
||||
{
|
||||
// The smaller one gets promoted, ties are broken by _M_source.
|
||||
if ((_M_sup && (!_M_losers[__pos]._M_sup || _M_losers[__pos]._M_source < _M_source))
|
||||
if ((_M_sup && (!_M_losers[__pos]._M_sup
|
||||
|| _M_losers[__pos]._M_source < _M_source))
|
||||
|| (!_M_sup && !_M_losers[__pos]._M_sup
|
||||
&& ((_M_comp(_M_losers[__pos]._M_key, _M_key))
|
||||
|| (!_M_comp(_M_key, _M_losers[__pos]._M_key)
|
||||
|
|
@ -280,8 +282,8 @@ public:
|
|||
{
|
||||
unsigned int __left = __init_winner (2 * __root);
|
||||
unsigned int __right = __init_winner (2 * __root + 1);
|
||||
if (_M_losers[__right]._M_sup ||
|
||||
(!_M_losers[__left]._M_sup
|
||||
if (_M_losers[__right]._M_sup
|
||||
|| (!_M_losers[__left]._M_sup
|
||||
&& !_M_comp(_M_losers[__right]._M_key, _M_losers[__left]._M_key)))
|
||||
{
|
||||
// Left one is less or equal.
|
||||
|
|
@ -320,7 +322,8 @@ public:
|
|||
for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
|
||||
{
|
||||
// The smaller one gets promoted.
|
||||
if (_M_sup || (!_M_losers[__pos]._M_sup && _M_comp(_M_losers[__pos]._M_key, _M_key)))
|
||||
if (_M_sup || (!_M_losers[__pos]._M_sup
|
||||
&& _M_comp(_M_losers[__pos]._M_key, _M_key)))
|
||||
{
|
||||
// The other one is smaller.
|
||||
std::swap(_M_losers[__pos]._M_sup, _M_sup);
|
||||
|
|
@ -414,7 +417,8 @@ public:
|
|||
unsigned int __left = __init_winner (2 * __root);
|
||||
unsigned int __right = __init_winner (2 * __root + 1);
|
||||
if (_M_losers[__right]._M_sup
|
||||
|| (!_M_losers[__left]._M_sup && !_M_comp(*_M_losers[__right]._M_keyp,
|
||||
|| (!_M_losers[__left]._M_sup
|
||||
&& !_M_comp(*_M_losers[__right]._M_keyp,
|
||||
*_M_losers[__left]._M_keyp)))
|
||||
{
|
||||
// Left one is less or equal.
|
||||
|
|
@ -445,7 +449,8 @@ public:
|
|||
for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
|
||||
{
|
||||
// The smaller one gets promoted, ties are broken by _M_source.
|
||||
if ((_M_sup && (!_M_losers[__pos]._M_sup || _M_losers[__pos]._M_source < _M_source)) ||
|
||||
if ((_M_sup && (!_M_losers[__pos]._M_sup ||
|
||||
_M_losers[__pos]._M_source < _M_source)) ||
|
||||
(!_M_sup && !_M_losers[__pos]._M_sup &&
|
||||
((_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)) ||
|
||||
(!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp)
|
||||
|
|
@ -495,7 +500,8 @@ public:
|
|||
unsigned int __right = __init_winner (2 * __root + 1);
|
||||
if (_M_losers[__right]._M_sup
|
||||
|| (!_M_losers[__left]._M_sup
|
||||
&& !_M_comp(*_M_losers[__right]._M_keyp, *_M_losers[__left]._M_keyp)))
|
||||
&& !_M_comp(*_M_losers[__right]._M_keyp,
|
||||
*_M_losers[__left]._M_keyp)))
|
||||
{
|
||||
// Left one is less or equal.
|
||||
_M_losers[__root] = _M_losers[__right];
|
||||
|
|
@ -525,7 +531,8 @@ public:
|
|||
for (unsigned int __pos = (_M_k + _M_source) / 2; __pos > 0; __pos /= 2)
|
||||
{
|
||||
// The smaller one gets promoted.
|
||||
if (_M_sup || (!_M_losers[__pos]._M_sup && _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)))
|
||||
if (_M_sup || (!_M_losers[__pos]._M_sup
|
||||
&& _M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)))
|
||||
{
|
||||
// The other one is smaller.
|
||||
std::swap(_M_losers[__pos]._M_sup, _M_sup);
|
||||
|
|
@ -576,7 +583,8 @@ public:
|
|||
_M_k = 1 << (__log2(_M_ik - 1) + 1);
|
||||
_M_offset = _M_k;
|
||||
// Avoid default-constructing _M_losers[]._M_key
|
||||
_M_losers = static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
|
||||
_M_losers
|
||||
= static_cast<_Loser*>(::operator new(2 * _M_k * sizeof(_Loser)));
|
||||
|
||||
for (unsigned int __i = _M_k + _M_ik - 1; __i < (2 * _M_k); ++__i)
|
||||
{
|
||||
|
|
@ -677,7 +685,8 @@ public:
|
|||
{
|
||||
// The smaller one gets promoted, ties are broken by _M_source.
|
||||
if (_M_comp(_M_losers[__pos]._M_key, _M_key)
|
||||
|| (!_M_comp(_M_key, _M_losers[__pos]._M_key) && _M_losers[__pos]._M_source < _M_source))
|
||||
|| (!_M_comp(_M_key, _M_losers[__pos]._M_key)
|
||||
&& _M_losers[__pos]._M_source < _M_source))
|
||||
{
|
||||
// The other one is smaller.
|
||||
std::swap(_M_losers[__pos]._M_source, _M_source);
|
||||
|
|
@ -914,7 +923,8 @@ public:
|
|||
{
|
||||
// The smaller one gets promoted, ties are broken by _M_source.
|
||||
if (_M_comp(*_M_losers[__pos]._M_keyp, *_M_keyp)
|
||||
|| (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp) && _M_losers[__pos]._M_source < _M_source))
|
||||
|| (!_M_comp(*_M_keyp, *_M_losers[__pos]._M_keyp)
|
||||
&& _M_losers[__pos]._M_source < _M_source))
|
||||
{
|
||||
// The other one is smaller.
|
||||
std::swap(_M_losers[__pos]._M_source, _M_source);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ namespace __gnu_parallel
|
|||
/** @brief Compare __a pair of types lexicographically, ascending. */
|
||||
template<typename _T1, typename _T2, typename _Compare>
|
||||
class _Lexicographic
|
||||
: public std::binary_function<std::pair<_T1, _T2>, std::pair<_T1, _T2>, bool>
|
||||
: public std::binary_function<
|
||||
std::pair<_T1, _T2>, std::pair<_T1, _T2>, bool>
|
||||
{
|
||||
private:
|
||||
_Compare& _M_comp;
|
||||
|
|
@ -146,9 +147,11 @@ namespace __gnu_parallel
|
|||
|
||||
for (int __i = 0; __i < __m; __i++)
|
||||
{
|
||||
__N += std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second);
|
||||
__N += std::distance(__begin_seqs[__i].first,
|
||||
__begin_seqs[__i].second);
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second) > 0);
|
||||
std::distance(__begin_seqs[__i].first,
|
||||
__begin_seqs[__i].second) > 0);
|
||||
}
|
||||
|
||||
if (__rank == __N)
|
||||
|
|
@ -173,7 +176,8 @@ namespace __gnu_parallel
|
|||
__nmax = __ns[0];
|
||||
for (int __i = 0; __i < __m; __i++)
|
||||
{
|
||||
__ns[__i] = std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second);
|
||||
__ns[__i] = std::distance(__begin_seqs[__i].first,
|
||||
__begin_seqs[__i].second);
|
||||
__nmax = std::max(__nmax, __ns[__i]);
|
||||
}
|
||||
|
||||
|
|
@ -208,12 +212,14 @@ namespace __gnu_parallel
|
|||
|
||||
for (int __i = 0; __i < __m; __i++) //conceptual infinity
|
||||
if (__n >= __ns[__i]) //__sequence too short, conceptual infinity
|
||||
__sample.push_back(std::make_pair(__S(__i)[0] /*__dummy element*/, __i));
|
||||
__sample.push_back(
|
||||
std::make_pair(__S(__i)[0] /*__dummy element*/, __i));
|
||||
|
||||
_DifferenceType localrank = __rank * __m / __N ;
|
||||
|
||||
int __j;
|
||||
for (__j = 0; __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j)
|
||||
for (__j = 0;
|
||||
__j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j)
|
||||
__a[__sample[__j].second] += __n + 1;
|
||||
for (; __j < __m; __j++)
|
||||
__b[__sample[__j].second] -= __n + 1;
|
||||
|
|
@ -289,7 +295,8 @@ namespace __gnu_parallel
|
|||
__b[source] += __n + 1;
|
||||
|
||||
if (__b[source] < __ns[source])
|
||||
__pq.push(std::make_pair(__S(source)[__b[source]], source));
|
||||
__pq.push(
|
||||
std::make_pair(__S(source)[__b[source]], source));
|
||||
}
|
||||
}
|
||||
else if (__skew < 0)
|
||||
|
|
@ -312,14 +319,15 @@ namespace __gnu_parallel
|
|||
__b[source] -= __n + 1;
|
||||
|
||||
if (__a[source] > 0)
|
||||
__pq.push(std::make_pair(__S(source)[__a[source] - 1], source));
|
||||
__pq.push(
|
||||
std::make_pair(__S(source)[__a[source] - 1], source));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Postconditions:
|
||||
// __a[__i] == __b[__i] in most cases, except when __a[__i] has been clamped
|
||||
// because of having reached the boundary
|
||||
// __a[__i] == __b[__i] in most cases, except when __a[__i] has been
|
||||
// clamped because of having reached the boundary
|
||||
|
||||
// Now return the result, calculate the offset.
|
||||
|
||||
|
|
@ -381,7 +389,8 @@ namespace __gnu_parallel
|
|||
template<typename _Tp, typename _RanSeqs, typename _RankType,
|
||||
typename _Compare>
|
||||
_Tp
|
||||
multiseq_selection(_RanSeqs __begin_seqs, _RanSeqs __end_seqs, _RankType __rank,
|
||||
multiseq_selection(_RanSeqs __begin_seqs, _RanSeqs __end_seqs,
|
||||
_RankType __rank,
|
||||
_RankType& __offset, _Compare __comp = std::less<_Tp>())
|
||||
{
|
||||
_GLIBCXX_CALL(__end_seqs - __begin_seqs)
|
||||
|
|
@ -401,11 +410,12 @@ namespace __gnu_parallel
|
|||
_DifferenceType __nmax, __n, __r;
|
||||
|
||||
for (int __i = 0; __i < __m; __i++)
|
||||
__N += std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second);
|
||||
__N += std::distance(__begin_seqs[__i].first,
|
||||
__begin_seqs[__i].second);
|
||||
|
||||
if (__m == 0 || __N == 0 || __rank < 0 || __rank >= __N)
|
||||
{
|
||||
// _Result undefined when there is no data or __rank is outside bounds.
|
||||
// result undefined if there is no data or __rank is outside bounds
|
||||
throw std::exception();
|
||||
}
|
||||
|
||||
|
|
@ -419,7 +429,8 @@ namespace __gnu_parallel
|
|||
__nmax = __ns[0];
|
||||
for (int __i = 0; __i < __m; ++__i)
|
||||
{
|
||||
__ns[__i] = std::distance(__begin_seqs[__i].first, __begin_seqs[__i].second);
|
||||
__ns[__i] = std::distance(__begin_seqs[__i].first,
|
||||
__begin_seqs[__i].second);
|
||||
__nmax = std::max(__nmax, __ns[__i]);
|
||||
}
|
||||
|
||||
|
|
@ -456,12 +467,14 @@ namespace __gnu_parallel
|
|||
// Conceptual infinity.
|
||||
for (int __i = 0; __i < __m; __i++)
|
||||
if (__n >= __ns[__i])
|
||||
__sample.push_back(std::make_pair(__S(__i)[0] /*__dummy element*/, __i));
|
||||
__sample.push_back(
|
||||
std::make_pair(__S(__i)[0] /*__dummy element*/, __i));
|
||||
|
||||
_DifferenceType localrank = __rank * __m / __N ;
|
||||
|
||||
int __j;
|
||||
for (__j = 0; __j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j)
|
||||
for (__j = 0;
|
||||
__j < localrank && ((__n + 1) <= __ns[__sample[__j].second]); ++__j)
|
||||
__a[__sample[__j].second] += __n + 1;
|
||||
for (; __j < __m; ++__j)
|
||||
__b[__sample[__j].second] -= __n + 1;
|
||||
|
|
@ -490,7 +503,8 @@ namespace __gnu_parallel
|
|||
for (__i = 0; __i < __m; __i++)
|
||||
{
|
||||
_DifferenceType __middle = (__b[__i] + __a[__i]) / 2;
|
||||
if (__lmax && __middle < __ns[__i] && __comp(__S(__i)[__middle], *__lmax))
|
||||
if (__lmax && __middle < __ns[__i]
|
||||
&& __comp(__S(__i)[__middle], *__lmax))
|
||||
__a[__i] = std::min(__a[__i] + __n + 1, __ns[__i]);
|
||||
else
|
||||
__b[__i] -= __n + 1;
|
||||
|
|
@ -526,7 +540,8 @@ namespace __gnu_parallel
|
|||
__b[source] += __n + 1;
|
||||
|
||||
if (__b[source] < __ns[source])
|
||||
__pq.push(std::make_pair(__S(source)[__b[source]], source));
|
||||
__pq.push(
|
||||
std::make_pair(__S(source)[__b[source]], source));
|
||||
}
|
||||
}
|
||||
else if (__skew < 0)
|
||||
|
|
@ -549,14 +564,15 @@ namespace __gnu_parallel
|
|||
__b[source] -= __n + 1;
|
||||
|
||||
if (__a[source] > 0)
|
||||
__pq.push(std::make_pair(__S(source)[__a[source] - 1], source));
|
||||
__pq.push(
|
||||
std::make_pair(__S(source)[__a[source] - 1], source));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Postconditions:
|
||||
// __a[__i] == __b[__i] in most cases, except when __a[__i] has been clamped
|
||||
// because of having reached the boundary
|
||||
// __a[__i] == __b[__i] in most cases, except when __a[__i] has been
|
||||
// clamped because of having reached the boundary
|
||||
|
||||
// Now return the result, calculate the offset.
|
||||
|
||||
|
|
@ -613,7 +629,8 @@ namespace __gnu_parallel
|
|||
|
||||
for (int __i = 0; __i < __m; ++__i)
|
||||
{
|
||||
_DifferenceType lb = std::lower_bound(__S(__i), __S(__i) + __ns[__i],
|
||||
_DifferenceType lb
|
||||
= std::lower_bound(__S(__i), __S(__i) + __ns[__i],
|
||||
__minright,
|
||||
__comp) - __S(__i);
|
||||
__offset += __a[__i] - lb;
|
||||
|
|
|
|||
|
|
@ -638,7 +638,8 @@ template<typename LT,
|
|||
for (int __t = 0; __t < __k; ++__t)
|
||||
{
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
_GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first != __seqs_begin[__t].second);
|
||||
_GLIBCXX_PARALLEL_ASSERT(__seqs_begin[__t].first
|
||||
!= __seqs_begin[__t].second);
|
||||
#endif
|
||||
__lt.__insert_start(*__seqs_begin[__t].first, __t, false);
|
||||
}
|
||||
|
|
@ -914,7 +915,8 @@ struct __multiway_merge_k_variant_sentinel_switch
|
|||
_LoserTreeTraits<_ValueType>::_M_use_pointer
|
||||
, LoserTreePointerUnguarded<__stable, _ValueType, _Compare>
|
||||
, _LoserTreeUnguarded<__stable, _ValueType, _Compare>
|
||||
>::__type>(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
|
||||
>::__type>(
|
||||
__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -997,7 +999,8 @@ template<
|
|||
#if _GLIBCXX_ASSERTIONS
|
||||
for (_RAIterIterator __s = __seqs_begin; __s != __seqs_end; ++__s)
|
||||
{
|
||||
_GLIBCXX_PARALLEL_ASSERT(__is_sorted((*__s).first, (*__s).second, __comp));
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
__is_sorted((*__s).first, (*__s).second, __comp));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1053,11 +1056,13 @@ template<
|
|||
, _RAIterIterator
|
||||
, _RAIter3
|
||||
, _DifferenceTp
|
||||
, _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel, __length, __comp);
|
||||
, _Compare>()(__seqs_begin, __seqs_end, __target, __sentinel,
|
||||
__length, __comp);
|
||||
break;
|
||||
}
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
_GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target + __length, __comp));
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
__is_sorted(__target, __target + __length, __comp));
|
||||
#endif
|
||||
|
||||
return __return_target;
|
||||
|
|
@ -1163,7 +1168,8 @@ void multiway_merge_sampling_splitting(
|
|||
- __seqs_begin[__seq].first;
|
||||
else
|
||||
// Absolute end.
|
||||
__pieces[__slab][__seq].second = _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]);
|
||||
__pieces[__slab][__seq].second
|
||||
= _GLIBCXX_PARALLEL_LENGTH(__seqs_begin[__seq]);
|
||||
}
|
||||
::operator delete(__samples);
|
||||
}
|
||||
|
|
@ -1379,7 +1385,8 @@ template<
|
|||
} // parallel
|
||||
|
||||
#if _GLIBCXX_ASSERTIONS
|
||||
_GLIBCXX_PARALLEL_ASSERT(__is_sorted(__target, __target + __length, __comp));
|
||||
_GLIBCXX_PARALLEL_ASSERT(
|
||||
__is_sorted(__target, __target + __length, __comp));
|
||||
#endif
|
||||
|
||||
__k = 0;
|
||||
|
|
@ -1490,7 +1497,8 @@ multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
// Execute multiway merge *sequentially*.
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ false, /* __sentinels = */ false>
|
||||
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp);
|
||||
(__seqs_begin, __seqs_end, __target,
|
||||
*(__seqs_begin->second), __length, __comp);
|
||||
}
|
||||
|
||||
// public interface
|
||||
|
|
@ -1528,11 +1536,13 @@ multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_exact_splitting</* __stable = */ false,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ false, /* __sentinels = */ false>(
|
||||
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp);
|
||||
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second),
|
||||
__length, __comp);
|
||||
}
|
||||
|
||||
// public interface
|
||||
|
|
@ -1571,7 +1581,8 @@ multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_exact_splitting</* __stable = */ false,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ false, /* __sentinels = */ false>(
|
||||
|
|
@ -1637,7 +1648,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
// Execute multiway merge *sequentially*.
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ true, /* __sentinels = */ false>
|
||||
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp);
|
||||
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length,
|
||||
__comp);
|
||||
}
|
||||
|
||||
// public interface
|
||||
|
|
@ -1676,7 +1688,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_exact_splitting</* __stable = */ true,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge</* __stable = */ true,
|
||||
/* __sentinels = */ false>(
|
||||
|
|
@ -1720,7 +1733,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_sampling_splitting</* __stable = */ true,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ true, /* __sentinels = */ false>(
|
||||
|
|
@ -1742,7 +1756,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, parallel_tag __tag = parallel_tag(0))
|
||||
{
|
||||
return stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return stable_multiway_merge(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
@ -1759,7 +1774,8 @@ stable_multiway_merge(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, default_parallel_tag __tag)
|
||||
{
|
||||
return stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return stable_multiway_merge(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
@ -1902,7 +1918,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_exact_splitting</* __stable = */ false,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ false, /* __sentinels = */ true>(
|
||||
|
|
@ -1945,7 +1962,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_sampling_splitting</* __stable = */ false,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */false, /* __sentinels = */ true>(
|
||||
|
|
@ -1966,7 +1984,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, parallel_tag __tag = parallel_tag(0))
|
||||
{
|
||||
return multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return multiway_merge_sentinels(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
@ -1983,7 +2002,8 @@ multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, default_parallel_tag __tag)
|
||||
{
|
||||
return multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return multiway_merge_sentinels(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
@ -2011,7 +2031,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
// Execute multiway merge *sequentially*.
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ true, /* __sentinels = */ true>
|
||||
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp);
|
||||
(__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length,
|
||||
__comp);
|
||||
}
|
||||
|
||||
// public interface
|
||||
|
|
@ -2050,11 +2071,13 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_exact_splitting</* __stable = */ true,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ true, /* __sentinels = */ true>(
|
||||
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second), __length, __comp);
|
||||
__seqs_begin, __seqs_end, __target, *(__seqs_begin->second),
|
||||
__length, __comp);
|
||||
}
|
||||
|
||||
// public interface
|
||||
|
|
@ -2093,7 +2116,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
multiway_merge_sampling_splitting</* __stable = */ true,
|
||||
typename std::iterator_traits<_RAIterPairIterator>
|
||||
::value_type*, _Compare, _DifferenceTp>,
|
||||
static_cast<_DifferenceType>(__length), __comp, __tag.__get_num_threads());
|
||||
static_cast<_DifferenceType>(__length), __comp,
|
||||
__tag.__get_num_threads());
|
||||
else
|
||||
return __sequential_multiway_merge
|
||||
</* __stable = */ true, /* __sentinels = */ true>(
|
||||
|
|
@ -2114,7 +2138,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, parallel_tag __tag = parallel_tag(0))
|
||||
{
|
||||
return stable_multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return stable_multiway_merge_sentinels(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
@ -2131,7 +2156,8 @@ stable_multiway_merge_sentinels(_RAIterPairIterator __seqs_begin
|
|||
, _DifferenceTp __length, _Compare __comp
|
||||
, default_parallel_tag __tag)
|
||||
{
|
||||
return stable_multiway_merge_sentinels(__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
return stable_multiway_merge_sentinels(
|
||||
__seqs_begin, __seqs_end, __target, __length, __comp,
|
||||
exact_tag(__tag.__get_num_threads()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -145,20 +145,23 @@ template<typename _RAIter, typename _Compare,
|
|||
for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++)
|
||||
seqs[__s] = std::make_pair(__sd->_M_temporary[__s],
|
||||
__sd->_M_temporary[__s]
|
||||
+ (__sd->_M_starts[__s + 1] - __sd->_M_starts[__s]));
|
||||
+ (__sd->_M_starts[__s + 1]
|
||||
- __sd->_M_starts[__s]));
|
||||
|
||||
std::vector<_SortingPlacesIterator> _M_offsets(__sd->_M_num_threads);
|
||||
|
||||
// if not last thread
|
||||
if (__iam < __sd->_M_num_threads - 1)
|
||||
multiseq_partition(seqs.begin(), seqs.end(),
|
||||
__sd->_M_starts[__iam + 1], _M_offsets.begin(), __comp);
|
||||
__sd->_M_starts[__iam + 1], _M_offsets.begin(),
|
||||
__comp);
|
||||
|
||||
for (int __seq = 0; __seq < __sd->_M_num_threads; __seq++)
|
||||
{
|
||||
// for each sequence
|
||||
if (__iam < (__sd->_M_num_threads - 1))
|
||||
__sd->_M_pieces[__iam][__seq]._M_end = _M_offsets[__seq] - seqs[__seq].first;
|
||||
__sd->_M_pieces[__iam][__seq]._M_end
|
||||
= _M_offsets[__seq] - seqs[__seq].first;
|
||||
else
|
||||
// very end of this sequence
|
||||
__sd->_M_pieces[__iam][__seq]._M_end =
|
||||
|
|
@ -171,7 +174,8 @@ template<typename _RAIter, typename _Compare,
|
|||
{
|
||||
// For each sequence.
|
||||
if (__iam > 0)
|
||||
__sd->_M_pieces[__iam][__seq]._M_begin = __sd->_M_pieces[__iam - 1][__seq]._M_end;
|
||||
__sd->_M_pieces[__iam][__seq]._M_begin =
|
||||
__sd->_M_pieces[__iam - 1][__seq]._M_end;
|
||||
else
|
||||
// Absolute beginning.
|
||||
__sd->_M_pieces[__iam][__seq]._M_begin = 0;
|
||||
|
|
@ -204,7 +208,8 @@ template<typename _RAIter, typename _Compare,
|
|||
|
||||
# pragma omp single
|
||||
__gnu_sequential::sort(__sd->_M_samples,
|
||||
__sd->_M_samples + (__num_samples * __sd->_M_num_threads),
|
||||
__sd->_M_samples
|
||||
+ (__num_samples * __sd->_M_num_threads),
|
||||
__comp);
|
||||
|
||||
# pragma omp barrier
|
||||
|
|
@ -224,7 +229,8 @@ template<typename _RAIter, typename _Compare,
|
|||
// Absolute beginning.
|
||||
__sd->_M_pieces[__iam][__s]._M_begin = 0;
|
||||
|
||||
if ((__num_samples * (__iam + 1)) < (__num_samples * __sd->_M_num_threads))
|
||||
if ((__num_samples * (__iam + 1)) <
|
||||
(__num_samples * __sd->_M_num_threads))
|
||||
__sd->_M_pieces[__iam][__s]._M_end =
|
||||
std::lower_bound(__sd->_M_temporary[__s],
|
||||
__sd->_M_temporary[__s]
|
||||
|
|
@ -234,7 +240,8 @@ template<typename _RAIter, typename _Compare,
|
|||
- __sd->_M_temporary[__s];
|
||||
else
|
||||
// Absolute end.
|
||||
__sd->_M_pieces[__iam][__s]._M_end = __sd->_M_starts[__s + 1] - __sd->_M_starts[__s];
|
||||
__sd->_M_pieces[__iam][__s]._M_end = __sd->_M_starts[__s + 1]
|
||||
- __sd->_M_starts[__s];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -283,8 +290,8 @@ template<typename Seq_RAIter, typename _RAIter,
|
|||
_Compare& __comp,
|
||||
DiffType __length_am) const
|
||||
{
|
||||
stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length_am, __comp,
|
||||
sequential_tag());
|
||||
stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length_am,
|
||||
__comp, sequential_tag());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -322,7 +329,8 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
_ThreadIndex __iam = omp_get_thread_num();
|
||||
|
||||
// Length of this thread's chunk, before merging.
|
||||
_DifferenceType __length_local = __sd->_M_starts[__iam + 1] - __sd->_M_starts[__iam];
|
||||
_DifferenceType __length_local
|
||||
= __sd->_M_starts[__iam + 1] - __sd->_M_starts[__iam];
|
||||
|
||||
// Sort in temporary storage, leave space for sentinel.
|
||||
|
||||
|
|
@ -333,12 +341,15 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
::operator new(sizeof(_ValueType) * (__length_local + 1)));
|
||||
|
||||
// Copy there.
|
||||
std::uninitialized_copy(__sd->_M_source + __sd->_M_starts[__iam],
|
||||
std::uninitialized_copy(
|
||||
__sd->_M_source + __sd->_M_starts[__iam],
|
||||
__sd->_M_source + __sd->_M_starts[__iam] + __length_local,
|
||||
__sd->_M_temporary[__iam]);
|
||||
|
||||
__possibly_stable_sort<__stable, _SortingPlacesIterator, _Compare>()
|
||||
(__sd->_M_temporary[__iam], __sd->_M_temporary[__iam] + __length_local, __comp);
|
||||
(__sd->_M_temporary[__iam],
|
||||
__sd->_M_temporary[__iam] + __length_local,
|
||||
__comp);
|
||||
|
||||
// Invariant: locally sorted subsequence in sd->_M_temporary[__iam],
|
||||
// __sd->_M_temporary[__iam] + __length_local.
|
||||
|
|
@ -355,7 +366,8 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
_DifferenceType __offset = 0, __length_am = 0;
|
||||
for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++)
|
||||
{
|
||||
__length_am += __sd->_M_pieces[__iam][__s]._M_end - __sd->_M_pieces[__iam][__s]._M_begin;
|
||||
__length_am += __sd->_M_pieces[__iam][__s]._M_end
|
||||
- __sd->_M_pieces[__iam][__s]._M_begin;
|
||||
__offset += __sd->_M_pieces[__iam][__s]._M_begin;
|
||||
}
|
||||
|
||||
|
|
@ -367,7 +379,8 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
for (int __s = 0; __s < __sd->_M_num_threads; ++__s)
|
||||
{
|
||||
seqs[__s] =
|
||||
std::make_pair(__sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_begin,
|
||||
std::make_pair(
|
||||
__sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_begin,
|
||||
__sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_end);
|
||||
}
|
||||
|
||||
|
|
@ -441,10 +454,12 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
__sd._M_samples = NULL;
|
||||
|
||||
__sd._M_offsets = new _DifferenceType[__num_threads - 1];
|
||||
__sd._M_pieces = new std::vector<_Piece<_DifferenceType> >[__num_threads];
|
||||
__sd._M_pieces
|
||||
= new std::vector<_Piece<_DifferenceType> >[__num_threads];
|
||||
for (int __s = 0; __s < __num_threads; ++__s)
|
||||
__sd._M_pieces[__s].resize(__num_threads);
|
||||
_M_starts = __sd._M_starts = new _DifferenceType[__num_threads + 1];
|
||||
_M_starts = __sd._M_starts
|
||||
= new _DifferenceType[__num_threads + 1];
|
||||
|
||||
_DifferenceType __chunk_length = __n / __num_threads;
|
||||
_DifferenceType __split = __n % __num_threads;
|
||||
|
|
@ -452,7 +467,8 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
for (int __i = 0; __i < __num_threads; ++__i)
|
||||
{
|
||||
_M_starts[__i] = __pos;
|
||||
__pos += (__i < __split) ? (__chunk_length + 1) : __chunk_length;
|
||||
__pos += (__i < __split)
|
||||
? (__chunk_length + 1) : __chunk_length;
|
||||
}
|
||||
_M_starts[__num_threads] = __pos;
|
||||
} //single
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ namespace __parallel
|
|||
inline _Tp
|
||||
__accumulate_switch(_IIter __begin, _IIter __end,
|
||||
_Tp __init, _IteratorTag)
|
||||
{ return accumulate(__begin, __end, __init, __gnu_parallel::sequential_tag()); }
|
||||
{ return accumulate(__begin, __end, __init,
|
||||
__gnu_parallel::sequential_tag()); }
|
||||
|
||||
template<typename _IIter, typename _Tp, typename _BinaryOperation,
|
||||
typename _IteratorTag>
|
||||
|
|
@ -169,7 +170,8 @@ namespace __parallel
|
|||
inner_product(_IIter1 __first1, _IIter1 __last1,
|
||||
_IIter2 __first2, _Tp __init,
|
||||
__gnu_parallel::sequential_tag)
|
||||
{ return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init); }
|
||||
{ return _GLIBCXX_STD_P::inner_product(
|
||||
__first1, __last1, __first2, __init); }
|
||||
|
||||
template<typename _IIter1, typename _IIter2, typename _Tp,
|
||||
typename BinaryFunction1, typename BinaryFunction2>
|
||||
|
|
@ -243,9 +245,10 @@ namespace __parallel
|
|||
typedef iterator_traits<_IIter2> _TraitsType2;
|
||||
typedef typename _TraitsType2::iterator_category _IteratorCategory2;
|
||||
|
||||
return __inner_product_switch(__first1, __last1, __first2, __init, __binary_op1,
|
||||
__binary_op2, _IteratorCategory1(),
|
||||
_IteratorCategory2(), __parallelism_tag);
|
||||
return __inner_product_switch(
|
||||
__first1, __last1, __first2, __init, __binary_op1,
|
||||
__binary_op2, _IteratorCategory1(), _IteratorCategory2(),
|
||||
__parallelism_tag);
|
||||
}
|
||||
|
||||
template<typename _IIter1, typename _IIter2, typename _Tp,
|
||||
|
|
@ -261,9 +264,9 @@ namespace __parallel
|
|||
typedef iterator_traits<_IIter2> _TraitsType2;
|
||||
typedef typename _TraitsType2::iterator_category _IteratorCategory2;
|
||||
|
||||
return __inner_product_switch(__first1, __last1, __first2, __init, __binary_op1,
|
||||
__binary_op2, _IteratorCategory1(),
|
||||
_IteratorCategory2());
|
||||
return __inner_product_switch(
|
||||
__first1, __last1, __first2, __init, __binary_op1, __binary_op2,
|
||||
_IteratorCategory1(), _IteratorCategory2());
|
||||
}
|
||||
|
||||
template<typename _IIter1, typename _IIter2, typename _Tp>
|
||||
|
|
@ -378,8 +381,8 @@ namespace __parallel
|
|||
// Sequential fallback.
|
||||
template<typename _IIter, typename _OutputIterator>
|
||||
inline _OutputIterator
|
||||
adjacent_difference(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result, __gnu_parallel::sequential_tag)
|
||||
adjacent_difference(_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
__gnu_parallel::sequential_tag)
|
||||
{ return _GLIBCXX_STD_P::adjacent_difference(__begin, __end, __result); }
|
||||
|
||||
// Sequential fallback.
|
||||
|
|
@ -389,16 +392,17 @@ namespace __parallel
|
|||
adjacent_difference(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result, _BinaryOperation __bin_op,
|
||||
__gnu_parallel::sequential_tag)
|
||||
{ return _GLIBCXX_STD_P::adjacent_difference(__begin, __end, __result, __bin_op); }
|
||||
{ return _GLIBCXX_STD_P::adjacent_difference(
|
||||
__begin, __end, __result, __bin_op); }
|
||||
|
||||
// Sequential fallback for input iterator case.
|
||||
template<typename _IIter, typename _OutputIterator,
|
||||
typename _BinaryOperation, typename _IteratorTag1,
|
||||
typename _IteratorTag2>
|
||||
inline _OutputIterator
|
||||
__adjacent_difference_switch(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result, _BinaryOperation __bin_op,
|
||||
_IteratorTag1, _IteratorTag2)
|
||||
__adjacent_difference_switch(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
_BinaryOperation __bin_op, _IteratorTag1, _IteratorTag2)
|
||||
{ return adjacent_difference(__begin, __end, __result, __bin_op,
|
||||
__gnu_parallel::sequential_tag()); }
|
||||
|
||||
|
|
@ -406,10 +410,10 @@ namespace __parallel
|
|||
template<typename _IIter, typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_OutputIterator
|
||||
__adjacent_difference_switch(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result, _BinaryOperation __bin_op,
|
||||
random_access_iterator_tag,
|
||||
random_access_iterator_tag,
|
||||
__adjacent_difference_switch(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
_BinaryOperation __bin_op,
|
||||
random_access_iterator_tag, random_access_iterator_tag,
|
||||
__gnu_parallel::_Parallelism __parallelism_tag
|
||||
= __gnu_parallel::parallel_balanced)
|
||||
{
|
||||
|
|
@ -424,7 +428,8 @@ namespace __parallel
|
|||
*__result = *__begin;
|
||||
_ItTrip begin_pair(__begin + 1, __result + 1),
|
||||
end_pair(__end, __result + (__end - __begin));
|
||||
__gnu_parallel::__adjacent_difference_selector<_ItTrip> __functionality;
|
||||
__gnu_parallel::__adjacent_difference_selector<_ItTrip>
|
||||
__functionality;
|
||||
__gnu_parallel::
|
||||
for_each_template_random_access_ed(begin_pair, end_pair, __bin_op,
|
||||
__functionality,
|
||||
|
|
@ -446,7 +451,8 @@ namespace __parallel
|
|||
{
|
||||
typedef iterator_traits<_IIter> _TraitsType;
|
||||
typedef typename _TraitsType::value_type _ValueType;
|
||||
return adjacent_difference(__begin, __end, __result, std::minus<_ValueType>(),
|
||||
return adjacent_difference(
|
||||
__begin, __end, __result, std::minus<_ValueType>(),
|
||||
__parallelism_tag);
|
||||
}
|
||||
|
||||
|
|
@ -457,7 +463,8 @@ namespace __parallel
|
|||
{
|
||||
typedef iterator_traits<_IIter> _TraitsType;
|
||||
typedef typename _TraitsType::value_type _ValueType;
|
||||
return adjacent_difference(__begin, __end, __result, std::minus<_ValueType>());
|
||||
return adjacent_difference(__begin, __end, __result,
|
||||
std::minus<_ValueType>());
|
||||
}
|
||||
|
||||
template<typename _IIter, typename _OutputIterator,
|
||||
|
|
@ -473,9 +480,9 @@ namespace __parallel
|
|||
typedef iterator_traits<_OutputIterator> _OTraitsType;
|
||||
typedef typename _OTraitsType::iterator_category _OIterCategory;
|
||||
|
||||
return __adjacent_difference_switch(__begin, __end, __result, __binary_op,
|
||||
_IIteratorCategory(),
|
||||
_OIterCategory(), __parallelism_tag);
|
||||
return __adjacent_difference_switch(
|
||||
__begin, __end, __result, __binary_op,
|
||||
_IIteratorCategory(), _OIterCategory(), __parallelism_tag);
|
||||
}
|
||||
|
||||
template<typename _IIter, typename _OutputIterator,
|
||||
|
|
@ -490,9 +497,9 @@ namespace __parallel
|
|||
typedef iterator_traits<_OutputIterator> _OTraitsType;
|
||||
typedef typename _OTraitsType::iterator_category _OIterCategory;
|
||||
|
||||
return __adjacent_difference_switch(__begin, __end, __result, __binary_op,
|
||||
_IIteratorCategory(),
|
||||
_OIterCategory());
|
||||
return __adjacent_difference_switch(
|
||||
__begin, __end, __result, __binary_op,
|
||||
_IIteratorCategory(), _OIterCategory());
|
||||
}
|
||||
} // end namespace
|
||||
} // end namespace
|
||||
|
|
|
|||
|
|
@ -64,13 +64,10 @@ template<typename _RAIter,
|
|||
typename _Red,
|
||||
typename _Result>
|
||||
_Op
|
||||
for_each_template_random_access_omp_loop(_RAIter __begin,
|
||||
_RAIter __end,
|
||||
_Op __o, _Fu& __f, _Red __r, _Result __base,
|
||||
_Result& __output,
|
||||
typename std::iterator_traits
|
||||
<_RAIter>::
|
||||
difference_type __bound)
|
||||
for_each_template_random_access_omp_loop(
|
||||
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
|
||||
_Result __base, _Result& __output,
|
||||
typename std::iterator_traits<_RAIter>::difference_type __bound)
|
||||
{
|
||||
typedef typename
|
||||
std::iterator_traits<_RAIter>::difference_type
|
||||
|
|
|
|||
|
|
@ -64,13 +64,10 @@ template<typename _RAIter,
|
|||
typename _Red,
|
||||
typename _Result>
|
||||
_Op
|
||||
for_each_template_random_access_omp_loop_static(_RAIter __begin,
|
||||
_RAIter __end,
|
||||
_Op __o, _Fu& __f, _Red __r,
|
||||
for_each_template_random_access_omp_loop_static(
|
||||
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
|
||||
_Result __base, _Result& __output,
|
||||
typename std::iterator_traits
|
||||
<_RAIter>::
|
||||
difference_type __bound)
|
||||
typename std::iterator_traits<_RAIter>::difference_type __bound)
|
||||
{
|
||||
typedef typename
|
||||
std::iterator_traits<_RAIter>::difference_type
|
||||
|
|
@ -97,7 +94,8 @@ template<typename _RAIter,
|
|||
|
||||
#pragma omp for schedule(static, _Settings::get().workstealing_chunk_size)
|
||||
for (_DifferenceType __pos = 0; __pos < __length; ++__pos)
|
||||
__thread_results[__iam] = __r(__thread_results[__iam], __f(__o, __begin+__pos));
|
||||
__thread_results[__iam] = __r(__thread_results[__iam],
|
||||
__f(__o, __begin+__pos));
|
||||
} //parallel
|
||||
|
||||
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
|
||||
|
|
|
|||
|
|
@ -65,13 +65,10 @@ template<typename _RAIter,
|
|||
typename _Red,
|
||||
typename _Result>
|
||||
_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)
|
||||
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)
|
||||
{
|
||||
typedef std::iterator_traits<_RAIter> _TraitsType;
|
||||
typedef typename _TraitsType::difference_type _DifferenceType;
|
||||
|
|
@ -87,7 +84,8 @@ template<typename _RAIter,
|
|||
# pragma omp single
|
||||
{
|
||||
__num_threads = omp_get_num_threads();
|
||||
__thread_results = static_cast<_Result*>(
|
||||
__thread_results =
|
||||
static_cast<_Result*>(
|
||||
::operator new(__num_threads * sizeof(_Result)));
|
||||
__constructed = new bool[__num_threads];
|
||||
}
|
||||
|
|
@ -95,7 +93,8 @@ template<typename _RAIter,
|
|||
_ThreadIndex __iam = omp_get_thread_num();
|
||||
|
||||
// Neutral element.
|
||||
_Result* __reduct = static_cast<_Result*>(::operator new(sizeof(_Result)));
|
||||
_Result* __reduct =
|
||||
static_cast<_Result*>(::operator new(sizeof(_Result)));
|
||||
|
||||
_DifferenceType
|
||||
__start = equally_split_point(__length, __num_threads, __iam),
|
||||
|
|
|
|||
|
|
@ -55,10 +55,10 @@ template<typename _IIter,
|
|||
typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_OutputIterator
|
||||
__parallel_partial_sum_basecase(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result, _BinaryOperation __bin_op,
|
||||
typename std::iterator_traits
|
||||
<_IIter>::value_type __value)
|
||||
__parallel_partial_sum_basecase(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
_BinaryOperation __bin_op,
|
||||
typename std::iterator_traits <_IIter>::value_type __value)
|
||||
{
|
||||
if (__begin == __end)
|
||||
return __result;
|
||||
|
|
@ -87,10 +87,10 @@ template<typename _IIter,
|
|||
typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_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_linear(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
_BinaryOperation __bin_op,
|
||||
typename std::iterator_traits<_IIter>::difference_type __n)
|
||||
{
|
||||
typedef std::iterator_traits<_IIter> _TraitsType;
|
||||
typedef typename _TraitsType::value_type _ValueType;
|
||||
|
|
@ -148,8 +148,9 @@ template<typename _IIter,
|
|||
if (__iam == 0)
|
||||
{
|
||||
*__result = *__begin;
|
||||
__parallel_partial_sum_basecase(__begin + 1, __begin + __borders[1],
|
||||
__result + 1, __bin_op, *__begin);
|
||||
__parallel_partial_sum_basecase(
|
||||
__begin + 1, __begin + __borders[1], __result + 1,
|
||||
__bin_op, *__begin);
|
||||
::new(&(__sums[__iam])) _ValueType(*(__result + __borders[1] - 1));
|
||||
}
|
||||
else
|
||||
|
|
@ -165,16 +166,17 @@ template<typename _IIter,
|
|||
# pragma omp barrier
|
||||
|
||||
# pragma omp single
|
||||
__parallel_partial_sum_basecase(
|
||||
__sums + 1, __sums + __num_threads, __sums + 1, __bin_op, __sums[0]);
|
||||
__parallel_partial_sum_basecase(__sums + 1, __sums + __num_threads,
|
||||
__sums + 1, __bin_op, __sums[0]);
|
||||
|
||||
# pragma omp barrier
|
||||
|
||||
// Still same team.
|
||||
__parallel_partial_sum_basecase(__begin + __borders[__iam + 1],
|
||||
__parallel_partial_sum_basecase(
|
||||
__begin + __borders[__iam + 1],
|
||||
__begin + __borders[__iam + 2],
|
||||
__result + __borders[__iam + 1], __bin_op,
|
||||
__sums[__iam]);
|
||||
__result + __borders[__iam + 1],
|
||||
__bin_op, __sums[__iam]);
|
||||
} //parallel
|
||||
|
||||
::operator delete(__sums);
|
||||
|
|
@ -208,7 +210,8 @@ template<typename _IIter,
|
|||
{
|
||||
case LINEAR:
|
||||
// Need an initial offset.
|
||||
return __parallel_partial_sum_linear(__begin, __end, __result, __bin_op, __n);
|
||||
return __parallel_partial_sum_linear(
|
||||
__begin, __end, __result, __bin_op, __n);
|
||||
default:
|
||||
// Partial_sum algorithm not implemented.
|
||||
_GLIBCXX_PARALLEL_ASSERT(0);
|
||||
|
|
|
|||
|
|
@ -88,9 +88,10 @@ template<typename _RAIter, typename _Predicate>
|
|||
__reserved_right = new bool[__num_threads];
|
||||
|
||||
if (__s.partition_chunk_share > 0.0)
|
||||
__chunk_size = std::max<_DifferenceType>(__s.partition_chunk_size,
|
||||
(double)__n * __s.partition_chunk_share
|
||||
/ (double)__num_threads);
|
||||
__chunk_size = std::max<_DifferenceType>(
|
||||
__s.partition_chunk_size,
|
||||
(double)__n * __s.partition_chunk_share /
|
||||
(double)__num_threads);
|
||||
else
|
||||
__chunk_size = __s.partition_chunk_size;
|
||||
}
|
||||
|
|
@ -99,7 +100,8 @@ template<typename _RAIter, typename _Predicate>
|
|||
{
|
||||
# pragma omp single
|
||||
{
|
||||
_DifferenceType __num_chunks = (__right - __left + 1) / __chunk_size;
|
||||
_DifferenceType __num_chunks
|
||||
= (__right - __left + 1) / __chunk_size;
|
||||
|
||||
for (int __r = 0; __r < __num_threads; ++__r)
|
||||
{
|
||||
|
|
@ -198,7 +200,8 @@ template<typename _RAIter, typename _Predicate>
|
|||
&& __thread_left_border >= __leftnew)
|
||||
{
|
||||
// Chunk already in place, reserve spot.
|
||||
__reserved_left[(__left - (__thread_left_border + 1)) / __chunk_size]
|
||||
__reserved_left
|
||||
[(__left - (__thread_left_border + 1)) / __chunk_size]
|
||||
= true;
|
||||
}
|
||||
|
||||
|
|
@ -257,7 +260,8 @@ template<typename _RAIter, typename _Predicate>
|
|||
_GLIBCXX_PARALLEL_ASSERT(__swapstart != -1);
|
||||
#endif
|
||||
|
||||
std::swap_ranges(__begin + __thread_right_border,
|
||||
std::swap_ranges(
|
||||
__begin + __thread_right_border,
|
||||
__begin + __thread_right_border + __chunk_size,
|
||||
__begin + __swapstart);
|
||||
}
|
||||
|
|
@ -365,7 +369,8 @@ template<typename _RAIter, typename _Compare>
|
|||
|
||||
// Divide, leave pivot unchanged in last place.
|
||||
_RAIter __split_pos1, __split_pos2;
|
||||
__split_pos1 = __begin + __parallel_partition(__begin, __end - 1, __pred,
|
||||
__split_pos1 = __begin
|
||||
+ __parallel_partition(__begin, __end - 1, __pred,
|
||||
__get_max_threads());
|
||||
|
||||
// Left side: < __pivot_pos; __right side: >= __pivot_pos
|
||||
|
|
|
|||
|
|
@ -105,9 +105,12 @@ namespace __gnu_parallel
|
|||
while (__former_front > __former_back)
|
||||
{
|
||||
// Chance.
|
||||
_CASable __former_borders = __encode2(__former_front, __former_back);
|
||||
_CASable __new_borders = __encode2(__former_front - 1, __former_back);
|
||||
if (__compare_and_swap(&_M_borders, __former_borders, __new_borders))
|
||||
_CASable
|
||||
__former_borders = __encode2(__former_front, __former_back);
|
||||
_CASable
|
||||
__new_borders = __encode2(__former_front - 1, __former_back);
|
||||
if (__compare_and_swap(
|
||||
&_M_borders, __former_borders, __new_borders))
|
||||
{
|
||||
__t = *(_M_base + (__former_front - 1) % _M_max_size);
|
||||
return true;
|
||||
|
|
@ -129,9 +132,12 @@ namespace __gnu_parallel
|
|||
while (__former_front > __former_back)
|
||||
{
|
||||
// Chance.
|
||||
_CASable __former_borders = __encode2(__former_front, __former_back);
|
||||
_CASable __new_borders = __encode2(__former_front, __former_back + 1);
|
||||
if (__compare_and_swap(&_M_borders, __former_borders, __new_borders))
|
||||
_CASable
|
||||
__former_borders = __encode2(__former_front, __former_back);
|
||||
_CASable
|
||||
__new_borders = __encode2(__former_front, __former_back + 1);
|
||||
if (__compare_and_swap(
|
||||
&_M_borders, __former_borders, __new_borders))
|
||||
{
|
||||
__t = *(_M_base + __former_back % _M_max_size);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ namespace __gnu_parallel
|
|||
|
||||
for (_DifferenceType __s = 0; __s < __num_samples; ++__s)
|
||||
{
|
||||
const unsigned long long __index = static_cast<unsigned long long>(__s)
|
||||
* __n / __num_samples;
|
||||
const unsigned long long __index
|
||||
= static_cast<unsigned long long>(__s) * __n / __num_samples;
|
||||
::new(&(__samples[__s])) _ValueType(__begin[__index]);
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,8 @@ namespace __gnu_parallel
|
|||
if (__num_threads > __n)
|
||||
__num_threads = static_cast<_ThreadIndex>(__n);
|
||||
|
||||
__parallel_sort_qs_conquer(__begin, __begin + __n, __comp, __num_threads);
|
||||
__parallel_sort_qs_conquer(
|
||||
__begin, __begin + __n, __comp, __num_threads);
|
||||
}
|
||||
|
||||
} //namespace __gnu_parallel
|
||||
|
|
|
|||
|
|
@ -131,7 +131,8 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
_DRandomShufflingGlobalData<_RAIter>* _M_sd = d->_M_sd;
|
||||
|
||||
// Indexing: _M_dist[bin][processor]
|
||||
_DifferenceType __length = _M_sd->_M_starts[__iam + 1] - _M_sd->_M_starts[__iam];
|
||||
_DifferenceType __length = _M_sd->_M_starts[__iam + 1] -
|
||||
_M_sd->_M_starts[__iam];
|
||||
_BinIndex* __oracles = new _BinIndex[__length];
|
||||
_DifferenceType* _M_dist = new _DifferenceType[_M_sd->_M_num_bins + 1];
|
||||
_BinIndex* _M_bin_proc = new _BinIndex[_M_sd->_M_num_bins];
|
||||
|
|
@ -161,10 +162,11 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
|
||||
# pragma omp single
|
||||
{
|
||||
// Sum up bins, _M_sd->_M_dist[__s + 1][d->_M_num_threads] now contains the
|
||||
// total number of items in bin __s
|
||||
// Sum up bins, _M_sd->_M_dist[__s + 1][d->_M_num_threads] now contains
|
||||
// the total number of items in bin __s
|
||||
for (_BinIndex __s = 0; __s < _M_sd->_M_num_bins; ++__s)
|
||||
__gnu_sequential::partial_sum(_M_sd->_M_dist[__s + 1],
|
||||
__gnu_sequential::partial_sum(
|
||||
_M_sd->_M_dist[__s + 1],
|
||||
_M_sd->_M_dist[__s + 1] + d->_M_num_threads + 1,
|
||||
_M_sd->_M_dist[__s + 1]);
|
||||
}
|
||||
|
|
@ -223,12 +225,15 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
{
|
||||
_ValueType* __begin =
|
||||
_M_sd->_M_temporaries[__iam] +
|
||||
((__b == d->_M_bins_begin) ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]),
|
||||
((__b == d->_M_bins_begin)
|
||||
? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]),
|
||||
* __end =
|
||||
_M_sd->_M_temporaries[__iam] + _M_sd->_M_dist[__b + 1][d->_M_num_threads];
|
||||
_M_sd->_M_temporaries[__iam] +
|
||||
_M_sd->_M_dist[__b + 1][d->_M_num_threads];
|
||||
__sequential_random_shuffle(__begin, __end, __rng);
|
||||
std::copy(__begin, __end, _M_sd->_M_source + __global_offset +
|
||||
((__b == d->_M_bins_begin) ? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]));
|
||||
((__b == d->_M_bins_begin)
|
||||
? 0 : _M_sd->_M_dist[__b][d->_M_num_threads]));
|
||||
}
|
||||
|
||||
::operator delete(_M_sd->_M_temporaries[__iam]);
|
||||
|
|
@ -343,7 +348,8 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
_M_sd._M_dist[0][0] = 0;
|
||||
_M_sd._M_dist[__b][0] = 0;
|
||||
}
|
||||
_M_starts = _M_sd._M_starts = new _DifferenceType[__num_threads + 1];
|
||||
_M_starts = _M_sd._M_starts
|
||||
= new _DifferenceType[__num_threads + 1];
|
||||
int bin_cursor = 0;
|
||||
_M_sd._M_num_bins = _M_num_bins;
|
||||
_M_sd._M_num_bits = __log2(_M_num_bins);
|
||||
|
|
@ -355,7 +361,8 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
|
||||
{
|
||||
_M_starts[__i] = __start;
|
||||
__start += (__i < __split) ? (__chunk_length + 1) : __chunk_length;
|
||||
__start += (__i < __split)
|
||||
? (__chunk_length + 1) : __chunk_length;
|
||||
int __j = __pus[__i]._M_bins_begin = bin_cursor;
|
||||
|
||||
// Range of bins for this processor.
|
||||
|
|
@ -469,14 +476,16 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
}
|
||||
|
||||
// Sum up bins.
|
||||
__gnu_sequential::partial_sum(__dist0, __dist0 + _M_num_bins + 1, __dist0);
|
||||
__gnu_sequential::
|
||||
partial_sum(__dist0, __dist0 + _M_num_bins + 1, __dist0);
|
||||
|
||||
for (int __b = 0; __b < _M_num_bins + 1; ++__b)
|
||||
__dist1[__b] = __dist0[__b];
|
||||
|
||||
// Distribute according to oracles.
|
||||
for (_DifferenceType __i = 0; __i < __n; ++__i)
|
||||
::new(&(__target[(__dist0[__oracles[__i]])++])) _ValueType(*(__begin + __i));
|
||||
::new(&(__target[(__dist0[__oracles[__i]])++]))
|
||||
_ValueType(*(__begin + __i));
|
||||
|
||||
for (int __b = 0; __b < _M_num_bins; ++__b)
|
||||
{
|
||||
|
|
@ -511,7 +520,8 @@ template<typename _RAIter, typename RandomNumberGenerator>
|
|||
typedef std::iterator_traits<_RAIter> _TraitsType;
|
||||
typedef typename _TraitsType::difference_type _DifferenceType;
|
||||
_DifferenceType __n = __end - __begin;
|
||||
__parallel_random_shuffle_drs(__begin, __end, __n, __get_max_threads(), __rng) ;
|
||||
__parallel_random_shuffle_drs(
|
||||
__begin, __end, __n, __get_max_threads(), __rng) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ template<typename __RAIter1,
|
|||
|
||||
_ThreadIndex __iam = omp_get_thread_num();
|
||||
|
||||
_DifferenceType __start = __splitters[__iam], __stop = __splitters[__iam + 1];
|
||||
_DifferenceType __start = __splitters[__iam],
|
||||
__stop = __splitters[__iam + 1];
|
||||
|
||||
_DifferenceType __pos_in_pattern = 0;
|
||||
bool __found_pattern = false;
|
||||
|
|
@ -156,7 +157,8 @@ template<typename __RAIter1,
|
|||
// Make safe jump.
|
||||
__start += (__pos_in_pattern - __advances[__pos_in_pattern]);
|
||||
__pos_in_pattern =
|
||||
(__advances[__pos_in_pattern] < 0) ? 0 : __advances[__pos_in_pattern];
|
||||
(__advances[__pos_in_pattern] < 0) ?
|
||||
0 : __advances[__pos_in_pattern];
|
||||
}
|
||||
} //parallel
|
||||
|
||||
|
|
|
|||
|
|
@ -400,7 +400,8 @@ template<typename _IIter,
|
|||
_IIter __offset[2];
|
||||
const _DifferenceType __rank = __borders[__iam + 1];
|
||||
|
||||
multiseq_partition(__sequence, __sequence + 2, __rank, __offset, __op._M_comp);
|
||||
multiseq_partition(__sequence, __sequence + 2,
|
||||
__rank, __offset, __op._M_comp);
|
||||
|
||||
// allowed to read?
|
||||
// together
|
||||
|
|
@ -427,14 +428,15 @@ template<typename _IIter,
|
|||
if (__iam == 0)
|
||||
{
|
||||
// The first thread can copy already.
|
||||
__lengths[ __iam ] = __op._M_invoke(__block_begin.first, block_end.first,
|
||||
__block_begin.second, block_end.second,
|
||||
__result)
|
||||
__lengths[ __iam ] =
|
||||
__op._M_invoke(__block_begin.first, block_end.first,
|
||||
__block_begin.second, block_end.second, __result)
|
||||
- __result;
|
||||
}
|
||||
else
|
||||
{
|
||||
__lengths[ __iam ] = __op.__count(__block_begin.first, block_end.first,
|
||||
__lengths[ __iam ] =
|
||||
__op.__count(__block_begin.first, block_end.first,
|
||||
__block_begin.second, block_end.second);
|
||||
}
|
||||
|
||||
|
|
@ -478,8 +480,8 @@ template<typename _IIter,
|
|||
_IIter __begin2, _IIter __end2,
|
||||
_OutputIterator __result, _Compare _M_comp)
|
||||
{
|
||||
return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result,
|
||||
__union_func< _IIter, _OutputIterator, _Compare>(_M_comp));
|
||||
return __parallel_set_operation(__begin1, __end1, __begin2, __end2,
|
||||
__result, __union_func< _IIter, _OutputIterator, _Compare>(_M_comp));
|
||||
}
|
||||
|
||||
template<typename _IIter,
|
||||
|
|
@ -490,7 +492,8 @@ template<typename _IIter,
|
|||
_IIter __begin2, _IIter __end2,
|
||||
_OutputIterator __result, _Compare _M_comp)
|
||||
{
|
||||
return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result,
|
||||
return __parallel_set_operation(
|
||||
__begin1, __end1, __begin2, __end2, __result,
|
||||
__intersection_func<_IIter, _OutputIterator, _Compare>(_M_comp));
|
||||
}
|
||||
|
||||
|
|
@ -502,7 +505,8 @@ template<typename _IIter,
|
|||
_IIter __begin2, _IIter __end2,
|
||||
_OutputIterator __result, _Compare _M_comp)
|
||||
{
|
||||
return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result,
|
||||
return __parallel_set_operation(
|
||||
__begin1, __end1, __begin2, __end2, __result,
|
||||
__difference_func<_IIter, _OutputIterator, _Compare>(_M_comp));
|
||||
}
|
||||
|
||||
|
|
@ -512,9 +516,11 @@ template<typename _IIter,
|
|||
inline _OutputIterator
|
||||
__parallel_set_symmetric_difference(_IIter __begin1, _IIter __end1,
|
||||
_IIter __begin2, _IIter __end2,
|
||||
_OutputIterator __result, _Compare _M_comp)
|
||||
_OutputIterator __result,
|
||||
_Compare _M_comp)
|
||||
{
|
||||
return __parallel_set_operation(__begin1, __end1, __begin2, __end2, __result,
|
||||
return __parallel_set_operation(
|
||||
__begin1, __end1, __begin2, __end2, __result,
|
||||
symmetric_difference_func<_IIter, _OutputIterator, _Compare>
|
||||
(_M_comp));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,12 @@
|
|||
* __gnu_parallel::_Settings::algorithm_strategy. Usually a decision
|
||||
* based on the input size.
|
||||
*/
|
||||
#define _GLIBCXX_PARALLEL_CONDITION(__c) (__gnu_parallel::_Settings::get().algorithm_strategy != __gnu_parallel::force_sequential && ((__gnu_parallel::__get_max_threads() > 1 && (__c)) || __gnu_parallel::_Settings::get().algorithm_strategy == __gnu_parallel::force_parallel))
|
||||
#define _GLIBCXX_PARALLEL_CONDITION(__c) \
|
||||
(__gnu_parallel::_Settings::get().algorithm_strategy \
|
||||
!= __gnu_parallel::force_sequential \
|
||||
&& ((__gnu_parallel::__get_max_threads() > 1 && (__c)) \
|
||||
|| __gnu_parallel::_Settings::get().algorithm_strategy \
|
||||
== __gnu_parallel::force_parallel))
|
||||
|
||||
/*
|
||||
inline bool
|
||||
|
|
@ -114,7 +119,7 @@ parallel_condition(bool __c)
|
|||
namespace __gnu_parallel
|
||||
{
|
||||
/// class _Settings
|
||||
/// Run-time settings for the parallel mode, including all tunable parameters.
|
||||
/// Run-time settings for the parallel mode including all tunable parameters.
|
||||
struct _Settings
|
||||
{
|
||||
_AlgorithmStrategy algorithm_strategy;
|
||||
|
|
@ -273,7 +278,56 @@ namespace __gnu_parallel
|
|||
set(_Settings&) throw();
|
||||
|
||||
explicit
|
||||
_Settings() : algorithm_strategy(heuristic), sort_algorithm(MWMS), partial_sum_algorithm(LINEAR), multiway_merge_algorithm(LOSER_TREE), find_algorithm(CONSTANT_SIZE_BLOCKS), sort_splitting(EXACT), merge_splitting(EXACT), multiway_merge_splitting(EXACT), accumulate_minimal_n(1000), adjacent_difference_minimal_n(1000), count_minimal_n(1000), fill_minimal_n(1000), find_increasing_factor(2.0), find_initial_block_size(256), find_maximum_block_size(8192), find_sequential_search_size(256), for_each_minimal_n(1000), generate_minimal_n(1000), max_element_minimal_n(1000), merge_minimal_n(1000), merge_oversampling(10), min_element_minimal_n(1000), multiway_merge_minimal_n(1000), multiway_merge_minimal_k(2), multiway_merge_oversampling(10), nth_element_minimal_n(1000), partition_chunk_size(1000), partition_chunk_share(0.0), partition_minimal_n(1000), partial_sort_minimal_n(1000), partial_sum_dilation(1.0f), partial_sum_minimal_n(1000), random_shuffle_minimal_n(1000), replace_minimal_n(1000), set_difference_minimal_n(1000), set_intersection_minimal_n(1000), set_symmetric_difference_minimal_n(1000), set_union_minimal_n(1000), sort_minimal_n(1000), sort_mwms_oversampling(10), sort_qs_num_samples_preset(100), sort_qsb_base_case_maximal_n(100), transform_minimal_n(1000), unique_copy_minimal_n(10000), workstealing_chunk_size(100), L1_cache_size(16 << 10), L2_cache_size(256 << 10), TLB_size(128), cache_line_size(64), qsb_steals(0)
|
||||
_Settings() :
|
||||
algorithm_strategy(heuristic),
|
||||
sort_algorithm(MWMS),
|
||||
partial_sum_algorithm(LINEAR),
|
||||
multiway_merge_algorithm(LOSER_TREE),
|
||||
find_algorithm(CONSTANT_SIZE_BLOCKS),
|
||||
sort_splitting(EXACT),
|
||||
merge_splitting(EXACT),
|
||||
multiway_merge_splitting(EXACT),
|
||||
accumulate_minimal_n(1000),
|
||||
adjacent_difference_minimal_n(1000),
|
||||
count_minimal_n(1000),
|
||||
fill_minimal_n(1000),
|
||||
find_increasing_factor(2.0),
|
||||
find_initial_block_size(256),
|
||||
find_maximum_block_size(8192),
|
||||
find_sequential_search_size(256),
|
||||
for_each_minimal_n(1000),
|
||||
generate_minimal_n(1000),
|
||||
max_element_minimal_n(1000),
|
||||
merge_minimal_n(1000),
|
||||
merge_oversampling(10),
|
||||
min_element_minimal_n(1000),
|
||||
multiway_merge_minimal_n(1000),
|
||||
multiway_merge_minimal_k(2), multiway_merge_oversampling(10),
|
||||
nth_element_minimal_n(1000),
|
||||
partition_chunk_size(1000),
|
||||
partition_chunk_share(0.0),
|
||||
partition_minimal_n(1000),
|
||||
partial_sort_minimal_n(1000),
|
||||
partial_sum_dilation(1.0f),
|
||||
partial_sum_minimal_n(1000),
|
||||
random_shuffle_minimal_n(1000),
|
||||
replace_minimal_n(1000),
|
||||
set_difference_minimal_n(1000),
|
||||
set_intersection_minimal_n(1000),
|
||||
set_symmetric_difference_minimal_n(1000),
|
||||
set_union_minimal_n(1000),
|
||||
sort_minimal_n(1000),
|
||||
sort_mwms_oversampling(10),
|
||||
sort_qs_num_samples_preset(100),
|
||||
sort_qsb_base_case_maximal_n(100),
|
||||
transform_minimal_n(1000),
|
||||
unique_copy_minimal_n(10000),
|
||||
workstealing_chunk_size(100),
|
||||
L1_cache_size(16 << 10),
|
||||
L2_cache_size(256 << 10),
|
||||
TLB_size(128),
|
||||
cache_line_size(64),
|
||||
qsb_steals(0)
|
||||
{ }
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,7 +138,8 @@ namespace __gnu_parallel
|
|||
|
||||
_GLIBCXX_PARALLEL_ASSERT(__stable == false);
|
||||
|
||||
__parallel_sort_qs(__begin, __end, __comp, __parallelism.__get_num_threads());
|
||||
__parallel_sort_qs(__begin, __end, __comp,
|
||||
__parallelism.__get_num_threads());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -158,7 +159,8 @@ namespace __gnu_parallel
|
|||
|
||||
_GLIBCXX_PARALLEL_ASSERT(__stable == false);
|
||||
|
||||
__parallel_sort_qsb(__begin, __end, __comp, __parallelism.__get_num_threads());
|
||||
__parallel_sort_qsb(__begin, __end, __comp,
|
||||
__parallelism.__get_num_threads());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -215,11 +217,13 @@ namespace __gnu_parallel
|
|||
#endif
|
||||
#if _GLIBCXX_QUICKSORT
|
||||
else if (_Settings::get().sort_algorithm == QS)
|
||||
__parallel_sort_qs(__begin, __end, __comp, __parallelism.__get_num_threads());
|
||||
__parallel_sort_qs(__begin, __end, __comp,
|
||||
__parallelism.__get_num_threads());
|
||||
#endif
|
||||
#if _GLIBCXX_BAL_QUICKSORT
|
||||
else if (_Settings::get().sort_algorithm == QS_BALANCED)
|
||||
__parallel_sort_qsb(__begin, __end, __comp, __parallelism.__get_num_threads());
|
||||
__parallel_sort_qsb(__begin, __end, __comp,
|
||||
__parallelism.__get_num_threads());
|
||||
#endif
|
||||
else
|
||||
__gnu_sequential::sort(__begin, __end, __comp);
|
||||
|
|
|
|||
|
|
@ -149,7 +149,8 @@ namespace __gnu_parallel
|
|||
static const int _CASable_bits = sizeof(_CASable) * 8;
|
||||
|
||||
/// ::_CASable with the right half of bits set to 1.
|
||||
static const _CASable _CASable_mask = ((_CASable(1) << (_CASable_bits / 2)) - 1);
|
||||
static const _CASable _CASable_mask =
|
||||
((_CASable(1) << (_CASable_bits / 2)) - 1);
|
||||
}
|
||||
|
||||
#endif /* _GLIBCXX_PARALLEL_TYPES_H */
|
||||
|
|
|
|||
|
|
@ -96,13 +96,10 @@ template<typename _RAIter,
|
|||
typename _Red,
|
||||
typename _Result>
|
||||
_Op
|
||||
for_each_template_random_access_workstealing(_RAIter __begin,
|
||||
_RAIter __end,
|
||||
_Op __op, _Fu& __f, _Red __r,
|
||||
for_each_template_random_access_workstealing(
|
||||
_RAIter __begin, _RAIter __end, _Op __op, _Fu& __f, _Red __r,
|
||||
_Result __base, _Result& __output,
|
||||
typename std::iterator_traits
|
||||
<_RAIter>::
|
||||
difference_type __bound)
|
||||
typename std::iterator_traits<_RAIter>::difference_type __bound)
|
||||
{
|
||||
_GLIBCXX_CALL(__end - __begin)
|
||||
|
||||
|
|
@ -111,13 +108,15 @@ template<typename _RAIter,
|
|||
|
||||
const _Settings& __s = _Settings::get();
|
||||
|
||||
_DifferenceType __chunk_size = static_cast<_DifferenceType>(__s.workstealing_chunk_size);
|
||||
_DifferenceType __chunk_size =
|
||||
static_cast<_DifferenceType>(__s.workstealing_chunk_size);
|
||||
|
||||
// How many jobs?
|
||||
_DifferenceType __length = (__bound < 0) ? (__end - __begin) : __bound;
|
||||
|
||||
// To avoid false sharing in a cache line.
|
||||
const int __stride = __s.cache_line_size * 10 / sizeof(_Job<_DifferenceType>) + 1;
|
||||
const int __stride =
|
||||
__s.cache_line_size * 10 / sizeof(_Job<_DifferenceType>) + 1;
|
||||
|
||||
// Total number of threads currently working.
|
||||
_ThreadIndex __busy = 0;
|
||||
|
|
@ -184,7 +183,7 @@ template<typename _RAIter,
|
|||
(__length - 1) : ((__iam + 1) * (__length / __num_threads) - 1);
|
||||
__my_job._M_load = __my_job._M_last - __my_job._M_first + 1;
|
||||
|
||||
// Init result with _M_first __value (to have a base value for reduction).
|
||||
// Init result with _M_first value (to have a base value for reduction)
|
||||
if (__my_job._M_first <= __my_job._M_last)
|
||||
{
|
||||
// Cannot use volatile variable directly.
|
||||
|
|
@ -211,13 +210,15 @@ template<typename _RAIter,
|
|||
// fetch-and-add call
|
||||
// Reserve current job block (size __chunk_size) in my queue.
|
||||
_DifferenceType current_job =
|
||||
__fetch_and_add<_DifferenceType>(&(__my_job._M_first), __chunk_size);
|
||||
__fetch_and_add<_DifferenceType>(
|
||||
&(__my_job._M_first), __chunk_size);
|
||||
|
||||
// Update _M_load, to make the three values consistent,
|
||||
// _M_first might have been changed in the meantime
|
||||
__my_job._M_load = __my_job._M_last - __my_job._M_first + 1;
|
||||
for (_DifferenceType job_counter = 0;
|
||||
job_counter < __chunk_size && current_job <= __my_job._M_last;
|
||||
job_counter < __chunk_size
|
||||
&& current_job <= __my_job._M_last;
|
||||
++job_counter)
|
||||
{
|
||||
// Yes: process it!
|
||||
|
|
@ -254,7 +255,8 @@ template<typename _RAIter,
|
|||
}
|
||||
while (__busy > 0
|
||||
&& ((__supposed_load <= 0)
|
||||
|| ((__supposed_first + __supposed_load - 1) != __supposed_last)));
|
||||
|| ((__supposed_first + __supposed_load - 1)
|
||||
!= __supposed_last)));
|
||||
|
||||
if (__busy == 0)
|
||||
break;
|
||||
|
|
@ -273,7 +275,8 @@ template<typename _RAIter,
|
|||
__stolen_first + __steal - _DifferenceType(1);
|
||||
|
||||
__my_job._M_first = __stolen_first;
|
||||
__my_job._M_last = __gnu_parallel::min(stolen_try, __supposed_last);
|
||||
__my_job._M_last =
|
||||
__gnu_parallel::min(stolen_try, __supposed_last);
|
||||
__my_job._M_load = __my_job._M_last - __my_job._M_first + 1;
|
||||
|
||||
// Has potential work again.
|
||||
|
|
|
|||
Loading…
Reference in New Issue