public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [v3] libstdc++/33489
@ 2007-10-06 15:31 Benjamin Kosnik
  0 siblings, 0 replies; only message in thread
From: Benjamin Kosnik @ 2007-10-06 15:31 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 353 bytes --]

Here are the low-hanging fixes for this issue. Fixed are nth_element,
set_difference, set_intersection, set_symmetric_difference, set_union.

Remaining are issues all of the form:

 new value_type[num_threads]

Seems like maybe std::vector could be used here...

I'll wait till Monday on this one.

tested x86/linux
tested x86/linux parallel

-benjamin

[-- Attachment #2: p.20071006-2 --]
[-- Type: application/octet-stream, Size: 7073 bytes --]

2007-10-06  Benjamin Kosnik  <bkoz@redhat.com>

	PR libstdc++/33487	
	* include/parallel/multiseq_selection.h: Don't default construct
	value_type.
	* include/parallel/partition.h: Same.
	* include/parallel/partial_sum.h: Format.

Index: include/parallel/multiseq_selection.h
===================================================================
--- include/parallel/multiseq_selection.h	(revision 129054)
+++ include/parallel/multiseq_selection.h	(working copy)
@@ -42,16 +42,15 @@
 
 #include <vector>
 #include <queue>
-
 #include <bits/stl_algo.h>
-
 #include <parallel/sort.h>
 
 namespace __gnu_parallel
 {
   /** @brief Compare a pair of types lexicographically, ascending. */
   template<typename T1, typename T2, typename Comparator>
-  class lexicographic : public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool>
+  class lexicographic 
+  : public std::binary_function<std::pair<T1, T2>, std::pair<T1, T2>, bool>
   {
   private:
     Comparator& comp;
@@ -59,7 +58,6 @@
   public:
     lexicographic(Comparator& _comp) : comp(_comp) { }
 
-    // XXX const
     inline bool
     operator()(const std::pair<T1, T2>& p1, const std::pair<T1, T2>& p2) const
     {
@@ -125,10 +123,10 @@
 
     typedef typename std::iterator_traits<RanSeqs>::value_type::first_type It;
     typedef typename std::iterator_traits<It>::difference_type difference_type;
-    typedef typename std::iterator_traits<It>::value_type T;
+    typedef typename std::iterator_traits<It>::value_type value_type;
 
-    lexicographic<T, int, Comparator> lcomp(comp);
-    lexicographic_reverse<T, int, Comparator> lrcomp(comp);
+    lexicographic<value_type, int, Comparator> lcomp(comp);
+    lexicographic_reverse<value_type, int, Comparator> lrcomp(comp);
 
     // Number of sequences, number of elements in total (possibly
     // including padding).
@@ -181,15 +179,15 @@
 #define S(i) (begin_seqs[i].first)
 
     // Initial partition.
-    std::vector<std::pair<T, int> > sample;
+    std::vector<std::pair<value_type, int> > sample;
 
     for (int i = 0; i < m; i++)
-      if (n < ns[i])	//sequence long enough
+      if (n < ns[i])	// Sequence long enough.
 	sample.push_back(std::make_pair(S(i)[n], i));
     __gnu_sequential::sort(sample.begin(), sample.end(), lcomp);
 
-    for (int i = 0; i < m; i++)	//conceptual infinity
-      if (n >= ns[i])	//sequence too short, conceptual infinity
+    for (int i = 0; i < m; i++)	// Conceptual infinity.
+      if (n >= ns[i])	// Sequence too short, conceptual infinity.
 	sample.push_back(std::make_pair(S(i)[0] /*dummy element*/, i));
 
     difference_type localrank = rank * m / N ;
@@ -206,7 +204,7 @@
 	n /= 2;
 
 	int lmax_seq = -1;	// to avoid warning
-	const T* lmax = NULL;	// impossible to avoid the warning?
+	const value_type* lmax = NULL;	// impossible to avoid the warning?
 	for (int i = 0; i < m; i++)
 	  {
 	    if (a[i] > 0)
@@ -251,7 +249,7 @@
 	if (skew > 0)
 	  {
 	    // Move to the left, find smallest.
-	    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int> >, lexicographic_reverse<T, int, Comparator> > pq(lrcomp);
+	    std::priority_queue<std::pair<value_type, int>, std::vector<std::pair<value_type, int> >, lexicographic_reverse<value_type, int, Comparator> > pq(lrcomp);
 
 	    for (int i = 0; i < m; i++)
 	      if (b[i] < ns[i])
@@ -272,7 +270,7 @@
 	else if (skew < 0)
 	  {
 	    // Move to the right, find greatest.
-	    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int> >, lexicographic<T, int, Comparator> > pq(lcomp);
+	    std::priority_queue<std::pair<value_type, int>, std::vector<std::pair<value_type, int> >, lexicographic<value_type, int, Comparator> > pq(lcomp);
 
 	    for (int i = 0; i < m; i++)
 	      if (a[i] > 0)
@@ -299,10 +297,10 @@
     // Now return the result, calculate the offset.
 
     // Compare the keys on both edges of the border.
-
     // Maximum of left edge, minimum of right edge.
     bool maxleftset = false, minrightset = false;
-    T maxleft, minright;	// Impossible to avoid the warning?
+    value_type maxleft(S(0)[a[0] - 1]);
+    value_type minright(S(0)[b[0]]);
     for (int i = 0; i < m; i++)
       {
 	if (a[i] > 0)
Index: include/parallel/partition.h
===================================================================
--- include/parallel/partition.h	(revision 129054)
+++ include/parallel/partition.h	(working copy)
@@ -70,7 +70,9 @@
 
     // Shared.
     _GLIBCXX_VOLATILE difference_type left = 0, right = n - 1;
-    _GLIBCXX_VOLATILE difference_type leftover_left, leftover_right, leftnew, rightnew;
+    _GLIBCXX_VOLATILE difference_type leftover_left, leftover_right;
+    _GLIBCXX_VOLATILE difference_type leftnew, rightnew;
+
     bool* reserved_left, * reserved_right;
 
     reserved_left = new bool[max_num_threads];
@@ -299,7 +301,8 @@
    */
   template<typename RandomAccessIterator, typename Comparator>
   void 
-  parallel_nth_element(RandomAccessIterator begin, RandomAccessIterator nth, RandomAccessIterator end, Comparator comp)
+  parallel_nth_element(RandomAccessIterator begin, RandomAccessIterator nth, 
+		       RandomAccessIterator end, Comparator comp)
   {
     typedef std::iterator_traits<RandomAccessIterator> traits_type;
     typedef typename traits_type::value_type value_type;
@@ -308,7 +311,6 @@
     _GLIBCXX_CALL(end - begin)
 
     RandomAccessIterator split;
-    value_type pivot;
     random_number rng;
 
     difference_type minimum_length = std::max<difference_type>(2, Settings::partition_minimal_n);
Index: include/parallel/partial_sum.h
===================================================================
--- include/parallel/partial_sum.h	(revision 129054)
+++ include/parallel/partial_sum.h	(working copy)
@@ -128,26 +128,34 @@
       if (id == 0)
 	{
 	  *result = *begin;
-	  parallel_partial_sum_basecase(begin + 1, begin + borders[1], result + 1, bin_op, *begin);
+	  parallel_partial_sum_basecase(begin + 1, begin + borders[1], 
+					result + 1, bin_op, *begin);
 	  sums[0] = *(result + borders[1] - 1);
 	}
       else
 	{
-	  sums[id] = std::accumulate(begin + borders[id] + 1, begin + borders[id + 1], *(begin + borders[id]), bin_op, __gnu_parallel::sequential_tag());
+	  sums[id] = std::accumulate(begin + borders[id] + 1, 
+				     begin + borders[id + 1], 
+				     *(begin + borders[id]), 
+				     bin_op, __gnu_parallel::sequential_tag());
 	}
 
 #pragma omp barrier
 
 #pragma omp single
-      parallel_partial_sum_basecase(sums + 1, sums + num_threads, sums + 1, bin_op, sums[0]);
+      parallel_partial_sum_basecase(sums + 1, sums + num_threads, sums + 1, 
+				    bin_op, sums[0]);
 
 #pragma omp barrier
 
       // Still same team.
-      parallel_partial_sum_basecase(begin + borders[id + 1], begin + borders[id + 2], result + borders[id + 1], bin_op, sums[id]);
+      parallel_partial_sum_basecase(begin + borders[id + 1], 
+				    begin + borders[id + 2], 
+				    result + borders[id + 1], bin_op, 
+				    sums[id]);
     }
 
-    delete[] sums;
+    delete [] sums;
 
     return result + n;
   }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-10-06 15:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-06 15:31 [v3] libstdc++/33489 Benjamin Kosnik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).