From 6d54cab02feb69d427edd8d4e6f60ecdd3e6b2e6 Mon Sep 17 00:00:00 2001 From: Denis Demidov Date: Mon, 9 Sep 2013 20:43:38 +0400 Subject: [PATCH] Documented creation of new reduction kind --- vexcl/reductor.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vexcl/reductor.hpp b/vexcl/reductor.hpp index dc944d57d..1f5616ddd 100644 --- a/vexcl/reductor.hpp +++ b/vexcl/reductor.hpp @@ -48,16 +48,29 @@ namespace vex { /// Summation. Should be used as a template parameter for Reductor class. struct SUM { + /* In order to define a reduction kind for vex::Reductor, one should: + * + * 1. Define initial value (e.g. 0 for sums, 1 for products, plus-minus + * infinity for extrema): + */ template static T initial() { return T(); }; + /* + * 2. Provide an OpenCL function that will be used on compute device to do + * incremental reductions. That is nested struct "function": + */ template struct function : UserFunction, T(T, T)> { static std::string body() { return "return prm1 + prm2;"; } }; + /* + * 3. Provide a host-side function that will be used for final reduction of + * small result vector on host: + */ template static typename std::iterator_traits::value_type reduce(Iterator begin, Iterator end) {