Commit 77d16198 by Paolo Carlini Committed by Paolo Carlini

multiway_merge.h: Simple formatting and uglification fixes.

2009-11-06  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/parallel/multiway_merge.h: Simple formatting and
	uglification fixes.
	* include/parallel/find_selectors.h: Likewise.
	* include/parallel/losertree.h: Likewise.
	* include/parallel/list_partition.h: Likewise.
	* include/parallel/for_each.h: Likewise.
	* include/parallel/multiseq_selection.h: Likewise.
	* include/parallel/workstealing.h: Likewise.
	* include/parallel/par_loop.h: Likewise.
	* include/parallel/numeric: Likewise.
	* include/parallel/quicksort.h: Likewise.
	* include/parallel/equally_split.h: Likewise.
	* include/parallel/omp_loop_static.h: Likewise.
	* include/parallel/random_shuffle.h: Likewise.
	* include/parallel/balanced_quicksort.h: Likewise.
	* include/parallel/tags.h: Likewise.
	* include/parallel/set_operations.h: Likewise.
	* include/parallel/merge.h: Likewise.
	* include/parallel/unique_copy.h: Likewise.
	* include/parallel/multiway_mergesort.h: Likewise.
	* include/parallel/search.h: Likewise.
	* include/parallel/partition.h: Likewise.
	* include/parallel/partial_sum.h: Likewise.
	* include/parallel/find.h: Likewise.
	* include/parallel/queue.h: Likewise.
	* include/parallel/omp_loop.h: Likewise.
	* include/parallel/checkers.h: Likewise.
	* include/parallel/sort.h: Likewise.

