Bolt  1.3
C++ template library with support for OpenCL
Functions
AMP-for_each

Functions

template<typename InputIterator , typename UnaryFunction >
InputIterator bolt::amp::for_each (InputIterator first, InputIterator last, UnaryFunction f)
 ForEach applies the unary function f to each element in the range [first,last] without modifying the input sequence.
 
template<typename InputIterator , typename UnaryFunction >
InputIterator bolt::amp::for_each (control &ctl, InputIterator first, InputIterator last, UnaryFunction f)
 
template<typename InputIterator , typename Size , typename UnaryFunction >
InputIterator bolt::amp::for_each_n (InputIterator first, Size n, UnaryFunction f)
 ForEach_n applies the unary function f to each element in the range [first,first+n] without modifying the input sequence.
 
template<typename InputIterator , typename Size , typename UnaryFunction >
InputIterator bolt::amp::for_each_n (control &ctl, InputIterator first, Size n, UnaryFunction f)
 

Detailed Description

Function Documentation

template<typename InputIterator , typename UnaryFunction >
InputIterator bolt::amp::for_each ( InputIterator  first,
InputIterator  last,
UnaryFunction  f 
)

ForEach applies the unary function f to each element in the range [first,last] without modifying the input sequence.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
firstThe first element in the range of interest.
lastThe last element in the range of interest.
fUnary Function to apply to elements in the range [first,last].
Template Parameters
InputIteratoris a model of InputIterator is mutable.

The following code snippet demonstrates how to use for_each with a device_vector..

#include <stdlib.h>
...
template< typename T >
struct unary_op
{
void operator()( T &x ) const restrict(amp, cpu)
{
x+=2;
}
};
std::vector<int> sv(10, rand()%10);
bolt::amp::device_vector<int> v(sv.begin(), sv.end());
bolt::amp::for_each(v.begin(), v.end(), unary_op<int>());
// the elements of v are printed.
See Also
http://www.sgi.com/tech/stl/for_each.html
template<typename InputIterator , typename Size , typename UnaryFunction >
InputIterator bolt::amp::for_each_n ( InputIterator  first,
Size  n,
UnaryFunction  f 
)

ForEach_n applies the unary function f to each element in the range [first,first+n] without modifying the input sequence.

Parameters
ctlOptional Control structure to control accelerator, debug, tuning, etc.See bolt::amp::control.
firstThe first element in the range of interest.
nThe size of the range of interest.
fUnary Function to apply to elements in the range [first,first+n].
Template Parameters
InputIteratoris a model of InputIterator is mutable.

The following code snippet demonstrates how to use for_each_n with a device_vector..

#include <stdlib.h>
...
template< typename T >
struct unary_op
{
void operator()( T &x ) const restrict(amp, cpu)
{
x+=2;
}
};
std::vector<int> sv(10, rand()%10);
bolt::amp::device_vector<float> v(sv.begin(), sv.end());
int n = 5;
bolt::amp::for_each_n(v.begin(), n, unary_op<int>());
// First 5 elements of v are printed.
See Also
http://www.sgi.com/tech/stl/for_each.html