This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][libstdc++-v3 parallel mode] PR 42712 search_n serial fallbacks


This patch should fix PR 42712.

Disclaimer: Adding a member to __gnu_parallel::_Settings may change the
library binary.

Tested x86_64-unknown-linux-gnu: some failures as for normal mode;
abi_check fails, just as for unpatched version (rev 156003).
Still okay?

Please approve for mainline.

2010-01-18  Johannes Singler  <singler@kit.edu>

	* include/parallel/settings.h (_Settings): Add search_minimal_n.
	* include/parallel/algo.h (__search_switch):
	Add serial fallback for too small inputs.
	(__search_n_switch): Likewise.  Call serial fallback on higher
        level to gain special treatment for __count 0 or 1.
        * testsuite/25_algorithms/search_n/iterator.cc:
        Reenable full test depth for parallel mode.

Johannes
Index: include/parallel/settings.h
===================================================================
--- include/parallel/settings.h	(revision 156007)
+++ include/parallel/settings.h	(working copy)
@@ -215,6 +215,9 @@
     /// Minimal input size for replace and replace_if.
     _SequenceIndex              replace_minimal_n;
 
+    /// Minimal input size for search and search_n.
+    _SequenceIndex              search_minimal_n;
+
     /// Minimal input size for set_difference.
     _SequenceIndex              set_difference_minimal_n;
 
@@ -312,6 +315,7 @@
             partial_sum_minimal_n(1000),
             random_shuffle_minimal_n(1000),
             replace_minimal_n(1000),
+            search_minimal_n(1000),
             set_difference_minimal_n(1000),
             set_intersection_minimal_n(1000),
             set_symmetric_difference_minimal_n(1000),
Index: include/parallel/algo.h
===================================================================
--- include/parallel/algo.h	(revision 156007)
+++ include/parallel/algo.h	(working copy)
@@ -1043,7 +1043,9 @@
       typedef std::iterator_traits<_RAIter2> _Iterator2Traits;
       typedef typename _Iterator2Traits::value_type _ValueType2;
 
-      if (_GLIBCXX_PARALLEL_CONDITION(true))
+      if (_GLIBCXX_PARALLEL_CONDITION(
+                static_cast<__gnu_parallel::_SequenceIndex>(__end1 - __begin1)
+            >= __gnu_parallel::_Settings::get().search_minimal_n))
         return __gnu_parallel::
           __search_template(
             __begin1, __end1, __begin2, __end2,
@@ -1097,7 +1099,9 @@
                   _BinaryPredicate __pred,
                   random_access_iterator_tag, random_access_iterator_tag)
     {
-      if (_GLIBCXX_PARALLEL_CONDITION(true))
+      if (_GLIBCXX_PARALLEL_CONDITION(
+                static_cast<__gnu_parallel::_SequenceIndex>(__end1 - __begin1)
+            >= __gnu_parallel::_Settings::get().search_minimal_n))
         return __gnu_parallel::__search_template(__begin1, __end1,
                                                __begin2, __end2, __pred);
       else
@@ -1168,15 +1172,17 @@
                       const _Tp& __val, _BinaryPredicate __binary_pred,
                       random_access_iterator_tag)
     {
-      if (_GLIBCXX_PARALLEL_CONDITION(true))
+      if (_GLIBCXX_PARALLEL_CONDITION(
+                static_cast<__gnu_parallel::_SequenceIndex>(__end - __begin)
+            >= __gnu_parallel::_Settings::get().search_minimal_n))
         {
           __gnu_parallel::_PseudoSequence<_Tp, _Integer> __ps(__val, __count);
           return __gnu_parallel::__search_template(
                    __begin, __end, __ps.begin(), __ps.end(), __binary_pred);
         }
       else
-        return std::__search_n(__begin, __end, __count, __val,
-                               __binary_pred, random_access_iterator_tag());
+        return _GLIBCXX_STD_P::search_n(__begin, __end, __count, __val,
+                                        __binary_pred);
     }
 
   // Sequential fallback for input iterator case.
@@ -1186,8 +1192,8 @@
     __search_n_switch(_FIterator __begin, _FIterator __end, _Integer __count,
                       const _Tp& __val, _BinaryPredicate __binary_pred,
                       _IteratorTag)
-    { return __search_n(__begin, __end, __count, __val, __binary_pred,
-                        _IteratorTag()); }
+    { return _GLIBCXX_STD_P::search_n(__begin, __end, __count, __val,
+                                      __binary_pred); }
 
   // Public interface.
   template<typename _FIterator, typename _Integer, typename _Tp,
Index: testsuite/25_algorithms/search_n/iterator.cc
===================================================================
--- testsuite/25_algorithms/search_n/iterator.cc	(revision 156007)
+++ testsuite/25_algorithms/search_n/iterator.cc	(working copy)
@@ -25,11 +25,6 @@
 #include <testsuite_hooks.h>
 #include <testsuite_iterators.h>
 
-// XXX FIXME: why parallel-mode is so slow?
-#if !defined(TEST_DEPTH) && defined(_GLIBCXX_PARALLEL)
-#define TEST_DEPTH 10
-#endif
-
 #ifndef TEST_DEPTH
 #define TEST_DEPTH 14
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]