Commit f9985df5 by Johannes Singler Committed by Johannes Singler

re PR libstdc++/35588 ([parallel mode] parallel std::sort and bind())

2008-04-07  Johannes Singler  <singler@ira.uka.de>

         * include/parallel/multiway_merge.h:
           Moved decisions to compiletime instead of runtime.
         * include/parallel/losertree.h:
           Removed obsolete variants, added variant that uses pointers
           in the loser tree.
         * include/parallel/types.h:
           Remove obsolete settings options from enum.
         * include/parallel/features.h:
           Remove obsolete compile-time switches.
         * include/parallel/compiletime_settings.h:
           Remove obsolete variant that copies back *after* sorting.
         * include/parallel/tags.h:
           Add one new tag for compile-time switch.
         * include/parallel/merge.h:
           Adapt to changes in multiway_merge.h.
         * include/parallel/multiway_mergesort.h:
           Adapt to changes in multiway_merge.h.
           Factor out splitting variants.
           Remove obsolete variant that copies back *after* sorting.
         * include/parallel/sort.h:
           Adapt to changes in multiway_mergesort.h.
         * testsuite/25_algorithms/sort/35588.cc:
           Added test case from / for PR 35588.

From-SVN: r133975
parent 1d4cd3d0
2008-04-07 Johannes Singler <singler@ira.uka.de>
* include/parallel/multiway_merge.h:
Moved decisions to compiletime instead of runtime.
* include/parallel/losertree.h:
Removed obsolete variants, added variant that uses pointers
in the loser tree.
* include/parallel/types.h:
Remove obsolete settings options from enum.
* include/parallel/features.h:
Remove obsolete compile-time switches.
* include/parallel/compiletime_settings.h:
Remove obsolete variant that copies back *after* sorting.
* include/parallel/tags.h:
Add one new tag for compile-time switch.
* include/parallel/merge.h:
Adapt to changes in multiway_merge.h.
* include/parallel/multiway_mergesort.h:
Adapt to changes in multiway_merge.h.
Factor out splitting variants.
Remove obsolete variant that copies back *after* sorting.
* include/parallel/sort.h:
Adapt to changes in multiway_mergesort.h.
* testsuite/25_algorithms/sort/35588.cc:
Added test case from / for PR 35588.
2008-03-29 Paolo Carlini <pcarlini@suse.de> 2008-03-29 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/35725 PR libstdc++/35725
......
...@@ -73,17 +73,9 @@ ...@@ -73,17 +73,9 @@
* __gnu_parallel::parallel_random_shuffle(). */ * __gnu_parallel::parallel_random_shuffle(). */
#define _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_L1 0 #define _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_L1 0
#endif #endif
#ifndef _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_TLB #ifndef _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_TLB
/** @brief Switch on many _GLIBCXX_PARALLEL_ASSERTions in parallel code. /** @brief Switch on many _GLIBCXX_PARALLEL_ASSERTions in parallel code.
* Consider the size of the TLB for * Consider the size of the TLB for
* __gnu_parallel::parallel_random_shuffle(). */ * __gnu_parallel::parallel_random_shuffle(). */
#define _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_TLB 0 #define _GLIBCXX_RANDOM_SHUFFLE_CONSIDER_TLB 0
#endif #endif
#ifndef _GLIBCXX_MULTIWAY_MERGESORT_COPY_LAST
/** @brief First copy the data, sort it locally, and merge it back
* (0); or copy it back after everything is done (1).
*
* Recommendation: 0 */
#define _GLIBCXX_MULTIWAY_MERGESORT_COPY_LAST 0
#endif
...@@ -61,66 +61,6 @@ ...@@ -61,66 +61,6 @@
#define _GLIBCXX_BAL_QUICKSORT 1 #define _GLIBCXX_BAL_QUICKSORT 1
#endif #endif
#ifndef _GLIBCXX_LOSER_TREE
/** @def _GLIBCXX_LOSER_TREE
* @brief Include guarded (sequences may run empty) loser tree,
* moving objects.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE 1
#endif
#ifndef _GLIBCXX_LOSER_TREE_EXPLICIT
/** @def _GLIBCXX_LOSER_TREE_EXPLICIT
* @brief Include standard loser tree, storing two flags for infimum
* and supremum.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_EXPLICIT 0
#endif
#ifndef _GLIBCXX_LOSER_TREE_REFERENCE
/** @def _GLIBCXX_LOSER_TREE_REFERENCE
* @brief Include some loser tree variant.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_REFERENCE 0
#endif
#ifndef _GLIBCXX_LOSER_TREE_POINTER
/** @def _GLIBCXX_LOSER_TREE_POINTER
* @brief Include some loser tree variant.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_POINTER 1
#endif
#ifndef _GLIBCXX_LOSER_TREE_UNGUARDED
/** @def _GLIBCXX_LOSER_TREE_UNGUARDED
* @brief Include unguarded (sequences must not run empty) loser
* tree, moving objects.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_UNGUARDED 0
#endif
#ifndef _GLIBCXX_LOSER_TREE_POINTER_UNGUARDED
/** @def _GLIBCXX_LOSER_TREE_POINTER_UNGUARDED
* @brief Include some loser tree variant.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_POINTER_UNGUARDED 1
#endif
#ifndef _GLIBCXX_LOSER_TREE_COMBINED
/** @def _GLIBCXX_LOSER_TREE_COMBINED
* @brief Include some loser tree variant.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_COMBINED 0
#endif
#ifndef _GLIBCXX_LOSER_TREE_SENTINEL
/** @def _GLIBCXX_LOSER_TREE_SENTINEL
* @brief Include some loser tree variant.
* @see __gnu_parallel::_Settings multiway_merge_algorithm */
#define _GLIBCXX_LOSER_TREE_SENTINEL 0
#endif
#ifndef _GLIBCXX_FIND_GROWING_BLOCKS #ifndef _GLIBCXX_FIND_GROWING_BLOCKS
/** @brief Include the growing blocks variant for std::find. /** @brief Include the growing blocks variant for std::find.
* @see __gnu_parallel::_Settings::find_algorithm */ * @see __gnu_parallel::_Settings::find_algorithm */
......
...@@ -239,19 +239,26 @@ namespace __gnu_parallel ...@@ -239,19 +239,26 @@ namespace __gnu_parallel
std::iterator_traits<RandomAccessIterator1>:: std::iterator_traits<RandomAccessIterator1>::
difference_type max_length, Comparator comp) difference_type max_length, Comparator comp)
{ {
typedef typename std::iterator_traits<RandomAccessIterator1>::value_type typedef typename
value_type; std::iterator_traits<RandomAccessIterator1>::value_type value_type;
typedef typename std::iterator_traits<RandomAccessIterator1>:: typedef typename std::iterator_traits<RandomAccessIterator1>::
difference_type difference_type1 /* == difference_type2 */; difference_type difference_type1 /* == difference_type2 */;
typedef typename std::iterator_traits<RandomAccessIterator3>:: typedef typename std::iterator_traits<RandomAccessIterator3>::
difference_type difference_type3; difference_type difference_type3;
typedef typename std::pair<RandomAccessIterator1, RandomAccessIterator1>
iterator_pair;
std::pair<RandomAccessIterator1, RandomAccessIterator1> std::pair<RandomAccessIterator1, RandomAccessIterator1>
seqs[2] = { std::make_pair(begin1, end1), seqs[2] = { std::make_pair(begin1, end1),
std::make_pair(begin2, end2) }; std::make_pair(begin2, end2) };
RandomAccessIterator3 RandomAccessIterator3
target_end = parallel_multiway_merge(seqs, seqs + 2, target, target_end = parallel_multiway_merge
comp, max_length, true, false); < /* stable = */ true, /* sentinels = */ false>(
seqs, seqs + 2, target, comp,
multiway_merge_exact_splitting
< /* stable = */ true, iterator_pair*,
Comparator, difference_type1>,
max_length);
return target_end; return target_end;
} }
......
...@@ -71,7 +71,7 @@ namespace __gnu_parallel ...@@ -71,7 +71,7 @@ namespace __gnu_parallel
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void inline void
parallel_sort(RandomAccessIterator begin, RandomAccessIterator end, parallel_sort(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, bool stable) Comparator comp, bool stable)
{ {
_GLIBCXX_CALL(end - begin) _GLIBCXX_CALL(end - begin)
typedef std::iterator_traits<RandomAccessIterator> traits_type; typedef std::iterator_traits<RandomAccessIterator> traits_type;
...@@ -79,25 +79,43 @@ namespace __gnu_parallel ...@@ -79,25 +79,43 @@ namespace __gnu_parallel
typedef typename traits_type::difference_type difference_type; typedef typename traits_type::difference_type difference_type;
if (begin != end) if (begin != end)
{ {
difference_type n = end - begin; difference_type n = end - begin;
if (false) ; if (false) ;
#if _GLIBCXX_MERGESORT #if _GLIBCXX_MERGESORT
else if (stable || _Settings::get().sort_algorithm == MWMS) else if (stable)
parallel_sort_mwms(begin, end, comp, n, get_max_threads(), stable); {
if(_Settings::get().sort_splitting == EXACT)
parallel_sort_mwms<true, true>
(begin, end, comp, get_max_threads());
else
parallel_sort_mwms<true, false>
(begin, end, comp, get_max_threads());
}
else if (_Settings::get().sort_algorithm == MWMS)
{
if(_Settings::get().sort_splitting == EXACT)
parallel_sort_mwms<false, true>
(begin, end, comp, get_max_threads());
else
parallel_sort_mwms<false, false>
(begin, end, comp, get_max_threads());
}
#endif #endif
#if _GLIBCXX_QUICKSORT #if _GLIBCXX_QUICKSORT
else if (!stable && _Settings::get().sort_algorithm == QS) else if (!stable && _Settings::get().sort_algorithm == QS)
parallel_sort_qs(begin, end, comp, n, get_max_threads()); parallel_sort_qs(begin, end, comp, n, get_max_threads());
#endif #endif
#if _GLIBCXX_BAL_QUICKSORT #if _GLIBCXX_BAL_QUICKSORT
else if (!stable && _Settings::get().sort_algorithm == QS_BALANCED) else if (!stable && _Settings::get().sort_algorithm == QS_BALANCED)
parallel_sort_qsb(begin, end, comp, n, get_max_threads()); parallel_sort_qsb(begin, end, comp, n, get_max_threads());
#endif #endif
else else if(stable)
__gnu_sequential::sort(begin, end, comp); __gnu_sequential::stable_sort(begin, end, comp);
} else
__gnu_sequential::sort(begin, end, comp);
}
} }
} // end namespace __gnu_parallel } // end namespace __gnu_parallel
......
...@@ -44,6 +44,9 @@ namespace __gnu_parallel ...@@ -44,6 +44,9 @@ namespace __gnu_parallel
/** @brief Forces sequential execution at compile time. */ /** @brief Forces sequential execution at compile time. */
struct sequential_tag { }; struct sequential_tag { };
/** @brief Forces exact splitting in multiway merge at compile time. */
struct exact_tag { };
/** @brief Recommends parallel execution at compile time. */ /** @brief Recommends parallel execution at compile time. */
struct parallel_tag { }; struct parallel_tag { };
......
...@@ -87,15 +87,10 @@ namespace __gnu_parallel ...@@ -87,15 +87,10 @@ namespace __gnu_parallel
/// Merging algorithms: /// Merging algorithms:
// bubblesort-alike, loser-tree variants, enum sentinel. // bubblesort-alike, loser-tree variants, enum sentinel.
enum _MultiwayMergeAlgorithm enum _MultiwayMergeAlgorithm
{ {
BUBBLE, LOSER_TREE
LOSER_TREE_EXPLICIT,
LOSER_TREE,
LOSER_TREE_COMBINED,
LOSER_TREE_SENTINEL,
ENUM_SENTINEL
}; };
/// Partial sum algorithms: recursive, linear. /// Partial sum algorithms: recursive, linear.
enum _PartialSumAlgorithm enum _PartialSumAlgorithm
{ {
......
// Copyright (C) 2008 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
#include <algorithm>
#include <functional>
#include <tr1/functional>
// libstdc++/35588
int main()
{
using namespace std;
using namespace tr1;
using namespace placeholders;
int t[10];
sort(t, t+10, bind(less<int>(), _1, _2));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment