HPX - High Performance ParalleX

PrevUpHomeNext

Function template transform_reduce

hpx::parallel::v1::transform_reduce

Synopsis

// In header: <hpx/parallel/detail/transform_reduce.hpp>


template<typename ExPolicy, typename InIter, typename T, typename Reduce, 
         typename Convert> 
  unspecified transform_reduce(ExPolicy && policy, InIter first, InIter last, 
                               T init, Reduce && red_op, Convert && conv_op);

Description

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

[Note] Note

Complexity: O(last - first) applications of the predicates red_op and conv_op.

The reduce operations in the parallel reduce algorithm invoked with an execution policy object of type sequential_execution_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_execution_policy or task_execution_policy are permitted to execute in an unordered fashion in unspecified threads, and indeterminately sequenced within each thread.

[Note] 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.

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

Parameters:

conv_op

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 unary predicate. The signature of this predicate should be equivalent to:

R fun(const Type &a);


The signature does not need to have const&, but the function must not modify the objects passed to it. The type Type must be such that an object of type InIter can be dereferenced and then implicitly converted to Type. The type R must be such that an object of this type can be implicitly converted to T.

first

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

init

The initial value for the generalized sum.

last

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

policy

The execution policy to use for the scheduling of the iterations.

red_op

Specifies the function (or function object) which will be invoked for each of the values returned from the invocation of conv_op. This is a binary predicate. The signature of this predicate should be equivalent to:

Ret fun(const Type1 &a, const Type2 &b);


The signature does not need to have const&, but the function must not modify the objects passed to it. The types Type1, Type2, and Ret must be such that an object of a type as returned from conv_op can be implicitly converted to any of those types.

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.

InIter

The type of the source iterators used (deduced). This iterator type must meet the requirements of an input iterator.

T

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

Returns:

The reduce algorithm returns a hpx::future<T> if the execution policy is of type task_execution_policy and returns T otherwise. The reduce algorithm returns the result of the generalized sum over the values returned from conv_op when applied to the elements given by the input range [first, last).


PrevUpHomeNext