From-SVN: r153966
parent b169fe9d
2009-11-06 Paolo Carlini <paolo.carlini@oracle.com>
* include/parallel/multiway_merge.h: Simple formatting and
uglification fixes.
* include/parallel/find_selectors.h: Likewise.
* include/parallel/losertree.h: Likewise.
* include/parallel/list_partition.h: Likewise.
* include/parallel/for_each.h: Likewise.
* include/parallel/multiseq_selection.h: Likewise.
* include/parallel/workstealing.h: Likewise.
* include/parallel/par_loop.h: Likewise.
* include/parallel/numeric: Likewise.
* include/parallel/quicksort.h: Likewise.
* include/parallel/equally_split.h: Likewise.
* include/parallel/omp_loop_static.h: Likewise.
* include/parallel/random_shuffle.h: Likewise.
* include/parallel/balanced_quicksort.h: Likewise.
* include/parallel/tags.h: Likewise.
* include/parallel/set_operations.h: Likewise.
* include/parallel/merge.h: Likewise.
* include/parallel/unique_copy.h: Likewise.
* include/parallel/multiway_mergesort.h: Likewise.
* include/parallel/search.h: Likewise.
* include/parallel/partition.h: Likewise.
* include/parallel/partial_sum.h: Likewise.
* include/parallel/find.h: Likewise.
* include/parallel/queue.h: Likewise.
* include/parallel/omp_loop.h: Likewise.
* include/parallel/checkers.h: Likewise.
* include/parallel/sort.h: Likewise.
2009-11-06 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/41949
......
......@@ -68,5 +68,6 @@ namespace __gnu_parallel
return true;
}
}
#endif /* _GLIBCXX_PARALLEL_CHECKERS_H */
// -*- C++ -*-
// Copyright (C) 2007, 2009 Free Software Foundation, Inc.
// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -33,17 +33,17 @@
namespace __gnu_parallel
{
/** @brief function to split a sequence into parts of almost equal size.
/** @brief function to split a sequence into parts of almost equal size.
*
* The resulting sequence __s of length __num_threads+1 contains the splitting
* positions when splitting the range [0,__n) into parts of almost
* equal size (plus minus 1). The first entry is 0, the last one
* n. There may result empty parts.
* The resulting sequence __s of length __num_threads+1 contains the
* splitting positions when splitting the range [0,__n) into parts of
* almost equal size (plus minus 1). The first entry is 0, the last
* one n. There may result empty parts.
* @param __n Number of elements
* @param __num_threads Number of parts
* @param __s Splitters
* @returns End of __splitter sequence, i.e. @__c __s+__num_threads+1 */
template<typename _DifferenceType, typename _OutputIterator>
template<typename _DifferenceType, typename _OutputIterator>
_OutputIterator
equally_split(_DifferenceType __n, _ThreadIndex __num_threads,
_OutputIterator __s)
......@@ -54,15 +54,14 @@ 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;
}
/** @brief function to split a sequence into parts of almost equal size.
/** @brief function to split a sequence into parts of almost equal size.
*
* Returns the position of the splitting point between
* thread number __thread_no (included) and
......@@ -70,7 +69,7 @@ template<typename _DifferenceType, typename _OutputIterator>
* @param __n Number of elements
* @param __num_threads Number of parts
* @returns splitting point */
template<typename _DifferenceType>
template<typename _DifferenceType>
_DifferenceType
equally_split_point(_DifferenceType __n,
_ThreadIndex __num_threads,
......
......@@ -143,8 +143,8 @@ 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()); }
};
......@@ -155,7 +155,8 @@ namespace __gnu_parallel
_FIterator _M_begin;
_FIterator _M_end;
explicit __find_first_of_selector(_FIterator __begin, _FIterator __end)
explicit __find_first_of_selector(_FIterator __begin,
_FIterator __end)
: _M_begin(__begin), _M_end(__end) { }
/** @brief Test on one position.
......@@ -186,8 +187,8 @@ namespace __gnu_parallel
_RAIter1 __end1,
_RAIter2 __begin2, _Pred __pred)
{
return std::make_pair(
find_first_of(__begin1, __end1, _M_begin, _M_end, __pred,
return std::make_pair(find_first_of(__begin1, __end1,
_M_begin, _M_end, __pred,
sequential_tag()), __begin2);
}
};
......
......@@ -69,31 +69,21 @@ namespace __gnu_parallel
_Parallelism __parallelism_tag)
{
if (__parallelism_tag == parallel_unbalanced)
return __for_each_template_random_access_ed(__begin, __end, __user_op,
__functionality, __reduction,
__reduction_start,
__output, __bound);
return __for_each_template_random_access_ed
(__begin, __end, __user_op, __functionality, __reduction,
__reduction_start, __output, __bound);
else if (__parallelism_tag == parallel_omp_loop)
return __for_each_template_random_access_omp_loop(
__begin, __end, __user_op,
__functionality,
__reduction,
__reduction_start,
__output, __bound);
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,
__functionality,
__reduction,
__reduction_start,
__output, __bound);
return __for_each_template_random_access_omp_loop
(__begin, __end, __user_op, __functionality, __reduction,
__reduction_start, __output, __bound);
else //e. g. parallel_balanced
return __for_each_template_random_access_workstealing(__begin, __end,
__user_op,
__functionality,
__reduction,
__reduction_start,
__output, __bound);
return __for_each_template_random_access_workstealing
(__begin, __end, __user_op, __functionality, __reduction,
__reduction_start, __output, __bound);
}
}
......
......@@ -52,7 +52,7 @@ namespace __gnu_parallel
const bool __make_twice)
{
++__count_to_two;
if (not __make_twice or __count_to_two < 2)
if (!__make_twice || __count_to_two < 2)
__shrink(__os_starts, __count_to_two, __range_length);
else
{
......@@ -112,7 +112,7 @@ namespace __gnu_parallel
std::vector<_IIter> __os_starts(2 * __oversampling * __num_parts + 1);
__os_starts[0]= __begin;
__os_starts[0] = __begin;
_IIter __prev = __begin, __it = __begin;
size_t __dist_limit = 0, __dist = 0;
size_t __cur = 1, __next = 1;
......
......@@ -54,10 +54,9 @@ namespace __gnu_parallel
typename _OutputIterator, typename _DifferenceTp,
typename _Compare>
_OutputIterator
__merge_advance_usual(_RAIter1& __begin1,
_RAIter1 __end1,
_RAIter2& __begin2,
_RAIter2 __end2, _OutputIterator __target,
__merge_advance_usual(_RAIter1& __begin1, _RAIter1 __end1,
_RAIter2& __begin2, _RAIter2 __end2,
_OutputIterator __target,
_DifferenceTp __max_length, _Compare __comp)
{
typedef _DifferenceTp _DifferenceType;
......@@ -103,10 +102,8 @@ namespace __gnu_parallel
typename _OutputIterator, typename _DifferenceTp,
typename _Compare>
_OutputIterator
__merge_advance_movc(_RAIter1& __begin1,
_RAIter1 __end1,
_RAIter2& __begin2,
_RAIter2 __end2,
__merge_advance_movc(_RAIter1& __begin1, _RAIter1 __end1,
_RAIter2& __begin2, _RAIter2 __end2,
_OutputIterator __target,
_DifferenceTp __max_length, _Compare __comp)
{
......@@ -178,8 +175,8 @@ namespace __gnu_parallel
{
_GLIBCXX_CALL(__max_length)
return __merge_advance_movc(__begin1, __end1, __begin2, __end2, __target,
__max_length, __comp);
return __merge_advance_movc(__begin1, __end1, __begin2, __end2,
__target, __max_length, __comp);
}
/** @brief Merge routine fallback to sequential in case the
......@@ -195,13 +192,11 @@ namespace __gnu_parallel
template<typename _RAIter1, typename _RAIter2,
typename _RAIter3, typename _Compare>
inline _RAIter3
__parallel_merge_advance(_RAIter1& __begin1,
_RAIter1 __end1,
__parallel_merge_advance(_RAIter1& __begin1, _RAIter1 __end1,
_RAIter2& __begin2,
// different iterators, parallel implementation
// not available
_RAIter2 __end2,
_RAIter3 __target, typename
_RAIter2 __end2, _RAIter3 __target, typename
std::iterator_traits<_RAIter1>::
difference_type __max_length, _Compare __comp)
{ return __merge_advance(__begin1, __end1, __begin2, __end2, __target,
......@@ -225,10 +220,8 @@ namespace __gnu_parallel
template<typename _RAIter1, typename _RAIter3,
typename _Compare>
inline _RAIter3
__parallel_merge_advance(_RAIter1& __begin1,
_RAIter1 __end1,
_RAIter1& __begin2,
_RAIter1 __end2,
__parallel_merge_advance(_RAIter1& __begin1, _RAIter1 __end1,
_RAIter1& __begin2, _RAIter1 __end2,
_RAIter3 __target, typename
std::iterator_traits<_RAIter1>::
difference_type __max_length, _Compare __comp)
......@@ -242,17 +235,14 @@ namespace __gnu_parallel
typedef typename std::pair<_RAIter1, _RAIter1>
_IteratorPair;
_IteratorPair
seqs[2] = { std::make_pair(__begin1, __end1),
_IteratorPair __seqs[2] = { std::make_pair(__begin1, __end1),
std::make_pair(__begin2, __end2) };
_RAIter3
__target_end = parallel_multiway_merge
< /* __stable = */ true, /* __sentinels = */ false>(
seqs, seqs + 2, __target,
multiway_merge_exact_splitting
_RAIter3 __target_end = parallel_multiway_merge
< /* __stable = */ true, /* __sentinels = */ false>
(__seqs, __seqs + 2, __target, multiway_merge_exact_splitting
< /* __stable = */ true, _IteratorPair*,
_Compare, _DifferenceType1>,
__max_length, __comp, omp_get_max_threads());
_Compare, _DifferenceType1>, __max_length, __comp,
omp_get_max_threads());
return __target_end;
}
......
......@@ -53,8 +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;
......@@ -142,19 +142,19 @@ namespace __gnu_parallel
// Number of sequences, number of elements in total (possibly
// including padding).
_DifferenceType __m = std::distance(__begin_seqs, __end_seqs), __N = 0,
_DifferenceType __m = std::distance(__begin_seqs, __end_seqs), __nn = 0,
__nmax, __n, __r;
for (int __i = 0; __i < __m; __i++)
{
__N += std::distance(__begin_seqs[__i].first,
__nn += std::distance(__begin_seqs[__i].first,
__begin_seqs[__i].second);
_GLIBCXX_PARALLEL_ASSERT(
std::distance(__begin_seqs[__i].first,
__begin_seqs[__i].second) > 0);
}
if (__rank == __N)
if (__rank == __nn)
{
for (int __i = 0; __i < __m; __i++)
__begin_offsets[__i] = __begin_seqs[__i].second; // Very end.
......@@ -163,9 +163,9 @@ namespace __gnu_parallel
}
_GLIBCXX_PARALLEL_ASSERT(__m != 0);
_GLIBCXX_PARALLEL_ASSERT(__N != 0);
_GLIBCXX_PARALLEL_ASSERT(__nn != 0);
_GLIBCXX_PARALLEL_ASSERT(__rank >= 0);
_GLIBCXX_PARALLEL_ASSERT(__rank < __N);
_GLIBCXX_PARALLEL_ASSERT(__rank < __nn);
_DifferenceType* __ns = new _DifferenceType[__m];
_DifferenceType* __a = new _DifferenceType[__m];
......@@ -401,14 +401,14 @@ namespace __gnu_parallel
// Number of sequences, number of elements in total (possibly
// including padding).
_DifferenceType __m = std::distance(__begin_seqs, __end_seqs);
_DifferenceType __N = 0;
_DifferenceType __nn = 0;
_DifferenceType __nmax, __n, __r;
for (int __i = 0; __i < __m; __i++)
__N += std::distance(__begin_seqs[__i].first,
__nn += std::distance(__begin_seqs[__i].first,
__begin_seqs[__i].second);
if (__m == 0 || __N == 0 || __rank < 0 || __rank >= __N)
if (__m == 0 || __nn == 0 || __rank < 0 || __rank >= __nn)
{
// result undefined if there is no data or __rank is outside bounds
throw std::exception();
......@@ -433,7 +433,7 @@ namespace __gnu_parallel
// Pad all lists to this length, at least as long as any ns[__i],
// equality iff __nmax = 2^__k - 1
__l = pow2(__r) - 1;
__l = __round_up_to_pow2(__r) - 1;
for (int __i = 0; __i < __m; ++__i)
{
......
......@@ -125,8 +125,7 @@ namespace __gnu_parallel
/** @brief Split by exact splitting. */
template<typename _RAIter, typename _Compare,
typename _SortingPlacesIterator>
struct _SplitConsistently<true, _RAIter,
_Compare, _SortingPlacesIterator>
struct _SplitConsistently<true, _RAIter, _Compare, _SortingPlacesIterator>
{
void
operator()(const _ThreadIndex __iam,
......@@ -140,19 +139,19 @@ namespace __gnu_parallel
std::vector<std::pair<_SortingPlacesIterator,
_SortingPlacesIterator> >
seqs(__sd->_M_num_threads);
__seqs(__sd->_M_num_threads);
for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++)
seqs[__s] = std::make_pair(__sd->_M_temporary[__s],
__seqs[__s] = std::make_pair(__sd->_M_temporary[__s],
__sd->_M_temporary[__s]
+ (__sd->_M_starts[__s + 1]
- __sd->_M_starts[__s]));
std::vector<_SortingPlacesIterator> _M_offsets(__sd->_M_num_threads);
std::vector<_SortingPlacesIterator> __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(),
multiseq_partition(__seqs.begin(), __seqs.end(),
__sd->_M_starts[__iam + 1], __offsets.begin(),
__comp);
for (int __seq = 0; __seq < __sd->_M_num_threads; __seq++)
......@@ -160,7 +159,7 @@ namespace __gnu_parallel
// for each sequence
if (__iam < (__sd->_M_num_threads - 1))
__sd->_M_pieces[__iam][__seq]._M_end
= _M_offsets[__seq] - seqs[__seq].first;
= __offsets[__seq] - __seqs[__seq].first;
else
// very end of this sequence
__sd->_M_pieces[__iam][__seq]._M_end =
......@@ -185,8 +184,7 @@ namespace __gnu_parallel
/** @brief Split by sampling. */
template<typename _RAIter, typename _Compare,
typename _SortingPlacesIterator>
struct _SplitConsistently<false, _RAIter, _Compare,
_SortingPlacesIterator>
struct _SplitConsistently<false, _RAIter, _Compare, _SortingPlacesIterator>
{
void
operator()(const _ThreadIndex __iam,
......@@ -282,10 +280,8 @@ namespace __gnu_parallel
const _RAIter& __target,
_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()); }
};
template<typename Seq_RAIter, typename _RAIter,
......@@ -298,10 +294,8 @@ namespace __gnu_parallel
const _RAIter& __target,
_Compare& __comp,
_DiffType __length_am) const
{
multiway_merge(__seqs_begin, __seqs_end, __target, __length_am, __comp,
sequential_tag());
}
{ multiway_merge(__seqs_begin, __seqs_end, __target, __length_am,
__comp, sequential_tag()); }
};
/** @brief PMWMS code executed by each thread.
......@@ -321,8 +315,8 @@ namespace __gnu_parallel
_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.
......@@ -350,8 +344,7 @@ namespace __gnu_parallel
_DifferenceType __num_samples =
_Settings::get().sort_mwms_oversampling * __sd->_M_num_threads - 1;
_SplitConsistently
<__exact, _RAIter, _Compare, _SortingPlacesIterator>()
_SplitConsistently<__exact, _RAIter, _Compare, _SortingPlacesIterator>()
(__iam, __sd, __comp, __num_samples);
// Offset from __target __begin, __length after merging.
......@@ -366,22 +359,20 @@ namespace __gnu_parallel
typedef std::vector<
std::pair<_SortingPlacesIterator, _SortingPlacesIterator> >
_SeqVector;
_SeqVector seqs(__sd->_M_num_threads);
_SeqVector __seqs(__sd->_M_num_threads);
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,
__sd->_M_temporary[__s] + __sd->_M_pieces[__iam][__s]._M_end);
__seqs[__s] =
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);
}
__possibly_stable_multiway_merge<
__stable,
typename _SeqVector::iterator,
_RAIter,
_Compare, _DifferenceType>()
(seqs.begin(), seqs.end(),
__stable, typename _SeqVector::iterator,
_RAIter, _Compare, _DifferenceType>()(__seqs.begin(), __seqs.end(),
__sd->_M_source + __offset, __comp,
__length_am);
......@@ -421,7 +412,7 @@ namespace __gnu_parallel
// shared variables
_PMWMSSortingData<_RAIter> __sd;
_DifferenceType* _M_starts;
_DifferenceType* __starts;
# pragma omp parallel num_threads(__num_threads)
{
......@@ -450,26 +441,25 @@ namespace __gnu_parallel
= 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];
__starts = __sd._M_starts = new _DifferenceType[__num_threads + 1];
_DifferenceType __chunk_length = __n / __num_threads;
_DifferenceType __split = __n % __num_threads;
_DifferenceType __pos = 0;
for (int __i = 0; __i < __num_threads; ++__i)
{
_M_starts[__i] = __pos;
__pos += (__i < __split)
? (__chunk_length + 1) : __chunk_length;
__starts[__i] = __pos;
__pos += ((__i < __split)
? (__chunk_length + 1) : __chunk_length);
}
_M_starts[__num_threads] = __pos;
__starts[__num_threads] = __pos;
} //single
// Now sort in parallel.
parallel_sort_mwms_pu<__stable, __exact>(&__sd, __comp);
} //parallel
delete[] _M_starts;
delete[] __starts;
delete[] __sd._M_temporary;
if (!__exact)
......
......@@ -69,7 +69,7 @@ namespace __parallel
__accumulate_switch(_IIter __begin, _IIter __end,
_Tp __init, _IteratorTag)
{ return accumulate(__begin, __end, __init,
__gnu_parallel::sequential_tag()); }
__gnu_parallel::sequential_tag()); }
template<typename _IIter, typename _Tp, typename _BinaryOperation,
typename _IteratorTag>
......
......@@ -74,8 +74,8 @@ namespace __gnu_parallel
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
_ThreadIndex __num_threads = __gnu_parallel::min<_DifferenceType>
(__get_max_threads(), __length);
_Result *__thread_results;
......@@ -94,8 +94,8 @@ namespace __gnu_parallel
#pragma omp for schedule(dynamic, _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)
......
......@@ -74,8 +74,8 @@ namespace __gnu_parallel
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
std::min<_DifferenceType>(__get_max_threads(), __length);
_ThreadIndex __num_threads = std::min<_DifferenceType>
(__get_max_threads(), __length);
_Result *__thread_results;
......
......@@ -75,25 +75,24 @@ namespace __gnu_parallel
_Result *__thread_results;
bool* __constructed;
_ThreadIndex __num_threads =
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
_ThreadIndex __num_threads = __gnu_parallel::min<_DifferenceType>
(__get_max_threads(), __length);
# pragma omp parallel num_threads(__num_threads)
{
# pragma omp single
{
__num_threads = omp_get_num_threads();
__thread_results =
static_cast<_Result*>(::operator new(__num_threads
* sizeof(_Result)));
__thread_results = static_cast<_Result*>
(::operator new(__num_threads * sizeof(_Result)));
__constructed = new bool[__num_threads];
}
_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),
......
......@@ -149,8 +149,9 @@ namespace __gnu_parallel
if (__iam == 0)
{
*__result = *__begin;
__parallel_partial_sum_basecase(
__begin + 1, __begin + __borders[1], __result + 1,
__parallel_partial_sum_basecase(__begin + 1,
__begin + __borders[1],
__result + 1,
__bin_op, *__begin);
::new(&(__sums[__iam])) _ValueType(*(__result + __borders[1] - 1));
}
......
......@@ -44,13 +44,14 @@
namespace __gnu_parallel
{
/** @brief Parallel implementation of std::partition.
/** @brief Parallel implementation of std::partition.
* @param __begin Begin iterator of input sequence to split.
* @param __end End iterator of input sequence to split.
* @param __pred Partition predicate, possibly including some kind of pivot.
* @param __pred Partition predicate, possibly including some kind
* of pivot.
* @param __num_threads Maximum number of threads to use for this task.
* @return Number of elements not fulfilling the predicate. */
template<typename _RAIter, typename _Predicate>
template<typename _RAIter, typename _Predicate>
typename std::iterator_traits<_RAIter>::difference_type
__parallel_partition(_RAIter __begin, _RAIter __end,
_Predicate __pred, _ThreadIndex __num_threads)
......@@ -78,7 +79,7 @@ template<typename _RAIter, typename _Predicate>
omp_init_lock(&__result_lock);
//at least two chunks per thread
if(__right - __left + 1 >= 2 * __num_threads * __chunk_size)
if (__right - __left + 1 >= 2 * __num_threads * __chunk_size)
# pragma omp parallel num_threads(__num_threads)
{
# pragma omp single
......@@ -88,10 +89,9 @@ 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;
}
......@@ -100,8 +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)
{
......@@ -171,7 +171,8 @@ template<typename _RAIter, typename _Predicate>
// Fetch new chunk(__s).
break;
std::swap(__begin[__thread_left], __begin[__thread_right]);
std::swap(__begin[__thread_left],
__begin[__thread_right]);
++__thread_left;
--__thread_right;
}
......@@ -200,9 +201,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]
= true;
__reserved_left[(__left - (__thread_left_border + 1))
/ __chunk_size] = true;
}
// <=> __thread_right_border - (__chunk_size - 1) <= __rightnew
......@@ -260,10 +260,9 @@ template<typename _RAIter, typename _Predicate>
_GLIBCXX_PARALLEL_ASSERT(__swapstart != -1);
#endif
std::swap_ranges(
__begin + __thread_right_border,
__begin + __thread_right_border + __chunk_size,
__begin + __swapstart);
std::swap_ranges(__begin + __thread_right_border,
__begin + __thread_right_border
+ __chunk_size, __begin + __swapstart);
}
#if _GLIBCXX_ASSERTIONS
# pragma omp barrier
......@@ -284,6 +283,7 @@ template<typename _RAIter, typename _Predicate>
__left = __leftnew;
__right = __rightnew;
}
# pragma omp flush(__left, __right)
} // end "recursion" //parallel
......@@ -292,11 +292,13 @@ template<typename _RAIter, typename _Predicate>
while (__final_left < __final_right)
{
// Go right until key is geq than pivot.
while (__pred(__begin[__final_left]) && __final_left < __final_right)
while (__pred(__begin[__final_left])
&& __final_left < __final_right)
++__final_left;
// Go left until key is less than pivot.
while (!__pred(__begin[__final_right]) && __final_left < __final_right)
while (!__pred(__begin[__final_right])
&& __final_left < __final_right)
--__final_right;
if (__final_left == __final_right)
......@@ -322,14 +324,14 @@ template<typename _RAIter, typename _Predicate>
return __final_left + 1;
}
/**
/**
* @brief Parallel implementation of std::nth_element().
* @param __begin Begin iterator of input sequence.
* @param __nth _Iterator of element that must be in position afterwards.
* @param __end End iterator of input sequence.
* @param __comp Comparator.
*/
template<typename _RAIter, typename _Compare>
template<typename _RAIter, typename _Compare>
void
__parallel_nth_element(_RAIter __begin, _RAIter __nth,
_RAIter __end, _Compare __comp)
......@@ -361,15 +363,16 @@ template<typename _RAIter, typename _Compare>
// _Compare must have first_value_type, second_value_type,
// result_type
// _Compare ==
// __gnu_parallel::_Lexicographic<S, int, __gnu_parallel::_Less<S, S> >
// __gnu_parallel::_Lexicographic<S, int,
// __gnu_parallel::_Less<S, S> >
// __pivot_pos == std::pair<S, int>*
__gnu_parallel::binder2nd<_Compare, _ValueType, _ValueType, bool>
__pred(__comp, *__pivot_pos);
// 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
......@@ -386,7 +389,8 @@ template<typename _RAIter, typename _Compare>
// Very unequal split, one part smaller than one 128th
// elements not strictly larger than the pivot.
__gnu_parallel::__unary_negate<__gnu_parallel::
__binder1st<_Compare, _ValueType, _ValueType, bool>, _ValueType>
__binder1st<_Compare, _ValueType,
_ValueType, bool>, _ValueType>
__pred(__gnu_parallel::__binder1st<_Compare, _ValueType,
_ValueType, bool>(__comp, *__pivot_pos));
......@@ -411,12 +415,12 @@ template<typename _RAIter, typename _Compare>
__gnu_sequential::sort(__begin, __end, __comp);
}
/** @brief Parallel implementation of std::partial_sort().
* @param __begin Begin iterator of input sequence.
* @param __middle Sort until this position.
* @param __end End iterator of input sequence.
* @param __comp Comparator. */
template<typename _RAIter, typename _Compare>
/** @brief Parallel implementation of std::partial_sort().
* @param __begin Begin iterator of input sequence.
* @param __middle Sort until this position.
* @param __end End iterator of input sequence.
* @param __comp Comparator. */
template<typename _RAIter, typename _Compare>
void
__parallel_partial_sort(_RAIter __begin,
_RAIter __middle,
......
......@@ -65,10 +65,10 @@ namespace __gnu_parallel
public:
/** @brief Constructor. Not to be called concurrent, of course.
* @param _M_max_size Maximal number of elements to be contained. */
_RestrictedBoundedConcurrentQueue(_SequenceIndex _M_max_size)
_RestrictedBoundedConcurrentQueue(_SequenceIndex __max_size)
{
this->_M_max_size = _M_max_size;
_M_base = new _Tp[_M_max_size];
_M_max_size = __max_size;
_M_base = new _Tp[__max_size];
_M_borders = __encode2(0, 0);
#pragma omp flush
}
......@@ -105,12 +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;
......@@ -132,12 +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;
......
......@@ -48,8 +48,7 @@ namespace __gnu_parallel
*/
template<typename _RAIter, typename _Compare>
typename std::iterator_traits<_RAIter>::difference_type
__parallel_sort_qs_divide(_RAIter __begin,
_RAIter __end,
__parallel_sort_qs_divide(_RAIter __begin, _RAIter __end,
_Compare __comp, typename std::iterator_traits
<_RAIter>::difference_type __pivot_rank,
typename std::iterator_traits
......@@ -64,25 +63,24 @@ namespace __gnu_parallel
__num_samples = std::min(__num_samples, __n);
// Allocate uninitialized, to avoid default constructor.
_ValueType* __samples =
static_cast<_ValueType*>(::operator new(__num_samples
* sizeof(_ValueType)));
_ValueType* __samples = static_cast<_ValueType*>
(::operator new(__num_samples * sizeof(_ValueType)));
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]);
}
__gnu_sequential::sort(__samples, __samples + __num_samples, __comp);
_ValueType& pivot = __samples[__pivot_rank * __num_samples / __n];
_ValueType& __pivot = __samples[__pivot_rank * __num_samples / __n];
__gnu_parallel::binder2nd<_Compare, _ValueType, _ValueType, bool>
__pred(__comp, pivot);
_DifferenceType __split =
__parallel_partition(__begin, __end, __pred, __num_threads);
__pred(__comp, __pivot);
_DifferenceType __split = __parallel_partition(__begin, __end,
__pred, __num_threads);
::operator delete(__samples);
......@@ -98,8 +96,7 @@ namespace __gnu_parallel
*/
template<typename _RAIter, typename _Compare>
void
__parallel_sort_qs_conquer(_RAIter __begin,
_RAIter __end,
__parallel_sort_qs_conquer(_RAIter __begin, _RAIter __end,
_Compare __comp,
_ThreadIndex __num_threads)
{
......@@ -127,10 +124,9 @@ namespace __gnu_parallel
__pivot_rank = __n * __num_threads_left / __num_threads;
_DifferenceType __split =
__parallel_sort_qs_divide(__begin, __end, __comp, __pivot_rank,
_Settings::get().sort_qs_num_samples_preset,
__num_threads);
_DifferenceType __split = __parallel_sort_qs_divide
(__begin, __end, __comp, __pivot_rank,
_Settings::get().sort_qs_num_samples_preset, __num_threads);
#pragma omp parallel sections num_threads(2)
{
......@@ -144,7 +140,6 @@ namespace __gnu_parallel
}
/** @brief Unbalanced quicksort main call.
* @param __begin Begin iterator of input sequence.
* @param __end End iterator input sequence, ignored.
......@@ -154,8 +149,7 @@ namespace __gnu_parallel
*/
template<typename _RAIter, typename _Compare>
void
__parallel_sort_qs(_RAIter __begin,
_RAIter __end,
__parallel_sort_qs(_RAIter __begin, _RAIter __end,
_Compare __comp,
_ThreadIndex __num_threads)
{
......
......@@ -38,7 +38,6 @@
#include <parallel/parallel.h>
#include <parallel/equally_split.h>
namespace __gnu_parallel
{
/**
......@@ -47,7 +46,7 @@ namespace __gnu_parallel
* @param __length Length of sequence to search for.
* @param __advances Returned __offsets.
*/
template<typename _RAIter, typename _DifferenceTp>
template<typename _RAIter, typename _DifferenceTp>
void
__calc_borders(_RAIter __elements, _DifferenceTp __length,
_DifferenceTp* __off)
......@@ -75,7 +74,7 @@ template<typename _RAIter, typename _DifferenceTp>
* @param __end2 End iterator of second sequence.
* @param __pred Find predicate.
* @return Place of finding in first sequences. */
template<typename __RAIter1,
template<typename __RAIter1,
typename __RAIter2,
typename _Pred>
__RAIter1
......@@ -108,9 +107,9 @@ template<typename __RAIter1,
omp_lock_t __result_lock;
omp_init_lock(&__result_lock);
_ThreadIndex __num_threads =
std::max<_DifferenceType>(1,
std::min<_DifferenceType>(__input_length, __get_max_threads()));
_ThreadIndex __num_threads = std::max<_DifferenceType>
(1, std::min<_DifferenceType>(__input_length,
__get_max_threads()));
_DifferenceType __advances[__pattern_length];
__calc_borders(__begin2, __pattern_length, __advances);
......@@ -135,7 +134,7 @@ template<typename __RAIter1,
while (__start <= __stop && !__found_pattern)
{
// Get new value of result.
#pragma omp flush(__result)
#pragma omp flush(__result)
// No chance for this thread to find first occurrence.
if (__result < __start)
break;
......@@ -156,9 +155,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];
__pos_in_pattern = (__advances[__pos_in_pattern] < 0
? 0 : __advances[__pos_in_pattern]);
}
} //parallel
......
......@@ -95,7 +95,8 @@ namespace __gnu_parallel
template<bool __stable, typename _RAIter, typename _Compare>
inline void
__parallel_sort(_RAIter __begin, _RAIter __end,
_Compare __comp, multiway_mergesort_exact_tag __parallelism)
_Compare __comp,
multiway_mergesort_exact_tag __parallelism)
{
_GLIBCXX_CALL(__end - __begin)
......@@ -114,7 +115,8 @@ namespace __gnu_parallel
template<bool __stable, typename _RAIter, typename _Compare>
inline void
__parallel_sort(_RAIter __begin, _RAIter __end,
_Compare __comp, multiway_mergesort_sampling_tag __parallelism)
_Compare __comp,
multiway_mergesort_sampling_tag __parallelism)
{
_GLIBCXX_CALL(__end - __begin)
......@@ -163,7 +165,6 @@ namespace __gnu_parallel
__parallelism.__get_num_threads());
}
/**
* @brief Choose multiway mergesort with exact splitting,
* for parallel sorting.
......@@ -184,7 +185,6 @@ namespace __gnu_parallel
multiway_mergesort_exact_tag(__parallelism.__get_num_threads()));
}
/**
* @brief Choose a parallel sorting algorithm.
* @param __begin Begin iterator of input sequence.
......
......@@ -51,20 +51,16 @@ namespace __gnu_parallel
public:
/** @brief Default constructor. Use default number of threads. */
parallel_tag()
{
this->_M_num_threads = 0;
}
{ _M_num_threads = 0; }
/** @brief Default constructor. Recommend number of threads to use.
* @param __num_threads Desired number of threads. */
parallel_tag(_ThreadIndex __num_threads)
{
this->_M_num_threads = __num_threads;
}
{ _M_num_threads = __num_threads; }
/** @brief Find out desired number of threads.
* @return Desired number of threads. */
inline _ThreadIndex __get_num_threads()
_ThreadIndex __get_num_threads()
{
if(_M_num_threads == 0)
return omp_get_max_threads();
......@@ -74,10 +70,8 @@ namespace __gnu_parallel
/** @brief Set the desired number of threads.
* @param __num_threads Desired number of threads. */
inline void set_num_threads(_ThreadIndex __num_threads)
{
this->_M_num_threads = __num_threads;
}
void set_num_threads(_ThreadIndex __num_threads)
{ _M_num_threads = __num_threads; }
};
/** @brief Recommends parallel execution using the
......
......@@ -37,19 +37,19 @@
namespace __gnu_parallel
{
/** @brief Parallel std::unique_copy(), w/__o explicit equality predicate.
/** @brief Parallel std::unique_copy(), w/__o explicit equality predicate.
* @param __first Begin iterator of input sequence.
* @param __last End iterator of input sequence.
* @param __result Begin iterator of result __sequence.
* @param __binary_pred Equality predicate.
* @return End iterator of result __sequence. */
template<typename _IIter,
template<typename _IIter,
class _OutputIterator,
class _BinaryPredicate>
_OutputIterator
__parallel_unique_copy(_IIter __first, _IIter __last,
_OutputIterator __result, _BinaryPredicate __binary_pred)
_OutputIterator __result,
_BinaryPredicate __binary_pred)
{
_GLIBCXX_CALL(__last - __first)
......@@ -57,9 +57,9 @@ template<typename _IIter,
typedef typename _TraitsType::value_type _ValueType;
typedef typename _TraitsType::difference_type _DifferenceType;
_DifferenceType size = __last - __first;
_DifferenceType __size = __last - __first;
if (size == 0)
if (__size == 0)
return __result;
// Let the first thread process two parts.
......@@ -74,7 +74,7 @@ template<typename _IIter,
{
__num_threads = omp_get_num_threads();
__borders = new _DifferenceType[__num_threads + 2];
equally_split(size, __num_threads + 1, __borders);
equally_split(__size, __num_threads + 1, __borders);
__counter = new _DifferenceType[__num_threads + 1];
}
......@@ -95,12 +95,13 @@ template<typename _IIter,
++__i;
*__out++ = *__first;
for (_IIter iter = __first + __begin; iter < __first + __end; ++iter)
for (_IIter __iter = __first + __begin; __iter < __first + __end;
++__iter)
{
if (!__binary_pred(*iter, *(iter-1)))
if (!__binary_pred(*__iter, *(__iter - 1)))
{
++__i;
*__out++ = *iter;
*__out++ = *__iter;
}
}
}
......@@ -109,9 +110,10 @@ template<typename _IIter,
__begin = __borders[__iam]; //one part
__end = __borders[__iam + 1];
for (_IIter iter = __first + __begin; iter < __first + __end; ++iter)
for (_IIter __iter = __first + __begin; __iter < __first + __end;
++__iter)
{
if (!__binary_pred(*iter, *(iter - 1)))
if (!__binary_pred(*__iter, *(__iter - 1)))
++__i;
}
}
......@@ -135,14 +137,16 @@ template<typename _IIter,
_OutputIterator __iter_out = __result + __begin_output;
__begin = __borders[__num_threads];
__end = size;
__end = __size;
for (_IIter iter = __first + __begin; iter < __first + __end; ++iter)
for (_IIter __iter = __first + __begin; __iter < __first + __end;
++__iter)
{
if (iter == __first || !__binary_pred(*iter, *(iter - 1)))
if (__iter == __first
|| !__binary_pred(*__iter, *(__iter - 1)))
{
++__i;
*__iter_out++ = *iter;
*__iter_out++ = *__iter;
}
}
......@@ -154,10 +158,11 @@ template<typename _IIter,
__begin_output += __counter[__t];
_OutputIterator __iter_out = __result + __begin_output;
for (_IIter iter = __first + __begin; iter < __first + __end; ++iter)
for (_IIter __iter = __first + __begin; __iter < __first + __end;
++__iter)
{
if (!__binary_pred(*iter, *(iter-1)))
*__iter_out++ = *iter;
if (!__binary_pred(*__iter, *(__iter - 1)))
*__iter_out++ = *__iter;
}
}
}
......@@ -171,12 +176,12 @@ template<typename _IIter,
return __result + __end_output;
}
/** @brief Parallel std::unique_copy(), without explicit equality predicate
/** @brief Parallel std::unique_copy(), without explicit equality predicate
* @param __first Begin iterator of input sequence.
* @param __last End iterator of input sequence.
* @param __result Begin iterator of result __sequence.
* @return End iterator of result __sequence. */
template<typename _IIter, class _OutputIterator>
template<typename _IIter, class _OutputIterator>
inline _OutputIterator
__parallel_unique_copy(_IIter __first, _IIter __last,
_OutputIterator __result)
......
......@@ -49,8 +49,8 @@ namespace __gnu_parallel
#define _GLIBCXX_JOB_VOLATILE volatile
/** @brief One __job for a certain thread. */
template<typename _DifferenceTp>
/** @brief One __job for a certain thread. */
template<typename _DifferenceTp>
struct _Job
{
typedef _DifferenceTp _DifferenceType;
......@@ -72,7 +72,7 @@ template<typename _DifferenceTp>
_GLIBCXX_JOB_VOLATILE _DifferenceType _M_load;
};
/** @brief Work stealing algorithm for random access iterators.
/** @brief Work stealing algorithm for random access iterators.
*
* Uses O(1) additional memory. Synchronization at job lists is
* done with atomic operations.
......@@ -90,15 +90,17 @@ template<typename _DifferenceTp>
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
template<typename _RAIter,
template<typename _RAIter,
typename _Op,
typename _Fu,
typename _Red,
typename _Result>
_Op
__for_each_template_random_access_workstealing(
_RAIter __begin, _RAIter __end, _Op __op, _Fu& __f, _Red __r,
_Result __base, _Result& __output,
__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)
{
_GLIBCXX_CALL(__end - __begin)
......@@ -115,8 +117,8 @@ template<typename _RAIter,
_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;
......@@ -130,13 +132,12 @@ template<typename _RAIter,
__output = __base;
// No more threads than jobs, at least one thread.
_ThreadIndex __num_threads =
__gnu_parallel::max<_ThreadIndex>(1,
__gnu_parallel::min<_DifferenceType>(__length, __get_max_threads()));
_ThreadIndex __num_threads = __gnu_parallel::max<_ThreadIndex>
(1, __gnu_parallel::min<_DifferenceType>(__length,
__get_max_threads()));
# pragma omp parallel shared(__busy) num_threads(__num_threads)
{
# pragma omp single
{
__num_threads = omp_get_num_threads();
......@@ -167,7 +168,7 @@ template<typename _RAIter,
// Every thread has its own random number generator
// (modulo __num_threads).
_RandomNumber rand_gen(__iam, __num_threads);
_RandomNumber __rand_gen(__iam, __num_threads);
// This thread is currently working.
# pragma omp atomic
......@@ -176,11 +177,12 @@ template<typename _RAIter,
__iam_working = true;
// How many jobs per thread? last thread gets the rest.
__my_job._M_first =
static_cast<_DifferenceType>(__iam * (__length / __num_threads));
__my_job._M_first = static_cast<_DifferenceType>
(__iam * (__length / __num_threads));
__my_job._M_last = (__iam == (__num_threads - 1)) ?
(__length - 1) : ((__iam + 1) * (__length / __num_threads) - 1);
__my_job._M_last = (__iam == (__num_threads - 1)
? (__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)
......@@ -210,8 +212,8 @@ 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
......@@ -242,13 +244,14 @@ template<typename _RAIter,
__iam_working = false;
}
_DifferenceType __supposed_first, __supposed_last, __supposed_load;
_DifferenceType __supposed_first, __supposed_last,
__supposed_load;
do
{
// Find random nonempty deque (not own), do consistency check.
__yield();
# pragma omp flush(__busy)
__victim = rand_gen();
__victim = __rand_gen();
__supposed_first = __job[__victim * __stride]._M_first;
__supposed_last = __job[__victim * __stride]._M_last;
__supposed_load = __job[__victim * __stride]._M_load;
......@@ -269,14 +272,14 @@ template<typename _RAIter,
// Push __victim's current start forward.
_DifferenceType __stolen_first =
__fetch_and_add<_DifferenceType>(
&(__job[__victim * __stride]._M_first), __steal);
_DifferenceType __stolen_try =
__stolen_first + __steal - _DifferenceType(1);
__fetch_and_add<_DifferenceType>
(&(__job[__victim * __stride]._M_first), __steal);
_DifferenceType __stolen_try = (__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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment