MCPcopy Create free account
hub / github.com/boostorg/compute / generic_accumulate

Function generic_accumulate

include/boost/compute/algorithm/accumulate.hpp:33–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31// Space complexity O(1)
32template<class InputIterator, class T, class BinaryFunction>
33inline T generic_accumulate(InputIterator first,
34 InputIterator last,
35 T init,
36 BinaryFunction function,
37 command_queue &queue)
38{
39 const context &context = queue.get_context();
40
41 size_t size = iterator_range_size(first, last);
42 if(size == 0){
43 return init;
44 }
45
46 // accumulate on device
47 array<T, 1> device_result(context);
48 detail::serial_accumulate(
49 first, last, device_result.begin(), init, function, queue
50 );
51
52 // copy result to host
53 T result;
54 ::boost::compute::copy_n(device_result.begin(), 1, &result, queue);
55 return result;
56}
57
58// returns true if we can use reduce() instead of accumulate() when
59// accumulate() this is true when the function is commutative (such as

Callers 1

dispatch_accumulateFunction · 0.85

Calls 5

iterator_range_sizeFunction · 0.85
serial_accumulateFunction · 0.85
copy_nFunction · 0.85
get_contextMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected