aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJohannes Singler <singler@ira.uka.de>2009-02-03 17:49:36 +0000
committerJohannes Singler <singler@gcc.gnu.org>2009-02-03 17:49:36 +0000
commit22ec53ec6654575458e90cb0df6cae65442c91dd (patch)
tree7b9bbb4d6b31fd911b11a1bac14e81c3464cb56d /libstdc++-v3
parent70f1628747fd4ec69fce0e26067e1a42f7b2504a (diff)
downloadgcc-22ec53ec6654575458e90cb0df6cae65442c91dd.zip
gcc-22ec53ec6654575458e90cb0df6cae65442c91dd.tar.gz
gcc-22ec53ec6654575458e90cb0df6cae65442c91dd.tar.bz2
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/parallel/algorithmfwd.h27
-rw-r--r--libstdc++-v3/include/parallel/iterator.h3
-rw-r--r--libstdc++-v3/include/parallel/numeric12
-rw-r--r--libstdc++-v3/include/parallel/numericfwd.h9
-rw-r--r--libstdc++-v3/include/parallel/par_loop.h24
6 files changed, 63 insertions, 26 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index f34742c..ec7aa47 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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>
* config/os/gnu-linux/os_defines.h: Remove superfluous
diff --git a/libstdc++-v3/include/parallel/algorithmfwd.h b/libstdc++-v3/include/parallel/algorithmfwd.h
index 3f386a5..7aed7c7 100644
--- a/libstdc++-v3/include/parallel/algorithmfwd.h
+++ b/libstdc++-v3/include/parallel/algorithmfwd.h
@@ -99,7 +99,8 @@ namespace __parallel
template<typename _RAIter, typename _Tp>
typename iterator_traits<_RAIter>::difference_type
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>
@@ -121,7 +122,8 @@ namespace __parallel
template<typename _RAIter, typename _Predicate>
typename iterator_traits<_RAIter>::difference_type
count_if_switch(_RAIter, _RAIter, _Predicate, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_unbalanced);
// algobase.h
template<typename _IIter1, typename _IIter2>
@@ -228,7 +230,8 @@ namespace __parallel
template<typename _RAIter, typename _Function>
_Function
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>
@@ -250,7 +253,8 @@ namespace __parallel
template<typename _RAIter, typename _Generator>
void
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>
_OIter
@@ -272,7 +276,8 @@ namespace __parallel
template<typename _RAIter, typename _Size, typename _Generator>
_RAIter
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>
bool
@@ -429,7 +434,8 @@ namespace __parallel
_RAOIter
transform1_switch(_RAIIter, _RAIIter, _RAOIter, UnaryOperation,
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,
@@ -455,7 +461,8 @@ namespace __parallel
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation,
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,
typename _BiOperation, typename _Tag1,
@@ -546,7 +553,8 @@ namespace __parallel
template<typename _RAIter, typename _Compare>
_RAIter
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>
@@ -615,7 +623,8 @@ namespace __parallel
template<typename _RAIter, typename _Compare>
_RAIter
min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_balanced);
template<typename _RAIter>
void
diff --git a/libstdc++-v3/include/parallel/iterator.h b/libstdc++-v3/include/parallel/iterator.h
index 7aaafee..95ef844 100644
--- a/libstdc++-v3/include/parallel/iterator.h
+++ b/libstdc++-v3/include/parallel/iterator.h
@@ -131,7 +131,8 @@ namespace __gnu_parallel
public:
typedef IteratorCategory iterator_category;
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& reference;
diff --git a/libstdc++-v3/include/parallel/numeric b/libstdc++-v3/include/parallel/numeric
index 1269c52..8706e3f 100644
--- a/libstdc++-v3/include/parallel/numeric
+++ b/libstdc++-v3/include/parallel/numeric
@@ -103,13 +103,13 @@ namespace __parallel
__gnu_parallel::accumulate_selector<_RandomAccessIterator>
my_selector;
__gnu_parallel::
- for_each_template_random_access(begin, end,
+ for_each_template_random_access_ed(begin, end,
__gnu_parallel::nothing(),
my_selector,
__gnu_parallel::
accumulate_binop_reduct
<BinaryOperation>(binary_op),
- res, res, -1, parallelism_tag);
+ res, res, -1);
return res;
}
else
@@ -211,9 +211,9 @@ namespace __parallel
inner_product_selector<RandomAccessIterator1,
RandomAccessIterator2, T> my_selector(first1, first2);
__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,
- res, res, -1, parallelism_tag);
+ res, res, -1);
return res;
}
else
@@ -432,10 +432,10 @@ namespace __parallel
end_pair(end, result + (end - begin));
__gnu_parallel::adjacent_difference_selector<ip> functionality;
__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,
__gnu_parallel::dummy_reduct(),
- dummy, dummy, -1, parallelism_tag);
+ dummy, dummy, -1);
return functionality.finish_iterator;
}
else
diff --git a/libstdc++-v3/include/parallel/numericfwd.h b/libstdc++-v3/include/parallel/numericfwd.h
index 362725b..b9bbe96 100644
--- a/libstdc++-v3/include/parallel/numericfwd.h
+++ b/libstdc++-v3/include/parallel/numericfwd.h
@@ -83,7 +83,8 @@ namespace __parallel
_Tp
accumulate_switch(_RAIter, _RAIter, _Tp, _BinaryOper,
random_access_iterator_tag,
- __gnu_parallel::_Parallelism);
+ __gnu_parallel::_Parallelism parallelism
+ = __gnu_parallel::parallel_unbalanced);
template<typename _IIter, typename _OIter>
_OIter
@@ -124,7 +125,8 @@ namespace __parallel
adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper,
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>
_Tp
@@ -164,7 +166,8 @@ namespace __parallel
inner_product_switch(_RAIter1, _RAIter1, _RAIter2, _Tp, BinaryFunction1,
BinaryFunction2, 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,
typename _BinaryFunction1, typename _BinaryFunction2,
diff --git a/libstdc++-v3/include/parallel/par_loop.h b/libstdc++-v3/include/parallel/par_loop.h
index c8d2a22..a028ecb 100644
--- a/libstdc++-v3/include/parallel/par_loop.h
+++ b/libstdc++-v3/include/parallel/par_loop.h
@@ -42,6 +42,7 @@
#include <omp.h>
#include <parallel/settings.h>
#include <parallel/base.h>
+#include <parallel/equally_split.h>
namespace __gnu_parallel
{
@@ -80,9 +81,9 @@ template<typename RandomAccessIterator,
{
typedef std::iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::difference_type difference_type;
-
const difference_type length = end - begin;
Result *thread_results;
+ bool* constructed;
thread_index_t num_threads =
__gnu_parallel::min<difference_type>(get_max_threads(), length);
@@ -92,13 +93,15 @@ template<typename RandomAccessIterator,
# pragma omp single
{
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();
// Neutral element.
- Result reduct = Result();
+ Result* reduct = static_cast<Result*>(::operator new(sizeof(Result)));
difference_type
start = equally_split_point(length, num_threads, iam),
@@ -106,23 +109,30 @@ template<typename RandomAccessIterator,
if (start < stop)
{
- reduct = f(o, begin + start);
+ 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));
+ *reduct = r(*reduct, f(o, begin + start));
- thread_results[iam] = reduct;
+ thread_results[iam] = *reduct;
} //parallel
for (thread_index_t i = 0; i < num_threads; ++i)
- output = r(output, thread_results[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.finish_iterator = begin + length;
+ delete[] thread_results;
+ delete[] constructed;
+
return o;
}