multiway_merge.h: Simple formatting and uglification fixes.
2009-11-05 Paolo Carlini <paolo.carlini@oracle.com> * include/parallel/multiway_merge.h: Simple formatting and uglification fixes. * include/parallel/losertree.h: Likewise. * include/parallel/base.h: Likewise. * include/parallel/par_loop.h: Likewise. * include/parallel/omp_loop_static.h: Likewise. * include/parallel/multiway_mergesort.h: Likewise. * include/parallel/partial_sum.h: Likewise. * include/parallel/omp_loop.h: Likewise. From-SVN: r153939
This commit is contained in:
parent
94086ef69c
commit
338311e5d7
|
@ -1,3 +1,15 @@
|
|||
2009-11-05 Paolo Carlini <paolo.carlini@oracle.com>
|
||||
|
||||
* include/parallel/multiway_merge.h: Simple formatting and
|
||||
uglification fixes.
|
||||
* include/parallel/losertree.h: Likewise.
|
||||
* include/parallel/base.h: Likewise.
|
||||
* include/parallel/par_loop.h: Likewise.
|
||||
* include/parallel/omp_loop_static.h: Likewise.
|
||||
* include/parallel/multiway_mergesort.h: Likewise.
|
||||
* include/parallel/partial_sum.h: Likewise.
|
||||
* include/parallel/omp_loop.h: Likewise.
|
||||
|
||||
2009-11-04 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* testsuite/25_algorithms/fill/5.cc: Move...
|
||||
|
|
|
@ -93,11 +93,11 @@ namespace __gnu_parallel
|
|||
__is_parallel(const _Parallelism __p) { return __p != sequential; }
|
||||
|
||||
|
||||
/** @brief Calculates the rounded-down logarithm of @__c __n for base 2.
|
||||
/** @brief Calculates the rounded-down logarithm of @__c __n for base 2.
|
||||
* @param __n Argument.
|
||||
* @return Returns 0 for any argument <1.
|
||||
*/
|
||||
template<typename _Size>
|
||||
template<typename _Size>
|
||||
inline _Size
|
||||
__rd_log2(_Size __n)
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ template<typename _Size>
|
|||
return __k;
|
||||
}
|
||||
|
||||
/** @brief Encode two integers into one gnu_parallel::_CASable.
|
||||
/** @brief Encode two integers into one gnu_parallel::_CASable.
|
||||
* @param __a First integer, to be encoded in the most-significant @__c
|
||||
* _CASable_bits/2 bits.
|
||||
* @param __b Second integer, to be encoded in the least-significant
|
||||
|
@ -115,13 +115,13 @@ template<typename _Size>
|
|||
* @return value encoding @__c __a and @__c __b.
|
||||
* @see decode2
|
||||
*/
|
||||
inline _CASable
|
||||
__encode2(int __a, int __b) //must all be non-negative, actually
|
||||
{
|
||||
inline _CASable
|
||||
__encode2(int __a, int __b) //must all be non-negative, actually
|
||||
{
|
||||
return (((_CASable)__a) << (_CASable_bits / 2)) | (((_CASable)__b) << 0);
|
||||
}
|
||||
}
|
||||
|
||||
/** @brief Decode two integers from one gnu_parallel::_CASable.
|
||||
/** @brief Decode two integers from one gnu_parallel::_CASable.
|
||||
* @param __x __gnu_parallel::_CASable to decode integers from.
|
||||
* @param __a First integer, to be decoded from the most-significant
|
||||
* @__c _CASable_bits/2 bits of @__c __x.
|
||||
|
@ -129,31 +129,31 @@ __encode2(int __a, int __b) //must all be non-negative, actually
|
|||
* @__c _CASable_bits/2 bits of @__c __x.
|
||||
* @see __encode2
|
||||
*/
|
||||
inline void
|
||||
decode2(_CASable __x, int& __a, int& __b)
|
||||
{
|
||||
inline void
|
||||
decode2(_CASable __x, int& __a, int& __b)
|
||||
{
|
||||
__a = (int)((__x >> (_CASable_bits / 2)) & _CASable_mask);
|
||||
__b = (int)((__x >> 0 ) & _CASable_mask);
|
||||
}
|
||||
}
|
||||
|
||||
//needed for parallel "numeric", even if "algorithm" not included
|
||||
//needed for parallel "numeric", even if "algorithm" not included
|
||||
|
||||
/** @brief Equivalent to std::min. */
|
||||
template<typename _Tp>
|
||||
/** @brief Equivalent to std::min. */
|
||||
template<typename _Tp>
|
||||
const _Tp&
|
||||
min(const _Tp& __a, const _Tp& __b)
|
||||
{ return (__a < __b) ? __a : __b; }
|
||||
|
||||
/** @brief Equivalent to std::max. */
|
||||
template<typename _Tp>
|
||||
/** @brief Equivalent to std::max. */
|
||||
template<typename _Tp>
|
||||
const _Tp&
|
||||
max(const _Tp& __a, const _Tp& __b)
|
||||
{ return (__a > __b) ? __a : __b; }
|
||||
|
||||
/** @brief Constructs predicate for equality from strict weak
|
||||
/** @brief Constructs predicate for equality from strict weak
|
||||
* ordering predicate
|
||||
*/
|
||||
template<typename _T1, typename _T2, typename _Compare>
|
||||
template<typename _T1, typename _T2, typename _Compare>
|
||||
class _EqualFromLess : public std::binary_function<_T1, _T2, bool>
|
||||
{
|
||||
private:
|
||||
|
@ -163,15 +163,13 @@ template<typename _T1, typename _T2, typename _Compare>
|
|||
_EqualFromLess(_Compare& __comp) : _M_comp(__comp) { }
|
||||
|
||||
bool operator()(const _T1& __a, const _T2& __b)
|
||||
{
|
||||
return !_M_comp(__a, __b) && !_M_comp(__b, __a);
|
||||
}
|
||||
{ return !_M_comp(__a, __b) && !_M_comp(__b, __a); }
|
||||
};
|
||||
|
||||
|
||||
/** @brief Similar to std::binder1st,
|
||||
/** @brief Similar to std::binder1st,
|
||||
* but giving the argument types explicitly. */
|
||||
template<typename _Predicate, typename argument_type>
|
||||
template<typename _Predicate, typename argument_type>
|
||||
class __unary_negate
|
||||
: public std::unary_function<argument_type, bool>
|
||||
{
|
||||
|
@ -187,9 +185,9 @@ template<typename _Predicate, typename argument_type>
|
|||
{ return !_M_pred(__x); }
|
||||
};
|
||||
|
||||
/** @brief Similar to std::binder1st,
|
||||
/** @brief Similar to std::binder1st,
|
||||
* but giving the argument types explicitly. */
|
||||
template<typename _Operation, typename _FirstArgumentType,
|
||||
template<typename _Operation, typename _FirstArgumentType,
|
||||
typename _SecondArgumentType, typename _ResultType>
|
||||
class __binder1st
|
||||
: public std::unary_function<_SecondArgumentType, _ResultType>
|
||||
|
@ -199,8 +197,7 @@ template<typename _Operation, typename _FirstArgumentType,
|
|||
_FirstArgumentType _M_value;
|
||||
|
||||
public:
|
||||
__binder1st(const _Operation& __x,
|
||||
const _FirstArgumentType& __y)
|
||||
__binder1st(const _Operation& __x, const _FirstArgumentType& __y)
|
||||
: _M_op(__x), _M_value(__y) { }
|
||||
|
||||
_ResultType
|
||||
|
@ -214,11 +211,11 @@ template<typename _Operation, typename _FirstArgumentType,
|
|||
{ return _M_op(_M_value, __x); }
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Similar to std::binder2nd, but giving the argument types
|
||||
* explicitly.
|
||||
*/
|
||||
template<typename _Operation, typename _FirstArgumentType,
|
||||
template<typename _Operation, typename _FirstArgumentType,
|
||||
typename _SecondArgumentType, typename _ResultType>
|
||||
class binder2nd
|
||||
: public std::unary_function<_FirstArgumentType, _ResultType>
|
||||
|
@ -228,8 +225,7 @@ template<typename _Operation, typename _FirstArgumentType,
|
|||
_SecondArgumentType _M_value;
|
||||
|
||||
public:
|
||||
binder2nd(const _Operation& __x,
|
||||
const _SecondArgumentType& __y)
|
||||
binder2nd(const _Operation& __x, const _SecondArgumentType& __y)
|
||||
: _M_op(__x), _M_value(__y) { }
|
||||
|
||||
_ResultType
|
||||
|
@ -243,16 +239,16 @@ template<typename _Operation, typename _FirstArgumentType,
|
|||
{ return _M_op(__x, _M_value); }
|
||||
};
|
||||
|
||||
/** @brief Similar to std::equal_to, but allows two different types. */
|
||||
template<typename _T1, typename _T2>
|
||||
/** @brief Similar to std::equal_to, but allows two different types. */
|
||||
template<typename _T1, typename _T2>
|
||||
struct _EqualTo : std::binary_function<_T1, _T2, bool>
|
||||
{
|
||||
bool operator()(const _T1& __t1, const _T2& __t2) const
|
||||
{ return __t1 == __t2; }
|
||||
};
|
||||
|
||||
/** @brief Similar to std::less, but allows two different types. */
|
||||
template<typename _T1, typename _T2>
|
||||
/** @brief Similar to std::less, but allows two different types. */
|
||||
template<typename _T1, typename _T2>
|
||||
struct _Less : std::binary_function<_T1, _T2, bool>
|
||||
{
|
||||
bool
|
||||
|
@ -264,9 +260,9 @@ template<typename _T1, typename _T2>
|
|||
{ return __t2 < __t1; }
|
||||
};
|
||||
|
||||
// Partial specialization for one type. Same as std::less.
|
||||
template<typename _Tp>
|
||||
struct _Less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool>
|
||||
// Partial specialization for one type. Same as std::less.
|
||||
template<typename _Tp>
|
||||
struct _Less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool>
|
||||
{
|
||||
bool
|
||||
operator()(const _Tp& __x, const _Tp& __y) const
|
||||
|
@ -275,7 +271,7 @@ struct _Less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool>
|
|||
|
||||
|
||||
/** @brief Similar to std::plus, but allows two different types. */
|
||||
template<typename _Tp1, typename _Tp2>
|
||||
template<typename _Tp1, typename _Tp2>
|
||||
struct _Plus : public std::binary_function<_Tp1, _Tp2, _Tp1>
|
||||
{
|
||||
typedef __typeof__(*static_cast<_Tp1*>(NULL)
|
||||
|
@ -286,8 +282,8 @@ template<typename _Tp1, typename _Tp2>
|
|||
{ return __x + __y; }
|
||||
};
|
||||
|
||||
// Partial specialization for one type. Same as std::plus.
|
||||
template<typename _Tp>
|
||||
// Partial specialization for one type. Same as std::plus.
|
||||
template<typename _Tp>
|
||||
struct _Plus<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
|
||||
{
|
||||
typedef __typeof__(*static_cast<_Tp*>(NULL)
|
||||
|
@ -299,8 +295,8 @@ template<typename _Tp>
|
|||
};
|
||||
|
||||
|
||||
/** @brief Similar to std::multiplies, but allows two different types. */
|
||||
template<typename _Tp1, typename _Tp2>
|
||||
/** @brief Similar to std::multiplies, but allows two different types. */
|
||||
template<typename _Tp1, typename _Tp2>
|
||||
struct _Multiplies : public std::binary_function<_Tp1, _Tp2, _Tp1>
|
||||
{
|
||||
typedef __typeof__(*static_cast<_Tp1*>(NULL)
|
||||
|
@ -311,8 +307,8 @@ template<typename _Tp1, typename _Tp2>
|
|||
{ return __x * __y; }
|
||||
};
|
||||
|
||||
// Partial specialization for one type. Same as std::multiplies.
|
||||
template<typename _Tp>
|
||||
// Partial specialization for one type. Same as std::multiplies.
|
||||
template<typename _Tp>
|
||||
struct _Multiplies<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, _Tp>
|
||||
{
|
||||
typedef __typeof__(*static_cast<_Tp*>(NULL)
|
||||
|
@ -324,15 +320,15 @@ template<typename _Tp>
|
|||
};
|
||||
|
||||
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
class _PseudoSequence;
|
||||
|
||||
/** @brief _Iterator associated with __gnu_parallel::_PseudoSequence.
|
||||
/** @brief _Iterator associated with __gnu_parallel::_PseudoSequence.
|
||||
* If features the usual random-access iterator functionality.
|
||||
* @param _Tp Sequence _M_value type.
|
||||
* @param _DifferenceType Sequence difference type.
|
||||
*/
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
class _PseudoSequenceIterator
|
||||
{
|
||||
public:
|
||||
|
@ -343,8 +339,8 @@ template<typename _Tp, typename _DifferenceTp>
|
|||
_DifferenceType _M_pos;
|
||||
|
||||
public:
|
||||
_PseudoSequenceIterator(const _Tp& _M_val, _DifferenceType _M_pos)
|
||||
: _M_val(_M_val), _M_pos(_M_pos) { }
|
||||
_PseudoSequenceIterator(const _Tp& __val, _DifferenceType __pos)
|
||||
: _M_val(__val), _M_pos(__pos) { }
|
||||
|
||||
// Pre-increment operator.
|
||||
_PseudoSequenceIterator&
|
||||
|
@ -380,13 +376,13 @@ template<typename _Tp, typename _DifferenceTp>
|
|||
{ return _M_pos - __i2._M_pos; }
|
||||
};
|
||||
|
||||
/** @brief Sequence that conceptually consists of multiple copies of
|
||||
/** @brief Sequence that conceptually consists of multiple copies of
|
||||
the same element.
|
||||
* The copies are not stored explicitly, of course.
|
||||
* @param _Tp Sequence _M_value type.
|
||||
* @param _DifferenceType Sequence difference type.
|
||||
*/
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
template<typename _Tp, typename _DifferenceTp>
|
||||
class _PseudoSequence
|
||||
{
|
||||
public:
|
||||
|
@ -399,8 +395,8 @@ template<typename _Tp, typename _DifferenceTp>
|
|||
* @param _M_val Element of the sequence.
|
||||
* @param __count Number of (virtual) copies.
|
||||
*/
|
||||
_PseudoSequence(const _Tp& _M_val, _DifferenceType __count)
|
||||
: _M_val(_M_val), __count(__count) { }
|
||||
_PseudoSequence(const _Tp& __val, _DifferenceType __count)
|
||||
: _M_val(__val), _M_count(__count) { }
|
||||
|
||||
/** @brief Begin iterator. */
|
||||
iterator
|
||||
|
@ -410,29 +406,29 @@ template<typename _Tp, typename _DifferenceTp>
|
|||
/** @brief End iterator. */
|
||||
iterator
|
||||
end() const
|
||||
{ return iterator(_M_val, __count); }
|
||||
{ return iterator(_M_val, _M_count); }
|
||||
|
||||
private:
|
||||
const _Tp& _M_val;
|
||||
_DifferenceType __count;
|
||||
_DifferenceType _M_count;
|
||||
};
|
||||
|
||||
/** @brief Functor that does nothing */
|
||||
template<typename _ValueTp>
|
||||
/** @brief Functor that does nothing */
|
||||
template<typename _ValueTp>
|
||||
class _VoidFunctor
|
||||
{
|
||||
inline void
|
||||
operator()(const _ValueTp& __v) const { }
|
||||
};
|
||||
|
||||
/** @brief Compute the median of three referenced elements,
|
||||
/** @brief Compute the median of three referenced elements,
|
||||
according to @__c __comp.
|
||||
* @param __a First iterator.
|
||||
* @param __b Second iterator.
|
||||
* @param __c Third iterator.
|
||||
* @param __comp Comparator.
|
||||
*/
|
||||
template<typename _RAIter, typename _Compare>
|
||||
template<typename _RAIter, typename _Compare>
|
||||
_RAIter
|
||||
__median_of_three_iterators(_RAIter __a, _RAIter __b,
|
||||
_RAIter __c, _Compare& __comp)
|
||||
|
|
|
@ -163,7 +163,8 @@ template<typename _Tp, typename _Compare>
|
|||
*/
|
||||
template<bool __stable/* default == true */, typename _Tp,
|
||||
typename _Compare>
|
||||
class _LoserTree : public _LoserTreeBase<_Tp, _Compare>
|
||||
class _LoserTree
|
||||
: public _LoserTreeBase<_Tp, _Compare>
|
||||
{
|
||||
typedef _LoserTreeBase<_Tp, _Compare> _Base;
|
||||
using _Base::_M_k;
|
||||
|
@ -797,7 +798,7 @@ public:
|
|||
* run empty. This is a very fast variant.
|
||||
*/
|
||||
template<typename _Tp, typename _Compare>
|
||||
class LoserTreePointerUnguardedBase
|
||||
class _LoserTreePointerUnguardedBase
|
||||
{
|
||||
protected:
|
||||
struct _Loser
|
||||
|
@ -812,7 +813,7 @@ template<typename _Tp, typename _Compare>
|
|||
|
||||
public:
|
||||
|
||||
LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
|
||||
_LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
|
||||
_Compare __comp = std::less<_Tp>())
|
||||
: _M_comp(__comp)
|
||||
{
|
||||
|
@ -831,7 +832,7 @@ template<typename _Tp, typename _Compare>
|
|||
}
|
||||
}
|
||||
|
||||
~LoserTreePointerUnguardedBase()
|
||||
~_LoserTreePointerUnguardedBase()
|
||||
{ delete[] _M_losers; }
|
||||
|
||||
int
|
||||
|
@ -861,16 +862,16 @@ template<typename _Tp, typename _Compare>
|
|||
*/
|
||||
template<bool __stable/* default == true */, typename _Tp, typename _Compare>
|
||||
class _LoserTreePointerUnguarded
|
||||
: public LoserTreePointerUnguardedBase<_Tp, _Compare>
|
||||
: public _LoserTreePointerUnguardedBase<_Tp, _Compare>
|
||||
{
|
||||
typedef LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
|
||||
typedef _LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
|
||||
using _Base::_M_k;
|
||||
using _Base::_M_losers;
|
||||
|
||||
public:
|
||||
_LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
|
||||
_Compare __comp = std::less<_Tp>())
|
||||
: _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
|
||||
: _Base::_LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
|
||||
{ }
|
||||
|
||||
unsigned int
|
||||
|
@ -945,16 +946,16 @@ template<bool __stable/* default == true */, typename _Tp, typename _Compare>
|
|||
*/
|
||||
template<typename _Tp, typename _Compare>
|
||||
class _LoserTreePointerUnguarded</* __stable == */false, _Tp, _Compare>
|
||||
: public LoserTreePointerUnguardedBase<_Tp, _Compare>
|
||||
: public _LoserTreePointerUnguardedBase<_Tp, _Compare>
|
||||
{
|
||||
typedef LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
|
||||
typedef _LoserTreePointerUnguardedBase<_Tp, _Compare> _Base;
|
||||
using _Base::_M_k;
|
||||
using _Base::_M_losers;
|
||||
|
||||
public:
|
||||
_LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
|
||||
_Compare __comp = std::less<_Tp>())
|
||||
: _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
|
||||
: _Base::_LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
|
||||
{ }
|
||||
|
||||
unsigned int
|
||||
|
|
|
@ -54,24 +54,6 @@
|
|||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
|
||||
// Announce guarded and unguarded iterator.
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
class _GuardedIterator;
|
||||
|
||||
// Making the arguments const references seems to dangerous,
|
||||
// the user-defined comparator might not be const.
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
operator<(_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2);
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
operator<=(_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2);
|
||||
|
||||
/** @brief _Iterator wrapper supporting an implicit supremum at the end
|
||||
* of the sequence, dominating all comparisons.
|
||||
*
|
||||
|
@ -96,12 +78,11 @@ template<typename _RAIter, typename _Compare>
|
|||
public:
|
||||
/** @brief Constructor. Sets iterator to beginning of sequence.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param _M_end End iterator of sequence.
|
||||
* @param __end End iterator of sequence.
|
||||
* @param __comp Comparator provided for associated overloaded
|
||||
* compare operators. */
|
||||
_GuardedIterator(_RAIter __begin,
|
||||
_RAIter _M_end, _Compare& __comp)
|
||||
: _M_current(__begin), _M_end(_M_end), __comp(__comp)
|
||||
_GuardedIterator(_RAIter __begin, _RAIter __end, _Compare& __comp)
|
||||
: _M_current(__begin), _M_end(__end), __comp(__comp)
|
||||
{ }
|
||||
|
||||
/** @brief Pre-increment operator.
|
||||
|
@ -124,23 +105,11 @@ template<typename _RAIter, typename _Compare>
|
|||
operator _RAIter()
|
||||
{ return _M_current; }
|
||||
|
||||
friend bool
|
||||
operator< <_RAIter, _Compare>(
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2);
|
||||
|
||||
friend bool
|
||||
operator<= <_RAIter, _Compare>(
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2);
|
||||
};
|
||||
|
||||
/** @brief Compare two elements referenced by guarded iterators.
|
||||
/** @brief Compare two elements referenced by guarded iterators.
|
||||
* @param __bi1 First iterator.
|
||||
* @param __bi2 Second iterator.
|
||||
* @return @__c true if less. */
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
friend bool
|
||||
operator<(_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2)
|
||||
{
|
||||
|
@ -151,12 +120,11 @@ template<typename _RAIter, typename _Compare>
|
|||
return (__bi1.__comp)(*__bi1, *__bi2); //normal compare
|
||||
}
|
||||
|
||||
/** @brief Compare two elements referenced by guarded iterators.
|
||||
/** @brief Compare two elements referenced by guarded iterators.
|
||||
* @param __bi1 First iterator.
|
||||
* @param __bi2 Second iterator.
|
||||
* @return @__c True if less equal. */
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
friend bool
|
||||
operator<=(_GuardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_GuardedIterator<_RAIter, _Compare>& __bi2)
|
||||
{
|
||||
|
@ -166,19 +134,7 @@ template<typename _RAIter, typename _Compare>
|
|||
return false;
|
||||
return !(__bi1.__comp)(*__bi2, *__bi1); //normal compare
|
||||
}
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
class _UnguardedIterator;
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
operator<(_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2);
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
operator<=(_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2);
|
||||
};
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
class _UnguardedIterator
|
||||
|
@ -192,10 +148,10 @@ template<typename _RAIter, typename _Compare>
|
|||
public:
|
||||
/** @brief Constructor. Sets iterator to beginning of sequence.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param _M_end Unused, only for compatibility.
|
||||
* @param __end Unused, only for compatibility.
|
||||
* @param __comp Unused, only for compatibility. */
|
||||
_UnguardedIterator(_RAIter __begin,
|
||||
_RAIter _M_end, _Compare& __comp)
|
||||
_RAIter /* __end */, _Compare& __comp)
|
||||
: _M_current(__begin), __comp(__comp)
|
||||
{ }
|
||||
|
||||
|
@ -219,23 +175,11 @@ template<typename _RAIter, typename _Compare>
|
|||
operator _RAIter()
|
||||
{ return _M_current; }
|
||||
|
||||
friend bool
|
||||
operator< <_RAIter, _Compare>(
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2);
|
||||
|
||||
friend bool
|
||||
operator<= <_RAIter, _Compare>(
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2);
|
||||
};
|
||||
|
||||
/** @brief Compare two elements referenced by unguarded iterators.
|
||||
/** @brief Compare two elements referenced by unguarded iterators.
|
||||
* @param __bi1 First iterator.
|
||||
* @param __bi2 Second iterator.
|
||||
* @return @__c true if less. */
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
friend bool
|
||||
operator<(_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2)
|
||||
{
|
||||
|
@ -243,18 +187,18 @@ template<typename _RAIter, typename _Compare>
|
|||
return (__bi1.__comp)(*__bi1, *__bi2);
|
||||
}
|
||||
|
||||
/** @brief Compare two elements referenced by unguarded iterators.
|
||||
/** @brief Compare two elements referenced by unguarded iterators.
|
||||
* @param __bi1 First iterator.
|
||||
* @param __bi2 Second iterator.
|
||||
* @return @__c True if less equal. */
|
||||
template<typename _RAIter, typename _Compare>
|
||||
inline bool
|
||||
friend bool
|
||||
operator<=(_UnguardedIterator<_RAIter, _Compare>& __bi1,
|
||||
_UnguardedIterator<_RAIter, _Compare>& __bi2)
|
||||
{
|
||||
// Normal compare.
|
||||
return !(__bi1.__comp)(*__bi2, *__bi1);
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Highly efficient 3-way merging procedure.
|
||||
*
|
||||
|
@ -287,8 +231,7 @@ template<template<typename RAI, typename C> class iterator,
|
|||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
_RAIter3
|
||||
multiway_merge_3_variant(
|
||||
_RAIterIterator __seqs_begin,
|
||||
multiway_merge_3_variant(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
_DifferenceTp __length, _Compare __comp)
|
||||
|
@ -612,8 +555,7 @@ template<typename _LT,
|
|||
typename _RAIter3,
|
||||
typename _DifferenceTp, typename _Compare>
|
||||
_RAIter3
|
||||
multiway_merge_loser_tree_unguarded(
|
||||
_RAIterIterator __seqs_begin,
|
||||
multiway_merge_loser_tree_unguarded(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
const typename std::iterator_traits<typename std::iterator_traits<
|
||||
|
@ -702,8 +644,7 @@ template<typename UnguardedLoserTree,
|
|||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
_RAIter3
|
||||
multiway_merge_loser_tree_sentinel(
|
||||
_RAIterIterator __seqs_begin,
|
||||
multiway_merge_loser_tree_sentinel(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
const typename std::iterator_traits<typename std::iterator_traits<
|
||||
|
@ -773,8 +714,8 @@ template<typename UnguardedLoserTree,
|
|||
* @param _Tp type to give the loser tree traits for.
|
||||
*/
|
||||
template <typename _Tp>
|
||||
struct _LoserTreeTraits
|
||||
{
|
||||
struct _LoserTreeTraits
|
||||
{
|
||||
/**
|
||||
* @brief True iff to use pointers instead of values in loser trees.
|
||||
*
|
||||
|
@ -782,7 +723,7 @@ struct _LoserTreeTraits
|
|||
* times as big as the pointer to it.
|
||||
*/
|
||||
static const bool _M_use_pointer = (sizeof(_Tp) > 4 * sizeof(_Tp*));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Switch for 3-way merging with __sentinels turned off.
|
||||
|
@ -796,7 +737,8 @@ template<bool __sentinels /*default == false*/,
|
|||
typename _Compare>
|
||||
struct __multiway_merge_3_variant_sentinel_switch
|
||||
{
|
||||
_RAIter3 operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
_DifferenceTp __length, _Compare __comp)
|
||||
|
@ -815,10 +757,12 @@ template<typename _RAIterIterator,
|
|||
typename _RAIter3,
|
||||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
struct __multiway_merge_3_variant_sentinel_switch
|
||||
<true, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
|
||||
struct __multiway_merge_3_variant_sentinel_switch<true, _RAIterIterator,
|
||||
_RAIter3, _DifferenceTp,
|
||||
_Compare>
|
||||
{
|
||||
_RAIter3 operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
_DifferenceTp __length, _Compare __comp)
|
||||
|
@ -840,7 +784,8 @@ template<bool __sentinels /*default == false*/,
|
|||
typename _Compare>
|
||||
struct __multiway_merge_4_variant_sentinel_switch
|
||||
{
|
||||
_RAIter3 operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
_DifferenceTp __length, _Compare __comp)
|
||||
|
@ -859,10 +804,12 @@ template<typename _RAIterIterator,
|
|||
typename _RAIter3,
|
||||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
struct __multiway_merge_4_variant_sentinel_switch
|
||||
<true, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
|
||||
struct __multiway_merge_4_variant_sentinel_switch<true, _RAIterIterator,
|
||||
_RAIter3, _DifferenceTp,
|
||||
_Compare>
|
||||
{
|
||||
_RAIter3 operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
_DifferenceTp __length, _Compare __comp)
|
||||
|
@ -883,8 +830,8 @@ template<bool __sentinels,
|
|||
typename _Compare>
|
||||
struct __multiway_merge_k_variant_sentinel_switch
|
||||
{
|
||||
_RAIter3 operator()
|
||||
(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
const typename std::iterator_traits<typename std::iterator_traits<
|
||||
|
@ -903,8 +850,8 @@ template<bool __sentinels,
|
|||
_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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -916,11 +863,12 @@ template<bool __stable,
|
|||
typename _RAIter3,
|
||||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
struct __multiway_merge_k_variant_sentinel_switch
|
||||
<false, __stable, _RAIterIterator, _RAIter3, _DifferenceTp, _Compare>
|
||||
struct __multiway_merge_k_variant_sentinel_switch<false, __stable,
|
||||
_RAIterIterator, _RAIter3,
|
||||
_DifferenceTp, _Compare>
|
||||
{
|
||||
_RAIter3 operator()
|
||||
(_RAIterIterator __seqs_begin,
|
||||
_RAIter3
|
||||
operator()(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
const typename std::iterator_traits<typename std::iterator_traits<
|
||||
|
@ -963,8 +911,7 @@ template<bool __stable,
|
|||
typename _DifferenceTp,
|
||||
typename _Compare>
|
||||
_RAIter3
|
||||
__sequential_multiway_merge(
|
||||
_RAIterIterator __seqs_begin,
|
||||
__sequential_multiway_merge(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_RAIter3 __target,
|
||||
const typename std::iterator_traits<typename std::iterator_traits<
|
||||
|
@ -1061,8 +1008,8 @@ template<bool __stable,
|
|||
template<bool __stable, class _RAIter, class _StrictWeakOrdering>
|
||||
struct _SamplingSorter
|
||||
{
|
||||
void operator()(_RAIter __first, _RAIter __last,
|
||||
_StrictWeakOrdering __comp)
|
||||
void
|
||||
operator()(_RAIter __first, _RAIter __last, _StrictWeakOrdering __comp)
|
||||
{ __gnu_sequential::stable_sort(__first, __last, __comp); }
|
||||
};
|
||||
|
||||
|
@ -1074,8 +1021,8 @@ template<bool __stable, class _RAIter, class _StrictWeakOrdering>
|
|||
template<class _RAIter, class _StrictWeakOrdering>
|
||||
struct _SamplingSorter<false, _RAIter, _StrictWeakOrdering>
|
||||
{
|
||||
void operator()(_RAIter __first, _RAIter __last,
|
||||
_StrictWeakOrdering __comp)
|
||||
void
|
||||
operator()(_RAIter __first, _RAIter __last, _StrictWeakOrdering __comp)
|
||||
{ __gnu_sequential::sort(__first, __last, __comp); }
|
||||
};
|
||||
|
||||
|
@ -1087,10 +1034,11 @@ template<bool __stable,
|
|||
typename _Compare,
|
||||
typename _DifferenceType>
|
||||
void
|
||||
multiway_merge_sampling_splitting
|
||||
(_RAIterIterator __seqs_begin,
|
||||
multiway_merge_sampling_splitting(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_DifferenceType __length, _DifferenceType __total_length, _Compare __comp,
|
||||
_DifferenceType __length,
|
||||
_DifferenceType __total_length,
|
||||
_Compare __comp,
|
||||
std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
|
||||
{
|
||||
typedef typename std::iterator_traits<_RAIterIterator>
|
||||
|
@ -1168,10 +1116,10 @@ template<bool __stable,
|
|||
typename _Compare,
|
||||
typename _DifferenceType>
|
||||
void
|
||||
multiway_merge_exact_splitting
|
||||
(_RAIterIterator __seqs_begin,
|
||||
multiway_merge_exact_splitting(_RAIterIterator __seqs_begin,
|
||||
_RAIterIterator __seqs_end,
|
||||
_DifferenceType __length, _DifferenceType __total_length,
|
||||
_DifferenceType __length,
|
||||
_DifferenceType __total_length,
|
||||
_Compare __comp,
|
||||
std::vector<std::pair<_DifferenceType, _DifferenceType> > *__pieces)
|
||||
{
|
||||
|
|
|
@ -41,9 +41,8 @@
|
|||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
|
||||
/** @brief Subsequence description. */
|
||||
template<typename _DifferenceTp>
|
||||
/** @brief Subsequence description. */
|
||||
template<typename _DifferenceTp>
|
||||
struct _Piece
|
||||
{
|
||||
typedef _DifferenceTp _DifferenceType;
|
||||
|
@ -55,10 +54,10 @@ template<typename _DifferenceTp>
|
|||
_DifferenceType _M_end;
|
||||
};
|
||||
|
||||
/** @brief Data accessed by all threads.
|
||||
/** @brief Data accessed by all threads.
|
||||
*
|
||||
* PMWMS = parallel multiway mergesort */
|
||||
template<typename _RAIter>
|
||||
template<typename _RAIter>
|
||||
struct _PMWMSSortingData
|
||||
{
|
||||
typedef std::iterator_traits<_RAIter> _TraitsType;
|
||||
|
@ -85,15 +84,15 @@ template<typename _RAIter>
|
|||
|
||||
/** @brief Pieces of data to merge @__c [thread][__sequence] */
|
||||
std::vector<_Piece<_DifferenceType> >* _M_pieces;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Select _M_samples from a sequence.
|
||||
* @param __sd Pointer to algorithm data. _Result will be placed in
|
||||
* @__c __sd->_M_samples.
|
||||
* @param __num_samples Number of _M_samples to select.
|
||||
*/
|
||||
template<typename _RAIter, typename _DifferenceTp>
|
||||
template<typename _RAIter, typename _DifferenceTp>
|
||||
void
|
||||
__determine_samples(_PMWMSSortingData<_RAIter>* __sd,
|
||||
_DifferenceTp __num_samples)
|
||||
|
@ -111,36 +110,36 @@ template<typename _RAIter, typename _DifferenceTp>
|
|||
|
||||
for (_DifferenceType __i = 0; __i < __num_samples; ++__i)
|
||||
::new(&(__sd->_M_samples[__iam * __num_samples + __i]))
|
||||
_ValueType(__sd->_M_source[__sd->_M_starts[__iam] + __es[__i + 1]]);
|
||||
_ValueType(__sd->_M_source[__sd->_M_starts[__iam]
|
||||
+ __es[__i + 1]]);
|
||||
|
||||
delete[] __es;
|
||||
}
|
||||
|
||||
/** @brief Split consistently. */
|
||||
template<bool __exact, typename _RAIter,
|
||||
/** @brief Split consistently. */
|
||||
template<bool __exact, typename _RAIter,
|
||||
typename _Compare, typename _SortingPlacesIterator>
|
||||
struct _SplitConsistently
|
||||
{
|
||||
};
|
||||
{ };
|
||||
|
||||
/** @brief Split by exact splitting. */
|
||||
template<typename _RAIter, typename _Compare,
|
||||
/** @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,
|
||||
void
|
||||
operator()(const _ThreadIndex __iam,
|
||||
_PMWMSSortingData<_RAIter>* __sd,
|
||||
_Compare& __comp,
|
||||
const typename
|
||||
std::iterator_traits<_RAIter>::difference_type
|
||||
__num_samples)
|
||||
const
|
||||
__num_samples) const
|
||||
{
|
||||
# pragma omp barrier
|
||||
|
||||
std::vector<std::pair<_SortingPlacesIterator, _SortingPlacesIterator> >
|
||||
std::vector<std::pair<_SortingPlacesIterator,
|
||||
_SortingPlacesIterator> >
|
||||
seqs(__sd->_M_num_threads);
|
||||
for (_ThreadIndex __s = 0; __s < __sd->_M_num_threads; __s++)
|
||||
seqs[__s] = std::make_pair(__sd->_M_temporary[__s],
|
||||
|
@ -183,20 +182,19 @@ template<typename _RAIter, typename _Compare,
|
|||
}
|
||||
};
|
||||
|
||||
/** @brief Split by sampling. */
|
||||
template<typename _RAIter, typename _Compare,
|
||||
/** @brief Split by sampling. */
|
||||
template<typename _RAIter, typename _Compare,
|
||||
typename _SortingPlacesIterator>
|
||||
struct _SplitConsistently<false, _RAIter, _Compare,
|
||||
_SortingPlacesIterator>
|
||||
{
|
||||
void operator()(
|
||||
const _ThreadIndex __iam,
|
||||
void
|
||||
operator()(const _ThreadIndex __iam,
|
||||
_PMWMSSortingData<_RAIter>* __sd,
|
||||
_Compare& __comp,
|
||||
const typename
|
||||
std::iterator_traits<_RAIter>::difference_type
|
||||
__num_samples)
|
||||
const
|
||||
__num_samples) const
|
||||
{
|
||||
typedef std::iterator_traits<_RAIter> _TraitsType;
|
||||
typedef typename _TraitsType::value_type _ValueType;
|
||||
|
@ -221,7 +219,8 @@ template<typename _RAIter, typename _Compare,
|
|||
__sd->_M_pieces[__iam][__s]._M_begin =
|
||||
std::lower_bound(__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]),
|
||||
__sd->_M_samples[__num_samples * __iam],
|
||||
__comp)
|
||||
- __sd->_M_temporary[__s];
|
||||
|
@ -234,89 +233,82 @@ template<typename _RAIter, typename _Compare,
|
|||
__sd->_M_pieces[__iam][__s]._M_end =
|
||||
std::lower_bound(__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]),
|
||||
__sd->_M_samples[__num_samples * (__iam + 1)],
|
||||
__comp)
|
||||
- __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]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<bool __stable, typename _RAIter, typename _Compare>
|
||||
template<bool __stable, typename _RAIter, typename _Compare>
|
||||
struct __possibly_stable_sort
|
||||
{
|
||||
};
|
||||
{ };
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
template<typename _RAIter, typename _Compare>
|
||||
struct __possibly_stable_sort<true, _RAIter, _Compare>
|
||||
{
|
||||
void operator()(const _RAIter& __begin,
|
||||
const _RAIter& __end, _Compare& __comp) const
|
||||
{
|
||||
__gnu_sequential::stable_sort(__begin, __end, __comp);
|
||||
}
|
||||
{ __gnu_sequential::stable_sort(__begin, __end, __comp); }
|
||||
};
|
||||
|
||||
template<typename _RAIter, typename _Compare>
|
||||
template<typename _RAIter, typename _Compare>
|
||||
struct __possibly_stable_sort<false, _RAIter, _Compare>
|
||||
{
|
||||
void operator()(const _RAIter __begin,
|
||||
const _RAIter __end, _Compare& __comp) const
|
||||
{
|
||||
__gnu_sequential::sort(__begin, __end, __comp);
|
||||
}
|
||||
{ __gnu_sequential::sort(__begin, __end, __comp); }
|
||||
};
|
||||
|
||||
template<bool __stable, typename Seq_RAIter,
|
||||
template<bool __stable, typename Seq_RAIter,
|
||||
typename _RAIter, typename _Compare,
|
||||
typename DiffType>
|
||||
struct __possibly_stable_multiway_merge
|
||||
{
|
||||
};
|
||||
{ };
|
||||
|
||||
template<typename Seq_RAIter, typename _RAIter,
|
||||
typename _Compare, typename DiffType>
|
||||
struct __possibly_stable_multiway_merge
|
||||
<true, Seq_RAIter, _RAIter, _Compare,
|
||||
DiffType>
|
||||
template<typename Seq_RAIter, typename _RAIter,
|
||||
typename _Compare, typename _DiffType>
|
||||
struct __possibly_stable_multiway_merge<true, Seq_RAIter,
|
||||
_RAIter, _Compare, _DiffType>
|
||||
{
|
||||
void operator()(const Seq_RAIter& __seqs_begin,
|
||||
const Seq_RAIter& __seqs_end,
|
||||
const _RAIter& __target,
|
||||
_Compare& __comp,
|
||||
DiffType __length_am) const
|
||||
_DiffType __length_am) const
|
||||
{
|
||||
stable_multiway_merge(__seqs_begin, __seqs_end, __target, __length_am,
|
||||
__comp, sequential_tag());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Seq_RAIter, typename _RAIter,
|
||||
typename _Compare, typename DiffType>
|
||||
struct __possibly_stable_multiway_merge
|
||||
<false, Seq_RAIter, _RAIter, _Compare,
|
||||
DiffType>
|
||||
template<typename Seq_RAIter, typename _RAIter,
|
||||
typename _Compare, typename _DiffType>
|
||||
struct __possibly_stable_multiway_merge<false, Seq_RAIter,
|
||||
_RAIter, _Compare, _DiffType>
|
||||
{
|
||||
void operator()(const Seq_RAIter& __seqs_begin,
|
||||
const Seq_RAIter& __seqs_end,
|
||||
const _RAIter& __target,
|
||||
_Compare& __comp,
|
||||
DiffType __length_am) const
|
||||
_DiffType __length_am) const
|
||||
{
|
||||
multiway_merge(__seqs_begin, __seqs_end, __target, __length_am, __comp,
|
||||
sequential_tag());
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief PMWMS code executed by each thread.
|
||||
/** @brief PMWMS code executed by each thread.
|
||||
* @param __sd Pointer to algorithm data.
|
||||
* @param __comp Comparator.
|
||||
*/
|
||||
template<bool __stable, bool __exact, typename _RAIter,
|
||||
template<bool __stable, bool __exact, typename _RAIter,
|
||||
typename _Compare>
|
||||
void
|
||||
parallel_sort_mwms_pu(_PMWMSSortingData<_RAIter>* __sd,
|
||||
|
@ -337,13 +329,13 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
typedef _ValueType* _SortingPlacesIterator;
|
||||
|
||||
__sd->_M_temporary[__iam] =
|
||||
static_cast<_ValueType*>(
|
||||
::operator new(sizeof(_ValueType) * (__length_local + 1)));
|
||||
static_cast<_ValueType*>(::operator new(sizeof(_ValueType)
|
||||
* (__length_local + 1)));
|
||||
|
||||
// Copy there.
|
||||
std::uninitialized_copy(
|
||||
__sd->_M_source + __sd->_M_starts[__iam],
|
||||
__sd->_M_source + __sd->_M_starts[__iam] + __length_local,
|
||||
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>()
|
||||
|
@ -366,8 +358,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;
|
||||
}
|
||||
|
||||
|
@ -379,8 +371,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);
|
||||
}
|
||||
|
||||
|
@ -398,14 +390,14 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
::operator delete(__sd->_M_temporary[__iam]);
|
||||
}
|
||||
|
||||
/** @brief PMWMS main call.
|
||||
/** @brief PMWMS main call.
|
||||
* @param __begin Begin iterator of sequence.
|
||||
* @param __end End iterator of sequence.
|
||||
* @param __comp Comparator.
|
||||
* @param __n Length of sequence.
|
||||
* @param __num_threads Number of threads to use.
|
||||
*/
|
||||
template<bool __stable, bool __exact, typename _RAIter,
|
||||
template<bool __stable, bool __exact, typename _RAIter,
|
||||
typename _Compare>
|
||||
void
|
||||
parallel_sort_mwms(_RAIter __begin, _RAIter __end,
|
||||
|
@ -447,8 +439,8 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
_DifferenceType __size =
|
||||
(_Settings::get().sort_mwms_oversampling * __num_threads - 1)
|
||||
* __num_threads;
|
||||
__sd._M_samples = static_cast<_ValueType*>(
|
||||
::operator new(__size * sizeof(_ValueType)));
|
||||
__sd._M_samples = static_cast<_ValueType*>
|
||||
(::operator new(__size * sizeof(_ValueType)));
|
||||
}
|
||||
else
|
||||
__sd._M_samples = NULL;
|
||||
|
@ -486,6 +478,7 @@ template<bool __stable, bool __exact, typename _RAIter,
|
|||
delete[] __sd._M_offsets;
|
||||
delete[] __sd._M_pieces;
|
||||
}
|
||||
|
||||
} //namespace __gnu_parallel
|
||||
|
||||
#endif /* _GLIBCXX_PARALLEL_MULTIWAY_MERGESORT_H */
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
/** @brief Embarrassingly parallel algorithm for random access
|
||||
/** @brief Embarrassingly parallel algorithm for random access
|
||||
* iterators, using an OpenMP for loop.
|
||||
*
|
||||
* @param __begin Begin iterator of element sequence.
|
||||
|
@ -58,19 +58,19 @@ namespace __gnu_parallel
|
|||
* 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_omp_loop(
|
||||
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
|
||||
_Result __base, _Result& __output,
|
||||
__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
|
||||
typedef typename std::iterator_traits<_RAIter>::difference_type
|
||||
_DifferenceType;
|
||||
|
||||
_DifferenceType __length = __end - __begin;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
|
||||
/** @brief Embarrassingly parallel algorithm for random access
|
||||
* iterators, using an OpenMP for loop with static scheduling.
|
||||
*
|
||||
|
@ -58,19 +57,20 @@ namespace __gnu_parallel
|
|||
* 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_omp_loop_static(
|
||||
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
|
||||
_Result __base, _Result& __output,
|
||||
__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)
|
||||
{
|
||||
typedef typename
|
||||
std::iterator_traits<_RAIter>::difference_type
|
||||
typedef typename std::iterator_traits<_RAIter>::difference_type
|
||||
_DifferenceType;
|
||||
|
||||
_DifferenceType __length = __end - __begin;
|
||||
|
|
|
@ -40,8 +40,7 @@
|
|||
|
||||
namespace __gnu_parallel
|
||||
{
|
||||
|
||||
/** @brief Embarrassingly parallel algorithm for random access
|
||||
/** @brief Embarrassingly parallel algorithm for random access
|
||||
* iterators, using hand-crafted parallelization by equal splitting
|
||||
* the work.
|
||||
*
|
||||
|
@ -59,14 +58,14 @@ namespace __gnu_parallel
|
|||
* 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_ed(
|
||||
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r,
|
||||
__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)
|
||||
{
|
||||
|
@ -85,8 +84,8 @@ template<typename _RAIter,
|
|||
{
|
||||
__num_threads = omp_get_num_threads();
|
||||
__thread_results =
|
||||
static_cast<_Result*>(
|
||||
::operator new(__num_threads * sizeof(_Result)));
|
||||
static_cast<_Result*>(::operator new(__num_threads
|
||||
* sizeof(_Result)));
|
||||
__constructed = new bool[__num_threads];
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace __gnu_parallel
|
|||
{
|
||||
// Problem: there is no 0-element given.
|
||||
|
||||
/** @brief Base case prefix sum routine.
|
||||
/** @brief Base case prefix sum routine.
|
||||
* @param __begin Begin iterator of input sequence.
|
||||
* @param __end End iterator of input sequence.
|
||||
* @param __result Begin iterator of output sequence.
|
||||
|
@ -51,12 +51,12 @@ namespace __gnu_parallel
|
|||
* @param __value Start value. Must be passed since the neutral
|
||||
* element is unknown in general.
|
||||
* @return End iterator of output sequence. */
|
||||
template<typename _IIter,
|
||||
template<typename _IIter,
|
||||
typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_OutputIterator
|
||||
__parallel_partial_sum_basecase(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
__parallel_partial_sum_basecase(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result,
|
||||
_BinaryOperation __bin_op,
|
||||
typename std::iterator_traits <_IIter>::value_type __value)
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ template<typename _IIter,
|
|||
return __result;
|
||||
}
|
||||
|
||||
/** @brief Parallel partial sum implementation, two-phase approach,
|
||||
/** @brief Parallel partial sum implementation, two-phase approach,
|
||||
no recursion.
|
||||
* @param __begin Begin iterator of input sequence.
|
||||
* @param __end End iterator of input sequence.
|
||||
|
@ -83,12 +83,12 @@ template<typename _IIter,
|
|||
* @param __num_threads Number of threads to use.
|
||||
* @return End iterator of output sequence.
|
||||
*/
|
||||
template<typename _IIter,
|
||||
template<typename _IIter,
|
||||
typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_OutputIterator
|
||||
__parallel_partial_sum_linear(
|
||||
_IIter __begin, _IIter __end, _OutputIterator __result,
|
||||
__parallel_partial_sum_linear(_IIter __begin, _IIter __end,
|
||||
_OutputIterator __result,
|
||||
_BinaryOperation __bin_op,
|
||||
typename std::iterator_traits<_IIter>::difference_type __n)
|
||||
{
|
||||
|
@ -105,8 +105,9 @@ template<typename _IIter,
|
|||
if (__num_threads < 2)
|
||||
{
|
||||
*__result = *__begin;
|
||||
return __parallel_partial_sum_basecase(
|
||||
__begin + 1, __end, __result + 1, __bin_op, *__begin);
|
||||
return __parallel_partial_sum_basecase(__begin + 1, __end,
|
||||
__result + 1, __bin_op,
|
||||
*__begin);
|
||||
}
|
||||
|
||||
_DifferenceType* __borders;
|
||||
|
@ -172,8 +173,7 @@ template<typename _IIter,
|
|||
# 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]);
|
||||
|
@ -185,13 +185,13 @@ template<typename _IIter,
|
|||
return __result + __n;
|
||||
}
|
||||
|
||||
/** @brief Parallel partial sum front-__end.
|
||||
/** @brief Parallel partial sum front-__end.
|
||||
* @param __begin Begin iterator of input sequence.
|
||||
* @param __end End iterator of input sequence.
|
||||
* @param __result Begin iterator of output sequence.
|
||||
* @param __bin_op Associative binary function.
|
||||
* @return End iterator of output sequence. */
|
||||
template<typename _IIter,
|
||||
template<typename _IIter,
|
||||
typename _OutputIterator,
|
||||
typename _BinaryOperation>
|
||||
_OutputIterator
|
||||
|
@ -210,8 +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);
|
||||
|
|
Loading…
Reference in New Issue