algorithmfwd.h: Add parallelism default for many declarations.

2009-02-03  Johannes Singler  <singler@ira.uka.de>

        * include/parallel/algorithmfwd.h:
        Add parallelism default for many declarations.
        * include/parallel/numericfwd.h: Likewise.
        * include/parallel/iterator.h: Use iterator_traits as usual.
        * include/parallel/par_loop.h:
        Include equally_split.h.
        (for_each_template_random_access_ed):
        Avoid calling the Result default constructor.
        * include/parallel/numeric: Replace
        for_each_template_random_access by
        for_each_template_random_access_ed in numeric functions.

From-SVN: r143902
This commit is contained in:
Johannes Singler 2009-02-03 17:49:36 +00:00 committed by Johannes Singler
parent 70f1628747
commit 22ec53ec66
6 changed files with 63 additions and 26 deletions

View File

@ -1,3 +1,17 @@
2009-02-03 Johannes Singler <singler@ira.uka.de>
* include/parallel/algorithmfwd.h:
Add parallelism default for many declarations.
* include/parallel/numericfwd.h: Likewise.
* include/parallel/iterator.h: Use iterator_traits as usual.
* include/parallel/par_loop.h:
Include equally_split.h.
(for_each_template_random_access_ed):
Avoid calling the Result default constructor.
* include/parallel/numeric: Replace
for_each_template_random_access by
for_each_template_random_access_ed in numeric functions.
2009-02-02 Benjamin Kosnik <bkoz@redhat.com> 2009-02-02 Benjamin Kosnik <bkoz@redhat.com>
* config/os/gnu-linux/os_defines.h: Remove superfluous * config/os/gnu-linux/os_defines.h: Remove superfluous

View File

