Bolt  1.3
C++ template library with support for OpenCL
Functions
CL-reduce

Functions

template<typename InputIterator >
std::iterator_traits
< InputIterator >::value_type 
bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, const std::string &cl_code="")
 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::cl::reduce (InputIterator first, InputIterator last, const std::string &cl_code="")
 
template<typename InputIterator , typename T >
bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, T init, const std::string &cl_code="")
 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::cl::reduce (InputIterator first, InputIterator last, T init, const std::string &cl_code="")
 
template<typename InputIterator , typename T , typename BinaryFunction >
bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, T init, BinaryFunction binary_op=bolt::cl::plus< T >(), const std::string &cl_code="")
 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::cl::control structure as a first argument.
 
template<typename InputIterator , typename T , typename BinaryFunction >
bolt::cl::reduce (InputIterator first, InputIterator last, T init, BinaryFunction binary_op, const std::string &cl_code="")
 

Detailed Description

Function Documentation

template<typename InputIterator >
std::iterator_traits< InputIterator >::value_type bolt::cl::reduce ( bolt::cl::control ctl,
InputIterator  first,
InputIterator  last,
const std::string &  cl_code = "" 
)

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") be commutative. The order in which reduce applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.

The reduce operation is similar the std::accumulate function

Parameters
ctlOptional Control structure to control command-queue, debug, tuning.
firstThe first position in the sequence to be reduced.
lastThe last position in the sequence to be reduced.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in 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.

#include <bolt/cl/reduce.h>
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int sum = bolt::cl::reduce(a, a+10);
// sum = 55
See Also
http://www.sgi.com/tech/stl/accumulate.html
template<typename InputIterator , typename T >
T bolt::cl::reduce ( bolt::cl::control ctl,
InputIterator  first,
InputIterator  last,
init,
const std::string &  cl_code = "" 
)

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") be commutative. The order in which reduce applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.

The reduce operation is similar the std::accumulate function

Parameters
ctlOptional Control structure to control command-queue, debug, tuning.
firstThe first position in the sequence to be reduced.
lastThe last position in the sequence to be reduced.
initThe initial value for the accumulator.
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in 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.

#include <bolt/cl/reduce.h>
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int init = 10;
int sum = bolt::cl::reduce(a, a+10, init);
// sum = 65
See Also
http://www.sgi.com/tech/stl/accumulate.html
template<typename InputIterator , typename T , typename BinaryFunction >
T bolt::cl::reduce ( bolt::cl::control ctl,
InputIterator  first,
InputIterator  last,
init,
BinaryFunction  binary_op = bolt::cl::plus<T>(),
const std::string &  cl_code = "" 
)

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::cl::control structure as a first argument.

reduce requires that the binary reduction op ("binary_op") be commutative. The order in which reduce applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.

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

Parameters
ctlOptional Control structure to control command-queue, debug, tuning, etc.
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<>().
cl_codeOptional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in 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.
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.

#include <bolt/cl/reduce.h>
int a[10] = {2, 9, 3, 7, 5, 6, 3, 8, 3, 4};
int max = bolt::cl::reduce( a, a+10, -1, bolt::cl:maximum<int>());
// max = 9
See Also
http://www.sgi.com/tech/stl/accumulate.html