boost::compute::reduce
// In header: <boost/compute/algorithm/reduce.hpp> template<typename InputIterator, typename OutputIterator, typename BinaryFunction> void reduce(InputIterator first, InputIterator last, OutputIterator result, BinaryFunction function, command_queue & queue = system::default_queue()); template<typename InputIterator, typename OutputIterator> void reduce(InputIterator first, InputIterator last, OutputIterator result, command_queue & queue = system::default_queue());
Returns the result of applying function to the elements in the range [first, last).
If no function is specified, plus will be used.
The difference between the reduce() function and the accumulate() function is that reduce() requires the binary operator to be commutative.
This algorithm supports both host and device iterators for the result argument. This allows for values to be reduced and copied to the host all with a single function call.
For example, to calculate the sum of the values in a device vector and copy the result to a value on the host:
int sum = 0; boost::compute::reduce(vec.begin(), vec.end(), &sum, queue);
See Also:
accumulate()