From c5654e49f04534bf73f90914a20c22f690d6d77c Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Fri, 14 Sep 2007 20:37:25 +0000 Subject: [PATCH] base.h (__gnu_parallel::less): Add partial specialization for one argument. 2007-09-14 Benjamin Kosnik * include/parallel/base.h (__gnu_parallel::less): Add partial specialization for one argument. (__gnu_parallel::less): Add operator. * include/parallel/multiway_merge.h: Use __builtin_alloca. * include/parallel/partial_sum.h: Same. * include/parallel/find.h: Same. From-SVN: r128505 --- libstdc++-v3/ChangeLog | 12 +++++++++- libstdc++-v3/include/parallel/base.h | 24 ++++++++++++++++--- libstdc++-v3/include/parallel/find.h | 4 ++-- .../include/parallel/multiway_merge.h | 5 ++-- libstdc++-v3/include/parallel/partial_sum.h | 2 +- 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ef0c0e12e8a..575055ea692 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,4 +1,14 @@ -2007-09-10 Jonathan Wakely +2007-09-14 Benjamin Kosnik + + * include/parallel/base.h (__gnu_parallel::less): Add partial + specialization for one argument. + (__gnu_parallel::less): Add operator. + + * include/parallel/multiway_merge.h: Use __builtin_alloca. + * include/parallel/partial_sum.h: Same. + * include/parallel/find.h: Same. + +2007-09-14 Jonathan Wakely * include/tr1_impl/boost_shared_ptr.h: (__weak_ptr::lock()): Add missing template argument. diff --git a/libstdc++-v3/include/parallel/base.h b/libstdc++-v3/include/parallel/base.h index 117292ba44b..3074188e232 100644 --- a/libstdc++-v3/include/parallel/base.h +++ b/libstdc++-v3/include/parallel/base.h @@ -163,7 +163,10 @@ namespace __gnu_parallel { return op(value, __x); } }; - /** @brief Similar to std::binder2nd, but giving the argument types explicitly. */ + /** + * @brief Similar to std::binder2nd, but giving the argument types + * explicitly. + */ template class binder2nd : public std::unary_function @@ -192,10 +195,23 @@ namespace __gnu_parallel template struct less : std::binary_function { - bool operator()(const T1& t1, const T2& t2) const + bool + operator()(const T1& t1, const T2& t2) const { return t1 < t2; } + + bool + operator()(const T2& t2, const T1& t1) const + { return t2 < t1; } }; + // Partial specialization for one type. Same as std::less. + template + struct less<_Tp, _Tp> : public std::binary_function<_Tp, _Tp, bool> + { + bool + operator()(const _Tp& __x, const _Tp& __y) const + { return __x < __y; } + }; template class pseudo_sequence; @@ -268,7 +284,9 @@ namespace __gnu_parallel public: typedef _DifferenceTp difference_type; - typedef pseudo_sequence_iterator iterator; //better case down to uint64, than up to _DifferenceTp + + // Better case down to uint64, than up to _DifferenceTp. + typedef pseudo_sequence_iterator iterator; /** @brief Constructor. * @param val Element of the sequence. diff --git a/libstdc++-v3/include/parallel/find.h b/libstdc++-v3/include/parallel/find.h index d3fd1bc2ea0..0dbf119c7bf 100644 --- a/libstdc++-v3/include/parallel/find.h +++ b/libstdc++-v3/include/parallel/find.h @@ -105,8 +105,8 @@ namespace __gnu_parallel const thread_index_t num_threads = get_max_threads(); - // XXX VLA error. - difference_type borders[num_threads + 1]; + difference_type* borders = static_cast(__builtin_alloca(sizeof(difference_type) * (num_threads + 1))); + equally_split(length, num_threads, borders); #pragma omp parallel shared(result) num_threads(num_threads) diff --git a/libstdc++-v3/include/parallel/multiway_merge.h b/libstdc++-v3/include/parallel/multiway_merge.h index cdafacbd7a8..2a6c38a5a4f 100644 --- a/libstdc++-v3/include/parallel/multiway_merge.h +++ b/libstdc++-v3/include/parallel/multiway_merge.h @@ -1457,7 +1457,7 @@ namespace __gnu_parallel copy(seqs_begin, seqs_end, se.begin()); - difference_type borders[num_threads + 1]; + difference_type* borders = static_cast(__builtin_alloca(sizeof(difference_type) * (num_threads + 1))); equally_split(length, num_threads, borders); for (int s = 0; s < (num_threads - 1); s++) @@ -1470,7 +1470,8 @@ namespace __gnu_parallel if (!tight) { offsets[num_threads - 1].resize(k); - multiseq_partition(se.begin(), se.end(), (difference_type)length, + multiseq_partition(se.begin(), se.end(), + difference_type(length), offsets[num_threads - 1].begin(), comp); } } diff --git a/libstdc++-v3/include/parallel/partial_sum.h b/libstdc++-v3/include/parallel/partial_sum.h index 422f2537e86..c5bc9c955a9 100644 --- a/libstdc++-v3/include/parallel/partial_sum.h +++ b/libstdc++-v3/include/parallel/partial_sum.h @@ -103,7 +103,7 @@ namespace __gnu_parallel return parallel_partial_sum_basecase(begin + 1, end, result + 1, bin_op, *begin); } - difference_type* borders = __builtin_alloca(sizeof(difference_type) * (num_threads + 2)); + difference_type* borders = static_cast(__builtin_alloca(sizeof(difference_type) * (num_threads + 2))); if (Settings::partial_sum_dilatation == 1.0f) equally_split(n, num_threads + 1, borders);