
This patch rebases the C++17 parallel algorithms implementation (pstl) against the current upstream version, commit 843c12d6a. This version does not currently include the recently added OpenMP backend, that will be considered for a future version. libstdc++-v3/ChangeLog: * include/pstl/algorithm_fwd.h: Synchronize with upstream. * include/pstl/algorithm_impl.h: Likewise. * include/pstl/execution_defs.h: Likewise. * include/pstl/execution_impl.h: Likewise. * include/pstl/glue_algorithm_impl.h: Likewise. * include/pstl/glue_execution_defs.h: Likewise. * include/pstl/glue_memory_impl.h: Likewise. * include/pstl/glue_numeric_impl.h: Likewise. * include/pstl/memory_impl.h: Likewise. * include/pstl/numeric_fwd.h: Likewise. * include/pstl/numeric_impl.h: Likewise. * include/pstl/parallel_backend.h: Likewise. * include/pstl/parallel_backend_serial.h: Likewise. * include/pstl/parallel_backend_tbb.h: Likewise. * include/pstl/parallel_impl.h: Likewise. * include/pstl/pstl_config.h: Likewise. * include/pstl/unseq_backend_simd.h: Likewise. * include/pstl/utils.h: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_construct.cc: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_copy_move.cc: Likewise. * testsuite/20_util/specialized_algorithms/pstl/uninitialized_fill_destroy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_merge/inplace_merge.cc: Likewise. * testsuite/25_algorithms/pstl/alg_merge/merge.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/copy_if.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/copy_move.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/fill.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/generate.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/is_partitioned.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/partition.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/partition_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/remove.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/remove_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/replace.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/replace_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/rotate.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/rotate_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/swap_ranges.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/transform_binary.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/transform_unary.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/unique.cc: Likewise. * testsuite/25_algorithms/pstl/alg_modifying_operations/unique_copy_equal.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/adjacent_find.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/all_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/any_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/count.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/equal.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_end.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_first_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/find_if.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/for_each.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/mismatch.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/none_of.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/nth_element.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/reverse.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/reverse_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_nonmodifying/search_n.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/includes.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/is_heap.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/is_sorted.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/lexicographical_compare.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/minmax_element.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/partial_sort.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/partial_sort_copy.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/set.cc: Likewise. * testsuite/25_algorithms/pstl/alg_sorting/sort.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/adjacent_difference.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/reduce.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/scan.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/transform_reduce.cc: Likewise. * testsuite/26_numerics/pstl/numeric_ops/transform_scan.cc: Likewise. * testsuite/util/pstl/test_utils.h: Likewise.
225 lines
12 KiB
C++
225 lines
12 KiB
C++
// -*- C++ -*-
|
|
//===-- glue_numeric_impl.h -----------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _PSTL_GLUE_NUMERIC_IMPL_H
|
|
#define _PSTL_GLUE_NUMERIC_IMPL_H
|
|
|
|
#include <functional>
|
|
|
|
#include "utils.h"
|
|
#include "numeric_fwd.h"
|
|
|
|
namespace std
|
|
{
|
|
|
|
// [reduce]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
|
|
reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
|
|
_BinaryOperation __binary_op)
|
|
{
|
|
return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, __init, __binary_op,
|
|
__pstl::__internal::__no_op());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
|
|
reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init)
|
|
{
|
|
return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, __init, std::plus<_Tp>(),
|
|
__pstl::__internal::__no_op());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy,
|
|
typename iterator_traits<_ForwardIterator>::value_type>
|
|
reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last)
|
|
{
|
|
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
|
|
return transform_reduce(std::forward<_ExecutionPolicy>(__exec), __first, __last, _ValueType{},
|
|
std::plus<_ValueType>(), __pstl::__internal::__no_op());
|
|
}
|
|
|
|
// [transform.reduce]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
|
|
transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
|
_ForwardIterator2 __first2, _Tp __init)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
|
|
|
|
typedef typename iterator_traits<_ForwardIterator1>::value_type _InputType;
|
|
return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
|
|
__first1, __last1, __first2, __init, std::plus<_InputType>(),
|
|
std::multiplies<_InputType>());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation1,
|
|
class _BinaryOperation2>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
|
|
transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
|
|
_ForwardIterator2 __first2, _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first1, __first2);
|
|
return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
|
|
__first1, __last1, __first2, __init, __binary_op1,
|
|
__binary_op2);
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _BinaryOperation, class _UnaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _Tp>
|
|
transform_reduce(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Tp __init,
|
|
_BinaryOperation __binary_op, _UnaryOperation __unary_op)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first);
|
|
return __pstl::__internal::__pattern_transform_reduce(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
|
|
__first, __last, __init, __binary_op, __unary_op);
|
|
}
|
|
|
|
// [exclusive.scan]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _Tp __init)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
|
|
|
|
using namespace __pstl;
|
|
return __internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
|
|
__result, __pstl::__internal::__no_op(), __init, std::plus<_Tp>(),
|
|
/*inclusive=*/std::false_type());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
|
|
|
|
using namespace __pstl;
|
|
return __internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first, __last,
|
|
__result, __pstl::__internal::__no_op(), __init, __binary_op,
|
|
/*inclusive=*/std::false_type());
|
|
}
|
|
|
|
// [inclusive.scan]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result)
|
|
{
|
|
typedef typename iterator_traits<_ForwardIterator1>::value_type _InputType;
|
|
return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result,
|
|
std::plus<_InputType>(), __pstl::__internal::__no_op());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _BinaryOperation __binary_op)
|
|
{
|
|
return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __binary_op,
|
|
__pstl::__internal::__no_op());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _BinaryOperation __binary_op, _Tp __init)
|
|
{
|
|
return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), __first, __last, __result, __binary_op,
|
|
__pstl::__internal::__no_op(), __init);
|
|
}
|
|
|
|
// [transform.exclusive.scan]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Tp, class _BinaryOperation,
|
|
class _UnaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
transform_exclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _Tp __init, _BinaryOperation __binary_op,
|
|
_UnaryOperation __unary_op)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
|
|
|
|
return __pstl::__internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
|
|
__last, __result, __unary_op, __init, __binary_op,
|
|
/*inclusive=*/std::false_type());
|
|
}
|
|
|
|
// [transform.inclusive.scan]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation,
|
|
class _UnaryOperation, class _Tp>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op,
|
|
_Tp __init)
|
|
{
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __result);
|
|
|
|
return __pstl::__internal::__pattern_transform_scan(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec), __first,
|
|
__last, __result, __unary_op, __init, __binary_op,
|
|
/*inclusive=*/std::true_type());
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _UnaryOperation,
|
|
class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
transform_inclusive_scan(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __result, _BinaryOperation __binary_op, _UnaryOperation __unary_op)
|
|
{
|
|
if (__first != __last)
|
|
{
|
|
auto __tmp = __unary_op(*__first);
|
|
*__result = __tmp;
|
|
return transform_inclusive_scan(std::forward<_ExecutionPolicy>(__exec), ++__first, __last, ++__result,
|
|
__binary_op, __unary_op, __tmp);
|
|
}
|
|
else
|
|
{
|
|
return __result;
|
|
}
|
|
}
|
|
|
|
// [adjacent.difference]
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryOperation>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __d_first, _BinaryOperation __op)
|
|
{
|
|
|
|
if (__first == __last)
|
|
return __d_first;
|
|
|
|
auto __dispatch_tag = __pstl::__internal::__select_backend(__exec, __first, __d_first);
|
|
|
|
return __pstl::__internal::__pattern_adjacent_difference(__dispatch_tag, std::forward<_ExecutionPolicy>(__exec),
|
|
__first, __last, __d_first, __op);
|
|
}
|
|
|
|
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2>
|
|
__pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2>
|
|
adjacent_difference(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last,
|
|
_ForwardIterator2 __d_first)
|
|
{
|
|
typedef typename iterator_traits<_ForwardIterator1>::value_type _ValueType;
|
|
return adjacent_difference(std::forward<_ExecutionPolicy>(__exec), __first, __last, __d_first,
|
|
std::minus<_ValueType>());
|
|
}
|
|
|
|
} // namespace std
|
|
|
|
#endif /* _PSTL_GLUE_NUMERIC_IMPL_H_ */
|