Commit 338311e5 by Paolo Carlini Committed by Paolo Carlini

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
parent 94086ef6
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> 2009-11-04 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/25_algorithms/fill/5.cc: Move... * testsuite/25_algorithms/fill/5.cc: Move...
......
...@@ -163,7 +163,8 @@ template<typename _Tp, typename _Compare> ...@@ -163,7 +163,8 @@ template<typename _Tp, typename _Compare>
*/ */
template<bool __stable/* default == true */, typename _Tp, template<bool __stable/* default == true */, typename _Tp,
typename _Compare> typename _Compare>
class _LoserTree : public _LoserTreeBase<_Tp, _Compare> class _LoserTree
: public _LoserTreeBase<_Tp, _Compare>
{ {
typedef _LoserTreeBase<_Tp, _Compare> _Base; typedef _LoserTreeBase<_Tp, _Compare> _Base;
using _Base::_M_k; using _Base::_M_k;
...@@ -797,7 +798,7 @@ public: ...@@ -797,7 +798,7 @@ public:
* run empty. This is a very fast variant. * run empty. This is a very fast variant.
*/ */
template<typename _Tp, typename _Compare> template<typename _Tp, typename _Compare>
class LoserTreePointerUnguardedBase class _LoserTreePointerUnguardedBase
{ {
protected: protected:
struct _Loser struct _Loser
...@@ -812,8 +813,8 @@ template<typename _Tp, typename _Compare> ...@@ -812,8 +813,8 @@ template<typename _Tp, typename _Compare>
public: public:
LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel, _LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
_Compare __comp = std::less<_Tp>()) _Compare __comp = std::less<_Tp>())
: _M_comp(__comp) : _M_comp(__comp)
{ {
_M_ik = __k; _M_ik = __k;
...@@ -831,7 +832,7 @@ template<typename _Tp, typename _Compare> ...@@ -831,7 +832,7 @@ template<typename _Tp, typename _Compare>
} }
} }
~LoserTreePointerUnguardedBase() ~_LoserTreePointerUnguardedBase()
{ delete[] _M_losers; } { delete[] _M_losers; }
int int
...@@ -861,16 +862,16 @@ template<typename _Tp, typename _Compare> ...@@ -861,16 +862,16 @@ template<typename _Tp, typename _Compare>
*/ */
template<bool __stable/* default == true */, typename _Tp, typename _Compare> template<bool __stable/* default == true */, typename _Tp, typename _Compare>
class _LoserTreePointerUnguarded 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_k;
using _Base::_M_losers; using _Base::_M_losers;
public: public:
_LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel, _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
_Compare __comp = std::less<_Tp>()) _Compare __comp = std::less<_Tp>())
: _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp) : _Base::_LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
{ } { }
unsigned int unsigned int
...@@ -945,16 +946,16 @@ template<bool __stable/* default == true */, typename _Tp, typename _Compare> ...@@ -945,16 +946,16 @@ template<bool __stable/* default == true */, typename _Tp, typename _Compare>
*/ */
template<typename _Tp, typename _Compare> template<typename _Tp, typename _Compare>
class _LoserTreePointerUnguarded</* __stable == */false, _Tp, _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_k;
using _Base::_M_losers; using _Base::_M_losers;
public: public:
_LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel, _LoserTreePointerUnguarded(unsigned int __k, const _Tp& _sentinel,
_Compare __comp = std::less<_Tp>()) _Compare __comp = std::less<_Tp>())
: _Base::LoserTreePointerUnguardedBase(__k, _sentinel, __comp) : _Base::_LoserTreePointerUnguardedBase(__k, _sentinel, __comp)
{ } { }
unsigned int unsigned int
......
...@@ -41,74 +41,74 @@ ...@@ -41,74 +41,74 @@
namespace __gnu_parallel namespace __gnu_parallel
{ {
/** @brief Embarrassingly parallel algorithm for random access /** @brief Embarrassingly parallel algorithm for random access
* iterators, using an OpenMP for loop. * iterators, using an OpenMP for loop.
* *
* @param __begin Begin iterator of element sequence. * @param __begin Begin iterator of element sequence.
* @param __end End iterator of element sequence. * @param __end End iterator of element sequence.
* @param __o User-supplied functor (comparator, predicate, adding * @param __o User-supplied functor (comparator, predicate, adding
* functor, etc.). * functor, etc.).
* @param __f Functor to "process" an element with __op (depends on * @param __f Functor to "process" an element with __op (depends on
* desired functionality, e. g. for std::for_each(), ...). * desired functionality, e. g. for std::for_each(), ...).
* @param __r Functor to "add" a single __result to the already * @param __r Functor to "add" a single __result to the already
* processed elements (depends on functionality). * processed elements (depends on functionality).
* @param __base Base value for reduction. * @param __base Base value for reduction.
* @param __output Pointer to position where final result is written to * @param __output Pointer to position where final result is written to
* @param __bound Maximum number of elements processed (e. g. for * @param __bound Maximum number of elements processed (e. g. for
* std::count_n()). * std::count_n()).
* @return User-supplied functor (that may contain a part of the result). * @return User-supplied functor (that may contain a part of the result).
*/ */
template<typename _RAIter, template<typename _RAIter,
typename _Op, typename _Op,
typename _Fu, typename _Fu,
typename _Red, typename _Red,
typename _Result> typename _Result>
_Op _Op
__for_each_template_random_access_omp_loop( __for_each_template_random_access_omp_loop(_RAIter __begin, _RAIter __end,
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, _Op __o, _Fu& __f, _Red __r,
_Result __base, _Result& __output, _Result __base,
typename std::iterator_traits<_RAIter>::difference_type __bound) _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;
_DifferenceType __length = __end - __begin; _DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads = _ThreadIndex __num_threads =
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length); __gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
_Result *__thread_results; _Result *__thread_results;
# pragma omp parallel num_threads(__num_threads) # pragma omp parallel num_threads(__num_threads)
{ {
# pragma omp single # pragma omp single
{ {
__num_threads = omp_get_num_threads(); __num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads]; __thread_results = new _Result[__num_threads];
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result(); __thread_results[__i] = _Result();
} }
_ThreadIndex __iam = omp_get_thread_num(); _ThreadIndex __iam = omp_get_thread_num();
#pragma omp for schedule(dynamic, _Settings::get().workstealing_chunk_size) #pragma omp for schedule(dynamic, _Settings::get().workstealing_chunk_size)
for (_DifferenceType __pos = 0; __pos < __length; ++__pos) for (_DifferenceType __pos = 0; __pos < __length; ++__pos)
__thread_results[__iam] = __thread_results[__iam] =
__r(__thread_results[__iam], __f(__o, __begin+__pos)); __r(__thread_results[__iam], __f(__o, __begin+__pos));
} //parallel } //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__output = __r(__output, __thread_results[__i]); __output = __r(__output, __thread_results[__i]);
delete [] __thread_results; delete [] __thread_results;
// Points to last element processed (needed as return value for // Points to last element processed (needed as return value for
// some algorithms like transform). // some algorithms like transform).
__f._M_finish_iterator = __begin + __length; __f._M_finish_iterator = __begin + __length;
return __o; return __o;
} }
} // end namespace } // end namespace
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
namespace __gnu_parallel namespace __gnu_parallel
{ {
/** @brief Embarrassingly parallel algorithm for random access /** @brief Embarrassingly parallel algorithm for random access
* iterators, using an OpenMP for loop with static scheduling. * iterators, using an OpenMP for loop with static scheduling.
* *
...@@ -58,37 +57,38 @@ namespace __gnu_parallel ...@@ -58,37 +57,38 @@ namespace __gnu_parallel
* std::count_n()). * std::count_n()).
* @return User-supplied functor (that may contain a part of the result). * @return User-supplied functor (that may contain a part of the result).
*/ */
template<typename _RAIter, template<typename _RAIter,
typename _Op, typename _Op,
typename _Fu, typename _Fu,
typename _Red, typename _Red,
typename _Result> typename _Result>
_Op _Op
__for_each_template_random_access_omp_loop_static( __for_each_template_random_access_omp_loop_static(_RAIter __begin,
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, _RAIter __end, _Op __o,
_Result __base, _Result& __output, _Fu& __f, _Red __r,
typename std::iterator_traits<_RAIter>::difference_type __bound) _Result __base,
{ _Result& __output,
typedef typename typename std::iterator_traits<_RAIter>::difference_type __bound)
std::iterator_traits<_RAIter>::difference_type {
_DifferenceType; typedef typename std::iterator_traits<_RAIter>::difference_type
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads = _DifferenceType __length = __end - __begin;
std::min<_DifferenceType>(__get_max_threads(), __length); _ThreadIndex __num_threads =
std::min<_DifferenceType>(__get_max_threads(), __length);
_Result *__thread_results;
_Result *__thread_results;
# pragma omp parallel num_threads(__num_threads)
# pragma omp parallel num_threads(__num_threads)
{ {
# pragma omp single # pragma omp single
{ {
__num_threads = omp_get_num_threads(); __num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads]; __thread_results = new _Result[__num_threads];
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result(); __thread_results[__i] = _Result();
} }
_ThreadIndex __iam = omp_get_thread_num(); _ThreadIndex __iam = omp_get_thread_num();
...@@ -98,17 +98,17 @@ template<typename _RAIter, ...@@ -98,17 +98,17 @@ template<typename _RAIter,
__f(__o, __begin+__pos)); __f(__o, __begin+__pos));
} //parallel } //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__output = __r(__output, __thread_results[__i]); __output = __r(__output, __thread_results[__i]);
delete [] __thread_results; delete [] __thread_results;
// Points to last element processed (needed as return value for // Points to last element processed (needed as return value for
// some algorithms like transform). // some algorithms like transform).
__f.finish_iterator = __begin + __length; __f.finish_iterator = __begin + __length;
return __o; return __o;
} }
} // end namespace } // end namespace
......
...@@ -40,94 +40,93 @@ ...@@ -40,94 +40,93 @@
namespace __gnu_parallel 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
* iterators, using hand-crafted parallelization by equal splitting * the work.
* the work. *
* * @param __begin Begin iterator of element sequence.
* @param __begin Begin iterator of element sequence. * @param __end End iterator of element sequence.
* @param __end End iterator of element sequence. * @param __o User-supplied functor (comparator, predicate, adding
* @param __o User-supplied functor (comparator, predicate, adding * functor, ...)
* functor, ...) * @param __f Functor to "process" an element with __op (depends on
* @param __f Functor to "process" an element with __op (depends on * desired functionality, e. g. for std::for_each(), ...).
* desired functionality, e. g. for std::for_each(), ...). * @param __r Functor to "add" a single __result to the already
* @param __r Functor to "add" a single __result to the already * processed elements (depends on functionality).
* processed elements (depends on functionality). * @param __base Base value for reduction.
* @param __base Base value for reduction. * @param __output Pointer to position where final result is written to
* @param __output Pointer to position where final result is written to * @param __bound Maximum number of elements processed (e. g. for
* @param __bound Maximum number of elements processed (e. g. for * std::count_n()).
* std::count_n()). * @return User-supplied functor (that may contain a part of the result).
* @return User-supplied functor (that may contain a part of the result). */
*/ template<typename _RAIter,
template<typename _RAIter, typename _Op,
typename _Op, typename _Fu,
typename _Fu, typename _Red,
typename _Red, typename _Result>
typename _Result> _Op
_Op __for_each_template_random_access_ed(_RAIter __begin, _RAIter __end,
__for_each_template_random_access_ed( _Op __o, _Fu& __f, _Red __r,
_RAIter __begin, _RAIter __end, _Op __o, _Fu& __f, _Red __r, _Result __base, _Result& __output,
_Result __base, _Result& __output, typename std::iterator_traits<_RAIter>::difference_type __bound)
typename std::iterator_traits<_RAIter>::difference_type __bound) {
{ typedef std::iterator_traits<_RAIter> _TraitsType;
typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::difference_type _DifferenceType;
typedef typename _TraitsType::difference_type _DifferenceType; const _DifferenceType __length = __end - __begin;
const _DifferenceType __length = __end - __begin; _Result *__thread_results;
_Result *__thread_results; bool* __constructed;
bool* __constructed;
_ThreadIndex __num_threads =
_ThreadIndex __num_threads = __gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
# pragma omp parallel num_threads(__num_threads)
# pragma omp parallel num_threads(__num_threads)
{ {
# pragma omp single # pragma omp single
{ {
__num_threads = omp_get_num_threads(); __num_threads = omp_get_num_threads();
__thread_results = __thread_results =
static_cast<_Result*>( static_cast<_Result*>(::operator new(__num_threads
::operator new(__num_threads * sizeof(_Result))); * sizeof(_Result)));
__constructed = new bool[__num_threads]; __constructed = new bool[__num_threads];
} }
_ThreadIndex __iam = omp_get_thread_num(); _ThreadIndex __iam = omp_get_thread_num();
// Neutral element. // Neutral element.
_Result* __reduct = _Result* __reduct =
static_cast<_Result*>(::operator new(sizeof(_Result))); static_cast<_Result*>(::operator new(sizeof(_Result)));
_DifferenceType _DifferenceType
__start = equally_split_point(__length, __num_threads, __iam), __start = equally_split_point(__length, __num_threads, __iam),
__stop = equally_split_point(__length, __num_threads, __iam + 1); __stop = equally_split_point(__length, __num_threads, __iam + 1);
if (__start < __stop) if (__start < __stop)
{ {
new(__reduct) _Result(__f(__o, __begin + __start)); new(__reduct) _Result(__f(__o, __begin + __start));
++__start; ++__start;
__constructed[__iam] = true; __constructed[__iam] = true;
} }
else else
__constructed[__iam] = false; __constructed[__iam] = false;
for (; __start < __stop; ++__start) for (; __start < __stop; ++__start)
*__reduct = __r(*__reduct, __f(__o, __begin + __start)); *__reduct = __r(*__reduct, __f(__o, __begin + __start));
__thread_results[__iam] = *__reduct; __thread_results[__iam] = *__reduct;
} //parallel } //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i) for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
if (__constructed[__i]) if (__constructed[__i])
__output = __r(__output, __thread_results[__i]); __output = __r(__output, __thread_results[__i]);
// Points to last element processed (needed as return value for // Points to last element processed (needed as return value for
// some algorithms like transform). // some algorithms like transform).
__f._M_finish_iterator = __begin + __length; __f._M_finish_iterator = __begin + __length;
delete[] __thread_results; delete[] __thread_results;
delete[] __constructed; delete[] __constructed;
return __o; return __o;
} }
} // end namespace } // end namespace
......
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