Patchwork [libstdc++-v3,parallel,mode] Ambiguities (incl. std::mismatch)

login
register
mail settings
Submitter Johannes Singler
Date Jan. 25, 2011, 6:27 p.m.
Message ID <4D3F1616.1020900@kit.edu>
Download mbox | patch
Permalink /patch/80395/
State New
Headers show

Comments

Johannes Singler - Jan. 25, 2011, 6:27 p.m.
On 01/24/2011 08:05 PM, Paolo Carlini wrote:
> On 01/24/2011 07:45 PM, Johannes Singler wrote:
>> Well, I have an test case that fails to compile with this version
>> (ambiguity), when calling __gnu_parallel::equal (explicitly
>> qualified).  Thus, I propose the attached patch.  Does it still work
>> for you then, François?
> Not a requirement for applying the patch, which is Ok with me if
> Francois doesn't have other comments, but if you could also add that
> testcase it would be great.

I have come to the conclusion that my patch from 2010-03-22 was mostly 
bogus (r157643), and deactivated parallel execution for the affected 
routines in certain cases.  The namespace _GLIBCXX_STD_P always suggests 
"parallel", but it is the very opposite :-(

I have added test cases (for conformance) to existing files since this 
is the problem of mixing implicit and explicit calls to the parallel 
mode again.

Tested x86_64-unknown-linux-gnu: No regressions

Please approve for mainline and gcc-4_5-branch, also waiting for the 
feedback of François.

2011-01-25  Johannes Singler  <singler@kit.edu>

         * include/parallel/numeric (inner_product, partial_sum):
         Qualify subsequent call with __gnu_parallel instead of
         _GLIBCXX_STD_P to reenable parallel execution without ambiguity.
         * include/parallel/algobase.h (equal): Likewise.
         * include/parallel/algo.h (find_first_of, search_n, merge,
         nth_element, partial_sort, max_element, min_element): Likewise.
         * testsuite/25_algorithms/headers/algorithm/
         parallel_algorithm_mixed1.cc (main): Add respective test cases.
         * testsuite/25_algorithms/headers/algorithm/
         parallel_algorithm_mixed2.cc (main): Likewise.
         * testsuite/26_numerics/headers/numeric/
         parallel_numeric_mixed1.cc (main): Likewise.
         * testsuite/26_numerics/headers/numeric/
         parallel_numeric_mixed2.cc (main): Likewise.

Johannes
Paolo Carlini - Jan. 25, 2011, 7:22 p.m.
Hi,
> I have come to the conclusion that my patch from 2010-03-22 was mostly
> bogus (r157643), and deactivated parallel execution for the affected
> routines in certain cases.  The namespace _GLIBCXX_STD_P always
> suggests "parallel", but it is the very opposite :-(
>
> I have added test cases (for conformance) to existing files since this
> is the problem of mixing implicit and explicit calls to the parallel
> mode again.
>
> Tested x86_64-unknown-linux-gnu: No regressions
>
> Please approve for mainline and gcc-4_5-branch, also waiting for the
> feedback of François.
Thanks for sorting out this issue. Patch is Ok for mainline now and in a
week or so for 4_5-branch too, assuming of course you tested both make
check and make check-parallel.

A nit: testcases too should be wrapped to 80 columns.

Thanks again,
Paolo.

Patch

Index: include/parallel/numeric
===================================================================
--- include/parallel/numeric	(revision 169160)
+++ include/parallel/numeric	(working copy)
@@ -283,7 +283,7 @@ 
       typedef typename
         __gnu_parallel::_Multiplies<_ValueType1, _ValueType2>::result_type
         _MultipliesResultType;
-      return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init,
+      return __gnu_parallel::inner_product(__first1, __last1, __first2, __init,
                            __gnu_parallel::_Plus<_Tp, _MultipliesResultType>(),
                            __gnu_parallel::
                            _Multiplies<_ValueType1, _ValueType2>(),
@@ -303,7 +303,7 @@ 
       typedef typename
         __gnu_parallel::_Multiplies<_ValueType1, _ValueType2>::result_type
         _MultipliesResultType;
-      return _GLIBCXX_STD_P::inner_product(__first1, __last1, __first2, __init,
+      return __gnu_parallel::inner_product(__first1, __last1, __first2, __init,
                            __gnu_parallel::_Plus<_Tp, _MultipliesResultType>(),
                            __gnu_parallel::
                            _Multiplies<_ValueType1, _ValueType2>());
@@ -359,7 +359,7 @@ 
     partial_sum(_IIter __begin, _IIter __end, _OutputIterator __result)
     {
       typedef typename iterator_traits<_IIter>::value_type _ValueType;
-      return _GLIBCXX_STD_P::partial_sum(__begin, __end,
+      return __gnu_parallel::partial_sum(__begin, __end,
                                          __result, std::plus<_ValueType>());
     }
 
Index: include/parallel/algobase.h
===================================================================
--- include/parallel/algobase.h	(revision 169160)
+++ include/parallel/algobase.h	(working copy)
@@ -142,7 +142,8 @@ 
     inline bool
     equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2)
     {
-      return mismatch(__begin1, __end1, __begin2).first == __end1;
+      return __gnu_parallel::mismatch(__begin1, __end1, __begin2).first
+              == __end1;
     }
 
   // Public interface
@@ -151,7 +152,8 @@ 
     equal(_IIter1 __begin1, _IIter1 __end1, _IIter2 __begin2, 
           _Predicate __pred)
     {
-      return mismatch(__begin1, __end1, __begin2, __pred).first == __end1;
+      return __gnu_parallel::mismatch(__begin1, __end1, __begin2, __pred).first
+              == __end1;
     }
 
   // Sequential fallback
Index: include/parallel/algo.h
===================================================================
--- include/parallel/algo.h	(revision 169160)
+++ include/parallel/algo.h	(working copy)
@@ -292,7 +292,7 @@ 
       typedef typename _IIterTraits::value_type _IValueType;
       typedef typename iteratorf_traits::value_type _FValueType;
 
-      return _GLIBCXX_STD_P::find_first_of(__begin1, __end1, __begin2, __end2,
+      return __gnu_parallel::find_first_of(__begin1, __end1, __begin2, __end2,
                          __gnu_parallel::_EqualTo<_IValueType, _FValueType>());
     }
 
@@ -1160,7 +1160,7 @@ 
              const _Tp& __val)
     {
       typedef typename iterator_traits<_FIterator>::value_type _ValueType;
-      return _GLIBCXX_STD_P::search_n(__begin, __end, __count, __val,
+      return __gnu_parallel::search_n(__begin, __end, __count, __val,
                       __gnu_parallel::_EqualTo<_ValueType, _Tp>());
     }
 
@@ -2086,7 +2086,7 @@ 
       typedef typename _Iterator1Traits::value_type _ValueType1;
       typedef typename _Iterator2Traits::value_type _ValueType2;
 
-      return _GLIBCXX_STD_P::merge(__begin1, __end1, __begin2, __end2,
+      return __gnu_parallel::merge(__begin1, __end1, __begin2, __end2,
                   __result, __gnu_parallel::_Less<_ValueType1, _ValueType2>());
     }
 
@@ -2128,7 +2128,7 @@ 
     {
       typedef iterator_traits<_RAIter> _TraitsType;
       typedef typename _TraitsType::value_type _ValueType;
-      _GLIBCXX_STD_P::nth_element(__begin, __nth, __end,
+      __gnu_parallel::nth_element(__begin, __nth, __end,
                                   std::less<_ValueType>());
     }
 
@@ -2171,7 +2171,7 @@ 
     {
       typedef iterator_traits<_RAIter> _TraitsType;
       typedef typename _TraitsType::value_type _ValueType;
-      _GLIBCXX_STD_P::partial_sort(__begin, __middle, __end,
+      __gnu_parallel::partial_sort(__begin, __middle, __end,
                                    std::less<_ValueType>());
     }
 
@@ -2241,7 +2241,7 @@ 
     max_element(_FIterator __begin, _FIterator __end)
     {
       typedef typename iterator_traits<_FIterator>::value_type _ValueType;
-      return _GLIBCXX_STD_P::max_element(__begin, __end,
+      return __gnu_parallel::max_element(__begin, __end,
                                          std::less<_ValueType>());
     }
 
@@ -2333,7 +2333,7 @@ 
     min_element(_FIterator __begin, _FIterator __end)
     {
       typedef typename iterator_traits<_FIterator>::value_type _ValueType;
-      return _GLIBCXX_STD_P::min_element(__begin, __end,
+      return __gnu_parallel::min_element(__begin, __end,
                                          std::less<_ValueType>());
     }
 
Index: testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed1.cc
===================================================================
--- testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed1.cc	(revision 169160)
+++ testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed1.cc	(working copy)
@@ -30,7 +30,56 @@ 
   
   const value_type c(0);
 
-  vector_type v(10);
+  vector_type v(10), result(20);
+
+  std::equal(v.begin(), v.end(), v.begin());
+  std::equal(v.begin(), v.end(), v.begin(), std::equal_to<value_type>());
+  __gnu_parallel::equal(v.begin(), v.end(), v.begin());
+  __gnu_parallel::equal(v.begin(), v.end(), v.begin(),
+                                            std::equal_to<value_type>());
+
   std::find(v.begin(), v.end(), c);
   __gnu_parallel::find(v.begin(), v.end(), c);
+
+  std::find_first_of(v.begin(), v.end(), v.begin(), v.end());
+  std::find_first_of(v.begin(), v.end(), v.begin(), v.end(), 
+                                                std::equal_to<value_type>());
+  __gnu_parallel::find_first_of(v.begin(), v.end(), v.begin(), v.end());
+  __gnu_parallel::find_first_of(v.begin(), v.end(), v.begin(), v.end(),
+                                                std::equal_to<value_type>());
+
+  std::search_n(v.begin(), v.end(), 5, value_type(1));
+  std::search_n(v.begin(), v.end(), 5, value_type(1),
+                                                std::equal_to<value_type>());
+  __gnu_parallel::search_n(v.begin(), v.end(), 5, value_type(1));
+  __gnu_parallel::search_n(v.begin(), v.end(), 5, value_type(1),
+                                                std::equal_to<value_type>());
+
+  std::merge(v.begin(), v.end(), v.begin(), v.end(), result.begin());
+  std::merge(v.begin(), v.end(), v.begin(), v.end(), result.begin(),
+                                                std::less<value_type>());
+  __gnu_parallel::merge(v.begin(), v.end(), v.begin(), v.end(),
+                        result.begin());
+  __gnu_parallel::merge(v.begin(), v.end(), v.begin(), v.end(),
+                        result.begin(), std::less<value_type>());
+
+  std::nth_element(v.begin(), v.begin() + 5, v.end());
+  std::nth_element(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+  __gnu_parallel::nth_element(v.begin(), v.begin() + 5, v.end());
+  __gnu_parallel::nth_element(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+
+  std::partial_sort(v.begin(), v.begin() + 5, v.end());
+  std::partial_sort(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+  __gnu_parallel::partial_sort(v.begin(), v.begin() + 5, v.end());
+  __gnu_parallel::partial_sort(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+
+  std::min_element(v.begin(), v.end());
+  std::min_element(v.begin(), v.end(), std::less<value_type>());
+  __gnu_parallel::min_element(v.begin(), v.end());
+  __gnu_parallel::min_element(v.begin(), v.end(), std::less<value_type>());
+
+  std::max_element(v.begin(), v.end());
+  std::max_element(v.begin(), v.end(), std::less<value_type>());
+  __gnu_parallel::max_element(v.begin(), v.end());
+  __gnu_parallel::max_element(v.begin(), v.end(), std::less<value_type>());
 }
Index: testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed2.cc
===================================================================
--- testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed2.cc	(revision 169160)
+++ testsuite/25_algorithms/headers/algorithm/parallel_algorithm_mixed2.cc	(working copy)
@@ -35,7 +35,56 @@ 
   
   const value_type c(0);
 
-  vector_type v(10);
+  vector_type v(10), result(20);
+
+  std::equal(v.begin(), v.end(), v.begin());
+  std::equal(v.begin(), v.end(), v.begin(), std::equal_to<value_type>());
+  __gnu_parallel::equal(v.begin(), v.end(), v.begin());
+  __gnu_parallel::equal(v.begin(), v.end(), v.begin(),
+                                            std::equal_to<value_type>());
+
   std::find(v.begin(), v.end(), c);
   __gnu_parallel::find(v.begin(), v.end(), c);
+
+  std::find_first_of(v.begin(), v.end(), v.begin(), v.end());
+  std::find_first_of(v.begin(), v.end(), v.begin(), v.end(), 
+                                                std::equal_to<value_type>());
+  __gnu_parallel::find_first_of(v.begin(), v.end(), v.begin(), v.end());
+  __gnu_parallel::find_first_of(v.begin(), v.end(), v.begin(), v.end(),
+                                                std::equal_to<value_type>());
+
+  std::search_n(v.begin(), v.end(), 5, value_type(1));
+  std::search_n(v.begin(), v.end(), 5, value_type(1),
+                                                std::equal_to<value_type>());
+  __gnu_parallel::search_n(v.begin(), v.end(), 5, value_type(1));
+  __gnu_parallel::search_n(v.begin(), v.end(), 5, value_type(1),
+                                                std::equal_to<value_type>());
+
+  std::merge(v.begin(), v.end(), v.begin(), v.end(), result.begin());
+  std::merge(v.begin(), v.end(), v.begin(), v.end(), result.begin(),
+                                                std::less<value_type>());
+  __gnu_parallel::merge(v.begin(), v.end(), v.begin(), v.end(),
+                        result.begin());
+  __gnu_parallel::merge(v.begin(), v.end(), v.begin(), v.end(),
+                        result.begin(), std::less<value_type>());
+
+  std::nth_element(v.begin(), v.begin() + 5, v.end());
+  std::nth_element(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+  __gnu_parallel::nth_element(v.begin(), v.begin() + 5, v.end());
+  __gnu_parallel::nth_element(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+
+  std::partial_sort(v.begin(), v.begin() + 5, v.end());
+  std::partial_sort(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+  __gnu_parallel::partial_sort(v.begin(), v.begin() + 5, v.end());
+  __gnu_parallel::partial_sort(v.begin(), v.begin() + 5, v.end(), std::less<value_type>());
+
+  std::min_element(v.begin(), v.end());
+  std::min_element(v.begin(), v.end(), std::less<value_type>());
+  __gnu_parallel::min_element(v.begin(), v.end());
+  __gnu_parallel::min_element(v.begin(), v.end(), std::less<value_type>());
+
+  std::max_element(v.begin(), v.end());
+  std::max_element(v.begin(), v.end(), std::less<value_type>());
+  __gnu_parallel::max_element(v.begin(), v.end());
+  __gnu_parallel::max_element(v.begin(), v.end(), std::less<value_type>());
 }
Index: testsuite/26_numerics/headers/numeric/parallel_numeric_mixed1.cc
===================================================================
--- testsuite/26_numerics/headers/numeric/parallel_numeric_mixed1.cc	(revision 169160)
+++ testsuite/26_numerics/headers/numeric/parallel_numeric_mixed1.cc	(working copy)
@@ -32,6 +32,17 @@ 
   const value_type c(0);
 
   vector_type v(10);
+
   std::accumulate(v.begin(), v.end(), value_type(1));
+  std::accumulate(v.begin(), v.end(), value_type(1), std::plus<value_type>());
   __gnu_parallel::accumulate(v.begin(), v.end(), value_type(1));
+  __gnu_parallel::accumulate(v.begin(), v.end(), value_type(1),
+                                                     std::plus<value_type>());
+
+  std::inner_product(v.begin(), v.end(), v.begin(), value_type(1));
+  std::inner_product(v.begin(), v.end(), v.begin(), value_type(1),
+                     std::multiplies<value_type>(), std::plus<value_type>());
+  __gnu_parallel::inner_product(v.begin(), v.end(), v.begin(), value_type(1));
+  __gnu_parallel::inner_product(v.begin(), v.end(), v.begin(), value_type(1),
+                     std::multiplies<value_type>(), std::plus<value_type>());
 }
Index: testsuite/26_numerics/headers/numeric/parallel_numeric_mixed2.cc
===================================================================
--- testsuite/26_numerics/headers/numeric/parallel_numeric_mixed2.cc	(revision 169160)
+++ testsuite/26_numerics/headers/numeric/parallel_numeric_mixed2.cc	(working copy)
@@ -37,6 +37,17 @@ 
   const value_type c(0);
 
   vector_type v(10);
+
   std::accumulate(v.begin(), v.end(), value_type(1));
+  std::accumulate(v.begin(), v.end(), value_type(1), std::plus<value_type>());
   __gnu_parallel::accumulate(v.begin(), v.end(), value_type(1));
+  __gnu_parallel::accumulate(v.begin(), v.end(), value_type(1),
+                                                     std::plus<value_type>());
+
+  std::inner_product(v.begin(), v.end(), v.begin(), value_type(1));
+  std::inner_product(v.begin(), v.end(), v.begin(), value_type(1),
+                     std::multiplies<value_type>(), std::plus<value_type>());
+  __gnu_parallel::inner_product(v.begin(), v.end(), v.begin(), value_type(1));
+  __gnu_parallel::inner_product(v.begin(), v.end(), v.begin(), value_type(1),
+                     std::multiplies<value_type>(), std::plus<value_type>());
 }