@ -99,7 +99,8 @@ namespace __parallel
template<typename _RAIter, typename _Tp> template<typename _RAIter, typename _Tp>
typename iterator_traits<_RAIter>::difference_type typename iterator_traits<_RAIter>::difference_type
count_switch(_RAIter, _RAIter, const _Tp&, random_access_iterator_tag, count_switch(_RAIter, _RAIter, const _Tp&, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_unbalanced);
template<typename _IIter, typename _Predicate> template<typename _IIter, typename _Predicate>
@ -121,7 +122,8 @@ namespace __parallel
template<typename _RAIter, typename _Predicate> template<typename _RAIter, typename _Predicate>
typename iterator_traits<_RAIter>::difference_type typename iterator_traits<_RAIter>::difference_type
count_if_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag, count_if_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_unbalanced);
// algobase.h // algobase.h
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
@ -228,7 +230,8 @@ namespace __parallel
template<typename _RAIter, typename _Function> template<typename _RAIter, typename _Function>
_Function _Function
for_each_switch(_RAIter, _RAIter, _Function, random_access_iterator_tag, for_each_switch(_RAIter, _RAIter, _Function, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _FIter, typename _Generator> template<typename _FIter, typename _Generator>
@ -250,7 +253,8 @@ namespace __parallel
template<typename _RAIter, typename _Generator> template<typename _RAIter, typename _Generator>
void void
generate_switch(_RAIter, _RAIter, _Generator, random_access_iterator_tag, generate_switch(_RAIter, _RAIter, _Generator, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _OIter, typename _Size, typename _Generator> template<typename _OIter, typename _Size, typename _Generator>
_OIter _OIter
@ -272,7 +276,8 @@ namespace __parallel
template<typename _RAIter, typename _Size, typename _Generator> template<typename _RAIter, typename _Size, typename _Generator>
_RAIter _RAIter
generate_n_switch(_RAIter, _Size, _Generator, random_access_iterator_tag, generate_n_switch(_RAIter, _Size, _Generator, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
bool bool
@ -429,7 +434,8 @@ namespace __parallel
_RAOIter _RAOIter
transform1_switch(_RAIIter, _RAIIter, _RAOIter, UnaryOperation, transform1_switch(_RAIIter, _RAIIter, _RAOIter, UnaryOperation,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter, template<typename _IIter1, typename _IIter2, typename _OIter,
@ -455,7 +461,8 @@ namespace __parallel
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation, transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter, template<typename _IIter1, typename _IIter2, typename _OIter,
typename _BiOperation, typename _Tag1, typename _BiOperation, typename _Tag1,
@ -546,7 +553,8 @@ namespace __parallel
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
_RAIter _RAIter
max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
@ -615,7 +623,8 @@ namespace __parallel
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
_RAIter _RAIter
min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_balanced);
template<typename _RAIter> template<typename _RAIter>
void void

View File

@ -131,7 +131,8 @@ namespace __gnu_parallel
public: public:
typedef IteratorCategory iterator_category; typedef IteratorCategory iterator_category;
typedef void value_type; typedef void value_type;
typedef typename Iterator1::difference_type difference_type; typedef typename std::iterator_traits<Iterator1>::difference_type
difference_type;
typedef type* pointer; typedef type* pointer;
typedef type& reference; typedef type& reference;

View File

@ -103,13 +103,13 @@ namespace __parallel
__gnu_parallel::accumulate_selector<_RandomAccessIterator> __gnu_parallel::accumulate_selector<_RandomAccessIterator>
my_selector; my_selector;
__gnu_parallel:: __gnu_parallel::
for_each_template_random_access(begin, end, for_each_template_random_access_ed(begin, end,
__gnu_parallel::nothing(), __gnu_parallel::nothing(),
my_selector, my_selector,
__gnu_parallel:: __gnu_parallel::
accumulate_binop_reduct accumulate_binop_reduct
<BinaryOperation>(binary_op), <BinaryOperation>(binary_op),
res, res, -1, parallelism_tag); res, res, -1);
return res; return res;
} }
else else
@ -211,9 +211,9 @@ namespace __parallel
inner_product_selector<RandomAccessIterator1, inner_product_selector<RandomAccessIterator1,
RandomAccessIterator2, T> my_selector(first1, first2); RandomAccessIterator2, T> my_selector(first1, first2);
__gnu_parallel:: __gnu_parallel::
for_each_template_random_access(first1, last1, binary_op2, for_each_template_random_access_ed(first1, last1, binary_op2,
my_selector, binary_op1, my_selector, binary_op1,
res, res, -1, parallelism_tag); res, res, -1);
return res; return res;
} }
else else
@ -432,10 +432,10 @@ namespace __parallel
end_pair(end, result + (end - begin)); end_pair(end, result + (end - begin));
__gnu_parallel::adjacent_difference_selector<ip> functionality; __gnu_parallel::adjacent_difference_selector<ip> functionality;
__gnu_parallel:: __gnu_parallel::
for_each_template_random_access(begin_pair, end_pair, bin_op, for_each_template_random_access_ed(begin_pair, end_pair, bin_op,
functionality, functionality,
__gnu_parallel::dummy_reduct(), __gnu_parallel::dummy_reduct(),
dummy, dummy, -1, parallelism_tag); dummy, dummy, -1);
return functionality.finish_iterator; return functionality.finish_iterator;
} }
else else

View File

@ -83,7 +83,8 @@ namespace __parallel
_Tp _Tp
accumulate_switch(_RAIter, _RAIter, _Tp, _BinaryOper, accumulate_switch(_RAIter, _RAIter, _Tp, _BinaryOper,
random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_unbalanced);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
_OIter _OIter
@ -124,7 +125,8 @@ namespace __parallel
adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism parallelism
= __gnu_parallel::parallel_unbalanced);
template<typename _IIter1, typename _IIter2, typename _Tp> template<typename _IIter1, typename _IIter2, typename _Tp>
_Tp _Tp
@ -164,7 +166,8 @@ namespace __parallel
inner_product_switch(_RAIter1, _RAIter1, _RAIter2, _Tp, BinaryFunction1, inner_product_switch(_RAIter1, _RAIter1, _RAIter2, _Tp, BinaryFunction1,
BinaryFunction2, random_access_iterator_tag, BinaryFunction2, random_access_iterator_tag,
random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::_Parallelism); __gnu_parallel::_Parallelism
= __gnu_parallel::parallel_unbalanced);
template<typename _IIter1, typename _IIter2, typename _Tp, template<typename _IIter1, typename _IIter2, typename _Tp,
typename _BinaryFunction1, typename _BinaryFunction2, typename _BinaryFunction1, typename _BinaryFunction2,

View File

@ -42,6 +42,7 @@
#include <omp.h> #include <omp.h>
#include <parallel/settings.h> #include <parallel/settings.h>
#include <parallel/base.h> #include <parallel/base.h>
#include <parallel/equally_split.h>
namespace __gnu_parallel namespace __gnu_parallel
{ {
@ -80,9 +81,9 @@ template<typename RandomAccessIterator,
{ {
typedef std::iterator_traits<RandomAccessIterator> traits_type; typedef std::iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::difference_type difference_type; typedef typename traits_type::difference_type difference_type;
const difference_type length = end - begin; const difference_type length = end - begin;
Result *thread_results; Result *thread_results;
bool* constructed;
thread_index_t num_threads = thread_index_t num_threads =
__gnu_parallel::min<difference_type>(get_max_threads(), length); __gnu_parallel::min<difference_type>(get_max_threads(), length);
@ -92,13 +93,15 @@ template<typename RandomAccessIterator,
# 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 = static_cast<Result*>(
::operator new(num_threads * sizeof(Result)));
constructed = new bool[num_threads];
} }
thread_index_t iam = omp_get_thread_num(); thread_index_t iam = omp_get_thread_num();
// Neutral element. // Neutral element.
Result reduct = Result(); Result* reduct = static_cast<Result*>(::operator new(sizeof(Result)));
difference_type difference_type
start = equally_split_point(length, num_threads, iam), start = equally_split_point(length, num_threads, iam),
@ -106,23 +109,30 @@ template<typename RandomAccessIterator,
if (start < stop) if (start < stop)
{ {
reduct = f(o, begin + start); new(reduct) Result(f(o, begin + start));
++start; ++start;
constructed[iam] = true;
} }
else
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 (thread_index_t i = 0; i < num_threads; ++i) for (thread_index_t i = 0; i < num_threads; ++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.finish_iterator = begin + length; f.finish_iterator = begin + length;
delete[] thread_results;
delete[] constructed;
return o; return o;
} }