diff --git a/ports-of-call/portability.hpp b/ports-of-call/portability.hpp index 4f27d806..4db5ba4a 100644 --- a/ports-of-call/portability.hpp +++ b/ports-of-call/portability.hpp @@ -236,6 +236,35 @@ void portableFor(const char *name, int startb, int stopb, int starta, int stopa, #endif } +template +void portableReduce(const char *name, int start, int stop, Function function, + T &reduced) { +#ifdef PORTABILITY_STRATEGY_KOKKOS + using Policy = Kokkos::RangePolicy<>; + Kokkos::parallel_reduce(name, Policy(start, stop), function, reduced); +#else + for (int i = start; i < stop; i++) { + function(i, reduced); + } +#endif +} + +template +void portableReduce(const char *name, int starty, int stopy, int startx, + int stopx, Function function, T &reduced) { +#ifdef PORTABILITY_STRATEGY_KOKKOS + using Policy2D = Kokkos::MDRangePolicy>; + Kokkos::parallel_reduce(name, Policy2D({starty, startx}, {stopy, stopx}), + function, reduced); +#else + for (int iy = starty; iy < stopy; iy++) { + for (int ix = startx; ix < stopx; ix++) { + function(iy, ix, reduced); + } + } +#endif +} + template void portableReduce(const char *name, int startz, int stopz, int starty, int stopy, int startx, int stopx, Function function,