HPX - High Performance ParalleX

PrevUpHomeNext

Function template for_each_n

hpx::parallel::v1::for_each_n

Synopsis

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


template<typename ExPolicy, typename InIter, typename Size, typename F> 
  unspecified for_each_n(ExPolicy && policy, InIter first, Size count, F && f);

Description

Applies f to the result of dereferencing every iterator in the range [first, first + count), starting from first and proceeding to first + count - 1.

[Note] Note

Complexity: Applies f exactly count times.

If f returns a result, the result is ignored.

If the type of first satisfies the requirements of a mutable iterator, f may apply non-constant functions through the dereferenced iterator.

Unlike its sequential form, the parallel overload of for_each does not return a copy of its Function parameter, since parallelization may not permit efficient state accumulation.

The application of function objects in parallel algorithm invoked with an execution policy object of type sequential_execution_policy execute in sequential order in the calling thread.

The application of function objects in parallel 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.

Parameters:

count

Refers to the number of elements starting at first 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). The signature of this predicate should be equivalent to:

<ignored> pred(const Type &a);


The signature does not need to have const&. The type Type must be such that an object of type InIter can be dereferenced and then implicitly converted to Type.

first

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

policy

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

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 applies user-provided function objects.

F

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

InIter

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

Size

The type of the argument specifying the number of elements to apply f to.

Returns:

The for_each_n algorithm returns a hpx::future<InIter> if the execution policy is of type task_execution_policy and returns InIter otherwise. It returns first + count for non-negative values of count and first for negative values.


PrevUpHomeNext