hpx::ranges::reduce#

Defined in header hpx/algorithm.hpp.

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace ranges

Functions

template<typename ExPolicy, typename FwdIter, typename Sent, typename F, typename T = typename std::iterator_traits<FwdIter>::value_type>
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, T> reduce(ExPolicy &&policy, FwdIter first, Sent last, T init, F &&f)#

Returns GENERALIZED_SUM(f, init, *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the predicate f.

Note

GENERALIZED_SUM(op, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(op, b1, …, bK), GENERALIZED_SUM(op, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

  • F – The type of the function/function object to use (deduced). Unlike its sequential form, the parallel overload of copy_if requires F to meet the requirements of CopyConstructible.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

  • f – Specifies the function (or function object) which will be invoked for each of the elements in the sequence specified by [first, last). This is a binary predicate. The signature of this predicate should be equivalent to:

    Ret fun(const Type1 &a, const Type1 &b);
    
    The signature does not need to have const&. The types Type1 Ret must be such that an object of type FwdIterB can be dereferenced and then implicitly converted to any of those types.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise. The reduce algorithm returns the result of the generalized sum over the elements given by the input range [first, last).

template<typename ExPolicy, typename Rng, typename F, typename T = typename std::iterator_traits<hpx::traits::range_iterator_t<Rng>>::value_type>
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, T> reduce(ExPolicy &&policy, Rng &&rng, T init, F &&f)#

Returns GENERALIZED_SUM(f, init, *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the predicate f.

Note

GENERALIZED_SUM(op, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(op, b1, …, bK), GENERALIZED_SUM(op, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

  • F – The type of the function/function object to use (deduced). Unlike its sequential form, the parallel overload of copy_if requires F to meet the requirements of CopyConstructible.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • rng – Refers to the sequence of elements the algorithm will be applied to.

  • f – Specifies the function (or function object) which will be invoked for each of the elements in the sequence specified by [first, last). This is a binary predicate. The signature of this predicate should be equivalent to:

    Ret fun(const Type1 &a, const Type1 &b);
    
    The signature does not need to have const&. The types Type1 Ret must be such that an object of type FwdIterB can be dereferenced and then implicitly converted to any of those types.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise. The reduce algorithm returns the result of the generalized sum over the elements given by the input range [first, last).

template<typename ExPolicy, typename FwdIter, typename Sent, typename T = typename std::iterator_traits<FwdIter>::value_type>
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, T> reduce(ExPolicy &&policy, FwdIter first, Sent last, T init)#

Returns GENERALIZED_SUM(+, init, *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise. The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename ExPolicy, typename Rng, typename T = typename std::iterator_traits<hpx::traits::range_iterator_t<Rng>>::value_type>
hpx::parallel::util::detail::algorithm_result_t<ExPolicy, T> reduce(ExPolicy &&policy, Rng &&rng, T init)#

Returns GENERALIZED_SUM(+, init, *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • rng – Refers to the sequence of elements the algorithm will be applied to.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise. The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename ExPolicy, typename FwdIter, typename Sent>
hpx::parallel::util::detail::algorithm_result<ExPolicy, typename std::iterator_traits<FwdIter>::value_type>::type reduce(ExPolicy &&policy, FwdIter first, Sent last)#

Returns GENERALIZED_SUM(+, T(), *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

The type of the initial value (and the result type) T is determined from the value_type of the used FwdIterB.

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise (where T is the value_type of FwdIterB). The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename ExPolicy, typename Rng>
hpx::parallel::util::detail::algorithm_result<ExPolicy, typename std::iterator_traits<typename hpx::traits::range_traits<Rng>::iterator_type>::value_type>::type reduce(ExPolicy &&policy, Rng &&rng)#

Returns GENERALIZED_SUM(+, T(), *first, …, *(first + (last - first) - 1)).

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequenced_policy execute in sequential order in the calling thread.

The reduce operations in the parallel copy_if algorithm invoked with an execution policy object of type parallel_policy or parallel_task_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

The type of the initial value (and the result type) T is determined from the value_type of the used FwdIterB.

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • ExPolicy – The type of the execution policy to use (deduced). It describes the manner in which the execution of the algorithm may be parallelized and the manner in which it executes the assignments.

  • Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

Parameters
  • policy – The execution policy to use for the scheduling of the iterations.

  • rng – Refers to the sequence of elements the algorithm will be applied to.

Returns

The reduce algorithm returns a hpx::future<T> if the execution policy is of type sequenced_task_policy or parallel_task_policy and returns T otherwise (where T is the value_type of FwdIterB). The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename FwdIter, typename Sent, typename F, typename T = typename std::iterator_traits<FwdIter>::value_type>
T reduce(FwdIter first, Sent last, T init, F &&f)#

Returns GENERALIZED_SUM(f, init, *first, …, *(first + (last - first) - 1)).

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the predicate f.

Note

GENERALIZED_SUM(op, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(op, b1, …, bK), GENERALIZED_SUM(op, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

  • F – The type of the function/function object to use (deduced). Unlike its sequential form, the parallel overload of copy_if requires F to meet the requirements of CopyConstructible.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

  • f – Specifies the function (or function object) which will be invoked for each of the elements in the sequence specified by [first, last). This is a binary predicate. The signature of this predicate should be equivalent to:

    Ret fun(const Type1 &a, const Type1 &b);
    
    The signature does not need to have const&. The types Type1 Ret must be such that an object of type FwdIterB can be dereferenced and then implicitly converted to any of those types.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns T. The reduce algorithm returns the result of the generalized sum over the elements given by the input range [first, last).

template<typename Rng, typename F, typename T = typename std::iterator_traits<hpx::traits::range_iterator_t<Rng>>::value_type>
T reduce(Rng &&rng, T init, F &&f)#

Returns GENERALIZED_SUM(f, init, *first, …, *(first + (last - first) - 1)).

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the predicate f.

Note

GENERALIZED_SUM(op, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(op, b1, …, bK), GENERALIZED_SUM(op, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

  • F – The type of the function/function object to use (deduced). Unlike its sequential form, the parallel overload of copy_if requires F to meet the requirements of CopyConstructible.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • rng – Refers to the sequence of elements the algorithm will be applied to.

  • f – Specifies the function (or function object) which will be invoked for each of the elements in the sequence specified by [first, last). This is a binary predicate. The signature of this predicate should be equivalent to:

    Ret fun(const Type1 &a, const Type1 &b);
    
    The signature does not need to have const&. The types Type1 Ret must be such that an object of type FwdIterB can be dereferenced and then implicitly converted to any of those types.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns T. The reduce algorithm returns the result of the generalized sum over the elements given by the input range [first, last).

template<typename FwdIter, typename Sent, typename T = typename std::iterator_traits<FwdIter>::value_type>
T reduce(FwdIter first, Sent last, T init)#

Returns GENERALIZED_SUM(+, init, *first, …, *(first + (last - first) - 1)).

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns T. The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename Rng, typename T = typename std::iterator_traits<hpx::traits::range_iterator_t<Rng>>::value_type>
T reduce(Rng &&rng, T init)#

Returns GENERALIZED_SUM(+, init, *first, …, *(first + (last - first) - 1)).

The difference between

reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

  • T – The type of the value to be used as initial (and intermediate) values (deduced).

Parameters
  • rng – Refers to the sequence of elements the algorithm will be applied to.

  • init – The initial value for the generalized sum.

Returns

The reduce algorithm returns T. The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename FwdIter, typename Sent>
std::iterator_traits<FwdIter>::value_type reduce(FwdIter first, Sent last)#

Returns GENERALIZED_SUM(+, T(), *first, …, *(first + (last - first) - 1)).

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

The type of the initial value (and the result type) T is determined from the value_type of the used FwdIterB.

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters
  • FwdIter – The type of the source begin iterator used (deduced). This iterator type must meet the requirements of an forward iterator.

  • Sent – The type of the source sentinel used (deduced). This iterator type must meet the requirements of an forward iterator.

Parameters
  • first – Refers to the beginning of the sequence of elements the algorithm will be applied to.

  • last – Refers to the end of the sequence of elements the algorithm will be applied to.

Returns

The reduce algorithm returns T (where T is the value_type of FwdIterB). The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).

template<typename Rng>
std::iterator_traits<typename hpx::traits::range_traits<Rng>::iterator_type>::value_type reduce(Rng &&rng)#

Returns GENERALIZED_SUM(+, T(), *first, …, *(first + (last - first) - 1)).

The difference between reduce and accumulate is that the behavior of reduce may be non-deterministic for non-associative or non-commutative binary predicate.

Note

Complexity: O(last - first) applications of the operator+().

Note

The type of the initial value (and the result type) T is determined from the value_type of the used FwdIterB.

Note

GENERALIZED_SUM(+, a1, …, aN) is defined as follows:

  • a1 when N is 1

  • op(GENERALIZED_SUM(+, b1, …, bK), GENERALIZED_SUM(+, bM, …, bN)), where:

    • b1, …, bN may be any permutation of a1, …, aN and

    • 1 < K+1 = M <= N.

Template Parameters

Rng – The type of the source range used (deduced). The iterators extracted from this range type must meet the requirements of an input iterator.

Parameters

rng – Refers to the sequence of elements the algorithm will be applied to.

Returns

The reduce algorithm returns T (where T is the value_type of FwdIterB). The reduce algorithm returns the result of the generalized sum (applying operator+()) over the elements given by the input range [first, last).