2007-10-06 Benjamin Kosnik 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 #include - #include - #include namespace __gnu_parallel { /** @brief Compare a pair of types lexicographically, ascending. */ template - class lexicographic : public std::binary_function, std::pair, bool> + class lexicographic + : public std::binary_function, std::pair, bool> { private: Comparator& comp; @@ -59,7 +58,6 @@ public: lexicographic(Comparator& _comp) : comp(_comp) { } - // XXX const inline bool operator()(const std::pair& p1, const std::pair& p2) const { @@ -125,10 +123,10 @@ typedef typename std::iterator_traits::value_type::first_type It; typedef typename std::iterator_traits::difference_type difference_type; - typedef typename std::iterator_traits::value_type T; + typedef typename std::iterator_traits::value_type value_type; - lexicographic lcomp(comp); - lexicographic_reverse lrcomp(comp); + lexicographic lcomp(comp); + lexicographic_reverse 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 > sample; + std::vector > 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::vector >, lexicographic_reverse > pq(lrcomp); + std::priority_queue, std::vector >, lexicographic_reverse > 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::vector >, lexicographic > pq(lcomp); + std::priority_queue, std::vector >, lexicographic > 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 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 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(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; }