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]


Fixes two small bugs concerning (partial) sort in parallel mode.

Tested, no regressions on x86_64-unknown-linux-gnu.

Please approve.

2007-11-13  Johannes Singler  <singler@ira.uka.de>

      * include/parallel/multiway_merge.h: More robust finding of an
        arbitrary existing element inside the input sequences.
      * include/bits/stl_algo.h: Fix typo to actually call appropriate
        sequential version.

Johannes
Index: include/parallel/multiway_merge.h
===================================================================
--- include/parallel/multiway_merge.h	(revision 129922)
+++ include/parallel/multiway_merge.h	(working copy)
@@ -900,25 +900,34 @@
     difference_type total_length = 0;
 
     // Default value for potentially non-default-constructible types.
-    value_type* defaultcons = NULL; 
+    value_type* arbitrary_element = NULL;
+
     for (int t = 0; t < k; t++)
       {
-	if (stable)
-	  {
-	    if (seqs_begin[t].first == seqs_begin[t].second)
-	      lt.insert_start_stable(*defaultcons, t, true);
-	    else
-	      lt.insert_start_stable(*seqs_begin[t].first, t, false);
-	  }
-	else
-	  {
-	    if (seqs_begin[t].first == seqs_begin[t].second)
-	      lt.insert_start(*defaultcons, t, true);
-	    else
-	      lt.insert_start(*seqs_begin[t].first, t, false);
-	  }
+        if(arbitrary_element == NULL && LENGTH(seqs_begin[t]) > 0)
+          arbitrary_element = &(*seqs_begin[t].first);
+        total_length += LENGTH(seqs_begin[t]);
+      }
 
-	total_length += LENGTH(seqs_begin[t]);
+    if(total_length == 0)
+      return target;
+
+    for (int t = 0; t < k; t++)
+      {
+        if (stable)
+          {
+            if (seqs_begin[t].first == seqs_begin[t].second)
+              lt.insert_start_stable(*arbitrary_element, t, true);
+            else
+              lt.insert_start_stable(*seqs_begin[t].first, t, false);
+          }
+        else
+          {
+            if (seqs_begin[t].first == seqs_begin[t].second)
+              lt.insert_start(*arbitrary_element, t, true);
+            else
+              lt.insert_start(*seqs_begin[t].first, t, false);
+          }
       }
 
     if (stable)
@@ -941,7 +950,7 @@
 
 	    // Feed.
 	    if (seqs_begin[source].first == seqs_begin[source].second)
-	      lt.delete_min_insert_stable(*defaultcons, true);
+	      lt.delete_min_insert_stable(*arbitrary_element, true);
 	    else
 	      // Replace from same source.
 	      lt.delete_min_insert_stable(*seqs_begin[source].first, false);
@@ -959,7 +968,7 @@
 
 	    // Feed.
 	    if (seqs_begin[source].first == seqs_begin[source].second)
-	      lt.delete_min_insert(*defaultcons, true);
+	      lt.delete_min_insert(*arbitrary_element, true);
 	    else
 	      // Replace from same source.
 	      lt.delete_min_insert(*seqs_begin[source].first, false);
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h	(revision 129922)
+++ include/bits/stl_algo.h	(working copy)
@@ -2028,7 +2028,7 @@
 	{
 	  if (__depth_limit == 0)
 	    {
-	      _GLIBCXX_STD_P:partial_sort(__first, __last, __last);
+	      _GLIBCXX_STD_P::partial_sort(__first, __last, __last);
 	      return;
 	    }
 	  --__depth_limit;


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