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>
* testsuite/25_algorithms/fill/5.cc: Move...
......
......@@ -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,8 +813,8 @@ template<typename _Tp, typename _Compare>
public:
LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
_Compare __comp = std::less<_Tp>())
_LoserTreePointerUnguardedBase(unsigned int __k, const _Tp& _sentinel,
_Compare __comp = std::less<_Tp>())
: _M_comp(__comp)
{
_M_ik = __k;
......@@ -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
......
......@@ -41,74 +41,74 @@
namespace __gnu_parallel
{
/** @brief Embarrassingly parallel algorithm for random access
* iterators, using an OpenMP for loop.
*
* @param __begin Begin iterator of element sequence.
* @param __end End iterator of element sequence.
* @param __o User-supplied functor (comparator, predicate, adding
* functor, etc.).
* @param __f Functor to "process" an element with __op (depends on
* desired functionality, e. g. for std::for_each(), ...).
* @param __r Functor to "add" a single __result to the already
* processed elements (depends on functionality).
* @param __base Base value for reduction.
* @param __output Pointer to position where final result is written to
* @param __bound Maximum number of elements processed (e. g. for
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
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,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef typename
std::iterator_traits<_RAIter>::difference_type
/** @brief Embarrassingly parallel algorithm for random access
* iterators, using an OpenMP for loop.
*
* @param __begin Begin iterator of element sequence.
* @param __end End iterator of element sequence.
* @param __o User-supplied functor (comparator, predicate, adding
* functor, etc.).
* @param __f Functor to "process" an element with __op (depends on
* desired functionality, e. g. for std::for_each(), ...).
* @param __r Functor to "add" a single __result to the already
* processed elements (depends on functionality).
* @param __base Base value for reduction.
* @param __output Pointer to position where final result is written to
* @param __bound Maximum number of elements processed (e. g. for
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
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,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef typename std::iterator_traits<_RAIter>::difference_type
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
__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
{
__num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads];
{
__num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads];
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result();
}
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result();
}
_ThreadIndex __iam = omp_get_thread_num();
#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));
__r(__thread_results[__iam], __f(__o, __begin+__pos));
} //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__output = __r(__output, __thread_results[__i]);
delete [] __thread_results;
delete [] __thread_results;
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f._M_finish_iterator = __begin + __length;
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f._M_finish_iterator = __begin + __length;
return __o;
}
return __o;
}
} // end namespace
......
......@@ -40,7 +40,6 @@
namespace __gnu_parallel
{
/** @brief Embarrassingly parallel algorithm for random access
* iterators, using an OpenMP for loop with static scheduling.
*
......@@ -58,37 +57,38 @@ namespace __gnu_parallel
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
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,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef typename
std::iterator_traits<_RAIter>::difference_type
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
std::min<_DifferenceType>(__get_max_threads(), __length);
_Result *__thread_results;
# pragma omp parallel num_threads(__num_threads)
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,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef typename std::iterator_traits<_RAIter>::difference_type
_DifferenceType;
_DifferenceType __length = __end - __begin;
_ThreadIndex __num_threads =
std::min<_DifferenceType>(__get_max_threads(), __length);
_Result *__thread_results;
# pragma omp parallel num_threads(__num_threads)
{
# pragma omp single
{
__num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads];
{
__num_threads = omp_get_num_threads();
__thread_results = new _Result[__num_threads];
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result();
}
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__thread_results[__i] = _Result();
}
_ThreadIndex __iam = omp_get_thread_num();
......@@ -98,17 +98,17 @@ template<typename _RAIter,
__f(__o, __begin+__pos));
} //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__output = __r(__output, __thread_results[__i]);
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
__output = __r(__output, __thread_results[__i]);
delete [] __thread_results;
delete [] __thread_results;
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f.finish_iterator = __begin + __length;
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f.finish_iterator = __begin + __length;
return __o;
}
return __o;
}
} // end namespace
......
......@@ -40,94 +40,93 @@
namespace __gnu_parallel
{
/** @brief Embarrassingly parallel algorithm for random access
* iterators, using hand-crafted parallelization by equal splitting
* the work.
*
* @param __begin Begin iterator of element sequence.
* @param __end End iterator of element sequence.
* @param __o User-supplied functor (comparator, predicate, adding
* functor, ...)
* @param __f Functor to "process" an element with __op (depends on
* desired functionality, e. g. for std::for_each(), ...).
* @param __r Functor to "add" a single __result to the already
* processed elements (depends on functionality).
* @param __base Base value for reduction.
* @param __output Pointer to position where final result is written to
* @param __bound Maximum number of elements processed (e. g. for
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
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,
_Result __base, _Result& __output,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef std::iterator_traits<_RAIter> _TraitsType;
typedef typename _TraitsType::difference_type _DifferenceType;
const _DifferenceType __length = __end - __begin;
_Result *__thread_results;
bool* __constructed;
_ThreadIndex __num_threads =
__gnu_parallel::min<_DifferenceType>(__get_max_threads(), __length);
# pragma omp parallel num_threads(__num_threads)
/** @brief Embarrassingly parallel algorithm for random access
* iterators, using hand-crafted parallelization by equal splitting
* the work.
*
* @param __begin Begin iterator of element sequence.
* @param __end End iterator of element sequence.
* @param __o User-supplied functor (comparator, predicate, adding
* functor, ...)
* @param __f Functor to "process" an element with __op (depends on
* desired functionality, e. g. for std::for_each(), ...).
* @param __r Functor to "add" a single __result to the already
* processed elements (depends on functionality).
* @param __base Base value for reduction.
* @param __output Pointer to position where final result is written to
* @param __bound Maximum number of elements processed (e. g. for
* std::count_n()).
* @return User-supplied functor (that may contain a part of the result).
*/
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,
_Result __base, _Result& __output,
typename std::iterator_traits<_RAIter>::difference_type __bound)
{
typedef std::iterator_traits<_RAIter> _TraitsType;
typedef typename _TraitsType::difference_type _DifferenceType;
const _DifferenceType __length = __end - __begin;
_Result *__thread_results;
bool* __constructed;
_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)));
__constructed = new bool[__num_threads];
}
_ThreadIndex __iam = omp_get_thread_num();
// Neutral element.
_Result* __reduct =
static_cast<_Result*>(::operator new(sizeof(_Result)));
_DifferenceType
__start = equally_split_point(__length, __num_threads, __iam),
__stop = equally_split_point(__length, __num_threads, __iam + 1);
if (__start < __stop)
{
new(__reduct) _Result(__f(__o, __begin + __start));
++__start;
__constructed[__iam] = true;
}
else
__constructed[__iam] = false;
for (; __start < __stop; ++__start)
*__reduct = __r(*__reduct, __f(__o, __begin + __start));
__thread_results[__iam] = *__reduct;
{
__num_threads = omp_get_num_threads();
__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)));
_DifferenceType
__start = equally_split_point(__length, __num_threads, __iam),
__stop = equally_split_point(__length, __num_threads, __iam + 1);
if (__start < __stop)
{
new(__reduct) _Result(__f(__o, __begin + __start));
++__start;
__constructed[__iam] = true;
}
else
__constructed[__iam] = false;
for (; __start < __stop; ++__start)
*__reduct = __r(*__reduct, __f(__o, __begin + __start));
__thread_results[__iam] = *__reduct;
} //parallel
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
if (__constructed[__i])
__output = __r(__output, __thread_results[__i]);
for (_ThreadIndex __i = 0; __i < __num_threads; ++__i)
if (__constructed[__i])
__output = __r(__output, __thread_results[__i]);
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f._M_finish_iterator = __begin + __length;
// Points to last element processed (needed as return value for
// some algorithms like transform).
__f._M_finish_iterator = __begin + __length;
delete[] __thread_results;
delete[] __constructed;
delete[] __thread_results;
delete[] __constructed;
return __o;
}
return __o;
}
} // 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