Bolt  1.1
C++ template library with support for OpenCL
Functions
Amp-reduce

Functions

template<typename InputIterator >
std::iterator_traits
< InputIterator >::value_type 
bolt::amp::reduce (bolt::amp::control &ctl, InputIterator first, InputIterator last)
 reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".
 
template<typename InputIterator >
std::iterator_traits
< InputIterator >::value_type 
bolt::amp::reduce (InputIterator first, InputIterator last)
 
template<typename InputIterator , typename T >
bolt::amp::reduce (bolt::amp::control &ctl, InputIterator first, InputIterator last, T init)
 reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".
 
template<typename InputIterator , typename T >
bolt::amp::reduce (InputIterator first, InputIterator last, T init)
 
template<typename InputIterator , typename T , typename BinaryFunction >
bolt::amp::reduce (bolt::amp::control &ctl, InputIterator first, InputIterator last, T init, BinaryFunction binary_op=bolt::amp::plus< T >())
 reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the binary operator is "plus<>()". The version takes a bolt::amp::control structure as a first argument.
 
template<typename InputIterator , typename T , typename BinaryFunction >
bolt::amp::reduce (InputIterator first, InputIterator last, T init, BinaryFunction binary_op)
 

Detailed Description

Function Documentation

template<typename InputIterator >
std::iterator_traits< InputIterator >::value_type bolt::amp::reduce ( bolt::amp::control ctl,
InputIterator  first,
InputIterator  last 
)

reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".

reduce requires that the binary reduction op ("binary_op") is cummutative. The order in which reduce applies the binary_op is not deterministic.

The reduce operation is similar the std::accumulate function

Parameters
ctlOptional Control structure to control accelerator,debug, tuning. See bolt::amp::control.
firstThe first position in the sequence to be reduced.
lastThe last position in the sequence to be reduced. the generated code, before the cl_code trait.
Template Parameters
InputIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
TThe type of the result.
Returns
The result of the reduction.

The following code example shows the use of reduce to sum 10 numbers, using the default plus operator.

int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
//Create an AMP Control object using the default accelerator
::Concurrency::accelerator accel(::Concurrency::accelerator::default_accelerator);
bolt::amp::control ctl(accel);
int sum = bolt::cl::reduce(ctl, a, a+10);
// sum = 55
See Also
http://www.sgi.com/tech/stl/accumulate.html
template<typename InputIterator , typename T >
T bolt::amp::reduce ( bolt::amp::control ctl,
InputIterator  first,
InputIterator  last,
init 
)

reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".

reduce requires that the binary reduction op ("binary_op") is cummutative. The order in which reduce applies the binary_op is not deterministic.

The reduce operation is similar the std::accumulate function

Parameters
ctlOptional Control structure to control accelerator,debug, tuning. See bolt::amp::control.
firstThe first position in the sequence to be reduced.
lastThe last position in the sequence to be reduced.
initThe initial value for the accumulator.
Template Parameters
InputIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
TThe type of the result.
Returns
The result of the reduction.
See Also
http://www.sgi.com/tech/stl/accumulate.html

The following code example shows the use of reduce to sum 10 numbers, using the default plus operator.

int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
//Create an AMP Control object using the default accelerator
::Concurrency::accelerator accel(::Concurrency::accelerator::default_accelerator);
bolt::amp::control ctl(accel);
int sum = bolt::amp::reduce(ctl, a, a+10, 0);
// sum = 55
template<typename InputIterator , typename T , typename BinaryFunction >
T bolt::amp::reduce ( bolt::amp::control ctl,
InputIterator  first,
InputIterator  last,
init,
BinaryFunction  binary_op = bolt::amp::plus<T>() 
)

reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the binary operator is "plus<>()". The version takes a bolt::amp::control structure as a first argument.

reduce requires that the binary reduction op ("binary_op") is cummutative. The order in which reduce applies the binary_op is not deterministic.

The reduce operation is similar the std::accumulate function.

Parameters
ctlOptional Control structure to control accelerator,debug, tuning. See bolt::amp::control.
firstThe first position in the sequence to be reduced.
lastThe last position in the sequence to be reduced.
initThe initial value for the accumulator.
binary_opThe binary operation used to combine two values. By default, the binary operation is plus<>().
Template Parameters
InputIteratorAn iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence.
BinaryFunctionA function object defining an operation that is applied to consecutive elements in the sequence.
Returns
The result of the reduction.

The following code example shows the use of reduce to find the max of 10 numbers, specifying a specific accelerator.

int a[10] = {2, 9, 3, 7, 5, 6, 3, 8, 3, 4};
//Create an AMP Control object using the default accelerator
::Concurrency::accelerator accel(::Concurrency::accelerator::default_accelerator);
bolt::amp::control ctl(accel);
int max = bolt::amp::reduce(ctl, a, a+10, -1, bolt::amp::maximum<int>());
// max = 9
See Also
http://www.sgi.com/tech/stl/accumulate.html