Commit 6f95a65a by Benjamin Kosnik Committed by Benjamin Kosnik

re PR libstdc++/33487 (parallel v3: more functions not in right namespace)

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

	PR libstdc++/33487
	* include/parallel/algorithmfwd.h (for_each, generate, generate_n,
	transform, replace, replace_if, max_element, min_element, count,
	count_if): Consistently construct overloads.
	* include/parallel/numericfwd.h (accumulate, adjacent_difference,
	inner_product): Same.
	* include/parallel/algobase.h: Same.
	* include/parallel/algo.h: Same.
	* include/parallel/numeric: Same.

	* include/bits/algorithmfwd.h: Correct find_end placement.

	* docs/html/parallel_mode.html: Document some of the interface
	conventions.

	* include/parallel/search.h (calc_borders): Only use operator ==.
	
	* include/parallel/algorithmfwd.h: Move __gnu_sequential bits to...
	* include/parallel/tags.h: ...here, and use a using directive.

	* include/parallel/random_shuffle.h: Include stl_numeric. Qualify
	uses of partial_num with __gnu_sequential.

	* include/parallel/tree.h: Formatting.

From-SVN: r129054
parent a0689cdf
2007-10-06 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/33487
* include/parallel/algorithmfwd.h (for_each, generate, generate_n,
transform, replace, replace_if, max_element, min_element, count,
count_if): Consistently construct overloads.
* include/parallel/numericfwd.h (accumulate, adjacent_difference,
inner_product): Same.
* include/parallel/algobase.h: Same.
* include/parallel/algo.h: Same.
* include/parallel/numeric: Same.
* include/bits/algorithmfwd.h: Correct find_end placement.
* docs/html/parallel_mode.html: Document some of the interface
conventions.
* include/parallel/search.h (calc_borders): Only use operator ==.
* include/parallel/algorithmfwd.h: Move __gnu_sequential bits to...
* include/parallel/tags.h: ...here, and use a using directive.
* include/parallel/random_shuffle.h: Include stl_numeric. Qualify
uses of partial_num with __gnu_sequential.
* include/parallel/tree.h: Formatting.
2007-10-05 Benjamin Kosnik <bkoz@redhat.com> 2007-10-05 Benjamin Kosnik <bkoz@redhat.com>
Fixes for --disable-libstdcxx-pch. Fixes for --disable-libstdcxx-pch.
......
...@@ -388,26 +388,109 @@ computing.</p> ...@@ -388,26 +388,109 @@ computing.</p>
<p> Something about compile-time settings and configuration, ie using <p> Something about compile-time settings and configuration, ie using
<code>__gnu_parallel::Settings</code>. XXX Up in the air.</p> <code>__gnu_parallel::Settings</code>. XXX Up in the air.</p>
<h4 class="left">Interface basics and relevant namespaces</h4> <h4 class="left">Interface basics and general design</h4>
<p>All parallel algorithms are intended to have signatures that are
equivalent to the ISO C++ algorithms replaced. For instance, the
<code>std::adjacent_find</code> function is declared as:
<pre>
namespace std
{
template&lt;typename _FIter&gt;
_FIter
adjacent_find(_FIter, _FIter);
}
</pre>
Which means that there should be something equivalent for the parallel
version. Indeed, this is the case:
<pre>
namespace std
{
namespace __parallel
{
template&lt;typename _FIter&gt;
_FIter
adjacent_find(_FIter, _FIter);
...
}
}
</pre>
<p>But.... why the elipses?
</p>
<p> Two namespaces contain the parallel mode: <p> The elipses in the example above represent additional overloads
<code>std::__parallel</code> and <code>__gnu_parallel</code>. required for the parallel version of the function. These additional
overloads are used to dispatch calls from the ISO C++ function
signature to the appropriate parallel function (or sequential
function, if no parallel functions are deemed worthy), based on either
compile-time or run-time conditions.
</p>
<p> Compile-time conditions are referred to as "embarrassingly
parallel," and are denoted with the appropriate dispatch object, ie
one of <code>__gnu_parallel::sequential_tag</code>,
<code>__gnu_parallel::parallel_tag</code>,
<code>__gnu_parallel::balanced_tag</code>,
<code>__gnu_parallel::unbalanced_tag</code>,
<code>__gnu_parallel::omp_loop_tag</code>, or
<code>__gnu_parallel::omp_loop_static_tag</code>.
</p> </p>
<p> Run-time conditions depend on the hardware being used, the number
of threads available, etc., and are denoted by the use of the enum
<code>__gnu_parallel::parallelism</code>. Values of this enum include
<code>__gnu_parallel::sequential</code>,
<code>__gnu_parallel::parallel_unbalanced</code>,
<code>__gnu_parallel::parallel_balanced</code>,
<code>__gnu_parallel::parallel_omp_loop</code>,
<code>__gnu_parallel::parallel_omp_loop_static</code>, or
<code>__gnu_parallel::parallel_taskqueue</code>.
</p>
<p> Putting all this together, the general view of overloads for the
parallel algorithms look like this:
<p>
<ul>
<li>ISO C++ signature</li>
<li>ISO C++ signature + sequential_tag argument</li>
<li>ISO C++ signature + parallelism argument</li>
</ul>
<p> Please note that the implementation may use additional functions
(designated with the <code>_switch</code> suffix) to dispatch from the
ISO C++ signature to the correct parallel version. Also, some of the
algorithms do not have support for run-time conditions, so the last
overload is therefore missing.
</p>
<h4 class="left">Relevant namespaces</h4>
<p> One namespace contain versions of code that are explicitly sequential: <p> One namespace contain versions of code that are explicitly sequential:
<code>__gnu_serial</code>. <code>__gnu_serial</code>.
</p> </p>
<p> Parallel implementations of the sequential standard components are <p> Two namespaces contain the parallel mode:
defined in <code>namespace std::__parallel</code>. For instance, <code>std::__parallel</code> and <code>__gnu_parallel</code>.
<code>std::transform</code> from &lt;algorithm&gt; has a parallel </p>
counterpart in <code>std::__parallel::transform</code> from
<p> Parallel implementations of standard components, including
template helpers to select parallelism, are defined in <code>namespace
std::__parallel</code>. For instance, <code>std::transform</code> from
&lt;algorithm&gt; has a parallel counterpart in
<code>std::__parallel::transform</code> from
&lt;parallel/algorithm&gt;. In addition, these parallel &lt;parallel/algorithm&gt;. In addition, these parallel
implementatations are injected into <code>namespace implementatations are injected into <code>namespace
__gnu_parallel</code> with using declarations. __gnu_parallel</code> with using declarations.
</p> </p>
<p> Support and infrastructure is in <code>namespace __gnu_parallel</code>. <p> Support and general infrastructure is in <code>namespace
__gnu_parallel</code>.
</p> </p>
<p> More information, and an organized index of types and functions <p> More information, and an organized index of types and functions
......
...@@ -148,7 +148,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -148,7 +148,15 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
fill_n(_OIter, _Size, const _Tp&); fill_n(_OIter, _Size, const _Tp&);
// find // find
// find_end
template<typename _FIter1, typename _FIter2>
_FIter1
find_end(_FIter1, _FIter1, _FIter2, _FIter2);
template<typename _FIter1, typename _FIter2, typename _BinaryPredicate>
_FIter1
find_end(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);
// find_first_of // find_first_of
// find_if // find_if
// for_each // for_each
...@@ -391,14 +399,6 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) ...@@ -391,14 +399,6 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
template<typename _FIter1, typename _FIter2> template<typename _FIter1, typename _FIter2>
_FIter1 _FIter1
find_end(_FIter1, _FIter1, _FIter2, _FIter2);
template<typename _FIter1, typename _FIter2, typename _BinaryPredicate>
_FIter1
find_end(_FIter1, _FIter1, _FIter2, _FIter2, _BinaryPredicate);
template<typename _FIter1, typename _FIter2>
_FIter1
find_first_of(_FIter1, _FIter1, _FIter2, _FIter2); find_first_of(_FIter1, _FIter1, _FIter2, _FIter2);
template<typename _FIter1, typename _FIter2, typename _BinaryPredicate> template<typename _FIter1, typename _FIter2, typename _BinaryPredicate>
......
...@@ -71,23 +71,24 @@ namespace __parallel ...@@ -71,23 +71,24 @@ namespace __parallel
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename Function> template<typename InputIterator, typename Function>
inline Function inline Function
for_each(InputIterator begin, InputIterator end, Function f, __gnu_parallel::sequential_tag) for_each(InputIterator begin, InputIterator end, Function f,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::for_each<InputIterator, Function>(begin, end, f); { return _GLIBCXX_STD_P::for_each(begin, end, f); }
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator, typename Function, typename IteratorTag> template<typename InputIterator, typename Function, typename IteratorTag>
Function Function
for_each_switch(InputIterator begin, InputIterator end, Function f, IteratorTag, __gnu_parallel::parallelism parallelism_tag) for_each_switch(InputIterator begin, InputIterator end, Function f,
{ IteratorTag)
return for_each<InputIterator, Function>(begin, end, f, __gnu_parallel::sequential_tag()); { return for_each(begin, end, f, __gnu_parallel::sequential_tag()); }
}
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator, typename Function> template<typename RandomAccessIterator, typename Function>
Function Function
for_each_switch(RandomAccessIterator begin, RandomAccessIterator end, Function f, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) for_each_switch(RandomAccessIterator begin, RandomAccessIterator end,
Function f, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::for_each_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::for_each_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -96,26 +97,37 @@ namespace __parallel ...@@ -96,26 +97,37 @@ namespace __parallel
return __gnu_parallel::for_each_template_random_access(begin, end, f, functionality, __gnu_parallel::dummy_reduct(), true, dummy, -1, parallelism_tag); return __gnu_parallel::for_each_template_random_access(begin, end, f, functionality, __gnu_parallel::dummy_reduct(), true, dummy, -1, parallelism_tag);
} }
else else
return for_each<RandomAccessIterator, Function>(begin, end, f, __gnu_parallel::sequential_tag()); return for_each(begin, end, f, __gnu_parallel::sequential_tag());
} }
// Public interface // Public interface
template<typename Iterator, typename Function> template<typename Iterator, typename Function>
inline Function inline Function
for_each(Iterator begin, Iterator end, Function f, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) for_each(Iterator begin, Iterator end, Function f,
__gnu_parallel::parallelism parallelism_tag)
{ {
typedef std::iterator_traits<Iterator> iterator_traits; typedef std::iterator_traits<Iterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::iterator_category iterator_category;
return for_each_switch(begin, end, f, iterator_category(),
parallelism_tag);
}
return for_each_switch(begin, end, f, iterator_category(), parallelism_tag); template<typename Iterator, typename Function>
inline Function
for_each(Iterator begin, Iterator end, Function f)
{
typedef std::iterator_traits<Iterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
return for_each_switch(begin, end, f, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename T> template<typename InputIterator, typename T>
inline InputIterator inline InputIterator
find(InputIterator begin, InputIterator end, const T& val, __gnu_parallel::sequential_tag) find(InputIterator begin, InputIterator end, const T& val,
{ return _GLIBCXX_STD_P::find<InputIterator, T>(begin, end, val); } __gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::find(begin, end, val); }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator, typename T, typename IteratorTag> template<typename InputIterator, typename T, typename IteratorTag>
...@@ -128,7 +140,8 @@ namespace __parallel ...@@ -128,7 +140,8 @@ namespace __parallel
RandomAccessIterator RandomAccessIterator
find_switch(RandomAccessIterator begin, RandomAccessIterator end, const T& val, random_access_iterator_tag) find_switch(RandomAccessIterator begin, RandomAccessIterator end, const T& val, random_access_iterator_tag)
{ {
typedef typename iterator_traits<RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type;
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
{ {
...@@ -152,26 +165,26 @@ namespace __parallel ...@@ -152,26 +165,26 @@ namespace __parallel
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename Predicate> template<typename InputIterator, typename Predicate>
inline InputIterator inline InputIterator
find_if(InputIterator begin, InputIterator end, Predicate pred, __gnu_parallel::sequential_tag) find_if(InputIterator begin, InputIterator end, Predicate pred,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::find_if<InputIterator, Predicate>(begin, end, pred); { return _GLIBCXX_STD_P::find_if(begin, end, pred); }
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator, typename Predicate, typename IteratorTag> template<typename InputIterator, typename Predicate, typename IteratorTag>
inline InputIterator inline InputIterator
find_if_switch(InputIterator begin, InputIterator end, Predicate pred, IteratorTag) find_if_switch(InputIterator begin, InputIterator end, Predicate pred,
{ IteratorTag)
return _GLIBCXX_STD_P::find_if(begin, end, pred); { return _GLIBCXX_STD_P::find_if(begin, end, pred); }
}
// Parallel find_if for random access iterators // Parallel find_if for random access iterators
template<typename RandomAccessIterator, typename Predicate> template<typename RandomAccessIterator, typename Predicate>
RandomAccessIterator RandomAccessIterator
find_if_switch(RandomAccessIterator begin, RandomAccessIterator end, Predicate pred, random_access_iterator_tag) find_if_switch(RandomAccessIterator begin, RandomAccessIterator end,
Predicate pred, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
return __gnu_parallel::find_template(begin, end, begin, pred, __gnu_parallel::find_if_selector()).first; return __gnu_parallel::find_template(begin, end, begin, pred,
__gnu_parallel::find_if_selector()).first;
else else
return _GLIBCXX_STD_P::find_if(begin, end, pred); return _GLIBCXX_STD_P::find_if(begin, end, pred);
} }
...@@ -189,10 +202,10 @@ namespace __parallel ...@@ -189,10 +202,10 @@ namespace __parallel
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename ForwardIterator> template<typename InputIterator, typename ForwardIterator>
inline InputIterator inline InputIterator
find_first_of(InputIterator begin1, InputIterator end1, ForwardIterator begin2, ForwardIterator end2, __gnu_parallel::sequential_tag) find_first_of(InputIterator begin1, InputIterator end1,
{ ForwardIterator begin2, ForwardIterator end2,
return _GLIBCXX_STD_P::find_first_of(begin1, end1, begin2, end2); __gnu_parallel::sequential_tag)
} { return _GLIBCXX_STD_P::find_first_of(begin1, end1, begin2, end2); }
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename ForwardIterator, template<typename InputIterator, typename ForwardIterator,
...@@ -201,24 +214,26 @@ namespace __parallel ...@@ -201,24 +214,26 @@ namespace __parallel
find_first_of(InputIterator begin1, InputIterator end1, find_first_of(InputIterator begin1, InputIterator end1,
ForwardIterator begin2, ForwardIterator end2, ForwardIterator begin2, ForwardIterator end2,
BinaryPredicate comp, __gnu_parallel::sequential_tag) BinaryPredicate comp, __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::find_first_of(begin1, end1, begin2, end2, comp); }
return _GLIBCXX_STD_P::find_first_of(begin1, end1, begin2, end2, comp);
}
// Sequential fallback for input iterator type // Sequential fallback for input iterator type
template<typename InputIterator, typename ForwardIterator, typename IteratorTag1, typename IteratorTag2> template<typename InputIterator, typename ForwardIterator, typename IteratorTag1, typename IteratorTag2>
inline InputIterator inline InputIterator
find_first_of_switch(InputIterator begin1, InputIterator end1, find_first_of_switch(InputIterator begin1, InputIterator end1,
ForwardIterator begin2, ForwardIterator end2, IteratorTag1, IteratorTag2) ForwardIterator begin2, ForwardIterator end2,
IteratorTag1, IteratorTag2)
{ {
return find_first_of(begin1, end1, begin2, end2, __gnu_parallel::sequential_tag()); return find_first_of(begin1, end1, begin2, end2,
__gnu_parallel::sequential_tag());
} }
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator, typename ForwardIterator, typename BinaryPredicate, typename IteratorTag> template<typename RandomAccessIterator, typename ForwardIterator, typename BinaryPredicate, typename IteratorTag>
inline RandomAccessIterator inline RandomAccessIterator
find_first_of_switch(RandomAccessIterator begin1, RandomAccessIterator end1, find_first_of_switch(RandomAccessIterator begin1, RandomAccessIterator end1,
ForwardIterator begin2, ForwardIterator end2, BinaryPredicate comp, random_access_iterator_tag, IteratorTag) ForwardIterator begin2, ForwardIterator end2,
BinaryPredicate comp, random_access_iterator_tag,
IteratorTag)
{ {
return __gnu_parallel::find_template(begin1, end1, begin1, comp, __gnu_parallel::find_first_of_selector<ForwardIterator>(begin2, end2)).first; return __gnu_parallel::find_template(begin1, end1, begin1, comp, __gnu_parallel::find_first_of_selector<ForwardIterator>(begin2, end2)).first;
} }
...@@ -228,36 +243,42 @@ namespace __parallel ...@@ -228,36 +243,42 @@ namespace __parallel
inline inline
InputIterator InputIterator
find_first_of_switch(InputIterator begin1, InputIterator end1, find_first_of_switch(InputIterator begin1, InputIterator end1,
ForwardIterator begin2, ForwardIterator end2, BinaryPredicate comp, IteratorTag1, IteratorTag2) ForwardIterator begin2, ForwardIterator end2,
BinaryPredicate comp, IteratorTag1, IteratorTag2)
{ {
return find_first_of(begin1, end1, begin2, end2, comp, __gnu_parallel::sequential_tag()); return find_first_of(begin1, end1, begin2, end2, comp,
__gnu_parallel::sequential_tag());
} }
// Public interface // Public interface
template<typename InputIterator, typename ForwardIterator, typename BinaryPredicate> template<typename InputIterator, typename ForwardIterator, typename BinaryPredicate>
inline InputIterator inline InputIterator
find_first_of(InputIterator begin1, InputIterator end1, find_first_of(InputIterator begin1, InputIterator end1,
ForwardIterator begin2, ForwardIterator end2, BinaryPredicate comp) ForwardIterator begin2, ForwardIterator end2,
BinaryPredicate comp)
{ {
typedef std::iterator_traits<InputIterator> iteratori_traits; typedef std::iterator_traits<InputIterator> iteratori_traits;
typedef std::iterator_traits<ForwardIterator> iteratorf_traits; typedef std::iterator_traits<ForwardIterator> iteratorf_traits;
typedef typename iteratori_traits::iterator_category iteratori_category; typedef typename iteratori_traits::iterator_category iteratori_category;
typedef typename iteratorf_traits::iterator_category iteratorf_category; typedef typename iteratorf_traits::iterator_category iteratorf_category;
return find_first_of_switch(begin1, end1, begin2, end2, comp, iteratori_category(), iteratorf_category()); return find_first_of_switch(begin1, end1, begin2, end2, comp,
iteratori_category(), iteratorf_category());
} }
// Public interface, insert default comparator // Public interface, insert default comparator
template<typename InputIterator, typename ForwardIterator> template<typename InputIterator, typename ForwardIterator>
InputIterator InputIterator
find_first_of(InputIterator begin1, InputIterator end1, ForwardIterator begin2, ForwardIterator end2) find_first_of(InputIterator begin1, InputIterator end1,
ForwardIterator begin2, ForwardIterator end2)
{ {
typedef std::iterator_traits<InputIterator> iteratori_traits; typedef std::iterator_traits<InputIterator> iteratori_traits;
typedef std::iterator_traits<ForwardIterator> iteratorf_traits; typedef std::iterator_traits<ForwardIterator> iteratorf_traits;
typedef typename iteratori_traits::value_type valuei_type; typedef typename iteratori_traits::value_type valuei_type;
typedef typename iteratorf_traits::value_type valuef_type; typedef typename iteratorf_traits::value_type valuef_type;
return find_first_of(begin1, end1, begin2, end2, __gnu_parallel::equal_to<valuei_type, valuef_type>()); return find_first_of(begin1, end1, begin2, end2,
__gnu_parallel::equal_to<valuei_type, valuef_type>());
} }
// Sequential fallback // Sequential fallback
...@@ -265,33 +286,29 @@ namespace __parallel ...@@ -265,33 +286,29 @@ namespace __parallel
inline OutputIterator inline OutputIterator
unique_copy(InputIterator begin1, InputIterator end1, OutputIterator out, unique_copy(InputIterator begin1, InputIterator end1, OutputIterator out,
__gnu_parallel::sequential_tag) __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::unique_copy(begin1, end1, out); }
return _GLIBCXX_STD_P::unique_copy<InputIterator, OutputIterator>(begin1, end1, out);
}
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename OutputIterator, typename Predicate> template<typename InputIterator, typename OutputIterator, typename Predicate>
inline OutputIterator inline OutputIterator
unique_copy(InputIterator begin1, InputIterator end1, OutputIterator out, unique_copy(InputIterator begin1, InputIterator end1, OutputIterator out,
Predicate pred, __gnu_parallel::sequential_tag) Predicate pred, __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::unique_copy(begin1, end1, out, pred); }
return _GLIBCXX_STD_P::unique_copy<InputIterator, OutputIterator, Predicate>(begin1, end1, out, pred);
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator, typename OutputIterator, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename InputIterator, typename OutputIterator, typename Predicate, typename IteratorTag1, typename IteratorTag2>
inline OutputIterator inline OutputIterator
unique_copy_switch(InputIterator begin, InputIterator last, OutputIterator out, unique_copy_switch(InputIterator begin, InputIterator last,
Predicate pred, IteratorTag1, IteratorTag2) OutputIterator out, Predicate pred,
{ IteratorTag1, IteratorTag2)
return _GLIBCXX_STD_P::unique_copy(begin, last, out, pred); { return _GLIBCXX_STD_P::unique_copy(begin, last, out, pred); }
}
// Parallel unique_copy for random access iterators // Parallel unique_copy for random access iterators
template<typename RandomAccessIterator, typename RandomAccessOutputIterator, typename Predicate> template<typename RandomAccessIterator, typename RandomAccessOutputIterator, typename Predicate>
RandomAccessOutputIterator RandomAccessOutputIterator
unique_copy_switch(RandomAccessIterator begin, RandomAccessIterator last, RandomAccessOutputIterator out, unique_copy_switch(RandomAccessIterator begin, RandomAccessIterator last,
Predicate pred, random_access_iterator_tag, random_access_iterator_tag) RandomAccessOutputIterator out, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(last - begin) > __gnu_parallel::Settings::unique_copy_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(last - begin) > __gnu_parallel::Settings::unique_copy_minimal_n))
return __gnu_parallel::parallel_unique_copy(begin, last, out, pred); return __gnu_parallel::parallel_unique_copy(begin, last, out, pred);
...@@ -325,7 +342,8 @@ namespace __parallel ...@@ -325,7 +342,8 @@ namespace __parallel
typedef typename iteratori_traits::iterator_category iteratori_category; typedef typename iteratori_traits::iterator_category iteratori_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return unique_copy_switch(begin1, end1, out, pred, iteratori_category(), iteratoro_category()); return unique_copy_switch(begin1, end1, out, pred, iteratori_category(),
iteratoro_category());
} }
// Sequential fallback // Sequential fallback
...@@ -334,9 +352,7 @@ namespace __parallel ...@@ -334,9 +352,7 @@ namespace __parallel
set_union(InputIterator1 begin1, InputIterator1 end1, set_union(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, __gnu_parallel::sequential_tag) OutputIterator out, __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, out); }
return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, out);
}
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
...@@ -344,16 +360,15 @@ namespace __parallel ...@@ -344,16 +360,15 @@ namespace __parallel
set_union(InputIterator1 begin1, InputIterator1 end1, set_union(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag) OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, out, pred); }
return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, out, pred);
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator1, typename InputIterator2, typename Predicate, template<typename InputIterator1, typename InputIterator2, typename Predicate,
typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3>
inline OutputIterator inline OutputIterator
set_union_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, set_union_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 end2, OutputIterator result, Predicate pred, IteratorTag1, InputIterator2 begin2, InputIterator2 end2,
OutputIterator result, Predicate pred, IteratorTag1,
IteratorTag2, IteratorTag3) IteratorTag2, IteratorTag3)
{ {
return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, result, pred); return _GLIBCXX_STD_P::set_union(begin1, end1, begin2, end2, result, pred);
...@@ -363,9 +378,11 @@ namespace __parallel ...@@ -363,9 +378,11 @@ namespace __parallel
template<typename RandomAccessIterator1, typename RandomAccessIterator2, template<typename RandomAccessIterator1, typename RandomAccessIterator2,
typename OutputRandomAccessIterator, typename Predicate> typename OutputRandomAccessIterator, typename Predicate>
OutputRandomAccessIterator OutputRandomAccessIterator
set_union_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, set_union_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred, RandomAccessIterator2 begin2, RandomAccessIterator2 end2,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag) OutputRandomAccessIterator result, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_union_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_union_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_union_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_union_minimal_n))
return __gnu_parallel::parallel_set_union(begin1, end1, begin2, end2, result, pred); return __gnu_parallel::parallel_set_union(begin1, end1, begin2, end2, result, pred);
...@@ -376,7 +393,8 @@ namespace __parallel ...@@ -376,7 +393,8 @@ namespace __parallel
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
set_union(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out) set_union(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
InputIterator2 end2, OutputIterator out)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef std::iterator_traits<InputIterator2> iteratori2_traits; typedef std::iterator_traits<InputIterator2> iteratori2_traits;
...@@ -387,8 +405,10 @@ namespace __parallel ...@@ -387,8 +405,10 @@ namespace __parallel
typedef typename iteratori1_traits::value_type value1_type; typedef typename iteratori1_traits::value_type value1_type;
typedef typename iteratori2_traits::value_type value2_type; typedef typename iteratori2_traits::value_type value2_type;
return set_union_switch(begin1, end1, begin2, end2, out, __gnu_parallel::less<value1_type, value2_type>(), return set_union_switch(begin1, end1, begin2, end2, out,
iteratori1_category(), iteratori2_category(), iteratoro_category()); __gnu_parallel::less<value1_type, value2_type>(),
iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Public interface // Public interface
...@@ -405,7 +425,8 @@ namespace __parallel ...@@ -405,7 +425,8 @@ namespace __parallel
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return set_union_switch(begin1, end1, begin2, end2, out, pred, return set_union_switch(begin1, end1, begin2, end2, out, pred,
iteratori1_category(), iteratori2_category(), iteratoro_category()); iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Sequential fallback. // Sequential fallback.
...@@ -423,40 +444,46 @@ namespace __parallel ...@@ -423,40 +444,46 @@ namespace __parallel
inline OutputIterator inline OutputIterator
set_intersection(InputIterator1 begin1, InputIterator1 end1, set_intersection(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag) OutputIterator out, Predicate pred,
__gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2, end2, out, pred); return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2, end2,
out, pred);
} }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator1, typename InputIterator2, typename Predicate, template<typename InputIterator1, typename InputIterator2, typename Predicate,
typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3>
inline OutputIterator inline OutputIterator
set_intersection_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, set_intersection_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 end2, OutputIterator result, Predicate pred, IteratorTag1, InputIterator2 begin2, InputIterator2 end2,
IteratorTag2, IteratorTag3) OutputIterator result, Predicate pred,
IteratorTag1, IteratorTag2, IteratorTag3)
{ {
return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2, end2, result, pred); return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2,
end2, result, pred);
} }
// Parallel set_intersection for random access iterators // Parallel set_intersection for random access iterators
template<typename RandomAccessIterator1, typename RandomAccessIterator2, template<typename RandomAccessIterator1, typename RandomAccessIterator2,
typename OutputRandomAccessIterator, typename Predicate> typename OutputRandomAccessIterator, typename Predicate>
OutputRandomAccessIterator OutputRandomAccessIterator
set_intersection_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, set_intersection_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_union_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_union_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_union_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_union_minimal_n))
return __gnu_parallel::parallel_set_intersection(begin1, end1, begin2, end2, result, pred); return __gnu_parallel::parallel_set_intersection(begin1, end1, begin2,
end2, result, pred);
else else
return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2, end2, result, pred); return _GLIBCXX_STD_P::set_intersection(begin1, end1, begin2,
end2, result, pred);
} }
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
set_intersection(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out) set_intersection(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
OutputIterator out)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef std::iterator_traits<InputIterator2> iteratori2_traits; typedef std::iterator_traits<InputIterator2> iteratori2_traits;
...@@ -467,8 +494,10 @@ namespace __parallel ...@@ -467,8 +494,10 @@ namespace __parallel
typedef typename iteratori1_traits::value_type value1_type; typedef typename iteratori1_traits::value_type value1_type;
typedef typename iteratori2_traits::value_type value2_type; typedef typename iteratori2_traits::value_type value2_type;
return set_intersection_switch(begin1, end1, begin2, end2, out, __gnu_parallel::less<value1_type, value2_type>(), return set_intersection_switch(begin1, end1, begin2, end2, out,
iteratori1_category(), iteratori2_category(), iteratoro_category()); __gnu_parallel::less<value1_type, value2_type>(),
iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
...@@ -484,7 +513,8 @@ namespace __parallel ...@@ -484,7 +513,8 @@ namespace __parallel
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return set_intersection_switch(begin1, end1, begin2, end2, out, pred, return set_intersection_switch(begin1, end1, begin2, end2, out, pred,
iteratori1_category(), iteratori2_category(), iteratoro_category()); iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Sequential fallback // Sequential fallback
...@@ -495,7 +525,8 @@ namespace __parallel ...@@ -495,7 +525,8 @@ namespace __parallel
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, __gnu_parallel::sequential_tag) OutputIterator out, __gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::set_symmetric_difference(begin1,end1, begin2, end2, out); return _GLIBCXX_STD_P::set_symmetric_difference(begin1,end1, begin2,
end2, out);
} }
// Sequential fallback // Sequential fallback
...@@ -506,7 +537,8 @@ namespace __parallel ...@@ -506,7 +537,8 @@ namespace __parallel
InputIterator2 begin2, InputIterator2 end2, InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag) OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::set_symmetric_difference(begin1, end1, begin2, end2, out, pred); return _GLIBCXX_STD_P::set_symmetric_difference(begin1, end1, begin2,
end2, out, pred);
} }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
...@@ -514,17 +546,15 @@ namespace __parallel ...@@ -514,17 +546,15 @@ namespace __parallel
inline OutputIterator inline OutputIterator
set_symmetric_difference_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Predicate pred, IteratorTag1, IteratorTag2, IteratorTag3) set_symmetric_difference_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Predicate pred, IteratorTag1, IteratorTag2, IteratorTag3)
{ {
return _GLIBCXX_STD_P::set_symmetric_difference(begin1, end1, begin2, end2, result, pred); return _GLIBCXX_STD_P::set_symmetric_difference(begin1, end1, begin2, end2,
result, pred);
} }
// Parallel set_symmetric_difference for random access iterators // Parallel set_symmetric_difference for random access iterators
template<typename RandomAccessIterator1, typename RandomAccessIterator2, template<typename RandomAccessIterator1, typename RandomAccessIterator2,
typename OutputRandomAccessIterator, typename Predicate> typename OutputRandomAccessIterator, typename Predicate>
OutputRandomAccessIterator OutputRandomAccessIterator
set_symmetric_difference_switch(RandomAccessIterator1 begin1, set_symmetric_difference_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
RandomAccessIterator1 end1, RandomAccessIterator2 begin2,
RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_symmetric_difference_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_symmetric_difference_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_symmetric_difference_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_symmetric_difference_minimal_n))
return __gnu_parallel::parallel_set_symmetric_difference(begin1, end1, begin2, end2, result, pred); return __gnu_parallel::parallel_set_symmetric_difference(begin1, end1, begin2, end2, result, pred);
...@@ -546,15 +576,16 @@ namespace __parallel ...@@ -546,15 +576,16 @@ namespace __parallel
typedef typename iteratori1_traits::value_type value1_type; typedef typename iteratori1_traits::value_type value1_type;
typedef typename iteratori2_traits::value_type value2_type; typedef typename iteratori2_traits::value_type value2_type;
return set_symmetric_difference_switch(begin1, end1, begin2, end2, out, __gnu_parallel::less<value1_type, value2_type>(), return set_symmetric_difference_switch(begin1, end1, begin2, end2, out,
iteratori1_category(), iteratori2_category(), iteratoro_category()); __gnu_parallel::less<value1_type, value2_type>(),
iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Public interface. // Public interface.
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
inline OutputIterator inline OutputIterator
set_symmetric_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, set_symmetric_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out, Predicate pred)
InputIterator2 end2, OutputIterator out, Predicate pred)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef std::iterator_traits<InputIterator2> iteratori2_traits; typedef std::iterator_traits<InputIterator2> iteratori2_traits;
...@@ -563,22 +594,26 @@ namespace __parallel ...@@ -563,22 +594,26 @@ namespace __parallel
typedef typename iteratori2_traits::iterator_category iteratori2_category; typedef typename iteratori2_traits::iterator_category iteratori2_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return set_symmetric_difference_switch(begin1, end1, begin2, end2, out, pred, return set_symmetric_difference_switch(begin1, end1, begin2, end2, out,
iteratori1_category(), iteratori2_category(), iteratoro_category()); pred, iteratori1_category(),
iteratori2_category(), iteratoro_category());
} }
// Sequential fallback. // Sequential fallback.
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
set_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out, __gnu_parallel::sequential_tag) set_difference(InputIterator1 begin1, InputIterator1 end1,
{ InputIterator2 begin2, InputIterator2 end2,
return _GLIBCXX_STD_P::set_difference(begin1,end1, begin2, end2, out); OutputIterator out, __gnu_parallel::sequential_tag)
} { return _GLIBCXX_STD_P::set_difference(begin1,end1, begin2, end2, out); }
// Sequential fallback. // Sequential fallback.
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
inline OutputIterator inline OutputIterator
set_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out, Predicate pred, __gnu_parallel::sequential_tag) set_difference(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, Predicate pred,
__gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::set_difference(begin1, end1, begin2, end2, out, pred); return _GLIBCXX_STD_P::set_difference(begin1, end1, begin2, end2, out, pred);
} }
...@@ -587,8 +622,10 @@ namespace __parallel ...@@ -587,8 +622,10 @@ namespace __parallel
template<typename InputIterator1, typename InputIterator2, typename Predicate, template<typename InputIterator1, typename InputIterator2, typename Predicate,
typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> typename OutputIterator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3>
inline OutputIterator inline OutputIterator
set_difference_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, set_difference_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 end2, OutputIterator result, Predicate pred, IteratorTag1, IteratorTag2, IteratorTag3) InputIterator2 begin2, InputIterator2 end2,
OutputIterator result, Predicate pred,
IteratorTag1, IteratorTag2, IteratorTag3)
{ {
return _GLIBCXX_STD_P::set_difference(begin1, end1, begin2, end2, result, pred); return _GLIBCXX_STD_P::set_difference(begin1, end1, begin2, end2, result, pred);
} }
...@@ -597,9 +634,7 @@ namespace __parallel ...@@ -597,9 +634,7 @@ namespace __parallel
template<typename RandomAccessIterator1, typename RandomAccessIterator2, template<typename RandomAccessIterator1, typename RandomAccessIterator2,
typename OutputRandomAccessIterator, typename Predicate> typename OutputRandomAccessIterator, typename Predicate>
OutputRandomAccessIterator OutputRandomAccessIterator
set_difference_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, set_difference_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
RandomAccessIterator2 end2, OutputRandomAccessIterator result, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_difference_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_difference_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::set_difference_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::set_difference_minimal_n))
return __gnu_parallel::parallel_set_difference(begin1, end1, begin2, end2, result, pred); return __gnu_parallel::parallel_set_difference(begin1, end1, begin2, end2, result, pred);
...@@ -610,7 +645,9 @@ namespace __parallel ...@@ -610,7 +645,9 @@ namespace __parallel
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
set_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator out) set_difference(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
OutputIterator out)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef std::iterator_traits<InputIterator2> iteratori2_traits; typedef std::iterator_traits<InputIterator2> iteratori2_traits;
...@@ -621,15 +658,18 @@ namespace __parallel ...@@ -621,15 +658,18 @@ namespace __parallel
typedef typename iteratori1_traits::value_type value1_type; typedef typename iteratori1_traits::value_type value1_type;
typedef typename iteratori2_traits::value_type value2_type; typedef typename iteratori2_traits::value_type value2_type;
return set_difference_switch(begin1, end1, begin2, end2, out, __gnu_parallel::less<value1_type, value2_type>(), return set_difference_switch(begin1, end1, begin2, end2, out,
iteratori1_category(), iteratori2_category(), iteratoro_category()); __gnu_parallel::less<value1_type, value2_type>(),
iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Predicate>
inline OutputIterator inline OutputIterator
set_difference(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, set_difference(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 end2, OutputIterator out, Predicate pred) InputIterator2 begin2, InputIterator2 end2,
OutputIterator out, Predicate pred)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef std::iterator_traits<InputIterator2> iteratori2_traits; typedef std::iterator_traits<InputIterator2> iteratori2_traits;
...@@ -639,31 +679,32 @@ namespace __parallel ...@@ -639,31 +679,32 @@ namespace __parallel
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return set_difference_switch(begin1, end1, begin2, end2, out, pred, return set_difference_switch(begin1, end1, begin2, end2, out, pred,
iteratori1_category(), iteratori2_category(), iteratoro_category()); iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator> template<typename ForwardIterator>
inline ForwardIterator inline ForwardIterator
adjacent_find(ForwardIterator begin, ForwardIterator end, __gnu_parallel::sequential_tag) adjacent_find(ForwardIterator begin, ForwardIterator end,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::adjacent_find<ForwardIterator>(begin, end); { return _GLIBCXX_STD_P::adjacent_find(begin, end); }
}
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename BinaryPredicate> template<typename ForwardIterator, typename BinaryPredicate>
inline ForwardIterator inline ForwardIterator
adjacent_find(ForwardIterator begin, ForwardIterator end, BinaryPredicate binary_pred, __gnu_parallel::sequential_tag) adjacent_find(ForwardIterator begin, ForwardIterator end,
{ BinaryPredicate binary_pred, __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::adjacent_find<ForwardIterator, BinaryPredicate>(begin, end, binary_pred); { return _GLIBCXX_STD_P::adjacent_find(begin, end, binary_pred); }
}
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
RandomAccessIterator RandomAccessIterator
adjacent_find_switch(RandomAccessIterator begin, RandomAccessIterator end, random_access_iterator_tag) adjacent_find_switch(RandomAccessIterator begin, RandomAccessIterator end,
random_access_iterator_tag)
{ {
typedef typename iterator_traits<RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type;
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
{ {
...@@ -674,138 +715,173 @@ namespace __parallel ...@@ -674,138 +715,173 @@ namespace __parallel
return spot; return spot;
} }
else else
return adjacent_find<RandomAccessIterator>(begin, end, __gnu_parallel::sequential_tag()); return adjacent_find(begin, end, __gnu_parallel::sequential_tag());
} }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename IteratorTag> template<typename ForwardIterator, typename IteratorTag>
inline ForwardIterator inline ForwardIterator
adjacent_find_switch(ForwardIterator begin, ForwardIterator end, IteratorTag) adjacent_find_switch(ForwardIterator begin, ForwardIterator end, IteratorTag)
{ { return adjacent_find(begin, end, __gnu_parallel::sequential_tag()); }
return adjacent_find<ForwardIterator>(begin, end, __gnu_parallel::sequential_tag());
}
// Public interface // Public interface
template<typename ForwardIterator> template<typename ForwardIterator>
inline ForwardIterator inline ForwardIterator
adjacent_find(ForwardIterator begin, ForwardIterator end) adjacent_find(ForwardIterator begin, ForwardIterator end)
{ {
return adjacent_find_switch(begin, end, typename std::iterator_traits<ForwardIterator>::iterator_category()); typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return adjacent_find_switch(begin, end, iterator_category());
} }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename BinaryPredicate, typename IteratorTag> template<typename ForwardIterator, typename BinaryPredicate, typename IteratorTag>
inline ForwardIterator inline ForwardIterator
adjacent_find_switch(ForwardIterator begin, ForwardIterator end, BinaryPredicate binary_pred, IteratorTag) adjacent_find_switch(ForwardIterator begin, ForwardIterator end,
{ BinaryPredicate pred, IteratorTag)
return adjacent_find<ForwardIterator, BinaryPredicate>(begin, end, binary_pred, __gnu_parallel::sequential_tag()); { return adjacent_find(begin, end, pred, __gnu_parallel::sequential_tag()); }
}
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator, typename BinaryPredicate> template<typename RandomAccessIterator, typename BinaryPredicate>
RandomAccessIterator RandomAccessIterator
adjacent_find_switch(RandomAccessIterator begin, RandomAccessIterator end, BinaryPredicate binary_pred, random_access_iterator_tag) adjacent_find_switch(RandomAccessIterator begin, RandomAccessIterator end,
BinaryPredicate pred, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
return __gnu_parallel::find_template(begin, end, begin, binary_pred, __gnu_parallel::adjacent_find_selector()).first; return __gnu_parallel::find_template(begin, end, begin, pred,
__gnu_parallel::adjacent_find_selector()).first;
else else
return adjacent_find(begin, end, binary_pred, __gnu_parallel::sequential_tag()); return adjacent_find(begin, end, pred, __gnu_parallel::sequential_tag());
} }
// Public interface // Public interface
template<typename ForwardIterator, typename BinaryPredicate> template<typename ForwardIterator, typename BinaryPredicate>
inline ForwardIterator inline ForwardIterator
adjacent_find(ForwardIterator begin, ForwardIterator end, BinaryPredicate binary_pred) adjacent_find(ForwardIterator begin, ForwardIterator end,
BinaryPredicate pred)
{ {
return adjacent_find_switch<ForwardIterator, BinaryPredicate>(begin, end, binary_pred, typename std::iterator_traits<ForwardIterator>::iterator_category()); typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return adjacent_find_switch(begin, end, pred, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename InputIterator, typename T> template<typename InputIterator, typename T>
inline typename iterator_traits<InputIterator>::difference_type inline typename iterator_traits<InputIterator>::difference_type
count(InputIterator begin, InputIterator end, const T& value, __gnu_parallel::sequential_tag) count(InputIterator begin, InputIterator end, const T& value,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::count<InputIterator, T>(begin, end, value); { return _GLIBCXX_STD_P::count(begin, end, value); }
}
// Parallel code for random access iterators // Parallel code for random access iterators
template<typename RandomAccessIterator, typename T> template<typename RandomAccessIterator, typename T>
typename iterator_traits<RandomAccessIterator>::difference_type typename iterator_traits<RandomAccessIterator>::difference_type
count_switch(RandomAccessIterator begin, RandomAccessIterator end, const T& value, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) count_switch(RandomAccessIterator begin, RandomAccessIterator end,
const T& value, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_unbalanced)
{ {
typedef typename iterator_traits<RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename iterator_traits<RandomAccessIterator>::difference_type difference_type; typedef typename traits_type::value_type value_type;
typedef typename traits_type::difference_type difference_type;
typedef __gnu_parallel::sequence_index_t sequence_index_t;
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::count_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<sequence_index_t>(end - begin) >= __gnu_parallel::Settings::count_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
difference_type res = 0;
__gnu_parallel::count_selector<RandomAccessIterator, difference_type> functionality; __gnu_parallel::count_selector<RandomAccessIterator, difference_type> functionality;
__gnu_parallel::for_each_template_random_access(begin, end, value, functionality, std::plus<__gnu_parallel::sequence_index_t>(), res, res, -1, parallelism_tag); difference_type res = 0;
__gnu_parallel::for_each_template_random_access(begin, end, value, functionality, std::plus<sequence_index_t>(), res, res, -1, parallelism_tag);
return res; return res;
} }
else else
return count<RandomAccessIterator, T>(begin, end, value, __gnu_parallel::sequential_tag()); return count(begin, end, value, __gnu_parallel::sequential_tag());
} }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename InputIterator, typename T, typename IteratorTag> template<typename InputIterator, typename T, typename IteratorTag>
typename iterator_traits<InputIterator>::difference_type typename iterator_traits<InputIterator>::difference_type
count_switch(InputIterator begin, InputIterator end, const T& value, IteratorTag, __gnu_parallel::parallelism parallelism_tag) count_switch(InputIterator begin, InputIterator end, const T& value,
IteratorTag)
{ return count(begin, end, value, __gnu_parallel::sequential_tag()); }
// Public interface.
template<typename InputIterator, typename T>
inline typename iterator_traits<InputIterator>::difference_type
count(InputIterator begin, InputIterator end, const T& value,
__gnu_parallel::parallelism parallelism_tag)
{ {
return count<InputIterator, T>(begin, end, value, __gnu_parallel::sequential_tag()); typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return count_switch(begin, end, value, iterator_category(),
parallelism_tag);
} }
// Public interface.
template<typename InputIterator, typename T> template<typename InputIterator, typename T>
inline typename iterator_traits<InputIterator>::difference_type inline typename iterator_traits<InputIterator>::difference_type
count(InputIterator begin, InputIterator end, const T& value, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced) count(InputIterator begin, InputIterator end, const T& value)
{ {
return count_switch(begin, end, value, typename std::iterator_traits<InputIterator>::iterator_category(), parallelism_tag); typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return count_switch(begin, end, value, iterator_category());
} }
// Sequential fallback. // Sequential fallback.
template<typename InputIterator, typename Predicate> template<typename InputIterator, typename Predicate>
inline typename iterator_traits<InputIterator>::difference_type inline typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator begin, InputIterator end, Predicate pred, __gnu_parallel::sequential_tag) count_if(InputIterator begin, InputIterator end, Predicate pred,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::count_if(begin, end, pred); { return _GLIBCXX_STD_P::count_if(begin, end, pred); }
}
// Parallel count_if for random access iterators // Parallel count_if for random access iterators
template<typename RandomAccessIterator, typename Predicate> template<typename RandomAccessIterator, typename Predicate>
typename iterator_traits<RandomAccessIterator>::difference_type typename iterator_traits<RandomAccessIterator>::difference_type
count_if_switch(RandomAccessIterator begin, RandomAccessIterator end, Predicate pred, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) count_if_switch(RandomAccessIterator begin, RandomAccessIterator end,
Predicate pred, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_unbalanced)
{ {
typedef typename iterator_traits<RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename iterator_traits<RandomAccessIterator>::difference_type difference_type; typedef typename traits_type::value_type value_type;
typedef typename traits_type::difference_type difference_type;
typedef __gnu_parallel::sequence_index_t sequence_index_t;
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::count_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<sequence_index_t>(end - begin) >= __gnu_parallel::Settings::count_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
difference_type res = 0; difference_type res = 0;
__gnu_parallel::count_if_selector<RandomAccessIterator, difference_type> functionality; __gnu_parallel::count_if_selector<RandomAccessIterator, difference_type> functionality;
__gnu_parallel::for_each_template_random_access(begin, end, pred, functionality, std::plus<__gnu_parallel::sequence_index_t>(), res, res, -1, parallelism_tag); __gnu_parallel::for_each_template_random_access(begin, end, pred, functionality, std::plus<sequence_index_t>(), res, res, -1, parallelism_tag);
return res; return res;
} }
else else
return count_if<RandomAccessIterator, Predicate>(begin, end, pred, __gnu_parallel::sequential_tag()); return count_if(begin, end, pred, __gnu_parallel::sequential_tag());
} }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename InputIterator, typename Predicate, typename IteratorTag> template<typename InputIterator, typename Predicate, typename IteratorTag>
typename iterator_traits<InputIterator>::difference_type typename iterator_traits<InputIterator>::difference_type
count_if_switch(InputIterator begin, InputIterator end, Predicate pred, IteratorTag, __gnu_parallel::parallelism) count_if_switch(InputIterator begin, InputIterator end, Predicate pred,
IteratorTag)
{ return count_if(begin, end, pred, __gnu_parallel::sequential_tag()); }
// Public interface.
template<typename InputIterator, typename Predicate>
inline typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator begin, InputIterator end, Predicate pred,
__gnu_parallel::parallelism parallelism_tag)
{ {
return count_if<InputIterator, Predicate>(begin, end, pred, __gnu_parallel::sequential_tag()); typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return count_if_switch(begin, end, pred, iterator_category(),
parallelism_tag);
} }
// Public interface.
template<typename InputIterator, typename Predicate> template<typename InputIterator, typename Predicate>
inline typename iterator_traits<InputIterator>::difference_type inline typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator begin, InputIterator end, Predicate pred, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced) count_if(InputIterator begin, InputIterator end, Predicate pred)
{ {
typedef iterator_traits<InputIterator> traits_type; typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category; typedef typename traits_type::iterator_category iterator_category;
return count_if_switch(begin, end, pred, iterator_category(), parallelism_tag); return count_if_switch(begin, end, pred, iterator_category());
} }
...@@ -950,53 +1026,88 @@ namespace __parallel ...@@ -950,53 +1026,88 @@ namespace __parallel
return search_n_switch(begin, end, count, val, binary_pred, typename std::iterator_traits<ForwardIterator>::iterator_category()); return search_n_switch(begin, end, count, val, binary_pred, typename std::iterator_traits<ForwardIterator>::iterator_category());
} }
// Sequential fallback. // Sequential fallback.
template<typename InputIterator, typename OutputIterator, typename UnaryOperation> template<typename InputIterator, typename OutputIterator, typename UnaryOperation>
inline OutputIterator inline OutputIterator
transform(InputIterator begin, InputIterator end, OutputIterator result, UnaryOperation unary_op, __gnu_parallel::sequential_tag) transform(InputIterator begin, InputIterator end, OutputIterator result,
{ UnaryOperation unary_op, __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::transform(begin, end, result, unary_op); { return _GLIBCXX_STD_P::transform(begin, end, result, unary_op); }
}
// Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation>
inline OutputIterator
transform(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, OutputIterator result, BinaryOperation binary_op, __gnu_parallel::sequential_tag)
{
return _GLIBCXX_STD_P::transform(begin1, end1, begin2, result, binary_op);
}
// Parallel unary transform for random access iterators. // Parallel unary transform for random access iterators.
template<typename RandomAccessIterator1, typename RandomAccessIterator3, typename UnaryOperation> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename UnaryOperation>
RandomAccessIterator3 RandomAccessIterator2
transform1_switch(RandomAccessIterator1 begin, RandomAccessIterator1 end, RandomAccessIterator3 result, UnaryOperation unary_op, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) transform1_switch(RandomAccessIterator1 begin, RandomAccessIterator1 end, RandomAccessIterator2 result, UnaryOperation unary_op, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::transform_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::transform_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
bool dummy = true; bool dummy = true;
typedef __gnu_parallel::iterator_pair<RandomAccessIterator1, RandomAccessIterator3, random_access_iterator_tag> ip; typedef __gnu_parallel::iterator_pair<RandomAccessIterator1, RandomAccessIterator2, random_access_iterator_tag> ip;
ip begin_pair(begin, result), end_pair(end, result + (end - begin)); ip begin_pair(begin, result), end_pair(end, result + (end - begin));
__gnu_parallel::transform1_selector<ip> functionality; __gnu_parallel::transform1_selector<ip> functionality;
__gnu_parallel::for_each_template_random_access(begin_pair, end_pair, unary_op, functionality, __gnu_parallel::dummy_reduct(), dummy, dummy, -1, parallelism_tag); __gnu_parallel::for_each_template_random_access(begin_pair, end_pair, unary_op, functionality, __gnu_parallel::dummy_reduct(), dummy, dummy, -1, parallelism_tag);
return functionality.finish_iterator; return functionality.finish_iterator;
} }
else else
return transform(begin, end, result, unary_op, __gnu_parallel::sequential_tag()); return transform(begin, end, result, unary_op,
__gnu_parallel::sequential_tag());
} }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename RandomAccessIterator1, typename RandomAccessIterator3, typename UnaryOperation, typename IteratorTag1, typename IteratorTag2> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename UnaryOperation, typename IteratorTag1, typename IteratorTag2>
inline RandomAccessIterator3 inline RandomAccessIterator2
transform1_switch(RandomAccessIterator1 begin, RandomAccessIterator1 end, RandomAccessIterator3 result, UnaryOperation unary_op, IteratorTag1, IteratorTag2, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) transform1_switch(RandomAccessIterator1 begin, RandomAccessIterator1 end, RandomAccessIterator2 result, UnaryOperation unary_op, IteratorTag1, IteratorTag2)
{
return transform(begin, end, result, unary_op,
__gnu_parallel::sequential_tag());
}
// Public interface.
template<typename InputIterator, typename OutputIterator, typename UnaryOperation>
inline OutputIterator
transform(InputIterator begin, InputIterator end, OutputIterator result,
UnaryOperation unary_op,
__gnu_parallel::parallelism parallelism_tag)
{ {
return _GLIBCXX_STD_P::transform(begin, end, result, unary_op); typedef std::iterator_traits<InputIterator> iteratori_traits;
typedef std::iterator_traits<OutputIterator> iteratoro_traits;
typedef typename iteratori_traits::iterator_category iteratori_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category;
return transform1_switch(begin, end, result, unary_op,
iteratori_category(), iteratoro_category(),
parallelism_tag);
}
template<typename InputIterator, typename OutputIterator, typename UnaryOperation>
inline OutputIterator
transform(InputIterator begin, InputIterator end, OutputIterator result,
UnaryOperation unary_op)
{
typedef std::iterator_traits<InputIterator> iteratori_traits;
typedef std::iterator_traits<OutputIterator> iteratoro_traits;
typedef typename iteratori_traits::iterator_category iteratori_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category;
return transform1_switch(begin, end, result, unary_op,
iteratori_category(), iteratoro_category());
} }
// Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation>
inline OutputIterator
transform(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
OutputIterator result, BinaryOperation binary_op,
__gnu_parallel::sequential_tag)
{
return _GLIBCXX_STD_P::transform(begin1, end1, begin2, result, binary_op);
}
// Parallel binary transform for random access iterators. // Parallel binary transform for random access iterators.
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename RandomAccessIterator3, typename BinaryOperation> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename RandomAccessIterator3, typename BinaryOperation>
RandomAccessIterator3 RandomAccessIterator3
transform2_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator3 result, BinaryOperation binary_op, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) transform2_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator3 result, BinaryOperation binary_op, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION((end1 - begin1) >= __gnu_parallel::Settings::transform_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION((end1 - begin1) >= __gnu_parallel::Settings::transform_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -1008,36 +1119,44 @@ namespace __parallel ...@@ -1008,36 +1119,44 @@ namespace __parallel
return functionality.finish_iterator; return functionality.finish_iterator;
} }
else else
return transform(begin1, end1, begin2, result, binary_op, __gnu_parallel::sequential_tag()); return transform(begin1, end1, begin2, result, binary_op,
__gnu_parallel::sequential_tag());
} }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename RandomAccessIterator3, typename BinaryOperation, typename tag1, typename tag2, typename tag3> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation, typename tag1, typename tag2, typename tag3>
inline RandomAccessIterator3 inline OutputIterator
transform2_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator3 result, BinaryOperation binary_op, tag1, tag2, tag3, __gnu_parallel::parallelism) transform2_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, OutputIterator result,
BinaryOperation binary_op, tag1, tag2, tag3)
{ {
return _GLIBCXX_STD_P::transform(begin1, end1, begin2, result, binary_op); return transform(begin1, end1, begin2, result, binary_op,
__gnu_parallel::sequential_tag());
} }
// Public interface. // Public interface.
template<typename InputIterator, typename OutputIterator, typename UnaryOperation> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation>
inline OutputIterator inline OutputIterator
transform(InputIterator begin, InputIterator end, OutputIterator result, transform(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
UnaryOperation unary_op, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) OutputIterator result, BinaryOperation binary_op,
__gnu_parallel::parallelism parallelism_tag)
{ {
typedef std::iterator_traits<InputIterator> iteratori_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef typename iteratori1_traits::iterator_category iteratori1_category;
typedef std::iterator_traits<InputIterator2> iteratori2_traits;
typedef typename iteratori2_traits::iterator_category iteratori2_category;
typedef std::iterator_traits<OutputIterator> iteratoro_traits; typedef std::iterator_traits<OutputIterator> iteratoro_traits;
typedef typename iteratori_traits::iterator_category iteratori_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return transform1_switch(begin, end, result, unary_op, return transform2_switch(begin1, end1, begin2, result, binary_op,
iteratori_category(), iteratoro_category(), parallelism_tag); iteratori1_category(), iteratori2_category(),
iteratoro_category(), parallelism_tag);
} }
// Public interface.
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename BinaryOperation>
inline OutputIterator inline OutputIterator
transform(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, OutputIterator result, BinaryOperation binary_op, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) transform(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
OutputIterator result, BinaryOperation binary_op)
{ {
typedef std::iterator_traits<InputIterator1> iteratori1_traits; typedef std::iterator_traits<InputIterator1> iteratori1_traits;
typedef typename iteratori1_traits::iterator_category iteratori1_category; typedef typename iteratori1_traits::iterator_category iteratori1_category;
...@@ -1046,54 +1165,87 @@ namespace __parallel ...@@ -1046,54 +1165,87 @@ namespace __parallel
typedef std::iterator_traits<OutputIterator> iteratoro_traits; typedef std::iterator_traits<OutputIterator> iteratoro_traits;
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return transform2_switch(begin1, end1, begin2, result, binary_op, return transform2_switch(begin1, end1, begin2, result, binary_op,
iteratori1_category(), iteratori2_category(), iteratoro_category(), parallelism_tag); iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename T> template<typename ForwardIterator, typename T>
inline void inline void
replace(ForwardIterator begin, ForwardIterator end, const T& old_value, const T& new_value, __gnu_parallel::sequential_tag) replace(ForwardIterator begin, ForwardIterator end, const T& old_value,
const T& new_value, __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::replace(begin, end, old_value, new_value); } { _GLIBCXX_STD_P::replace(begin, end, old_value, new_value); }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename T, typename IteratorTag> template<typename ForwardIterator, typename T, typename IteratorTag>
void void
replace_switch(ForwardIterator begin, ForwardIterator end, const T& old_value, const T& new_value, IteratorTag, __gnu_parallel::parallelism parallelism_tag) replace_switch(ForwardIterator begin, ForwardIterator end,
{ replace(begin, end, old_value, new_value, __gnu_parallel::sequential_tag()); } const T& old_value, const T& new_value, IteratorTag)
{
replace(begin, end, old_value, new_value,
__gnu_parallel::sequential_tag());
}
// Parallel replace for random access iterators // Parallel replace for random access iterators
template<typename RandomAccessIterator, typename T> template<typename RandomAccessIterator, typename T>
void void
replace_switch(RandomAccessIterator begin, RandomAccessIterator end, const T& old_value, const T& new_value, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) replace_switch(RandomAccessIterator begin, RandomAccessIterator end,
{ replace(begin, end, old_value, new_value, __gnu_parallel::sequential_tag()); } const T& old_value, const T& new_value,
random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{
// XXX parallel version is where?
replace(begin, end, old_value, new_value,
__gnu_parallel::sequential_tag());
}
// Public interface // Public interface
template<typename ForwardIterator, typename T> template<typename ForwardIterator, typename T>
inline void inline void
replace(ForwardIterator begin, ForwardIterator end, const T& old_value, const T& new_value, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) replace(ForwardIterator begin, ForwardIterator end, const T& old_value,
const T& new_value, __gnu_parallel::parallelism parallelism_tag)
{
typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
replace_switch(begin, end, old_value, new_value, iterator_category(),
parallelism_tag);
}
template<typename ForwardIterator, typename T>
inline void
replace(ForwardIterator begin, ForwardIterator end, const T& old_value,
const T& new_value)
{ {
replace_switch(begin, end, old_value, new_value, typename std::iterator_traits<ForwardIterator>::iterator_category(), parallelism_tag); typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
replace_switch(begin, end, old_value, new_value, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename Predicate, typename T> template<typename ForwardIterator, typename Predicate, typename T>
inline void inline void
replace_if(ForwardIterator begin, ForwardIterator end, Predicate pred, const T& new_value, __gnu_parallel::sequential_tag) replace_if(ForwardIterator begin, ForwardIterator end, Predicate pred,
const T& new_value, __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::replace_if(begin, end, pred, new_value); } { _GLIBCXX_STD_P::replace_if(begin, end, pred, new_value); }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename Predicate, typename T, typename IteratorTag> template<typename ForwardIterator, typename Predicate, typename T, typename IteratorTag>
void void
replace_if_switch(ForwardIterator begin, ForwardIterator end, Predicate pred, const T& new_value, IteratorTag, __gnu_parallel::parallelism parallelism_tag) replace_if_switch(ForwardIterator begin, ForwardIterator end, Predicate pred,
const T& new_value, IteratorTag)
{ replace_if(begin, end, pred, new_value, __gnu_parallel::sequential_tag()); } { replace_if(begin, end, pred, new_value, __gnu_parallel::sequential_tag()); }
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename RandomAccessIterator, typename Predicate, typename T> template<typename RandomAccessIterator, typename Predicate, typename T>
void void
replace_if_switch(RandomAccessIterator begin, RandomAccessIterator end, Predicate pred, const T& new_value, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) replace_if_switch(RandomAccessIterator begin, RandomAccessIterator end,
Predicate pred, const T& new_value,
random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::replace_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::replace_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -1102,38 +1254,54 @@ namespace __parallel ...@@ -1102,38 +1254,54 @@ namespace __parallel
__gnu_parallel::for_each_template_random_access(begin, end, pred, functionality, __gnu_parallel::dummy_reduct(), true, dummy, -1, parallelism_tag); __gnu_parallel::for_each_template_random_access(begin, end, pred, functionality, __gnu_parallel::dummy_reduct(), true, dummy, -1, parallelism_tag);
} }
else else
replace_if(begin, end, pred, new_value, __gnu_parallel::sequential_tag()); replace_if(begin, end, pred, new_value,
__gnu_parallel::sequential_tag());
} }
// Public interface. // Public interface.
template<typename ForwardIterator, typename Predicate, typename T> template<typename ForwardIterator, typename Predicate, typename T>
inline void inline void
replace_if(ForwardIterator begin, ForwardIterator end, replace_if(ForwardIterator begin, ForwardIterator end,
Predicate pred, const T& new_value, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) Predicate pred, const T& new_value,
__gnu_parallel::parallelism parallelism_tag)
{ {
typedef std::iterator_traits<ForwardIterator> iterator_traits; typedef std::iterator_traits<ForwardIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::iterator_category iterator_category;
replace_if_switch(begin, end, pred, new_value, iterator_category(),
parallelism_tag);
}
replace_if_switch(begin, end, pred, new_value, iterator_category(), parallelism_tag); template<typename ForwardIterator, typename Predicate, typename T>
inline void
replace_if(ForwardIterator begin, ForwardIterator end,
Predicate pred, const T& new_value)
{
typedef std::iterator_traits<ForwardIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
replace_if_switch(begin, end, pred, new_value, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename Generator> template<typename ForwardIterator, typename Generator>
inline void inline void
generate(ForwardIterator begin, ForwardIterator end, Generator gen, __gnu_parallel::sequential_tag) generate(ForwardIterator begin, ForwardIterator end, Generator gen,
{ _GLIBCXX_STD_P::generate<ForwardIterator, Generator>(begin, end, gen); } __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::generate(begin, end, gen); }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename ForwardIterator, typename Generator, typename IteratorTag> template<typename ForwardIterator, typename Generator, typename IteratorTag>
void void
generate_switch(ForwardIterator begin, ForwardIterator end, Generator gen, IteratorTag, __gnu_parallel::parallelism parallelism_tag) generate_switch(ForwardIterator begin, ForwardIterator end, Generator gen,
IteratorTag)
{ generate(begin, end, gen, __gnu_parallel::sequential_tag()); } { generate(begin, end, gen, __gnu_parallel::sequential_tag()); }
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename RandomAccessIterator, typename Generator> template<typename RandomAccessIterator, typename Generator>
void void
generate_switch(RandomAccessIterator begin, RandomAccessIterator end, generate_switch(RandomAccessIterator begin, RandomAccessIterator end,
Generator gen, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) Generator gen, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::generate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::generate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -1149,53 +1317,82 @@ namespace __parallel ...@@ -1149,53 +1317,82 @@ namespace __parallel
template<typename ForwardIterator, typename Generator> template<typename ForwardIterator, typename Generator>
inline void inline void
generate(ForwardIterator begin, ForwardIterator end, generate(ForwardIterator begin, ForwardIterator end,
Generator gen, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) Generator gen, __gnu_parallel::parallelism parallelism_tag)
{ {
typedef std::iterator_traits<ForwardIterator> iterator_traits; typedef std::iterator_traits<ForwardIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::iterator_category iterator_category;
generate_switch(begin, end, gen, iterator_category(), parallelism_tag); generate_switch(begin, end, gen, iterator_category(), parallelism_tag);
} }
template<typename ForwardIterator, typename Generator>
inline void
generate(ForwardIterator begin, ForwardIterator end, Generator gen)
{
typedef std::iterator_traits<ForwardIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
generate_switch(begin, end, gen, iterator_category());
}
// Sequential fallback. // Sequential fallback.
template<typename OutputIterator, typename Size, typename Generator> template<typename OutputIterator, typename Size, typename Generator>
inline OutputIterator inline OutputIterator
generate_n(OutputIterator begin, Size n, Generator gen, __gnu_parallel::sequential_tag) generate_n(OutputIterator begin, Size n, Generator gen,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::generate_n(begin, n, gen); } { return _GLIBCXX_STD_P::generate_n(begin, n, gen); }
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename OutputIterator, typename Size, typename Generator, typename IteratorTag> template<typename OutputIterator, typename Size, typename Generator, typename IteratorTag>
OutputIterator OutputIterator
generate_n_switch(OutputIterator begin, Size n, Generator gen, IteratorTag, __gnu_parallel::parallelism) generate_n_switch(OutputIterator begin, Size n, Generator gen, IteratorTag)
{ return generate_n(begin, n, gen, __gnu_parallel::sequential_tag()); } { return generate_n(begin, n, gen, __gnu_parallel::sequential_tag()); }
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename RandomAccessIterator, typename Size, typename Generator> template<typename RandomAccessIterator, typename Size, typename Generator>
RandomAccessIterator RandomAccessIterator
generate_n_switch(RandomAccessIterator begin, Size n, Generator gen, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) generate_n_switch(RandomAccessIterator begin, Size n, Generator gen,
{ return generate_n(begin, n, gen, __gnu_parallel::sequential_tag()); } random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{
// XXX parallel version is where?
return generate_n(begin, n, gen, __gnu_parallel::sequential_tag());
}
// Public interface. // Public interface.
template<typename OutputIterator, typename Size, typename Generator> template<typename OutputIterator, typename Size, typename Generator>
inline OutputIterator inline OutputIterator
generate_n(OutputIterator begin, Size n, Generator gen, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) generate_n(OutputIterator begin, Size n, Generator gen,
__gnu_parallel::parallelism parallelism_tag)
{
typedef std::iterator_traits<OutputIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
return generate_n_switch(begin, n, gen, iterator_category(),
parallelism_tag);
}
template<typename OutputIterator, typename Size, typename Generator>
inline OutputIterator
generate_n(OutputIterator begin, Size n, Generator gen)
{ {
typedef std::iterator_traits<OutputIterator> iterator_traits; typedef std::iterator_traits<OutputIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category; typedef typename iterator_traits::iterator_category iterator_category;
return generate_n_switch(begin, n, gen, iterator_category(), parallelism_tag); return generate_n_switch(begin, n, gen, iterator_category());
} }
// Sequential fallback. // Sequential fallback.
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
inline void inline void
random_shuffle(RandomAccessIterator begin, RandomAccessIterator end, __gnu_parallel::sequential_tag) random_shuffle(RandomAccessIterator begin, RandomAccessIterator end,
__gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::random_shuffle(begin, end); } { _GLIBCXX_STD_P::random_shuffle(begin, end); }
// Sequential fallback. // Sequential fallback.
template<typename RandomAccessIterator, typename RandomNumberGenerator> template<typename RandomAccessIterator, typename RandomNumberGenerator>
inline void inline void
random_shuffle(RandomAccessIterator begin, RandomAccessIterator end, RandomNumberGenerator& rand, __gnu_parallel::sequential_tag) random_shuffle(RandomAccessIterator begin, RandomAccessIterator end,
RandomNumberGenerator& rand, __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::random_shuffle(begin, end, rand); } { _GLIBCXX_STD_P::random_shuffle(begin, end, rand); }
...@@ -1220,7 +1417,8 @@ namespace __parallel ...@@ -1220,7 +1417,8 @@ namespace __parallel
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename RandomAccessIterator, typename RandomNumberGenerator> template<typename RandomAccessIterator, typename RandomNumberGenerator>
void void
random_shuffle(RandomAccessIterator begin, RandomAccessIterator end, RandomNumberGenerator& rand) random_shuffle(RandomAccessIterator begin, RandomAccessIterator end,
RandomNumberGenerator& rand)
{ {
if (begin == end) if (begin == end)
return; return;
...@@ -1262,19 +1460,23 @@ namespace __parallel ...@@ -1262,19 +1460,23 @@ namespace __parallel
inline ForwardIterator inline ForwardIterator
partition(ForwardIterator begin, ForwardIterator end, Predicate pred) partition(ForwardIterator begin, ForwardIterator end, Predicate pred)
{ {
return partition_switch(begin, end, pred, typename std::iterator_traits<ForwardIterator>::iterator_category()); typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return partition_switch(begin, end, pred, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
inline void inline void
sort(RandomAccessIterator begin, RandomAccessIterator end, __gnu_parallel::sequential_tag) sort(RandomAccessIterator begin, RandomAccessIterator end,
{ _GLIBCXX_STD_P::sort<RandomAccessIterator>(begin, end); } __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::sort(begin, end); }
// Sequential fallback // Sequential fallback
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void inline void
sort(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp, __gnu_parallel::sequential_tag) sort(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp,
__gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::sort<RandomAccessIterator, Comparator>(begin, end, comp); } { _GLIBCXX_STD_P::sort<RandomAccessIterator, Comparator>(begin, end, comp); }
// Public interface, insert default comparator // Public interface, insert default comparator
...@@ -1299,25 +1501,23 @@ namespace __parallel ...@@ -1299,25 +1501,23 @@ namespace __parallel
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::sort_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::sort_minimal_n))
__gnu_parallel::parallel_sort(begin, end, comp, false); __gnu_parallel::parallel_sort(begin, end, comp, false);
else else
sort<RandomAccessIterator, Comparator>(begin, end, comp, __gnu_parallel::sequential_tag()); sort(begin, end, comp, __gnu_parallel::sequential_tag());
} }
} }
// Sequential fallback. // Sequential fallback.
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
inline void inline void
stable_sort(RandomAccessIterator begin, RandomAccessIterator end, __gnu_parallel::sequential_tag) stable_sort(RandomAccessIterator begin, RandomAccessIterator end,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::stable_sort<RandomAccessIterator>(begin, end); { return _GLIBCXX_STD_P::stable_sort(begin, end); }
}
// Sequential fallback. // Sequential fallback.
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void inline void
stable_sort(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp, __gnu_parallel::sequential_tag) stable_sort(RandomAccessIterator begin, RandomAccessIterator end,
{ Comparator comp, __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::stable_sort<RandomAccessIterator, Comparator>(begin, end, comp); { return _GLIBCXX_STD_P::stable_sort(begin, end, comp); }
}
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
void void
...@@ -1325,65 +1525,69 @@ namespace __parallel ...@@ -1325,65 +1525,69 @@ namespace __parallel
{ {
typedef iterator_traits<RandomAccessIterator> traits_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
stable_sort(begin, end, std::less<value_type>()); stable_sort(begin, end, std::less<value_type>());
} }
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
void void
stable_sort(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp) stable_sort(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp)
{ {
if (begin != end) if (begin != end)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::sort_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::sort_minimal_n))
__gnu_parallel::parallel_sort(begin, end, comp, true); __gnu_parallel::parallel_sort(begin, end, comp, true);
else else
stable_sort<RandomAccessIterator, Comparator>(begin, end, comp, __gnu_parallel::sequential_tag()); stable_sort(begin, end, comp, __gnu_parallel::sequential_tag());
} }
} }
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
InputIterator2 end2, OutputIterator result,
__gnu_parallel::sequential_tag) __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result); }
return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result);
}
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator>
inline OutputIterator inline OutputIterator
merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Comparator comp, merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
InputIterator2 end2, OutputIterator result, Comparator comp,
__gnu_parallel::sequential_tag) __gnu_parallel::sequential_tag)
{ { return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result, comp); }
return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result, comp);
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3>
inline OutputIterator inline OutputIterator
merge_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Comparator comp, IteratorTag1, IteratorTag2, IteratorTag3) merge_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Comparator comp, IteratorTag1, IteratorTag2, IteratorTag3)
{ { return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result, comp); }
return _GLIBCXX_STD_P::merge(begin1, end1, begin2, end2, result, comp);
}
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator>
OutputIterator OutputIterator
merge_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Comparator comp, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag) merge_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
OutputIterator result, Comparator comp,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION((static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::merge_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::merge_minimal_n))) if (_GLIBCXX_PARALLEL_CONDITION((static_cast<__gnu_parallel::sequence_index_t>(end1 - begin1) >= __gnu_parallel::Settings::merge_minimal_n || static_cast<__gnu_parallel::sequence_index_t>(end2 - begin2) >= __gnu_parallel::Settings::merge_minimal_n)))
return __gnu_parallel::parallel_merge_advance(begin1, end1, begin2, end2, result, (end1 - begin1) + (end2 - begin2), comp); return __gnu_parallel::parallel_merge_advance(begin1, end1, begin2, end2,
result, (end1 - begin1) + (end2 - begin2), comp);
else else
return __gnu_parallel::merge_advance(begin1, end1, begin2, end2, result, (end1 - begin1) + (end2 - begin2), comp); return __gnu_parallel::merge_advance(begin1, end1, begin2, end2, result,
(end1 - begin1) + (end2 - begin2),
comp);
} }
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator, typename Comparator>
inline OutputIterator inline OutputIterator
merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result, Comparator comp) merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
InputIterator2 end2, OutputIterator result, Comparator comp)
{ {
typedef typename iterator_traits<InputIterator1>::value_type value_type; typedef typename iterator_traits<InputIterator1>::value_type value_type;
...@@ -1394,39 +1598,47 @@ namespace __parallel ...@@ -1394,39 +1598,47 @@ namespace __parallel
typedef typename iteratori2_traits::iterator_category iteratori2_category; typedef typename iteratori2_traits::iterator_category iteratori2_category;
typedef typename iteratoro_traits::iterator_category iteratoro_category; typedef typename iteratoro_traits::iterator_category iteratoro_category;
return merge_switch(begin1, end1, begin2, end2, result, comp, iteratori1_category(), iteratori2_category(), iteratoro_category()); return merge_switch(begin1, end1, begin2, end2, result, comp,
iteratori1_category(), iteratori2_category(),
iteratoro_category());
} }
// Public interface, insert default comparator // Public interface, insert default comparator
template<typename InputIterator1, typename InputIterator2, typename OutputIterator> template<typename InputIterator1, typename InputIterator2, typename OutputIterator>
inline OutputIterator inline OutputIterator
merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, OutputIterator result) merge(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
InputIterator2 end2, OutputIterator result)
{ {
typedef std::iterator_traits<InputIterator1> iterator1_traits; typedef std::iterator_traits<InputIterator1> iterator1_traits;
typedef std::iterator_traits<InputIterator2> iterator2_traits; typedef std::iterator_traits<InputIterator2> iterator2_traits;
typedef typename iterator1_traits::value_type value1_type; typedef typename iterator1_traits::value_type value1_type;
typedef typename iterator2_traits::value_type value2_type; typedef typename iterator2_traits::value_type value2_type;
return merge(begin1, end1, begin2, end2, result, __gnu_parallel::less<value1_type, value2_type>()); return merge(begin1, end1, begin2, end2, result,
__gnu_parallel::less<value1_type, value2_type>());
} }
// Sequential fallback // Sequential fallback
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
inline void inline void
nth_element(RandomAccessIterator begin, RandomAccessIterator nth, RandomAccessIterator end, __gnu_parallel::sequential_tag) nth_element(RandomAccessIterator begin, RandomAccessIterator nth,
RandomAccessIterator end, __gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::nth_element(begin, nth, end); } { return _GLIBCXX_STD_P::nth_element(begin, nth, end); }
// Sequential fallback // Sequential fallback
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
void void
nth_element(RandomAccessIterator begin, RandomAccessIterator nth, RandomAccessIterator end, Comparator comp, __gnu_parallel::sequential_tag) nth_element(RandomAccessIterator begin, RandomAccessIterator nth,
RandomAccessIterator end, Comparator comp,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::nth_element(begin, nth, end, comp); } { return _GLIBCXX_STD_P::nth_element(begin, nth, end, comp); }
// Public interface // Public interface
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
inline void inline void
nth_element(RandomAccessIterator begin, RandomAccessIterator nth, RandomAccessIterator end, Comparator comp) nth_element(RandomAccessIterator begin, RandomAccessIterator nth,
RandomAccessIterator end, Comparator comp)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::nth_element_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::nth_element_minimal_n))
__gnu_parallel::parallel_nth_element(begin, nth, end, comp); __gnu_parallel::parallel_nth_element(begin, nth, end, comp);
...@@ -1437,28 +1649,34 @@ namespace __parallel ...@@ -1437,28 +1649,34 @@ namespace __parallel
// Public interface, insert default comparator // Public interface, insert default comparator
template<typename RandomAccessIterator> template<typename RandomAccessIterator>
void void
nth_element(RandomAccessIterator begin, RandomAccessIterator nth, RandomAccessIterator end) nth_element(RandomAccessIterator begin, RandomAccessIterator nth,
RandomAccessIterator end)
{ {
typedef typename iterator_traits<RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type;
nth_element(begin, nth, end, std::less<value_type>()); nth_element(begin, nth, end, std::less<value_type>());
} }
// Sequential fallback // Sequential fallback
template<typename _RandomAccessIterator, typename _Compare> template<typename RandomAccessIterator, typename _Compare>
void void
partial_sort(_RandomAccessIterator begin, _RandomAccessIterator middle, _RandomAccessIterator end, _Compare comp, __gnu_parallel::sequential_tag) partial_sort(RandomAccessIterator begin, RandomAccessIterator middle,
RandomAccessIterator end, _Compare comp,
__gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::partial_sort(begin, middle, end, comp); } { _GLIBCXX_STD_P::partial_sort(begin, middle, end, comp); }
// Sequential fallback // Sequential fallback
template<typename _RandomAccessIterator> template<typename RandomAccessIterator>
void void
partial_sort(_RandomAccessIterator begin, _RandomAccessIterator middle, _RandomAccessIterator end, __gnu_parallel::sequential_tag) partial_sort(RandomAccessIterator begin, RandomAccessIterator middle,
RandomAccessIterator end, __gnu_parallel::sequential_tag)
{ _GLIBCXX_STD_P::partial_sort(begin, middle, end); } { _GLIBCXX_STD_P::partial_sort(begin, middle, end); }
// Public interface, parallel algorithm for random access iterators // Public interface, parallel algorithm for random access iterators
template<typename _RandomAccessIterator, typename _Compare> template<typename RandomAccessIterator, typename _Compare>
void void
partial_sort(_RandomAccessIterator begin, _RandomAccessIterator middle, _RandomAccessIterator end, _Compare comp) partial_sort(RandomAccessIterator begin, RandomAccessIterator middle,
RandomAccessIterator end, _Compare comp)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::partial_sort_minimal_n)) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::partial_sort_minimal_n))
__gnu_parallel::parallel_partial_sort(begin, middle, end, comp); __gnu_parallel::parallel_partial_sort(begin, middle, end, comp);
...@@ -1467,44 +1685,44 @@ namespace __parallel ...@@ -1467,44 +1685,44 @@ namespace __parallel
} }
// Public interface, insert default comparator // Public interface, insert default comparator
template<typename _RandomAccessIterator> template<typename RandomAccessIterator>
void void
partial_sort(_RandomAccessIterator begin, _RandomAccessIterator middle, _RandomAccessIterator end) partial_sort(RandomAccessIterator begin, RandomAccessIterator middle,
RandomAccessIterator end)
{ {
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; typedef iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type;
partial_sort(begin, middle, end, std::less<value_type>()); partial_sort(begin, middle, end, std::less<value_type>());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator> template<typename ForwardIterator>
inline ForwardIterator inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end, __gnu_parallel::sequential_tag) max_element(ForwardIterator begin, ForwardIterator end,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::max_element(begin, end); } { return _GLIBCXX_STD_P::max_element(begin, end); }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename Comparator> template<typename ForwardIterator, typename Comparator>
inline ForwardIterator inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end, Comparator comp, __gnu_parallel::sequential_tag) max_element(ForwardIterator begin, ForwardIterator end, Comparator comp,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::max_element(begin, end, comp); } { return _GLIBCXX_STD_P::max_element(begin, end, comp); }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename Comparator, typename IteratorTag> template<typename ForwardIterator, typename Comparator, typename IteratorTag>
ForwardIterator ForwardIterator
max_element_switch(ForwardIterator begin, ForwardIterator end, Comparator comp, IteratorTag, __gnu_parallel::parallelism parallelism_tag) max_element_switch(ForwardIterator begin, ForwardIterator end,
Comparator comp, IteratorTag)
{ return max_element(begin, end, comp, __gnu_parallel::sequential_tag()); } { return max_element(begin, end, comp, __gnu_parallel::sequential_tag()); }
// Public interface, insert default comparator // Parallel algorithm for random access iterators
template<typename ForwardIterator>
inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return max_element(begin, end, std::less<value_type>(), parallelism_tag);
}
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
RandomAccessIterator RandomAccessIterator
max_element_switch(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) max_element_switch(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::max_element_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::max_element_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -1514,49 +1732,78 @@ namespace __parallel ...@@ -1514,49 +1732,78 @@ namespace __parallel
return res; return res;
} }
else else
return max_element(begin, end, __gnu_parallel::sequential_tag()); return max_element(begin, end, comp, __gnu_parallel::sequential_tag());
}
// Public interface, insert default comparator
template<typename ForwardIterator>
inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end,
__gnu_parallel::parallelism parallelism_tag)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return max_element(begin, end, std::less<value_type>(), parallelism_tag);
}
template<typename ForwardIterator>
inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return max_element(begin, end, std::less<value_type>());
} }
// Public interface // Public interface
template<typename ForwardIterator, typename Comparator> template<typename ForwardIterator, typename Comparator>
inline ForwardIterator inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end, Comparator comp, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) max_element(ForwardIterator begin, ForwardIterator end, Comparator comp,
__gnu_parallel::parallelism parallelism_tag)
{
typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return max_element_switch(begin, end, comp, iterator_category(),
parallelism_tag);
}
template<typename ForwardIterator, typename Comparator>
inline ForwardIterator
max_element(ForwardIterator begin, ForwardIterator end, Comparator comp)
{ {
return max_element_switch(begin, end, comp, typename std::iterator_traits<ForwardIterator>::iterator_category(), parallelism_tag); typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return max_element_switch(begin, end, comp, iterator_category());
} }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator> template<typename ForwardIterator>
inline inline
ForwardIterator ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end, __gnu_parallel::sequential_tag) min_element(ForwardIterator begin, ForwardIterator end,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::min_element(begin, end); } { return _GLIBCXX_STD_P::min_element(begin, end); }
// Sequential fallback // Sequential fallback
template<typename ForwardIterator, typename Comparator> template<typename ForwardIterator, typename Comparator>
inline ForwardIterator inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end, Comparator comp, __gnu_parallel::sequential_tag) min_element(ForwardIterator begin, ForwardIterator end, Comparator comp,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::min_element(begin, end, comp); } { return _GLIBCXX_STD_P::min_element(begin, end, comp); }
// Public interface
template<typename ForwardIterator>
inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return min_element(begin, end, std::less<value_type>(), parallelism_tag);
}
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename ForwardIterator, typename Comparator, typename IteratorTag> template<typename ForwardIterator, typename Comparator, typename IteratorTag>
ForwardIterator ForwardIterator
min_element_switch(ForwardIterator begin, ForwardIterator end, Comparator comp, IteratorTag, __gnu_parallel::parallelism parallelism_tag) min_element_switch(ForwardIterator begin, ForwardIterator end,
Comparator comp, IteratorTag)
{ return min_element(begin, end, comp, __gnu_parallel::sequential_tag()); } { return min_element(begin, end, comp, __gnu_parallel::sequential_tag()); }
// Parallel algorithm for random access iterators // Parallel algorithm for random access iterators
template<typename RandomAccessIterator, typename Comparator> template<typename RandomAccessIterator, typename Comparator>
RandomAccessIterator RandomAccessIterator
min_element_switch(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) min_element_switch(RandomAccessIterator begin, RandomAccessIterator end,
Comparator comp, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::min_element_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::min_element_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -1566,17 +1813,46 @@ namespace __parallel ...@@ -1566,17 +1813,46 @@ namespace __parallel
return res; return res;
} }
else else
return min_element(begin, end, __gnu_parallel::sequential_tag()); return min_element(begin, end, comp, __gnu_parallel::sequential_tag());
}
// Public interface, insert default comparator
template<typename ForwardIterator>
inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end,
__gnu_parallel::parallelism parallelism_tag)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return min_element(begin, end, std::less<value_type>(), parallelism_tag);
}
template<typename ForwardIterator>
inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end)
{
typedef typename iterator_traits<ForwardIterator>::value_type value_type;
return min_element(begin, end, std::less<value_type>());
} }
// Public interface // Public interface
template<typename ForwardIterator, typename Comparator> template<typename ForwardIterator, typename Comparator>
inline ForwardIterator inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end, Comparator comp, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) min_element(ForwardIterator begin, ForwardIterator end, Comparator comp,
__gnu_parallel::parallelism parallelism_tag)
{
typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category;
return min_element_switch(begin, end, comp, iterator_category(),
parallelism_tag);
}
template<typename ForwardIterator, typename Comparator>
inline ForwardIterator
min_element(ForwardIterator begin, ForwardIterator end, Comparator comp)
{ {
typedef iterator_traits<ForwardIterator> traits_type; typedef iterator_traits<ForwardIterator> traits_type;
typedef typename traits_type::iterator_category iterator_category; typedef typename traits_type::iterator_category iterator_category;
return min_element_switch(begin, end, comp, iterator_category(), parallelism_tag); return min_element_switch(begin, end, comp, iterator_category());
} }
} // end namespace } // end namespace
} // end namespace } // end namespace
......
...@@ -59,15 +59,15 @@ namespace __parallel ...@@ -59,15 +59,15 @@ namespace __parallel
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2> template<typename InputIterator1, typename InputIterator2>
inline bool inline bool
equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, __gnu_parallel::sequential_tag) equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::equal<InputIterator1, InputIterator2>(begin1, end1, begin2); { return _GLIBCXX_STD_P::equal(begin1, end1, begin2); }
}
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename Predicate>
inline bool inline bool
equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, Predicate pred, __gnu_parallel::sequential_tag) equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
Predicate pred, __gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::equal(begin1, end1, begin2, pred); } { return _GLIBCXX_STD_P::equal(begin1, end1, begin2, pred); }
// Public interface // Public interface
...@@ -79,7 +79,8 @@ namespace __parallel ...@@ -79,7 +79,8 @@ namespace __parallel
// Public interface // Public interface
template<typename InputIterator1, typename InputIterator2, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename Predicate>
inline bool inline bool
equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, Predicate pred) equal(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
Predicate pred)
{ return mismatch(begin1, end1, begin2, pred).first == end1; } { return mismatch(begin1, end1, begin2, pred).first == end1; }
// NB: lexicographical_compare equires mismatch. // NB: lexicographical_compare equires mismatch.
...@@ -87,33 +88,36 @@ namespace __parallel ...@@ -87,33 +88,36 @@ namespace __parallel
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2> template<typename InputIterator1, typename InputIterator2>
inline pair<InputIterator1, InputIterator2> inline pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, __gnu_parallel::sequential_tag) mismatch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
{ __gnu_parallel::sequential_tag)
return _GLIBCXX_STD_P::mismatch<InputIterator1, InputIterator2>(begin1, end1, begin2); { return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2); }
}
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename Predicate>
inline pair<InputIterator1, InputIterator2> inline pair<InputIterator1, InputIterator2>
mismatch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, Predicate pred, __gnu_parallel::sequential_tag) mismatch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2,
Predicate pred, __gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred); } { return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred); }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator1, typename InputIterator2, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename InputIterator1, typename InputIterator2, typename Predicate, typename IteratorTag1, typename IteratorTag2>
inline pair<InputIterator1, InputIterator2> inline pair<InputIterator1, InputIterator2>
mismatch_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, Predicate pred, IteratorTag1, IteratorTag2) mismatch_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, Predicate pred, IteratorTag1,
IteratorTag2)
{ return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred); } { return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred); }
// Parallel mismatch for random access iterators // Parallel mismatch for random access iterators
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Predicate> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Predicate>
pair<RandomAccessIterator1, RandomAccessIterator2> pair<RandomAccessIterator1, RandomAccessIterator2>
mismatch_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, Predicate pred, random_access_iterator_tag, random_access_iterator_tag) mismatch_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1,
RandomAccessIterator2 begin2, Predicate pred,
random_access_iterator_tag, random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
{ {
RandomAccessIterator1 res_first = RandomAccessIterator1 res = __gnu_parallel::find_template(begin1, end1, begin2, pred, __gnu_parallel::mismatch_selector()).first;
__gnu_parallel::find_template(begin1, end1, begin2, pred, __gnu_parallel::mismatch_selector()).first; return make_pair(res , begin2 + (res - begin1));
return make_pair(res_first, begin2 + (res_first - begin1));
} }
else else
return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred); return _GLIBCXX_STD_P::mismatch(begin1, end1, begin2, pred);
...@@ -131,7 +135,10 @@ namespace __parallel ...@@ -131,7 +135,10 @@ namespace __parallel
typedef typename iterator1_traits::iterator_category iterator1_category; typedef typename iterator1_traits::iterator_category iterator1_category;
typedef typename iterator2_traits::iterator_category iterator2_category; typedef typename iterator2_traits::iterator_category iterator2_category;
return mismatch_switch(begin1, end1, begin2, __gnu_parallel::equal_to<value1_type, value2_type>(), iterator1_category(), iterator2_category()); typedef __gnu_parallel::equal_to<value1_type, value2_type> equal_to_type;
return mismatch_switch(begin1, end1, begin2, equal_to_type(),
iterator1_category(), iterator2_category());
} }
// Public interface // Public interface
...@@ -145,38 +152,52 @@ namespace __parallel ...@@ -145,38 +152,52 @@ namespace __parallel
typedef typename iterator1_traits::iterator_category iterator1_category; typedef typename iterator1_traits::iterator_category iterator1_category;
typedef typename iterator2_traits::iterator_category iterator2_category; typedef typename iterator2_traits::iterator_category iterator2_category;
return mismatch_switch(begin1, end1, begin2, pred, iterator1_category(), iterator2_category()); return mismatch_switch(begin1, end1, begin2, pred, iterator1_category(),
iterator2_category());
} }
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2> template<typename InputIterator1, typename InputIterator2>
inline bool inline bool
lexicographical_compare(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, __gnu_parallel::sequential_tag) lexicographical_compare(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
__gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::lexicographical_compare<InputIterator1, InputIterator2>(begin1, end1, begin2, end2); return _GLIBCXX_STD_P::lexicographical_compare(begin1, end1, begin2, end2);
} }
// Sequential fallback // Sequential fallback
template<typename InputIterator1, typename InputIterator2, typename Predicate> template<typename InputIterator1, typename InputIterator2, typename Predicate>
inline bool inline bool
lexicographical_compare(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, Predicate pred, __gnu_parallel::sequential_tag) lexicographical_compare(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
Predicate pred, __gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::lexicographical_compare(begin1, end1, begin2, end2, pred); return _GLIBCXX_STD_P::lexicographical_compare(begin1, end1,
begin2, end2, pred);
} }
// Sequential fallback for input iterator case // Sequential fallback for input iterator case
template<typename InputIterator1, typename InputIterator2, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename InputIterator1, typename InputIterator2, typename Predicate, typename IteratorTag1, typename IteratorTag2>
inline bool inline bool
lexicographical_compare_switch(InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2, InputIterator2 end2, Predicate pred, IteratorTag1, IteratorTag2) lexicographical_compare_switch(InputIterator1 begin1, InputIterator1 end1,
InputIterator2 begin2, InputIterator2 end2,
Predicate pred, IteratorTag1, IteratorTag2)
{ {
return _GLIBCXX_STD_P::lexicographical_compare(begin1, end1, begin2, end2, pred); return _GLIBCXX_STD_P::lexicographical_compare(begin1, end1,
begin2, end2, pred);
} }
// Parallel lexicographical_compare for random access iterators // Parallel lexicographical_compare for random access iterators
// Limitation: Both valuetypes must be the same // Limitation: Both valuetypes must be the same
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Predicate> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename Predicate>
bool bool
lexicographical_compare_switch(RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, Predicate pred, random_access_iterator_tag, random_access_iterator_tag) lexicographical_compare_switch(RandomAccessIterator1 begin1,
RandomAccessIterator1 end1,
RandomAccessIterator2 begin2,
RandomAccessIterator2 end2, Predicate pred,
random_access_iterator_tag,
random_access_iterator_tag)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
{ {
...@@ -192,7 +213,10 @@ namespace __parallel ...@@ -192,7 +213,10 @@ namespace __parallel
if ((end1 - begin1) < (end2 - begin2)) if ((end1 - begin1) < (end2 - begin2))
{ {
typedef pair<RandomAccessIterator1, RandomAccessIterator2> pair_type; typedef pair<RandomAccessIterator1, RandomAccessIterator2> pair_type;
pair_type mm = mismatch_switch(begin1, end1, begin2, equal_type(pred), random_access_iterator_tag(), random_access_iterator_tag()); pair_type mm = mismatch_switch(begin1, end1, begin2,
equal_type(pred),
random_access_iterator_tag(),
random_access_iterator_tag());
// Less because shorter. // Less because shorter.
const bool lbs = mm.first == end1; const bool lbs = mm.first == end1;
...@@ -205,7 +229,10 @@ namespace __parallel ...@@ -205,7 +229,10 @@ namespace __parallel
else else
{ {
typedef pair<RandomAccessIterator2, RandomAccessIterator1> pair_type; typedef pair<RandomAccessIterator2, RandomAccessIterator1> pair_type;
pair_type mm = mismatch_switch(begin2, end2, begin1, equal_type(pred), random_access_iterator_tag(), random_access_iterator_tag()); pair_type mm = mismatch_switch(begin2, end2, begin1,
equal_type(pred),
random_access_iterator_tag(),
random_access_iterator_tag());
// Less because shorter. // Less because shorter.
const bool lbs = mm.first != end2; const bool lbs = mm.first != end2;
...@@ -234,7 +261,9 @@ namespace __parallel ...@@ -234,7 +261,9 @@ namespace __parallel
typedef typename traits2_type::iterator_category iterator2_category; typedef typename traits2_type::iterator_category iterator2_category;
typedef __gnu_parallel::less<value1_type, value2_type> less_type; typedef __gnu_parallel::less<value1_type, value2_type> less_type;
return lexicographical_compare_switch(begin1, end1, begin2, end2, less_type(), iterator1_category(), iterator2_category()); return lexicographical_compare_switch(begin1, end1, begin2, end2,
less_type(), iterator1_category(),
iterator2_category());
} }
// Public interface // Public interface
...@@ -248,7 +277,9 @@ namespace __parallel ...@@ -248,7 +277,9 @@ namespace __parallel
typedef iterator_traits<InputIterator2> traits2_type; typedef iterator_traits<InputIterator2> traits2_type;
typedef typename traits2_type::iterator_category iterator2_category; typedef typename traits2_type::iterator_category iterator2_category;
return lexicographical_compare_switch(begin1, end1, begin2, end2, pred, iterator1_category(), iterator2_category()); return lexicographical_compare_switch(begin1, end1, begin2, end2, pred,
iterator1_category(),
iterator2_category());
} }
} // end namespace } // end namespace
} // end namespace } // end namespace
......
...@@ -45,216 +45,245 @@ namespace std ...@@ -45,216 +45,245 @@ namespace std
namespace __parallel namespace __parallel
{ {
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
adjacent_find(_FIter, _FIter, __gnu_parallel::sequential_tag); adjacent_find(_FIter, _FIter);
template<typename _FIter, typename BinaryPredicate>
inline _FIter
adjacent_find(_FIter, _FIter, BinaryPredicate, __gnu_parallel::sequential_tag);
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
adjacent_find(_FIter, _FIter); adjacent_find(_FIter, _FIter, __gnu_parallel::sequential_tag);
template<typename _FIter, typename BinaryPredicate> template<typename _FIter, typename _IterTag>
inline _FIter _FIter
adjacent_find(_FIter, _FIter, BinaryPredicate); adjacent_find_switch(_FIter, _FIter, _IterTag);
template<typename _RAIter> template<typename _RAIter>
_RAIter _RAIter
adjacent_find_switch(_RAIter, _RAIter, random_access_iterator_tag); adjacent_find_switch(_RAIter, _RAIter, random_access_iterator_tag);
template<typename _FIter, typename IteratorTag>
inline _FIter
adjacent_find_switch(_FIter, _FIter, IteratorTag);
template<typename _FIter, typename BinaryPredicate, typename IteratorTag> template<typename _FIter, typename _BiPredicate>
inline _FIter _FIter
adjacent_find_switch(_FIter, _FIter, BinaryPredicate, IteratorTag); adjacent_find(_FIter, _FIter, _BiPredicate);
template<typename _RAIter, typename BinaryPredicate> template<typename _FIter, typename _BiPredicate>
_RAIter _FIter
adjacent_find_switch(_RAIter, _RAIter, BinaryPredicate, random_access_iterator_tag); adjacent_find(_FIter, _FIter, _BiPredicate,
__gnu_parallel::sequential_tag);
template<typename _FIter, typename _BiPredicate, typename _IterTag>
_FIter
adjacent_find_switch(_FIter, _FIter, _BiPredicate, _IterTag);
template<typename _RAIter, typename _BiPredicate>
_RAIter
adjacent_find_switch(_RAIter, _RAIter, _BiPredicate,
random_access_iterator_tag);
template<typename _IIter, typename _Tp>
typename iterator_traits<_IIter>::difference_type
count(_IIter, _IIter, const _Tp&);
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline typename iterator_traits<_IIter>::difference_type typename iterator_traits<_IIter>::difference_type
count(_IIter, _IIter, const T& value, __gnu_parallel::sequential_tag); count(_IIter, _IIter, const T&, __gnu_parallel::sequential_tag);
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline typename iterator_traits<_IIter>::difference_type typename iterator_traits<_IIter>::difference_type
count(_IIter, _IIter, const T& value, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); count(_IIter, _IIter, const T&, __gnu_parallel::parallelism);
template<typename _IIter, typename T, typename _IterTag>
typename iterator_traits<_IIter>::difference_type
count_switch(_IIter, _IIter, const T&, _IterTag);
template<typename _RAIter, typename T> template<typename _RAIter, typename T>
typename iterator_traits<_RAIter>::difference_type typename iterator_traits<_RAIter>::difference_type
count_switch(_RAIter, _RAIter, const T& value, random_access_iterator_tag, __gnu_parallel::parallelism); count_switch(_RAIter, _RAIter, const T&, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _IIter, typename T, typename IteratorTag>
typename iterator_traits<_IIter>::difference_type
count_switch(_IIter, _IIter, const T& value, IteratorTag, __gnu_parallel::parallelism);
template<typename _IIter, typename Predicate>
typename iterator_traits<_IIter>::difference_type
count_if(_IIter, _IIter, Predicate);
template<typename _IIter, typename Predicate> template<typename _IIter, typename Predicate>
inline typename iterator_traits<_IIter>::difference_type typename iterator_traits<_IIter>::difference_type
count_if(_IIter, _IIter, Predicate, __gnu_parallel::sequential_tag); count_if(_IIter, _IIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter, typename Predicate> template<typename _IIter, typename Predicate>
inline typename iterator_traits<_IIter>::difference_type typename iterator_traits<_IIter>::difference_type
count_if(_IIter, _IIter, Predicate, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); count_if(_IIter, _IIter, Predicate, __gnu_parallel::parallelism);
template<typename _RAIter, typename Predicate> template<typename _IIter, typename Predicate, typename _IterTag>
typename iterator_traits<_RAIter>::difference_type typename iterator_traits<_IIter>::difference_type
count_if_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag, __gnu_parallel::parallelism); count_if_switch(_IIter, _IIter, Predicate, _IterTag);
template<typename _IIter, typename Predicate, typename IteratorTag> template<typename _RAIter, typename Predicate>
typename iterator_traits<_IIter>::difference_type typename iterator_traits<_RAIter>::difference_type
count_if_switch(_IIter, _IIter, Predicate, IteratorTag, __gnu_parallel::parallelism); count_if_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag,
__gnu_parallel::parallelism);
// algobase.h // algobase.h
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline bool bool
equal(_IIter1, _IIter1, _IIter2, __gnu_parallel::sequential_tag); equal(_IIter1, _IIter1, _IIter2, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline bool bool
equal(_IIter1, _IIter1, _IIter2, Predicate, __gnu_parallel::sequential_tag); equal(_IIter1, _IIter1, _IIter2, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline bool bool
equal(_IIter1, _IIter1, _IIter2); equal(_IIter1, _IIter1, _IIter2);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline bool bool
equal(_IIter1, _IIter1, _IIter2, Predicate); equal(_IIter1, _IIter1, _IIter2, Predicate);
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline _IIter _IIter
find(_IIter, _IIter, const T&, __gnu_parallel::sequential_tag); find(_IIter, _IIter, const T&, __gnu_parallel::sequential_tag);
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline _IIter _IIter
find(_IIter, _IIter, const T& val); find(_IIter, _IIter, const T& val);
template<typename _IIter, typename T, typename IteratorTag> template<typename _IIter, typename T, typename _IterTag>
inline _IIter _IIter
find_switch(_IIter, _IIter, const T&, IteratorTag); find_switch(_IIter, _IIter, const T&, _IterTag);
template<typename _RAIter, typename T> template<typename _RAIter, typename T>
_RAIter _RAIter
find_switch(_RAIter, _RAIter, const T&, random_access_iterator_tag); find_switch(_RAIter, _RAIter, const T&, random_access_iterator_tag);
template<typename _IIter, typename Predicate> template<typename _IIter, typename Predicate>
inline _IIter _IIter
find_if(_IIter, _IIter, Predicate, __gnu_parallel::sequential_tag); find_if(_IIter, _IIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter, typename Predicate> template<typename _IIter, typename Predicate>
inline _IIter _IIter
find_if(_IIter, _IIter, Predicate); find_if(_IIter, _IIter, Predicate);
template<typename _IIter, typename Predicate, typename IteratorTag> template<typename _IIter, typename Predicate, typename _IterTag>
inline _IIter _IIter
find_if_switch(_IIter, _IIter, Predicate, IteratorTag); find_if_switch(_IIter, _IIter, Predicate, _IterTag);
template<typename _RAIter, typename Predicate> template<typename _RAIter, typename Predicate>
_RAIter _RAIter
find_if_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag); find_if_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag);
template<typename _IIter, typename _FIter> template<typename _IIter, typename _FIter>
inline _IIter _IIter
find_first_of(_IIter, _IIter, _FIter, _FIter, __gnu_parallel::sequential_tag); find_first_of(_IIter, _IIter, _FIter, _FIter, __gnu_parallel::sequential_tag);
template<typename _IIter, typename _FIter, typename BinaryPredicate> template<typename _IIter, typename _FIter, typename _BiPredicate>
inline _IIter _IIter
find_first_of(_IIter, _IIter, _FIter, _FIter, BinaryPredicate, __gnu_parallel::sequential_tag); find_first_of(_IIter, _IIter, _FIter, _FIter, _BiPredicate, __gnu_parallel::sequential_tag);
template<typename _IIter, typename _FIter, typename BinaryPredicate> template<typename _IIter, typename _FIter, typename _BiPredicate>
inline _IIter _IIter
find_first_of(_IIter, _IIter, _FIter, _FIter, BinaryPredicate); find_first_of(_IIter, _IIter, _FIter, _FIter, _BiPredicate);
template<typename _IIter, typename _FIter> template<typename _IIter, typename _FIter>
_IIter _IIter
find_first_of(_IIter, _IIter, _FIter, _FIter); find_first_of(_IIter, _IIter, _FIter, _FIter);
template<typename _IIter, typename _FIter, typename IteratorTag1, typename IteratorTag2> template<typename _IIter, typename _FIter, typename _IterTag1, typename _IterTag2>
inline _IIter _IIter
find_first_of_switch(_IIter, _IIter, _FIter, _FIter, IteratorTag1, IteratorTag2); find_first_of_switch(_IIter, _IIter, _FIter, _FIter, _IterTag1, _IterTag2);
template<typename _RAIter, typename _FIter, typename BinaryPredicate, typename IteratorTag> template<typename _RAIter, typename _FIter, typename _BiPredicate, typename _IterTag>
inline _RAIter _RAIter
find_first_of_switch(_RAIter, _RAIter, _FIter, _FIter, BinaryPredicate, random_access_iterator_tag, IteratorTag); find_first_of_switch(_RAIter, _RAIter, _FIter, _FIter, _BiPredicate, random_access_iterator_tag, _IterTag);
template<typename _IIter, typename _FIter, typename BinaryPredicate, typename IteratorTag1, typename IteratorTag2> template<typename _IIter, typename _FIter, typename _BiPredicate, typename _IterTag1, typename _IterTag2>
inline _IIter _IIter
find_first_of_switch(_IIter, _IIter, _FIter, _FIter, BinaryPredicate, IteratorTag1, IteratorTag2); find_first_of_switch(_IIter, _IIter, _FIter, _FIter, _BiPredicate, _IterTag1, _IterTag2);
template<typename _IIter, typename Function> template<typename _IIter, typename Function>
inline Function Function
for_each(_IIter, _IIter, Function f, __gnu_parallel::sequential_tag); for_each(_IIter, _IIter, Function);
template<typename _IIter, typename Function>
Function
for_each(_IIter, _IIter, Function, __gnu_parallel::sequential_tag);
template<typename Iterator, typename Function> template<typename Iterator, typename Function>
inline Function Function
for_each(Iterator, Iterator, Function f, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); for_each(Iterator, Iterator, Function, __gnu_parallel::parallelism);
template<typename _IIter, typename Function, typename IteratorTag> template<typename _IIter, typename Function, typename _IterTag>
Function Function
for_each_switch(_IIter, _IIter, Function f, IteratorTag, __gnu_parallel::parallelism); for_each_switch(_IIter, _IIter, Function, _IterTag);
template<typename _RAIter, typename Function> template<typename _RAIter, typename Function>
Function Function
for_each_switch(_RAIter, _RAIter, Function f, random_access_iterator_tag, __gnu_parallel::parallelism); for_each_switch(_RAIter, _RAIter, Function, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _FIter, typename Generator> template<typename _FIter, typename Generator>
inline void void
generate(_FIter, _FIter, Generator, __gnu_parallel::sequential_tag); generate(_FIter, _FIter, Generator);
template<typename _FIter, typename Generator> template<typename _FIter, typename Generator>
inline void void
generate(_FIter, _FIter, Generator, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); generate(_FIter, _FIter, Generator, __gnu_parallel::sequential_tag);
template<typename _FIter, typename Generator, typename IteratorTag> template<typename _FIter, typename Generator>
void void
generate_switch(_FIter, _FIter, Generator, IteratorTag, __gnu_parallel::parallelism); generate(_FIter, _FIter, Generator, __gnu_parallel::parallelism);
template<typename _FIter, typename Generator, typename _IterTag>
void
generate_switch(_FIter, _FIter, Generator, _IterTag);
template<typename _RAIter, typename Generator> template<typename _RAIter, typename Generator>
void void
generate_switch(_RAIter, _RAIter, Generator, random_access_iterator_tag, __gnu_parallel::parallelism); generate_switch(_RAIter, _RAIter, Generator, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _OIter, typename Size, typename Generator> template<typename _OIter, typename Size, typename Generator>
inline _OIter _OIter
generate_n(_OIter, Size, Generator, __gnu_parallel::sequential_tag); generate_n(_OIter, Size, Generator);
template<typename _OIter, typename Size, typename Generator> template<typename _OIter, typename Size, typename Generator>
inline _OIter _OIter
generate_n(_OIter, Size, Generator, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); generate_n(_OIter, Size, Generator, __gnu_parallel::sequential_tag);
template<typename _OIter, typename Size, typename Generator, typename IteratorTag> template<typename _OIter, typename Size, typename Generator>
_OIter _OIter
generate_n_switch(_OIter, Size, Generator, IteratorTag, __gnu_parallel::parallelism); generate_n(_OIter, Size, Generator, __gnu_parallel::parallelism);
template<typename _OIter, typename Size, typename Generator, typename _IterTag>
_OIter
generate_n_switch(_OIter, Size, Generator, _IterTag);
template<typename _RAIter, typename Size, typename Generator> template<typename _RAIter, typename Size, typename Generator>
_RAIter _RAIter
generate_n_switch(_RAIter, Size, Generator, random_access_iterator_tag, __gnu_parallel::parallelism); generate_n_switch(_RAIter, Size, Generator, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline bool bool
lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, __gnu_parallel::sequential_tag); lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline bool bool
lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, Predicate, __gnu_parallel::sequential_tag); lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline bool bool
lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2); lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline bool bool
lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, Predicate); lexicographical_compare(_IIter1, _IIter1, _IIter2, _IIter2, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename _IIter1, typename _IIter2, typename Predicate, typename _IterTag1, typename _IterTag2>
inline bool bool
lexicographical_compare_switch(_IIter1, _IIter1, _IIter2, _IIter2, Predicate, IteratorTag1, IteratorTag2); lexicographical_compare_switch(_IIter1, _IIter1, _IIter2, _IIter2, Predicate, _IterTag1, _IterTag2);
template<typename _RAIter1, typename _RAIter2, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Predicate>
bool bool
...@@ -262,225 +291,286 @@ namespace __parallel ...@@ -262,225 +291,286 @@ namespace __parallel
// algo.h // algo.h
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline pair<_IIter1, _IIter2> pair<_IIter1, _IIter2>
mismatch(_IIter1, _IIter1, _IIter2, __gnu_parallel::sequential_tag); mismatch(_IIter1, _IIter1, _IIter2, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline pair<_IIter1, _IIter2> pair<_IIter1, _IIter2>
mismatch(_IIter1, _IIter1, _IIter2, Predicate, __gnu_parallel::sequential_tag); mismatch(_IIter1, _IIter1, _IIter2, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2> template<typename _IIter1, typename _IIter2>
inline pair<_IIter1, _IIter2> pair<_IIter1, _IIter2>
mismatch(_IIter1, _IIter1, _IIter2); mismatch(_IIter1, _IIter1, _IIter2);
template<typename _IIter1, typename _IIter2, typename Predicate> template<typename _IIter1, typename _IIter2, typename Predicate>
inline pair<_IIter1, _IIter2> pair<_IIter1, _IIter2>
mismatch(_IIter1, _IIter1, _IIter2, Predicate); mismatch(_IIter1, _IIter1, _IIter2, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename _IIter1, typename _IIter2, typename Predicate, typename _IterTag1, typename _IterTag2>
inline pair<_IIter1, _IIter2> pair<_IIter1, _IIter2>
mismatch_switch(_IIter1, _IIter1, _IIter2, Predicate, IteratorTag1, IteratorTag2); mismatch_switch(_IIter1, _IIter1, _IIter2, Predicate, _IterTag1, _IterTag2);
template<typename _RAIter1, typename _RAIter2, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Predicate>
pair<_RAIter1, _RAIter2> pair<_RAIter1, _RAIter2>
mismatch_switch(_RAIter1, _RAIter1, _RAIter2, Predicate, random_access_iterator_tag, random_access_iterator_tag); mismatch_switch(_RAIter1, _RAIter1, _RAIter2, Predicate, random_access_iterator_tag, random_access_iterator_tag);
template<typename _FIter1, typename _FIter2> template<typename _FIter1, typename _FIter2>
inline _FIter1 _FIter1
search(_FIter1, _FIter1, _FIter2, _FIter2, __gnu_parallel::sequential_tag); search(_FIter1, _FIter1, _FIter2, _FIter2, __gnu_parallel::sequential_tag);
template<typename _FIter1, typename _FIter2> template<typename _FIter1, typename _FIter2>
inline _FIter1 _FIter1
search(_FIter1, _FIter1, _FIter2, _FIter2); search(_FIter1, _FIter1, _FIter2, _FIter2);
template<typename _FIter1, typename _FIter2, typename BinaryPredicate> template<typename _FIter1, typename _FIter2, typename _BiPredicate>
inline _FIter1 _FIter1
search(_FIter1, _FIter1, _FIter2, _FIter2, BinaryPredicate, __gnu_parallel::sequential_tag); search(_FIter1, _FIter1, _FIter2, _FIter2, _BiPredicate, __gnu_parallel::sequential_tag);
template<typename _FIter1, typename _FIter2, typename BinaryPredicate> template<typename _FIter1, typename _FIter2, typename _BiPredicate>
inline _FIter1 _FIter1
search(_FIter1, _FIter1, _FIter2, _FIter2, BinaryPredicate); search(_FIter1, _FIter1, _FIter2, _FIter2, _BiPredicate);
template<typename _RAIter1, typename _RAIter2> template<typename _RAIter1, typename _RAIter2>
_RAIter1 _RAIter1
search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, random_access_iterator_tag, random_access_iterator_tag); search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, random_access_iterator_tag, random_access_iterator_tag);
template<typename _FIter1, typename _FIter2, typename IteratorTag1, typename IteratorTag2> template<typename _FIter1, typename _FIter2, typename _IterTag1, typename _IterTag2>
inline _FIter1 _FIter1
search_switch(_FIter1, _FIter1, _FIter2, _FIter2, IteratorTag1, IteratorTag2); search_switch(_FIter1, _FIter1, _FIter2, _FIter2, _IterTag1, _IterTag2);
template<typename _RAIter1, typename _RAIter2, typename BinaryPredicate> template<typename _RAIter1, typename _RAIter2, typename _BiPredicate>
_RAIter1 _RAIter1
search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, BinaryPredicate , random_access_iterator_tag, random_access_iterator_tag); search_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, _BiPredicate , random_access_iterator_tag, random_access_iterator_tag);
template<typename _FIter1, typename _FIter2, typename BinaryPredicate, typename IteratorTag1, typename IteratorTag2> template<typename _FIter1, typename _FIter2, typename _BiPredicate, typename _IterTag1, typename _IterTag2>
inline _FIter1 _FIter1
search_switch(_FIter1, _FIter1, _FIter2, _FIter2, BinaryPredicate, IteratorTag1, IteratorTag2); search_switch(_FIter1, _FIter1, _FIter2, _FIter2, _BiPredicate, _IterTag1, _IterTag2);
template<typename _FIter, typename Integer, typename T> template<typename _FIter, typename Integer, typename T>
inline _FIter _FIter
search_n(_FIter, _FIter, Integer, const T&, __gnu_parallel::sequential_tag); search_n(_FIter, _FIter, Integer, const T&, __gnu_parallel::sequential_tag);
template<typename _FIter, typename Integer, typename T, typename BinaryPredicate> template<typename _FIter, typename Integer, typename T, typename _BiPredicate>
inline _FIter _FIter
search_n(_FIter, _FIter, Integer, const T&, BinaryPredicate, __gnu_parallel::sequential_tag); search_n(_FIter, _FIter, Integer, const T&, _BiPredicate, __gnu_parallel::sequential_tag);
template<typename _FIter, typename Integer, typename T> template<typename _FIter, typename Integer, typename T>
inline _FIter _FIter
search_n(_FIter, _FIter, Integer, const T& val); search_n(_FIter, _FIter, Integer, const T& val);
template<typename _FIter, typename Integer, typename T, typename BinaryPredicate> template<typename _FIter, typename Integer, typename T, typename _BiPredicate>
inline _FIter _FIter
search_n(_FIter, _FIter, Integer, const T&, BinaryPredicate); search_n(_FIter, _FIter, Integer, const T&, _BiPredicate);
template<typename _RAIter, typename Integer, typename T, typename BinaryPredicate> template<typename _RAIter, typename Integer, typename T, typename _BiPredicate>
_RAIter _RAIter
search_n_switch(_RAIter, _RAIter, Integer, const T&, BinaryPredicate, random_access_iterator_tag); search_n_switch(_RAIter, _RAIter, Integer, const T&, _BiPredicate, random_access_iterator_tag);
template<typename _FIter, typename Integer, typename T, typename BinaryPredicate, typename IteratorTag> template<typename _FIter, typename Integer, typename T, typename _BiPredicate, typename _IterTag>
inline _FIter _FIter
search_n_switch(_FIter, _FIter, Integer, const T&, BinaryPredicate, IteratorTag); search_n_switch(_FIter, _FIter, Integer, const T&, _BiPredicate, _IterTag);
template<typename _IIter, typename _OIter, typename UnaryOperation> template<typename _IIter, typename _OIter, typename UnaryOperation>
inline _OIter _OIter
transform(_IIter, _IIter, _OIter, UnaryOperation, __gnu_parallel::sequential_tag); transform(_IIter, _IIter, _OIter, UnaryOperation);
template<typename _IIter1, typename _IIter2, typename _OIter, typename BinaryOperation> template<typename _IIter, typename _OIter, typename UnaryOperation>
inline _OIter _OIter
transform(_IIter1, _IIter1, _IIter2, _OIter, BinaryOperation binary_op, __gnu_parallel::sequential_tag); transform(_IIter, _IIter, _OIter, UnaryOperation,
__gnu_parallel::sequential_tag);
template<typename _IIter, typename _OIter, typename UnaryOperation> template<typename _IIter, typename _OIter, typename UnaryOperation>
inline _OIter _OIter
transform(_IIter, _IIter, _OIter, UnaryOperation, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); transform(_IIter, _IIter, _OIter, UnaryOperation,
__gnu_parallel::parallelism);
template<typename _IIter, typename _OIter, typename UnaryOperation, typename _IterTag1, typename _IterTag2>
_OIter
transform1_switch(_IIter, _IIter, _OIter, UnaryOperation,
_IterTag1, _IterTag2);
template<typename _IIter1, typename _IIter2, typename _OIter, typename BinaryOperation> template<typename _RAIIter, typename _RAOIter, typename UnaryOperation>
inline _OIter _RAOIter
transform(_IIter1, _IIter1, _IIter2, _OIter, BinaryOperation binary_op, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); transform1_switch(_RAIIter, _RAIIter, _RAOIter, UnaryOperation,
random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _RAIter1, typename _RAIter3, typename UnaryOperation>
_RAIter3
transform1_switch(_RAIter1, _RAIter1, _RAIter3, UnaryOperation, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced);
template<typename _RAIter1, typename _RAIter3, typename UnaryOperation, typename IteratorTag1, typename IteratorTag2> template<typename _IIter1, typename _IIter2, typename _OIter, typename _BiOperation>
inline _RAIter3 _OIter
transform1_switch(_RAIter1, _RAIter1, _RAIter3, UnaryOperation, IteratorTag1, IteratorTag2, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation);
template<typename _RAIter1, typename _RAIter2, typename _RAIter3, typename BinaryOperation> template<typename _IIter1, typename _IIter2, typename _OIter, typename _BiOperation>
_RAIter3 _OIter
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, BinaryOperation binary_op, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation,
__gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _BiOperation>
_OIter
transform(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation,
__gnu_parallel::parallelism);
template<typename _RAIter1, typename _RAIter2, typename _RAIter3, typename _BiOperation>
_RAIter3
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, _BiOperation,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _BiOperation, typename tag1, typename tag2, typename tag3>
_OIter
transform2_switch(_IIter1, _IIter1, _IIter2, _OIter, _BiOperation,
tag1, tag2, tag3);
template<typename _RAIter1, typename _RAIter2, typename _RAIter3, typename BinaryOperation, typename tag1, typename tag2, typename tag3>
inline _RAIter3
transform2_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter3, BinaryOperation binary_op, tag1, tag2, tag3, __gnu_parallel::parallelism);
template<typename _FIter, typename T> template<typename _FIter, typename T>
inline void void
replace(_FIter, _FIter, const T&, const T&, __gnu_parallel::sequential_tag); replace(_FIter, _FIter, const T&, const T&);
template<typename _FIter, typename T> template<typename _FIter, typename T>
inline void void
replace(_FIter, _FIter, const T&, const T&, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); replace(_FIter, _FIter, const T&, const T&,
__gnu_parallel::sequential_tag);
template<typename _FIter, typename T, typename IteratorTag> template<typename _FIter, typename T>
void void
replace_switch(_FIter, _FIter, const T&, const T&, IteratorTag, __gnu_parallel::parallelism); replace(_FIter, _FIter, const T&, const T&, __gnu_parallel::parallelism);
template<typename _FIter, typename T, typename _IterTag>
void
replace_switch(_FIter, _FIter, const T&, const T&, _IterTag);
template<typename _RAIter, typename T> template<typename _RAIter, typename T>
void void
replace_switch(_RAIter, _RAIter, const T&, const T&, random_access_iterator_tag, __gnu_parallel::parallelism); replace_switch(_RAIter, _RAIter, const T&, const T&,
random_access_iterator_tag, __gnu_parallel::parallelism);
template<typename _FIter, typename Predicate, typename T> template<typename _FIter, typename Predicate, typename T>
inline void void
replace_if(_FIter, _FIter, Predicate, const T&, __gnu_parallel::sequential_tag); replace_if(_FIter, _FIter, Predicate, const T&);
template<typename _FIter, typename Predicate, typename T> template<typename _FIter, typename Predicate, typename T>
inline void void
replace_if(_FIter, _FIter, Predicate, const T&, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); replace_if(_FIter, _FIter, Predicate, const T&,
__gnu_parallel::sequential_tag);
template<typename _FIter, typename Predicate, typename T, typename IteratorTag>
void
replace_if_switch(_FIter, _FIter, Predicate, const T&, IteratorTag, __gnu_parallel::parallelism);
template<typename _FIter, typename Predicate, typename T>
void
replace_if(_FIter, _FIter, Predicate, const T&,
__gnu_parallel::parallelism);
template<typename _FIter, typename Predicate, typename T, typename _IterTag>
void
replace_if_switch(_FIter, _FIter, Predicate, const T&, _IterTag);
template<typename _RAIter, typename Predicate, typename T> template<typename _RAIter, typename Predicate, typename T>
void void
replace_if_switch(_RAIter, _RAIter, Predicate, const T&, random_access_iterator_tag, __gnu_parallel::parallelism); replace_if_switch(_RAIter, _RAIter, Predicate, const T&,
random_access_iterator_tag, __gnu_parallel::parallelism);
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
max_element(_FIter, _FIter, __gnu_parallel::sequential_tag); max_element(_FIter, _FIter);
template<typename _FIter, typename _Compare> template<typename _FIter>
inline _FIter _FIter
max_element(_FIter, _FIter, _Compare, __gnu_parallel::sequential_tag); max_element(_FIter, _FIter, __gnu_parallel::sequential_tag);
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
max_element(_FIter, _FIter, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); max_element(_FIter, _FIter, __gnu_parallel::parallelism parallelism_tag);
template<typename _FIter, typename _Compare> template<typename _FIter, typename _Compare>
inline _FIter _FIter
max_element(_FIter, _FIter, _Compare, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); max_element(_FIter, _FIter, _Compare);
template<typename _FIter, typename _Compare, typename IteratorTag> template<typename _FIter, typename _Compare>
_FIter _FIter
max_element_switch(_FIter, _FIter, _Compare, IteratorTag, __gnu_parallel::parallelism); max_element(_FIter, _FIter, _Compare, __gnu_parallel::sequential_tag);
template<typename _FIter, typename _Compare>
_FIter
max_element(_FIter, _FIter, _Compare, __gnu_parallel::parallelism);
template<typename _FIter, typename _Compare, typename _IterTag>
_FIter
max_element_switch(_FIter, _FIter, _Compare, _IterTag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
_RAIter _RAIter
max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, __gnu_parallel::parallelism); max_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag); merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter,
__gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare> template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare>
inline _OIter _OIter
merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, __gnu_parallel::sequential_tag); merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare,
__gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare> template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare>
inline _OIter _OIter
merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare); merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare, typename _IterTag1, typename _IterTag2, typename _IterTag3>
inline _OIter _OIter
merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, IteratorTag1, IteratorTag2, IteratorTag3); merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare,
_IterTag1, _IterTag2, _IterTag3);
template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare> template<typename _IIter1, typename _IIter2, typename _OIter, typename _Compare>
_OIter _OIter
merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag); merge_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare,
random_access_iterator_tag, random_access_iterator_tag,
random_access_iterator_tag);
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
min_element(_FIter, _FIter, __gnu_parallel::sequential_tag); min_element(_FIter, _FIter);
template<typename _FIter, typename _Compare> template<typename _FIter>
inline _FIter _FIter
min_element(_FIter, _FIter, _Compare, __gnu_parallel::sequential_tag); min_element(_FIter, _FIter, __gnu_parallel::sequential_tag);
template<typename _FIter> template<typename _FIter>
inline _FIter _FIter
min_element(_FIter, _FIter, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); min_element(_FIter, _FIter, __gnu_parallel::parallelism parallelism_tag);
template<typename _FIter, typename _Compare> template<typename _FIter, typename _Compare>
inline _FIter _FIter
min_element(_FIter, _FIter, _Compare, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); min_element(_FIter, _FIter, _Compare);
template<typename _FIter, typename _Compare, typename IteratorTag> template<typename _FIter, typename _Compare>
_FIter _FIter
min_element_switch(_FIter, _FIter, _Compare, IteratorTag, __gnu_parallel::parallelism); min_element(_FIter, _FIter, _Compare, __gnu_parallel::sequential_tag);
template<typename _FIter, typename _Compare>
_FIter
min_element(_FIter, _FIter, _Compare, __gnu_parallel::parallelism);
template<typename _FIter, typename _Compare, typename _IterTag>
_FIter
min_element_switch(_FIter, _FIter, _Compare, _IterTag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
_RAIter _RAIter
min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag, __gnu_parallel::parallelism); min_element_switch(_RAIter, _RAIter, _Compare, random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _RAIter> template<typename _RAIter>
inline void void
nth_element(_RAIter, _RAIter, _RAIter, __gnu_parallel::sequential_tag); nth_element(_RAIter, _RAIter, _RAIter, __gnu_parallel::sequential_tag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
...@@ -488,7 +578,7 @@ namespace __parallel ...@@ -488,7 +578,7 @@ namespace __parallel
nth_element(_RAIter, _RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag); nth_element(_RAIter, _RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
inline void void
nth_element(_RAIter, _RAIter, _RAIter, _Compare); nth_element(_RAIter, _RAIter, _RAIter, _Compare);
template<typename _RAIter> template<typename _RAIter>
...@@ -512,31 +602,31 @@ namespace __parallel ...@@ -512,31 +602,31 @@ namespace __parallel
partial_sort(_RAIter, _RAIter, _RAIter); partial_sort(_RAIter, _RAIter, _RAIter);
template<typename _FIter, typename Predicate> template<typename _FIter, typename Predicate>
inline _FIter _FIter
partition(_FIter, _FIter, Predicate, __gnu_parallel::sequential_tag); partition(_FIter, _FIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _FIter, typename Predicate> template<typename _FIter, typename Predicate>
inline _FIter _FIter
partition(_FIter, _FIter, Predicate); partition(_FIter, _FIter, Predicate);
template<typename _FIter, typename Predicate, typename IteratorTag> template<typename _FIter, typename Predicate, typename _IterTag>
inline _FIter _FIter
partition_switch(_FIter, _FIter, Predicate, IteratorTag); partition_switch(_FIter, _FIter, Predicate, _IterTag);
template<typename _RAIter, typename Predicate> template<typename _RAIter, typename Predicate>
_RAIter _RAIter
partition_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag); partition_switch(_RAIter, _RAIter, Predicate, random_access_iterator_tag);
template<typename _RAIter> template<typename _RAIter>
inline void void
random_shuffle(_RAIter, _RAIter, __gnu_parallel::sequential_tag); random_shuffle(_RAIter, _RAIter, __gnu_parallel::sequential_tag);
template<typename _RAIter, typename RandomNumberGenerator> template<typename _RAIter, typename RandomNumberGenerator>
inline void void
random_shuffle(_RAIter, _RAIter, RandomNumberGenerator& rand, __gnu_parallel::sequential_tag); random_shuffle(_RAIter, _RAIter, RandomNumberGenerator& rand, __gnu_parallel::sequential_tag);
template<typename _RAIter> template<typename _RAIter>
inline void void
random_shuffle(_RAIter, _RAIter); random_shuffle(_RAIter, _RAIter);
template<typename _RAIter, typename RandomNumberGenerator> template<typename _RAIter, typename RandomNumberGenerator>
...@@ -544,72 +634,72 @@ namespace __parallel ...@@ -544,72 +634,72 @@ namespace __parallel
random_shuffle(_RAIter, _RAIter, RandomNumberGenerator& rand); random_shuffle(_RAIter, _RAIter, RandomNumberGenerator& rand);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag); set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag); set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate); set_union(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename _IterTag1, typename _IterTag2, typename _IterTag3>
inline _OIter _OIter
set_union_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, IteratorTag1, IteratorTag2, IteratorTag3); set_union_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, _IterTag1, _IterTag2, _IterTag3);
template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate>
Output_RAIter Output_RAIter
set_union_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, Output_RAIter, Predicate, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag); set_union_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, Output_RAIter, Predicate, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag); set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag); set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate); set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename _IterTag1, typename _IterTag2, typename _IterTag3>
inline _OIter _OIter
set_intersection_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, IteratorTag1, IteratorTag2, IteratorTag3); set_intersection_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, _IterTag1, _IterTag2, _IterTag3);
template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate>
Output_RAIter Output_RAIter
set_intersection_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, Output_RAIter, Predicate, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag); set_intersection_switch(_RAIter1, _RAIter1, _RAIter2, _RAIter2, Output_RAIter, Predicate, random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag); set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag); set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate); set_symmetric_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename _IterTag1, typename _IterTag2, typename _IterTag3>
inline _OIter _OIter
set_symmetric_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, IteratorTag1, IteratorTag2, IteratorTag3); set_symmetric_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, _IterTag1, _IterTag2, _IterTag3);
template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate>
Output_RAIter Output_RAIter
...@@ -617,24 +707,24 @@ namespace __parallel ...@@ -617,24 +707,24 @@ namespace __parallel
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag); set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag); set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename _OIter> template<typename _IIter1, typename _IIter2, typename _OIter>
inline _OIter _OIter
set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter); set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter);
template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate> template<typename _IIter1, typename _IIter2, typename _OIter, typename Predicate>
inline _OIter _OIter
set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate); set_difference(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate);
template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename IteratorTag1, typename IteratorTag2, typename IteratorTag3> template<typename _IIter1, typename _IIter2, typename Predicate, typename _OIter, typename _IterTag1, typename _IterTag2, typename _IterTag3>
inline _OIter _OIter
set_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, IteratorTag1, IteratorTag2, IteratorTag3); set_difference_switch(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, Predicate, _IterTag1, _IterTag2, _IterTag3);
template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate> template<typename _RAIter1, typename _RAIter2, typename Output_RAIter, typename Predicate>
Output_RAIter Output_RAIter
...@@ -642,15 +732,15 @@ namespace __parallel ...@@ -642,15 +732,15 @@ namespace __parallel
template<typename _RAIter> template<typename _RAIter>
inline void void
sort(_RAIter, _RAIter, __gnu_parallel::sequential_tag); sort(_RAIter, _RAIter, __gnu_parallel::sequential_tag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
inline void void
sort(_RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag); sort(_RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag);
template<typename _RAIter> template<typename _RAIter>
inline void void
sort(_RAIter, _RAIter); sort(_RAIter, _RAIter);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
...@@ -658,11 +748,11 @@ namespace __parallel ...@@ -658,11 +748,11 @@ namespace __parallel
sort(_RAIter, _RAIter, _Compare); sort(_RAIter, _RAIter, _Compare);
template<typename _RAIter> template<typename _RAIter>
inline void void
stable_sort(_RAIter, _RAIter, __gnu_parallel::sequential_tag); stable_sort(_RAIter, _RAIter, __gnu_parallel::sequential_tag);
template<typename _RAIter, typename _Compare> template<typename _RAIter, typename _Compare>
inline void void
stable_sort(_RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag); stable_sort(_RAIter, _RAIter, _Compare, __gnu_parallel::sequential_tag);
template<typename _RAIter> template<typename _RAIter>
...@@ -674,46 +764,30 @@ namespace __parallel ...@@ -674,46 +764,30 @@ namespace __parallel
stable_sort(_RAIter, _RAIter, _Compare); stable_sort(_RAIter, _RAIter, _Compare);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
inline _OIter _OIter
unique_copy(_IIter, _IIter, _OIter, __gnu_parallel::sequential_tag); unique_copy(_IIter, _IIter, _OIter, __gnu_parallel::sequential_tag);
template<typename _IIter, typename _OIter, typename Predicate> template<typename _IIter, typename _OIter, typename Predicate>
inline _OIter _OIter
unique_copy(_IIter, _IIter, _OIter, Predicate, __gnu_parallel::sequential_tag); unique_copy(_IIter, _IIter, _OIter, Predicate, __gnu_parallel::sequential_tag);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
inline _OIter _OIter
unique_copy(_IIter, _IIter, _OIter); unique_copy(_IIter, _IIter, _OIter);
template<typename _IIter, typename _OIter, typename Predicate> template<typename _IIter, typename _OIter, typename Predicate>
inline _OIter _OIter
unique_copy(_IIter, _IIter, _OIter, Predicate); unique_copy(_IIter, _IIter, _OIter, Predicate);
template<typename _IIter, typename _OIter, typename Predicate, typename IteratorTag1, typename IteratorTag2> template<typename _IIter, typename _OIter, typename Predicate, typename _IterTag1, typename _IterTag2>
inline _OIter _OIter
unique_copy_switch(_IIter, _IIter, _OIter, Predicate, IteratorTag1, IteratorTag2); unique_copy_switch(_IIter, _IIter, _OIter, Predicate, _IterTag1, _IterTag2);
template<typename _RAIter, typename RandomAccess_OIter, typename Predicate> template<typename _RAIter, typename RandomAccess_OIter, typename Predicate>
RandomAccess_OIter RandomAccess_OIter
unique_copy_switch(_RAIter, _RAIter, RandomAccess_OIter, Predicate, random_access_iterator_tag, random_access_iterator_tag); unique_copy_switch(_RAIter, _RAIter, RandomAccess_OIter, Predicate,
random_access_iterator_tag, random_access_iterator_tag);
} // end namespace __parallel } // end namespace __parallel
} // end namespace std } // end namespace std
// NB: cannot use _GLIBCXX_STD_P directly here, as it is both scoped
// (std::__norm) and unscoped (std::).
namespace __gnu_sequential
{
#ifdef _GLIBCXX_PARALLEL
using std::__norm::partition;
using std::__norm::sort;
using std::__norm::stable_sort;
using std::__norm::random_shuffle;
#else
using std::partition;
using std::sort;
using std::stable_sort;
using std::random_shuffle;
#endif
}
#endif #endif
...@@ -59,10 +59,10 @@ namespace __parallel ...@@ -59,10 +59,10 @@ namespace __parallel
// Sequential fallback. // Sequential fallback.
template<typename InputIterator, typename T> template<typename InputIterator, typename T>
inline T inline T
accumulate(InputIterator begin, InputIterator end, T init, __gnu_parallel::sequential_tag) accumulate(InputIterator begin, InputIterator end, T init,
__gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::accumulate(begin, end, init); } { return _GLIBCXX_STD_P::accumulate(begin, end, init); }
// Sequential fallback.
template<typename InputIterator, typename T, typename BinaryOperation> template<typename InputIterator, typename T, typename BinaryOperation>
inline T inline T
accumulate(InputIterator begin, InputIterator end, T init, accumulate(InputIterator begin, InputIterator end, T init,
...@@ -72,29 +72,25 @@ namespace __parallel ...@@ -72,29 +72,25 @@ namespace __parallel
// Sequential fallback for input iterator case. // Sequential fallback for input iterator case.
template<typename InputIterator, typename T, typename IteratorTag> template<typename InputIterator, typename T, typename IteratorTag>
inline T inline T
accumulate_switch(InputIterator begin, InputIterator end, T init, IteratorTag, __gnu_parallel::parallelism parallelism_tag) accumulate_switch(InputIterator begin, InputIterator end, T init, IteratorTag) { return accumulate(begin, end, init, __gnu_parallel::sequential_tag()); }
{ return accumulate(begin, end, init, __gnu_parallel::sequential_tag()); }
// Public interface.
template<typename InputIterator, typename T>
inline T
accumulate(InputIterator begin, InputIterator end, T init, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced)
{
return accumulate_switch(begin, end, init, std::plus<typename std::iterator_traits<InputIterator>::value_type>(), typename std::iterator_traits<InputIterator>::iterator_category(), parallelism_tag);
}
// Sequential fallback for input iterator case.
template<typename InputIterator, typename T, typename BinaryOperation, typename IteratorTag> template<typename InputIterator, typename T, typename BinaryOperation, typename IteratorTag>
T T
accumulate_switch(InputIterator begin, InputIterator end, T init, BinaryOperation binary_op, IteratorTag, __gnu_parallel::parallelism parallelism_tag) accumulate_switch(InputIterator begin, InputIterator end, T init,
BinaryOperation binary_op, IteratorTag)
{ {
return accumulate(begin, end, init, binary_op, __gnu_parallel::sequential_tag()); return accumulate(begin, end, init, binary_op,
__gnu_parallel::sequential_tag());
} }
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename _RandomAccessIterator, typename T, typename BinaryOperation> template<typename _RandomAccessIterator, typename T, typename BinaryOperation>
T T
accumulate_switch(_RandomAccessIterator begin, _RandomAccessIterator end, T init, BinaryOperation binary_op, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) accumulate_switch(_RandomAccessIterator begin, _RandomAccessIterator end,
T init, BinaryOperation binary_op,
random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_unbalanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::accumulate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::accumulate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -104,38 +100,81 @@ namespace __parallel ...@@ -104,38 +100,81 @@ namespace __parallel
return res; return res;
} }
else else
return accumulate(begin, end, init, binary_op, __gnu_parallel::sequential_tag()); return accumulate(begin, end, init, binary_op,
__gnu_parallel::sequential_tag());
} }
// Public interface. // Public interface.
template<typename InputIterator, typename T, typename BinaryOperation> template<typename InputIterator, typename T>
inline T inline T
accumulate(InputIterator begin, InputIterator end, T init, BinaryOperation binary_op, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced) accumulate(InputIterator begin, InputIterator end, T init,
__gnu_parallel::parallelism parallelism_tag)
{ {
return accumulate_switch(begin, end, init, binary_op, typename std::iterator_traits<InputIterator>::iterator_category(), parallelism_tag); typedef std::iterator_traits<InputIterator> iterator_traits;
typedef typename iterator_traits::value_type value_type;
typedef typename iterator_traits::iterator_category iterator_category;
return accumulate_switch(begin, end, init, std::plus<value_type>(),
iterator_category(), parallelism_tag);
} }
template<typename InputIterator, typename T>
inline T
accumulate(InputIterator begin, InputIterator end, T init)
{
typedef std::iterator_traits<InputIterator> iterator_traits;
typedef typename iterator_traits::value_type value_type;
typedef typename iterator_traits::iterator_category iterator_category;
// Sequential fallback. return accumulate_switch(begin, end, init, std::plus<value_type>(),
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2> iterator_category());
}
template<typename InputIterator, typename T, typename BinaryOperation>
inline T inline T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2, __gnu_parallel::sequential_tag) accumulate(InputIterator begin, InputIterator end, T init,
BinaryOperation binary_op,
__gnu_parallel::parallelism parallelism_tag)
{ {
return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init, binary_op1, binary_op2); typedef iterator_traits<InputIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
return accumulate_switch(begin, end, init, binary_op,
iterator_category(), parallelism_tag);
} }
template<typename InputIterator, typename T, typename BinaryOperation>
inline T
accumulate(InputIterator begin, InputIterator end, T init,
BinaryOperation binary_op)
{
typedef iterator_traits<InputIterator> iterator_traits;
typedef typename iterator_traits::iterator_category iterator_category;
return accumulate_switch(begin, end, init, binary_op,
iterator_category());
}
// Sequential fallback. // Sequential fallback.
template<typename InputIterator1, typename InputIterator2, typename T> template<typename InputIterator1, typename InputIterator2, typename T>
inline T inline T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, __gnu_parallel::sequential_tag) inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init, __gnu_parallel::sequential_tag)
{ return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init); }
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T
inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init, BinaryFunction1 binary_op1,
BinaryFunction2 binary_op2, __gnu_parallel::sequential_tag)
{ {
return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init); return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init,
binary_op1, binary_op2);
} }
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2> template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
T T
inner_product_switch(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag) inner_product_switch(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION((last1 - first1) >= __gnu_parallel::Settings::accumulate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION((last1 - first1) >= __gnu_parallel::Settings::accumulate_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -145,20 +184,45 @@ namespace __parallel ...@@ -145,20 +184,45 @@ namespace __parallel
return res; return res;
} }
else else
return inner_product(first1, last1, first2, init, __gnu_parallel::sequential_tag()); return inner_product(first1, last1, first2, init,
__gnu_parallel::sequential_tag());
} }
// No parallelism for input iterators. // No parallelism for input iterators.
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2, typename IteratorTag1, typename IteratorTag2> template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2, typename IteratorTag1, typename IteratorTag2>
inline T inline T
inner_product_switch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2, IteratorTag1, IteratorTag2, __gnu_parallel::parallelism parallelism_tag) inner_product_switch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryFunction1 binary_op1, BinaryFunction2 binary_op2,
IteratorTag1, IteratorTag2)
{ {
return _GLIBCXX_STD_P::inner_product(first1, last1, first2, init, binary_op1, binary_op2); return inner_product(first1, last1, first2, init, binary_op1, binary_op2,
__gnu_parallel::sequential_tag());
}
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T
inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init, BinaryFunction1 binary_op1,
BinaryFunction2 binary_op2,
__gnu_parallel::parallelism parallelism_tag)
{
typedef iterator_traits<InputIterator1> traits1_type;
typedef typename traits1_type::iterator_category iterator1_category;
typedef iterator_traits<InputIterator2> traits2_type;
typedef typename traits2_type::iterator_category iterator2_category;
return inner_product_switch(first1, last1, first2, init, binary_op1,
binary_op2, iterator1_category(),
iterator2_category(), parallelism_tag);
} }
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2> template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T inline T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, BinaryFunction1 binary_op1, BinaryFunction2 binary_op2, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced) inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init, BinaryFunction1 binary_op1,
BinaryFunction2 binary_op2)
{ {
typedef iterator_traits<InputIterator1> traits1_type; typedef iterator_traits<InputIterator1> traits1_type;
typedef typename traits1_type::iterator_category iterator1_category; typedef typename traits1_type::iterator_category iterator1_category;
...@@ -166,20 +230,34 @@ namespace __parallel ...@@ -166,20 +230,34 @@ namespace __parallel
typedef iterator_traits<InputIterator2> traits2_type; typedef iterator_traits<InputIterator2> traits2_type;
typedef typename traits2_type::iterator_category iterator2_category; typedef typename traits2_type::iterator_category iterator2_category;
return inner_product_switch(first1, last1, first2, init, binary_op1, binary_op2, iterator1_category(), iterator2_category(), parallelism_tag); return inner_product_switch(first1, last1, first2, init, binary_op1,
binary_op2, iterator1_category(),
iterator2_category());
} }
template<typename InputIterator1, typename InputIterator2, typename T> template<typename InputIterator1, typename InputIterator2, typename T>
inline T inline T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced) inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
__gnu_parallel::parallelism parallelism_tag)
{ {
typedef iterator_traits<InputIterator1> traits_type; typedef iterator_traits<InputIterator1> traits_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
return inner_product(first1, last1, first2, init, std::plus<value_type>(), return inner_product(first1, last1, first2, init, std::plus<value_type>(),
std::multiplies<value_type>(), parallelism_tag); std::multiplies<value_type>(), parallelism_tag);
} }
template<typename InputIterator1, typename InputIterator2, typename T>
inline T
inner_product(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init)
{
typedef iterator_traits<InputIterator1> traits_type;
typedef typename traits_type::value_type value_type;
return inner_product(first1, last1, first2, init, std::plus<value_type>(),
std::multiplies<value_type>());
}
// Sequential fallback. // Sequential fallback.
template<typename InputIterator, typename OutputIterator> template<typename InputIterator, typename OutputIterator>
inline OutputIterator inline OutputIterator
...@@ -262,16 +340,21 @@ namespace __parallel ...@@ -262,16 +340,21 @@ namespace __parallel
inline OutputIterator inline OutputIterator
adjacent_difference_switch(InputIterator begin, InputIterator end, adjacent_difference_switch(InputIterator begin, InputIterator end,
OutputIterator result, BinaryOperation bin_op, OutputIterator result, BinaryOperation bin_op,
IteratorTag1, IteratorTag2, __gnu_parallel::parallelism) IteratorTag1, IteratorTag2)
{ return adjacent_difference(begin, end, result, bin_op); } {
return adjacent_difference(begin, end, result, bin_op,
__gnu_parallel::sequential_tag());
}
// Parallel algorithm for random access iterators. // Parallel algorithm for random access iterators.
template<typename InputIterator, typename OutputIterator, typename BinaryOperation> template<typename InputIterator, typename OutputIterator, typename BinaryOperation>
OutputIterator OutputIterator
adjacent_difference_switch(InputIterator begin, InputIterator end, adjacent_difference_switch(InputIterator begin, InputIterator end,
OutputIterator result, BinaryOperation bin_op, OutputIterator result, BinaryOperation bin_op,
random_access_iterator_tag, random_access_iterator_tag, random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag) random_access_iterator_tag,
__gnu_parallel::parallelism parallelism_tag
= __gnu_parallel::parallel_balanced)
{ {
if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::adjacent_difference_minimal_n && __gnu_parallel::is_parallel(parallelism_tag))) if (_GLIBCXX_PARALLEL_CONDITION(static_cast<__gnu_parallel::sequence_index_t>(end - begin) >= __gnu_parallel::Settings::adjacent_difference_minimal_n && __gnu_parallel::is_parallel(parallelism_tag)))
{ {
...@@ -284,7 +367,8 @@ namespace __parallel ...@@ -284,7 +367,8 @@ namespace __parallel
return functionality.finish_iterator; return functionality.finish_iterator;
} }
else else
return adjacent_difference(begin, end, result, bin_op, __gnu_parallel::sequential_tag()); return adjacent_difference(begin, end, result, bin_op,
__gnu_parallel::sequential_tag());
} }
// Public interface. // Public interface.
...@@ -292,19 +376,29 @@ namespace __parallel ...@@ -292,19 +376,29 @@ namespace __parallel
inline OutputIterator inline OutputIterator
adjacent_difference(InputIterator begin, InputIterator end, adjacent_difference(InputIterator begin, InputIterator end,
OutputIterator result, OutputIterator result,
__gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) __gnu_parallel::parallelism parallelism_tag)
{
typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::value_type value_type;
return adjacent_difference(begin, end, result, std::minus<value_type>(),
parallelism_tag);
}
template<typename InputIterator, typename OutputIterator>
inline OutputIterator
adjacent_difference(InputIterator begin, InputIterator end,
OutputIterator result)
{ {
typedef iterator_traits<InputIterator> traits_type; typedef iterator_traits<InputIterator> traits_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
return adjacent_difference(begin, end, result, std::minus<value_type>()); return adjacent_difference(begin, end, result, std::minus<value_type>());
} }
// Public interface.
template<typename InputIterator, typename OutputIterator, typename BinaryOperation> template<typename InputIterator, typename OutputIterator, typename BinaryOperation>
inline OutputIterator inline OutputIterator
adjacent_difference(InputIterator begin, InputIterator end, adjacent_difference(InputIterator begin, InputIterator end,
OutputIterator result, BinaryOperation binary_op, OutputIterator result, BinaryOperation binary_op,
__gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced) __gnu_parallel::parallelism parallelism_tag)
{ {
typedef iterator_traits<InputIterator> traitsi_type; typedef iterator_traits<InputIterator> traitsi_type;
typedef typename traitsi_type::iterator_category iteratori_category; typedef typename traitsi_type::iterator_category iteratori_category;
...@@ -316,6 +410,22 @@ namespace __parallel ...@@ -316,6 +410,22 @@ namespace __parallel
iteratori_category(), iteratori_category(),
iteratoro_category(), parallelism_tag); iteratoro_category(), parallelism_tag);
} }
template<typename InputIterator, typename OutputIterator, typename BinaryOperation>
inline OutputIterator
adjacent_difference(InputIterator begin, InputIterator end,
OutputIterator result, BinaryOperation binary_op)
{
typedef iterator_traits<InputIterator> traitsi_type;
typedef typename traitsi_type::iterator_category iteratori_category;
typedef iterator_traits<OutputIterator> traitso_type;
typedef typename traitso_type::iterator_category iteratoro_category;
return adjacent_difference_switch(begin, end, result, binary_op,
iteratori_category(),
iteratoro_category());
}
} // end namespace } // end namespace
} // end namespace } // end namespace
......
...@@ -46,32 +46,50 @@ namespace __parallel ...@@ -46,32 +46,50 @@ namespace __parallel
{ {
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline T inline T
accumulate(_IIter, _IIter, T, __gnu_parallel::sequential_tag); accumulate(_IIter, _IIter, T);
template<typename _IIter, typename T, typename _BinaryOper> template<typename _IIter, typename T>
inline T inline T
accumulate(_IIter, _IIter, T, _BinaryOper, __gnu_parallel::sequential_tag); accumulate(_IIter, _IIter, T, __gnu_parallel::sequential_tag);
template<typename _IIter, typename T> template<typename _IIter, typename T>
inline T inline T
accumulate(_IIter, _IIter, T, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); accumulate(_IIter, _IIter, T, __gnu_parallel::parallelism parallelism_tag);
template<typename _IIter, typename T, typename _Tag>
inline T
accumulate_switch(_IIter, _IIter, T, _Tag);
template<typename _IIter, typename T, typename _BinaryOper> template<typename _IIter, typename T, typename _BinaryOper>
inline T inline T
accumulate(_IIter, _IIter, T, _BinaryOper, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); accumulate(_IIter, _IIter, T, _BinaryOper);
template<typename _IIter, typename T, typename _Tag> template<typename _IIter, typename T, typename _BinaryOper>
inline T inline T
accumulate_switch(_IIter, _IIter, T, _Tag, __gnu_parallel::parallelism parallelism_tag); accumulate(_IIter, _IIter, T, _BinaryOper, __gnu_parallel::sequential_tag);
template<typename _IIter, typename T, typename _BinaryOper>
inline T
accumulate(_IIter, _IIter, T, _BinaryOper,
__gnu_parallel::parallelism parallelism_tag);
template<typename _IIter, typename T, typename _BinaryOper, typename _Tag> template<typename _IIter, typename T, typename _BinaryOper, typename _Tag>
T T
accumulate_switch(_IIter, _IIter, T, _BinaryOper, _Tag, __gnu_parallel::parallelism parallelism_tag); accumulate_switch(_IIter, _IIter, T, _BinaryOper, _Tag);
template<typename _RAIter, typename T, typename _BinaryOper> template<typename _RAIter, typename T, typename _BinaryOper>
T T
accumulate_switch(_RAIter, _RAIter, T, _BinaryOper, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag); accumulate_switch(_RAIter, _RAIter, T, _BinaryOper,
random_access_iterator_tag, __gnu_parallel::parallelism);
template<typename _IIter, typename _OIter>
inline _OIter
adjacent_difference(_IIter, _IIter, _OIter);
template<typename _IIter, typename _OIter, typename _BinaryOper>
inline _OIter
adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
inline _OIter inline _OIter
...@@ -79,48 +97,68 @@ namespace __parallel ...@@ -79,48 +97,68 @@ namespace __parallel
template<typename _IIter, typename _OIter, typename _BinaryOper> template<typename _IIter, typename _OIter, typename _BinaryOper>
inline _OIter inline _OIter
adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper, __gnu_parallel::sequential_tag); adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper,
__gnu_parallel::sequential_tag);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
inline _OIter inline _OIter
adjacent_difference(_IIter, _IIter, _OIter, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); adjacent_difference(_IIter, _IIter, _OIter, __gnu_parallel::parallelism);
template<typename _IIter, typename _OIter, typename _BinaryOper> template<typename _IIter, typename _OIter, typename _BinaryOper>
inline _OIter inline _OIter
adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_balanced); adjacent_difference(_IIter, _IIter, _OIter, _BinaryOper,
__gnu_parallel::parallelism);
template<typename _IIter, typename _OIter, typename _BinaryOper, typename _Tag1, typename _Tag2> template<typename _IIter, typename _OIter, typename _BinaryOper, typename _Tag1, typename _Tag2>
inline _OIter inline _OIter
adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, _Tag1, _Tag2, __gnu_parallel::parallelism); adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, _Tag1, _Tag2);
template<typename _IIter, typename _OIter, typename _BinaryOper> template<typename _IIter, typename _OIter, typename _BinaryOper>
_OIter _OIter
adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag); adjacent_difference_switch(_IIter, _IIter, _OIter, _BinaryOper,
random_access_iterator_tag,
random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2> template<typename _IIter1, typename _IIter2, typename T>
inline T inline T
inner_product(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2, __gnu_parallel::sequential_tag); inner_product(_IIter1, _IIter1, _IIter2, T);
template<typename _IIter1, typename _IIter2, typename T> template<typename _IIter1, typename _IIter2, typename T>
inline T inline T
inner_product(_IIter1, _IIter1, _IIter2, T, __gnu_parallel::sequential_tag); inner_product(_IIter1, _IIter1, _IIter2, T, __gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename T>
inline T
inner_product(_IIter1, _IIter1, _IIter2, T, __gnu_parallel::parallelism);
template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2> template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T inline T
inner_product(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); inner_product(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2);
template<typename _IIter1, typename _IIter2, typename T> template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T
inner_product(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2,
__gnu_parallel::sequential_tag);
template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2>
inline T inline T
inner_product(_IIter1, _IIter1, _IIter2, T, __gnu_parallel::parallelism parallelism_tag = __gnu_parallel::parallel_unbalanced); inner_product(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2,
__gnu_parallel::parallelism);
template<typename _RAIter1, typename _RAIter2, typename T, typename BinaryFunction1, typename BinaryFunction2> template<typename _RAIter1, typename _RAIter2, typename T, typename BinaryFunction1, typename BinaryFunction2>
T T
inner_product_switch(_RAIter1, _RAIter1, _RAIter2, T, BinaryFunction1, BinaryFunction2, random_access_iterator_tag, random_access_iterator_tag, __gnu_parallel::parallelism parallelism_tag); inner_product_switch(_RAIter1, _RAIter1, _RAIter2, T, BinaryFunction1,
BinaryFunction2, random_access_iterator_tag,
random_access_iterator_tag,
__gnu_parallel::parallelism);
template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2, typename _Tag1, typename _Tag2> template<typename _IIter1, typename _IIter2, typename T, typename BinaryFunction1, typename BinaryFunction2, typename _Tag1, typename _Tag2>
inline T inline T
inner_product_switch(_IIter1, _IIter1, _IIter2, T, BinaryFunction1, BinaryFunction2, _Tag1, _Tag2, __gnu_parallel::parallelism parallelism_tag); inner_product_switch(_IIter1, _IIter1, _IIter2, T, BinaryFunction1,
BinaryFunction2, _Tag1, _Tag2);
template<typename _IIter, typename _OIter> template<typename _IIter, typename _OIter>
......
...@@ -39,12 +39,8 @@ ...@@ -39,12 +39,8 @@
#define _GLIBCXX_PARALLEL_RANDOM_SHUFFLE_H 1 #define _GLIBCXX_PARALLEL_RANDOM_SHUFFLE_H 1
#include <limits> #include <limits>
#include <bits/stl_numeric.h>
#include <parallel/basic_iterator.h>
#include <bits/stl_algo.h>
#include <parallel/parallel.h> #include <parallel/parallel.h>
#include <parallel/base.h>
#include <parallel/random_number.h> #include <parallel/random_number.h>
#include <parallel/timing.h> #include <parallel/timing.h>
...@@ -125,15 +121,16 @@ namespace __gnu_parallel ...@@ -125,15 +121,16 @@ namespace __gnu_parallel
* @param rng Random number generator to use. * @param rng Random number generator to use.
*/ */
template<typename RandomNumberGenerator> template<typename RandomNumberGenerator>
inline int random_number_pow2(int logp, RandomNumberGenerator& rng) inline int
{ random_number_pow2(int logp, RandomNumberGenerator& rng)
return rng.genrand_bits(logp); { return rng.genrand_bits(logp); }
}
/** @brief Random shuffle code executed by each thread. /** @brief Random shuffle code executed by each thread.
* @param pus Array of thread-local data records. */ * @param pus Array of thread-local data records. */
template<typename RandomAccessIterator, typename RandomNumberGenerator> template<typename RandomAccessIterator, typename RandomNumberGenerator>
inline void parallel_random_shuffle_drs_pu(DRSSorterPU<RandomAccessIterator, RandomNumberGenerator>* pus) inline void
parallel_random_shuffle_drs_pu(DRSSorterPU<RandomAccessIterator,
RandomNumberGenerator>* pus)
{ {
typedef std::iterator_traits<RandomAccessIterator> traits_type; typedef std::iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
...@@ -184,7 +181,9 @@ namespace __gnu_parallel ...@@ -184,7 +181,9 @@ namespace __gnu_parallel
// Sum up bins, sd->dist[s + 1][d->num_threads] now contains the // Sum up bins, sd->dist[s + 1][d->num_threads] now contains the
// total number of items in bin s // total number of items in bin s
for (bin_index s = 0; s < sd->num_bins; s++) for (bin_index s = 0; s < sd->num_bins; s++)
partial_sum(sd->dist[s + 1], sd->dist[s + 1] + d->num_threads + 1, sd->dist[s + 1]); __gnu_sequential::partial_sum(sd->dist[s + 1],
sd->dist[s + 1] + d->num_threads + 1,
sd->dist[s + 1]);
} }
#pragma omp barrier #pragma omp barrier
...@@ -263,7 +262,8 @@ namespace __gnu_parallel ...@@ -263,7 +262,8 @@ namespace __gnu_parallel
/** @brief Round up to the next greater power of 2. /** @brief Round up to the next greater power of 2.
* @param x Integer to round up */ * @param x Integer to round up */
template<typename T> template<typename T>
T round_up_to_pow2(T x) T
round_up_to_pow2(T x)
{ {
if (x <= 1) if (x <= 1)
return 1; return 1;
...@@ -396,7 +396,9 @@ namespace __gnu_parallel ...@@ -396,7 +396,9 @@ namespace __gnu_parallel
*/ */
template<typename RandomAccessIterator, typename RandomNumberGenerator> template<typename RandomAccessIterator, typename RandomNumberGenerator>
inline void inline void
sequential_random_shuffle(RandomAccessIterator begin, RandomAccessIterator end, RandomNumberGenerator& rng) sequential_random_shuffle(RandomAccessIterator begin,
RandomAccessIterator end,
RandomNumberGenerator& rng)
{ {
typedef std::iterator_traits<RandomAccessIterator> traits_type; typedef std::iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::value_type value_type; typedef typename traits_type::value_type value_type;
...@@ -468,7 +470,7 @@ namespace __gnu_parallel ...@@ -468,7 +470,7 @@ namespace __gnu_parallel
t.tic(); t.tic();
// Sum up bins. // Sum up bins.
partial_sum(dist0, dist0 + num_bins + 1, dist0); __gnu_sequential::partial_sum(dist0, dist0 + num_bins + 1, dist0);
for (int b = 0; b < num_bins + 1; b++) for (int b = 0; b < num_bins + 1; b++)
dist1[b] = dist0[b]; dist1[b] = dist0[b];
...@@ -503,7 +505,8 @@ namespace __gnu_parallel ...@@ -503,7 +505,8 @@ namespace __gnu_parallel
*/ */
template<typename RandomAccessIterator, typename RandomNumberGenerator> template<typename RandomAccessIterator, typename RandomNumberGenerator>
inline void inline void
parallel_random_shuffle(RandomAccessIterator begin, RandomAccessIterator end, RandomNumberGenerator rng = random_number()) parallel_random_shuffle(RandomAccessIterator begin, RandomAccessIterator end,
RandomNumberGenerator rng = random_number())
{ {
typedef std::iterator_traits<RandomAccessIterator> traits_type; typedef std::iterator_traits<RandomAccessIterator> traits_type;
typedef typename traits_type::difference_type difference_type; typedef typename traits_type::difference_type difference_type;
......
...@@ -55,7 +55,8 @@ namespace __gnu_parallel ...@@ -55,7 +55,8 @@ namespace __gnu_parallel
*/ */
template<typename RandomAccessIterator, typename _DifferenceTp> template<typename RandomAccessIterator, typename _DifferenceTp>
void void
calc_borders(RandomAccessIterator elements, _DifferenceTp length, _DifferenceTp* off) calc_borders(RandomAccessIterator elements, _DifferenceTp length,
_DifferenceTp* off)
{ {
typedef _DifferenceTp difference_type; typedef _DifferenceTp difference_type;
...@@ -65,7 +66,7 @@ namespace __gnu_parallel ...@@ -65,7 +66,7 @@ namespace __gnu_parallel
difference_type k = 0; difference_type k = 0;
for (difference_type j = 2; j <= length; j++) for (difference_type j = 2; j <= length; j++)
{ {
while ((k >= 0) && (elements[k] != elements[j-1])) while ((k >= 0) && !(elements[k] == elements[j-1]))
k = off[k]; k = off[k];
off[j] = ++k; off[j] = ++k;
} }
......
...@@ -49,7 +49,14 @@ namespace std ...@@ -49,7 +49,14 @@ namespace std
* @namespace __gnu_sequential * @namespace __gnu_sequential
* @brief GNU sequential classes for public use. * @brief GNU sequential classes for public use.
*/ */
namespace __gnu_sequential { } namespace __gnu_sequential
{
#ifdef _GLIBCXX_PARALLEL
using namespace std::__norm;
#else
using namespace std;
#endif
}
/** /**
* @namespace __gnu_parallel * @namespace __gnu_parallel
......
...@@ -159,7 +159,8 @@ namespace __gnu_parallel ...@@ -159,7 +159,8 @@ namespace __gnu_parallel
* @param _Alloc Allocator for the elements */ * @param _Alloc Allocator for the elements */
template<typename _Key, typename _Val, typename _KeyOfValue, template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc = std::allocator<_Val> > typename _Compare, typename _Alloc = std::allocator<_Val> >
class _Rb_tree : public std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc> class _Rb_tree
: public std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>
{ {
private: private:
/** @brief Sequential tree */ /** @brief Sequential tree */
...@@ -214,7 +215,8 @@ namespace __gnu_parallel ...@@ -214,7 +215,8 @@ namespace __gnu_parallel
* @param a Allocator object with which to initialize the class comparator * @param a Allocator object with which to initialize the class comparator
*/ */
_Rb_tree(const _Compare& c, const _Alloc& a) _Rb_tree(const _Compare& c, const _Alloc& a)
: base_type(c, a), strictly_less(base_type::_M_impl._M_key_compare), less_equal(base_type::_M_impl._M_key_compare) : base_type(c, a), strictly_less(base_type::_M_impl._M_key_compare),
less_equal(base_type::_M_impl._M_key_compare)
{ } { }
/** @brief Copy constructor. /** @brief Copy constructor.
...@@ -224,7 +226,8 @@ namespace __gnu_parallel ...@@ -224,7 +226,8 @@ namespace __gnu_parallel
* @param __x Parallel red-black instance to copy * @param __x Parallel red-black instance to copy
*/ */
_Rb_tree(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x) _Rb_tree(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x)
: base_type(__x), strictly_less(base_type::_M_impl._M_key_compare), less_equal(base_type::_M_impl._M_key_compare) : base_type(__x), strictly_less(base_type::_M_impl._M_key_compare),
less_equal(base_type::_M_impl._M_key_compare)
{ } { }
/** @brief Parallel replacement of the sequential /** @brief Parallel replacement of the sequential
...@@ -244,12 +247,14 @@ namespace __gnu_parallel ...@@ -244,12 +247,14 @@ namespace __gnu_parallel
if (_GLIBCXX_PARALLEL_CONDITION(true)) if (_GLIBCXX_PARALLEL_CONDITION(true))
if (base_type::_M_impl._M_node_count == 0) if (base_type::_M_impl._M_node_count == 0)
{ {
_M_bulk_insertion_construction(__first, __last, true, strictly_less); _M_bulk_insertion_construction(__first, __last, true,
strictly_less);
_GLIBCXX_PARALLEL_ASSERT(rb_verify()); _GLIBCXX_PARALLEL_ASSERT(rb_verify());
} }
else else
{ {
_M_bulk_insertion_construction(__first, __last, false, strictly_less); _M_bulk_insertion_construction(__first, __last, false,
strictly_less);
_GLIBCXX_PARALLEL_ASSERT(rb_verify()); _GLIBCXX_PARALLEL_ASSERT(rb_verify());
} }
else else
...@@ -293,8 +298,9 @@ namespace __gnu_parallel ...@@ -293,8 +298,9 @@ namespace __gnu_parallel
class nodes_initializer class nodes_initializer
{ {
/** @brief Renaming of tree size_type */ /** @brief Renaming of tree size_type */
typedef typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type size_type; typedef _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc> tree_type;
typedef typename tree_type::size_type size_type;
public: public:
/** @brief mask[%i]= 0..01..1, where the number of 1s is %i+1 */ /** @brief mask[%i]= 0..01..1, where the number of 1s is %i+1 */
...@@ -328,7 +334,8 @@ namespace __gnu_parallel ...@@ -328,7 +334,8 @@ namespace __gnu_parallel
* @param _n Total number of (used) nodes * @param _n Total number of (used) nodes
* @param _num_threads Number of threads into which divide the work * @param _num_threads Number of threads into which divide the work
* @param _rank Helper object to mind potential gaps in @c r_init */ * @param _rank Helper object to mind potential gaps in @c r_init */
nodes_initializer(const _Rb_tree_node_ptr* r, const size_type _n, const thread_index_t _num_threads, const ranker& _rank): nodes_initializer(const _Rb_tree_node_ptr* r, const size_type _n,
const thread_index_t _num_threads, const ranker& _rank):
r_init(r), r_init(r),
n(_n), n(_n),
num_threads(_num_threads), num_threads(_num_threads),
...@@ -352,24 +359,21 @@ namespace __gnu_parallel ...@@ -352,24 +359,21 @@ namespace __gnu_parallel
/** @brief Query for tree height /** @brief Query for tree height
* @return Tree height */ * @return Tree height */
int get_height() const int
{ get_height() const
return height; { return height; }
}
/** @brief Query for the splitting point /** @brief Query for the splitting point
* @return Splitting point */ * @return Splitting point */
size_type get_shifted_splitting_point() const size_type
{ get_shifted_splitting_point() const
return rank.get_shifted_rank(splitting_point, 0); { return rank.get_shifted_rank(splitting_point, 0); }
}
/** @brief Query for the tree root node /** @brief Query for the tree root node
* @return Tree root node */ * @return Tree root node */
_Rb_tree_node_ptr get_root() const _Rb_tree_node_ptr
{ get_root() const
return r_init[rank.get_shifted_rank(rank_root,num_threads/2)]; { return r_init[rank.get_shifted_rank(rank_root,num_threads/2)]; }
}
/** @brief Calculation of the parent position in the array of nodes /** @brief Calculation of the parent position in the array of nodes
* @hideinitializer */ * @hideinitializer */
...@@ -386,7 +390,8 @@ namespace __gnu_parallel ...@@ -386,7 +390,8 @@ namespace __gnu_parallel
* @param iam Partition of the array in which the node is, where * @param iam Partition of the array in which the node is, where
* iam is in [0..num_threads) * iam is in [0..num_threads)
* @sa link_complete */ * @sa link_complete */
void link_incomplete(const _Rb_tree_node_ptr& r, const int iam) const void
link_incomplete(const _Rb_tree_node_ptr& r, const int iam) const
{ {
size_type real_pos = rank.get_real_rank(&r-r_init, iam); size_type real_pos = rank.get_real_rank(&r-r_init, iam);
size_type l_s, r_s, p_s; size_type l_s, r_s, p_s;
...@@ -438,7 +443,8 @@ namespace __gnu_parallel ...@@ -438,7 +443,8 @@ namespace __gnu_parallel
* iam is in [0..@c num_threads) * iam is in [0..@c num_threads)
* @sa link_incomplete * @sa link_incomplete
*/ */
void link_complete(const _Rb_tree_node_ptr& r, const int iam) const void
link_complete(const _Rb_tree_node_ptr& r, const int iam) const
{ {
size_type real_pos = rank.get_real_rank(&r-r_init, iam); size_type real_pos = rank.get_real_rank(&r-r_init, iam);
size_type p_s; size_type p_s;
...@@ -477,20 +483,18 @@ namespace __gnu_parallel ...@@ -477,20 +483,18 @@ namespace __gnu_parallel
* @param pos Rank in the actual incomplete tree * @param pos Rank in the actual incomplete tree
* @return Rank in the corresponding complete tree * @return Rank in the corresponding complete tree
* @sa complete_to_original */ * @sa complete_to_original */
int original_to_complete(const int pos) const int
{ original_to_complete(const int pos) const
return (pos << 1) - splitting_point; { return (pos << 1) - splitting_point; }
}
/** @brief Change of "base": Convert the rank if the tree was /** @brief Change of "base": Convert the rank if the tree was
complete into the corresponding rank in the actual tree complete into the corresponding rank in the actual tree
* @param pos Rank in the complete tree * @param pos Rank in the complete tree
* @return Rank in the actual incomplete tree * @return Rank in the actual incomplete tree
* @sa original_to_complete */ * @sa original_to_complete */
int complete_to_original(const int pos) const int
{ complete_to_original(const int pos) const
return (pos + splitting_point) >> 1; { return (pos + splitting_point) >> 1; }
}
/** @brief Calculate the rank in the complete tree of the parent /** @brief Calculate the rank in the complete tree of the parent
...@@ -506,7 +510,10 @@ namespace __gnu_parallel ...@@ -506,7 +510,10 @@ namespace __gnu_parallel
* @param parent_shift Rank in the complete tree of the parent * @param parent_shift Rank in the complete tree of the parent
* of pos (out parameter) * of pos (out parameter)
*/ */
void calculate_shifts_pos_level(const size_type pos, const int level, size_type& left_shift, size_type& right_shift, size_type& parent_shift) const void
calculate_shifts_pos_level(const size_type pos, const int level,
size_type& left_shift, size_type& right_shift,
size_type& parent_shift) const
{ {
int stride = 1 << (level -1); int stride = 1 << (level -1);
left_shift = pos - stride; left_shift = pos - stride;
...@@ -523,7 +530,8 @@ namespace __gnu_parallel ...@@ -523,7 +530,8 @@ namespace __gnu_parallel
* @return Position of the first 0 bit in @c x (starting to * @return Position of the first 0 bit in @c x (starting to
* count with 1) * count with 1)
*/ */
int first_0_right(const size_type x) const int
first_0_right(const size_type x) const
{ {
if ((x & 0x2) == 0) if ((x & 0x2) == 0)
return 1; return 1;
...@@ -540,7 +548,8 @@ namespace __gnu_parallel ...@@ -540,7 +548,8 @@ namespace __gnu_parallel
* whose first 0 bit must be calculated * whose first 0 bit must be calculated
* @param k_beg Position in which to start searching. By default is 2. * @param k_beg Position in which to start searching. By default is 2.
* @return Position of the first 0 bit in x (starting to count with 1) */ * @return Position of the first 0 bit in x (starting to count with 1) */
int first_0_right_bs(const size_type x, int k_beg=2) const int
first_0_right_bs(const size_type x, int k_beg=2) const
{ {
int k_end = sizeof(size_type)*8; int k_end = sizeof(size_type)*8;
size_type not_x = x ^ mask[k_end-1]; size_type not_x = x ^ mask[k_end-1];
...@@ -566,7 +575,8 @@ namespace __gnu_parallel ...@@ -566,7 +575,8 @@ namespace __gnu_parallel
class ranker_gaps class ranker_gaps
{ {
/** @brief Renaming of tree's size_type */ /** @brief Renaming of tree's size_type */
typedef typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type size_type; typedef _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc> tree_type;
typedef typename tree_type::size_type size_type;
/** @brief Array containing the beginning ranks of all the /** @brief Array containing the beginning ranks of all the
num_threads partitions just considering the valid nodes, not num_threads partitions just considering the valid nodes, not
...@@ -594,7 +604,8 @@ namespace __gnu_parallel ...@@ -594,7 +604,8 @@ namespace __gnu_parallel
* gaps at the beginning of each partition * gaps at the beginning of each partition
* @param _num_threads Number of partitions (and threads that * @param _num_threads Number of partitions (and threads that
* work on it) */ * work on it) */
ranker_gaps(const size_type* size_p, const size_type* shift_r, const thread_index_t _num_threads) : ranker_gaps(const size_type* size_p, const size_type* shift_r,
const thread_index_t _num_threads) :
beg_shift_partition(size_p), beg_shift_partition(size_p),
rank_shift(shift_r), rank_shift(shift_r),
num_threads(_num_threads) num_threads(_num_threads)
...@@ -616,9 +627,7 @@ namespace __gnu_parallel ...@@ -616,9 +627,7 @@ namespace __gnu_parallel
* been allocated for beg_partition array * been allocated for beg_partition array
*/ */
~ranker_gaps() ~ranker_gaps()
{ { delete[] beg_partition; }
delete[] beg_partition;
}
/** @brief Convert a rank in the array of nodes considering /** @brief Convert a rank in the array of nodes considering
valid nodes and gaps, to the corresponding considering only valid nodes and gaps, to the corresponding considering only
...@@ -628,10 +637,9 @@ namespace __gnu_parallel ...@@ -628,10 +637,9 @@ namespace __gnu_parallel
* @return Rank in the array of nodes considering only the valid nodes * @return Rank in the array of nodes considering only the valid nodes
* @sa get_shifted_rank * @sa get_shifted_rank
*/ */
size_type get_real_rank(const size_type pos, const int index) const size_type
{ get_real_rank(const size_type pos, const int index) const
return pos - rank_shift[index]; { return pos - rank_shift[index]; }
}
/** @brief Inverse of get_real_rank: Convert a rank in the array /** @brief Inverse of get_real_rank: Convert a rank in the array
of nodes considering only valid nodes, to the corresponding of nodes considering only valid nodes, to the corresponding
...@@ -644,7 +652,8 @@ namespace __gnu_parallel ...@@ -644,7 +652,8 @@ namespace __gnu_parallel
* @post 0 <= @c return <= number_of_elements * @post 0 <= @c return <= number_of_elements
* @sa get_real_rank() * @sa get_real_rank()
*/ */
size_type get_shifted_rank(const size_type pos, const int index) const size_type
get_shifted_rank(const size_type pos, const int index) const
{ {
// Heuristic. // Heuristic.
if (beg_partition[index] <= pos and pos < beg_partition[index+1]) if (beg_partition[index] <= pos and pos < beg_partition[index+1])
...@@ -662,7 +671,8 @@ namespace __gnu_parallel ...@@ -662,7 +671,8 @@ namespace __gnu_parallel
* if there were no gaps * if there were no gaps
* @return Rank in the array of nodes considering valid nodes and gaps * @return Rank in the array of nodes considering valid nodes and gaps
*/ */
size_type get_shifted_rank_loop(const size_type pos, int index) const size_type
get_shifted_rank_loop(const size_type pos, int index) const
{ {
while (pos >= beg_partition[index+1]) while (pos >= beg_partition[index+1])
++index; ++index;
...@@ -681,7 +691,8 @@ namespace __gnu_parallel ...@@ -681,7 +691,8 @@ namespace __gnu_parallel
class ranker_no_gaps class ranker_no_gaps
{ {
/** @brief Renaming of tree's size_type */ /** @brief Renaming of tree's size_type */
typedef typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type size_type; typedef _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc> tree_type;
typedef typename tree_type::size_type size_type;
public: public:
/** @brief Convert a rank in the array of nodes considering /** @brief Convert a rank in the array of nodes considering
...@@ -693,10 +704,9 @@ namespace __gnu_parallel ...@@ -693,10 +704,9 @@ namespace __gnu_parallel
* @param pos Rank in the array of nodes considering valid nodes and gaps * @param pos Rank in the array of nodes considering valid nodes and gaps
* @param index Partition which the rank belongs to, unused here * @param index Partition which the rank belongs to, unused here
* @return Rank in the array of nodes considering only the valid nodes */ * @return Rank in the array of nodes considering only the valid nodes */
size_type get_real_rank(const size_type pos, const int index) const size_type
{ get_real_rank(const size_type pos, const int index) const
return pos; { return pos; }
}
/** @brief Inverse of get_real_rank: Convert a rank in the array /** @brief Inverse of get_real_rank: Convert a rank in the array
* of nodes considering only valid nodes, to the corresponding * of nodes considering only valid nodes, to the corresponding
...@@ -708,10 +718,9 @@ namespace __gnu_parallel ...@@ -708,10 +718,9 @@ namespace __gnu_parallel
* @param index Partition which the rank belongs to, unused here * @param index Partition which the rank belongs to, unused here
* @return Rank in the array of nodes considering valid nodes and gaps * @return Rank in the array of nodes considering valid nodes and gaps
*/ */
size_type get_shifted_rank(const size_type pos, const int index) const size_type
{ get_shifted_rank(const size_type pos, const int index) const
return pos; { return pos; }
}
}; };
...@@ -777,7 +786,8 @@ namespace __gnu_parallel ...@@ -777,7 +786,8 @@ namespace __gnu_parallel
* the element pointed by the the class member @c prev */ * the element pointed by the the class member @c prev */
void operator()(const _InputIterator it) void operator()(const _InputIterator it)
{ {
if (sorted and it != prev and comp(_KeyOfValue()(*it),_KeyOfValue()(*prev))) if (sorted and it != prev and comp(_KeyOfValue()(*it),
_KeyOfValue()(*prev)))
sorted = false; sorted = false;
prev = it; prev = it;
} }
...@@ -840,8 +850,10 @@ namespace __gnu_parallel ...@@ -840,8 +850,10 @@ namespace __gnu_parallel
{ return c(k, base_type::_S_key(r)); } { return c(k, base_type::_S_key(r)); }
}; };
/** @brief Helper comparator: compare a key with the key of a value pointed by an iterator /** @brief Helper comparator: compare a key with the key of a
* @param _Comparator Comparator for keys */ value pointed by an iterator
* @param _Comparator Comparator for keys
*/
template<typename _Iterator, typename _Comparator> template<typename _Iterator, typename _Comparator>
struct compare_value_key struct compare_value_key
{ {
...@@ -914,7 +926,8 @@ namespace __gnu_parallel ...@@ -914,7 +926,8 @@ namespace __gnu_parallel
* @param Comparator Comparator for values * @param Comparator Comparator for values
* @param _ValuePtr Pointer to values */ * @param _ValuePtr Pointer to values */
template<typename Comparator, typename _ValuePtr> template<typename Comparator, typename _ValuePtr>
class PtrComparator : public std::binary_function<_ValuePtr, _ValuePtr, bool> class PtrComparator
: public std::binary_function<_ValuePtr, _ValuePtr, bool>
{ {
/** @brief Comparator for values */ /** @brief Comparator for values */
Comparator comp; Comparator comp;
...@@ -1108,11 +1121,9 @@ namespace __gnu_parallel ...@@ -1108,11 +1121,9 @@ namespace __gnu_parallel
* @param _par_problem Parent concatenation problem to solve * @param _par_problem Parent concatenation problem to solve
* when @c is_ready = READY_YES * when @c is_ready = READY_YES
*/ */
concat_problem(const _Rb_tree_node_ptr _t, const int _black_h, concat_problem* _par_problem): concat_problem(const _Rb_tree_node_ptr _t, const int _black_h,
t(_t), concat_problem* _par_problem)
black_h(_black_h), : t(_t), black_h(_black_h), is_ready(READY_NO), par_problem(_par_problem)
is_ready(READY_NO),
par_problem(_par_problem)
{ {
// The root of an insertion problem must be black. // The root of an insertion problem must be black.
if (t != NULL and t->_M_color == std::_S_red) if (t != NULL and t->_M_color == std::_S_red)
...@@ -1131,7 +1142,8 @@ namespace __gnu_parallel ...@@ -1131,7 +1142,8 @@ namespace __gnu_parallel
struct insertion_problem struct insertion_problem
{ {
/** @brief Renaming of _Rb_tree @c size_type */ /** @brief Renaming of _Rb_tree @c size_type */
typedef typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type size_type; typedef _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc> tree_type;
typedef typename tree_type::size_type size_type;
/** @brief Root of the tree where the elements are to be inserted */ /** @brief Root of the tree where the elements are to be inserted */
_Rb_tree_node_ptr t; _Rb_tree_node_ptr t;
...@@ -1166,8 +1178,10 @@ namespace __gnu_parallel ...@@ -1166,8 +1178,10 @@ namespace __gnu_parallel
* @param _conc Concatenation problem to solve once the * @param _conc Concatenation problem to solve once the
* insertion problem is finished * insertion problem is finished
*/ */
insertion_problem(const size_type b, const size_type e, const int array_p, concat_problem* _conc) insertion_problem(const size_type b, const size_type e,
: t(_conc->t), pos_beg(b), pos_end(e), array_partition(array_p), conc(_conc) const int array_p, concat_problem* _conc)
: t(_conc->t), pos_beg(b), pos_end(e), array_partition(array_p),
conc(_conc)
{ {
_GLIBCXX_PARALLEL_ASSERT(pos_beg <= pos_end); _GLIBCXX_PARALLEL_ASSERT(pos_beg <= pos_end);
...@@ -1233,9 +1247,11 @@ namespace __gnu_parallel ...@@ -1233,9 +1247,11 @@ namespace __gnu_parallel
} }
if (is_construction) if (is_construction)
_M_sorted_bulk_construction(access, beg_partition, n, num_threads, strictly_less_or_less_equal); _M_sorted_bulk_construction(access, beg_partition, n, num_threads,
strictly_less_or_less_equal);
else else
_M_sorted_bulk_insertion(access, beg_partition, n, num_threads, strictly_less_or_less_equal); _M_sorted_bulk_insertion(access, beg_partition, n, num_threads,
strictly_less_or_less_equal);
} }
t.tic("main work"); t.tic("main work");
...@@ -1262,7 +1278,10 @@ namespace __gnu_parallel ...@@ -1262,7 +1278,10 @@ namespace __gnu_parallel
* @param is_construction If true, the tree was empty and so, this * @param is_construction If true, the tree was empty and so, this
* is constructed. Otherwise, the elements are added to an * is constructed. Otherwise, the elements are added to an
* existing tree. * existing tree.
* @param strictly_less_or_less_equal Comparator to deal transparently with repetitions with respect to the uniqueness of the wrapping container */ * @param strictly_less_or_less_equal Comparator to deal
* transparently with repetitions with respect to the uniqueness
* of the wrapping container
*/
template<typename _InputIterator, typename StrictlyLessOrLessEqual> template<typename _InputIterator, typename StrictlyLessOrLessEqual>
void void
_M_not_sorted_bulk_insertion_construction(_InputIterator* access, _M_not_sorted_bulk_insertion_construction(_InputIterator* access,
...@@ -1270,7 +1289,7 @@ namespace __gnu_parallel ...@@ -1270,7 +1289,7 @@ namespace __gnu_parallel
const size_type n, const size_type n,
const thread_index_t num_threads, const thread_index_t num_threads,
const bool is_construction, const bool is_construction,
StrictlyLessOrLessEqual strictly_less_or_less_equal) StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
// Copy entire elements. In the case of a map, we would be // Copy entire elements. In the case of a map, we would be
// copying the pair. Therefore, the copy should be reconsidered // copying the pair. Therefore, the copy should be reconsidered
...@@ -1360,7 +1379,8 @@ namespace __gnu_parallel ...@@ -1360,7 +1379,8 @@ namespace __gnu_parallel
* @param black_h Black height of the resulting tree (out) * @param black_h Black height of the resulting tree (out)
*/ */
static _Rb_tree_node_ptr static _Rb_tree_node_ptr
simple_tree_construct(_Rb_tree_node_ptr* r_array, const size_type pos_beg, const size_type pos_end, int& black_h) simple_tree_construct(_Rb_tree_node_ptr* r_array, const size_type pos_beg,
const size_type pos_end, int& black_h)
{ {
if (pos_beg == pos_end) if (pos_beg == pos_end)
{ {
...@@ -1416,7 +1436,8 @@ namespace __gnu_parallel ...@@ -1416,7 +1436,8 @@ namespace __gnu_parallel
* going to be shared * going to be shared
*/ */
template<typename _Iterator> template<typename _Iterator>
_Rb_tree_node_ptr* _M_unsorted_bulk_allocation_and_initialization(const _Iterator* access, const size_type* beg_partition, const size_type n, const thread_index_t num_threads) _Rb_tree_node_ptr*
_M_unsorted_bulk_allocation_and_initialization(const _Iterator* access, const size_type* beg_partition, const size_type n, const thread_index_t num_threads)
{ {
_Rb_tree_node_ptr* r = static_cast<_Rb_tree_node_ptr*> (::operator new (sizeof(_Rb_tree_node_ptr)*(n+1))); _Rb_tree_node_ptr* r = static_cast<_Rb_tree_node_ptr*> (::operator new (sizeof(_Rb_tree_node_ptr)*(n+1)));
...@@ -1471,7 +1492,8 @@ namespace __gnu_parallel ...@@ -1471,7 +1492,8 @@ namespace __gnu_parallel
* of the wrapping container * of the wrapping container
*/ */
template<typename _Iterator, typename StrictlyLessOrLessEqual> template<typename _Iterator, typename StrictlyLessOrLessEqual>
_Rb_tree_node_ptr* _M_sorted_bulk_allocation_and_initialization(_Iterator* access, size_type* beg_partition, size_type* rank_shift, const size_type n, thread_index_t& num_threads, StrictlyLessOrLessEqual strictly_less_or_less_equal) _Rb_tree_node_ptr*
_M_sorted_bulk_allocation_and_initialization(_Iterator* access, size_type* beg_partition, size_type* rank_shift, const size_type n, thread_index_t& num_threads, StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
// Ghost node at the end to avoid extra comparisons in nodes_initializer. // Ghost node at the end to avoid extra comparisons in nodes_initializer.
_Rb_tree_node_ptr* r = static_cast<_Rb_tree_node_ptr*> (::operator new (sizeof(_Rb_tree_node_ptr)*(n+1))); _Rb_tree_node_ptr* r = static_cast<_Rb_tree_node_ptr*> (::operator new (sizeof(_Rb_tree_node_ptr)*(n+1)));
...@@ -1598,7 +1620,8 @@ namespace __gnu_parallel ...@@ -1598,7 +1620,8 @@ namespace __gnu_parallel
* of the wrapping container * of the wrapping container
*/ */
template<typename _Iterator, typename StrictlyLessOrLessEqual> template<typename _Iterator, typename StrictlyLessOrLessEqual>
_Rb_tree_node_ptr* _M_sorted_no_gapped_bulk_allocation_and_initialization(_Iterator* access, size_type* beg_partition, size_type& n, const thread_index_t num_threads, StrictlyLessOrLessEqual strictly_less_or_less_equal) _Rb_tree_node_ptr*
_M_sorted_no_gapped_bulk_allocation_and_initialization(_Iterator* access, size_type* beg_partition, size_type& n, const thread_index_t num_threads, StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
size_type* sums = static_cast<size_type*> (::operator new (sizeof(size_type)*n)); size_type* sums = static_cast<size_type*> (::operator new (sizeof(size_type)*n));
// Allocate and initialize the nodes // Allocate and initialize the nodes
...@@ -2260,7 +2283,8 @@ namespace __gnu_parallel ...@@ -2260,7 +2283,8 @@ namespace __gnu_parallel
* @return Resulting tree after the elements have been inserted * @return Resulting tree after the elements have been inserted
*/ */
template<typename StrictlyLessOrLessEqual> template<typename StrictlyLessOrLessEqual>
_Rb_tree_node_ptr _M_bulk_insertion_merge(_Rb_tree_node_ptr* r_array, _Rb_tree_node_ptr t, const size_type pos_beg, const size_type pos_end, size_type& existing, int& black_h, StrictlyLessOrLessEqual strictly_less_or_less_equal) _Rb_tree_node_ptr
_M_bulk_insertion_merge(_Rb_tree_node_ptr* r_array, _Rb_tree_node_ptr t, const size_type pos_beg, const size_type pos_end, size_type& existing, int& black_h, StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
#ifndef NDEBUG #ifndef NDEBUG
int count; int count;
...@@ -2333,7 +2357,8 @@ namespace __gnu_parallel ...@@ -2333,7 +2357,8 @@ namespace __gnu_parallel
* of the wrapping container * of the wrapping container
*/ */
template<typename StrictlyLessOrLessEqual> template<typename StrictlyLessOrLessEqual>
void _M_bulk_insertion_merge_concatenate(_Rb_tree_node_ptr* r, insertion_problem& ip, size_type& existing, StrictlyLessOrLessEqual strictly_less_or_less_equal) void
_M_bulk_insertion_merge_concatenate(_Rb_tree_node_ptr* r, insertion_problem& ip, size_type& existing, StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
concat_problem* conc = ip.conc; concat_problem* conc = ip.conc;
_GLIBCXX_PARALLEL_ASSERT(ip.pos_beg <= ip.pos_end); _GLIBCXX_PARALLEL_ASSERT(ip.pos_beg <= ip.pos_end);
...@@ -2675,7 +2700,8 @@ namespace __gnu_parallel ...@@ -2675,7 +2700,8 @@ namespace __gnu_parallel
static int static int
black_height(const _Rb_tree_node_ptr t) black_height(const _Rb_tree_node_ptr t)
{ {
if (t == NULL) return 0; if (t == NULL)
return 0;
int bh = black_height (static_cast<const _Rb_tree_node_ptr> (t->_M_left)); int bh = black_height (static_cast<const _Rb_tree_node_ptr> (t->_M_left));
if (t->_M_color == std::_S_black) if (t->_M_color == std::_S_black)
++bh; ++bh;
...@@ -2719,7 +2745,8 @@ namespace __gnu_parallel ...@@ -2719,7 +2745,8 @@ namespace __gnu_parallel
*/ */
template<typename S> template<typename S>
static _Rb_tree_node_ptr static _Rb_tree_node_ptr
plant(const _Rb_tree_node_ptr root, const _Rb_tree_node_ptr l, const _Rb_tree_node_ptr r) plant(const _Rb_tree_node_ptr root, const _Rb_tree_node_ptr l,
const _Rb_tree_node_ptr r)
{ {
S::left(root) = l; S::left(root) = l;
S::right(root) = r; S::right(root) = r;
...@@ -2744,7 +2771,9 @@ namespace __gnu_parallel ...@@ -2744,7 +2771,9 @@ namespace __gnu_parallel
* @post @c t is correct red-black tree with height @c black_h. * @post @c t is correct red-black tree with height @c black_h.
*/ */
void void
concatenate(_Rb_tree_node_ptr root, _Rb_tree_node_ptr l, _Rb_tree_node_ptr r, int black_h_l, int black_h_r, _Rb_tree_node_ptr& t, int& black_h) const concatenate(_Rb_tree_node_ptr root, _Rb_tree_node_ptr l,
_Rb_tree_node_ptr r, int black_h_l, int black_h_r,
_Rb_tree_node_ptr& t, int& black_h) const
{ {
#ifndef NDEBUG #ifndef NDEBUG
int count = 0, count1 = 0, count2 = 0; int count = 0, count1 = 0, count2 = 0;
...@@ -2826,7 +2855,9 @@ namespace __gnu_parallel ...@@ -2826,7 +2855,9 @@ namespace __gnu_parallel
*/ */
template<typename S> template<typename S>
static void static void
concatenate(const _Rb_tree_node_ptr rt, _Rb_tree_node_ptr l, _Rb_tree_node_ptr r, int black_h_l, int black_h_r, _Rb_tree_node_ptr& t, int& black_h) concatenate(const _Rb_tree_node_ptr rt, _Rb_tree_node_ptr l,
_Rb_tree_node_ptr r, int black_h_l, int black_h_r,
_Rb_tree_node_ptr& t, int& black_h)
{ {
_Rb_tree_node_base* root = l; _Rb_tree_node_base* root = l;
_Rb_tree_node_ptr parent = NULL; _Rb_tree_node_ptr parent = NULL;
...@@ -2888,7 +2919,10 @@ namespace __gnu_parallel ...@@ -2888,7 +2919,10 @@ namespace __gnu_parallel
* @return Black height of t */ * @return Black height of t */
template<typename StrictlyLessOrEqual> template<typename StrictlyLessOrEqual>
int int
split(_Rb_tree_node_ptr t, const key_type& key, const key_type& prev_k, _Rb_tree_node_ptr& root, _Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r, int& black_h_l, int& black_h_r, StrictlyLessOrEqual strictly_less_or_less_equal) const split(_Rb_tree_node_ptr t, const key_type& key, const key_type& prev_k,
_Rb_tree_node_ptr& root, _Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r,
int& black_h_l, int& black_h_r,
StrictlyLessOrEqual strictly_less_or_less_equal) const
{ {
if (t != NULL) if (t != NULL)
{ {
...@@ -2936,7 +2970,11 @@ namespace __gnu_parallel ...@@ -2936,7 +2970,11 @@ namespace __gnu_parallel
* @return Black height of t */ * @return Black height of t */
template<typename StrictlyLessOrEqual> template<typename StrictlyLessOrEqual>
int int
split_not_null(const _Rb_tree_node_ptr t, const key_type& key, const key_type& prev_k, _Rb_tree_node_ptr& root, _Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r, int& black_h_l, int& black_h_r, StrictlyLessOrEqual strictly_less_or_equal) const split_not_null(const _Rb_tree_node_ptr t, const key_type& key,
const key_type& prev_k, _Rb_tree_node_ptr& root,
_Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r, int& black_h_l,
int& black_h_r,
StrictlyLessOrEqual strictly_less_or_equal) const
{ {
_GLIBCXX_PARALLEL_ASSERT (t != NULL); _GLIBCXX_PARALLEL_ASSERT (t != NULL);
int black_h, b_h; int black_h, b_h;
...@@ -3039,7 +3077,8 @@ namespace __gnu_parallel ...@@ -3039,7 +3077,8 @@ namespace __gnu_parallel
* @param black_h_r Black height of the right subtree. * @param black_h_r Black height of the right subtree.
* @return Black height of the original tree */ * @return Black height of the original tree */
int int
extract_min(const _Rb_tree_node_ptr t, _Rb_tree_node_ptr& root, _Rb_tree_node_ptr& r, int& black_h_r) const extract_min(const _Rb_tree_node_ptr t, _Rb_tree_node_ptr& root,
_Rb_tree_node_ptr& r, int& black_h_r) const
{ {
_GLIBCXX_PARALLEL_ASSERT (t != NULL); _GLIBCXX_PARALLEL_ASSERT (t != NULL);
int black_h, b_h; int black_h, b_h;
...@@ -3087,7 +3126,8 @@ namespace __gnu_parallel ...@@ -3087,7 +3126,8 @@ namespace __gnu_parallel
* @param black_h_l Black height of the left subtree. * @param black_h_l Black height of the left subtree.
* @return Black height of the original tree */ * @return Black height of the original tree */
int int
extract_max(const _Rb_tree_node_ptr t, _Rb_tree_node_ptr& root, _Rb_tree_node_ptr& l, int& black_h_l) const extract_max(const _Rb_tree_node_ptr t, _Rb_tree_node_ptr& root,
_Rb_tree_node_ptr& l, int& black_h_l) const
{ {
_GLIBCXX_PARALLEL_ASSERT (t != NULL); _GLIBCXX_PARALLEL_ASSERT (t != NULL);
int black_h, b_h; int black_h, b_h;
...@@ -3138,7 +3178,9 @@ namespace __gnu_parallel ...@@ -3138,7 +3178,9 @@ namespace __gnu_parallel
* @param black_h_r Black height of the right subtree. * @param black_h_r Black height of the right subtree.
* @return Black height of the original tree */ * @return Black height of the original tree */
int int
split(const _Rb_tree_node_ptr t, const key_type& key, _Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r, int& black_h_l, int& black_h_r) const split(const _Rb_tree_node_ptr t, const key_type& key,
_Rb_tree_node_ptr& l, _Rb_tree_node_ptr& r, int& black_h_l,
int& black_h_r) const
{ {
if (t != NULL) if (t != NULL)
{ {
...@@ -3197,7 +3239,9 @@ namespace __gnu_parallel ...@@ -3197,7 +3239,9 @@ namespace __gnu_parallel
* @return Resulting tree after insertion */ * @return Resulting tree after insertion */
template<typename StrictlyLessOrLessEqual> template<typename StrictlyLessOrLessEqual>
_Rb_tree_node_ptr _Rb_tree_node_ptr
_M_insert_local(_Rb_tree_node_base* t, const _Rb_tree_node_ptr new_t, size_type& existing, int& black_h, StrictlyLessOrLessEqual strictly_less_or_less_equal) _M_insert_local(_Rb_tree_node_base* t, const _Rb_tree_node_ptr new_t,
size_type& existing, int& black_h,
StrictlyLessOrLessEqual strictly_less_or_less_equal)
{ {
_GLIBCXX_PARALLEL_ASSERT(t != NULL); _GLIBCXX_PARALLEL_ASSERT(t != NULL);
if (_M_insert_local_top_down(t, new_t, NULL, NULL, true, strictly_less_or_less_equal)) if (_M_insert_local_top_down(t, new_t, NULL, NULL, true, strictly_less_or_less_equal))
...@@ -3233,7 +3277,11 @@ namespace __gnu_parallel ...@@ -3233,7 +3277,11 @@ namespace __gnu_parallel
*/ */
template<typename StrictlyLessOrLessEqual> template<typename StrictlyLessOrLessEqual>
bool bool
_M_insert_local_top_down(_Rb_tree_node_base* t, const _Rb_tree_node_ptr new_t, _Rb_tree_node_base* eq_t, _Rb_tree_node_base* parent, const bool is_left, StrictlyLessOrLessEqual strictly_less_or_less_equal) const _M_insert_local_top_down(_Rb_tree_node_base* t,
const _Rb_tree_node_ptr new_t,
_Rb_tree_node_base* eq_t,
_Rb_tree_node_base* parent, const bool is_left,
StrictlyLessOrLessEqual strictly_less_or_less_equal) const
{ {
if (t != NULL) if (t != NULL)
{ {
...@@ -3398,7 +3446,8 @@ namespace __gnu_parallel ...@@ -3398,7 +3446,8 @@ namespace __gnu_parallel
* @return Tree correct. * @return Tree correct.
*/ */
static bool static bool
rb_verify_tree(const typename base_type::_Const_Link_type __x, int& count, int& black_h) rb_verify_tree(const typename base_type::_Const_Link_type __x, int& count,
int& black_h)
{ {
if (__x == NULL) if (__x == NULL)
{ {
......
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