Skip to content

Commit

Permalink
Added 1D and 2D par reduces
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Oct 5, 2022
1 parent 20de024 commit 981d81a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ports-of-call/portability.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,35 @@ void portableFor(const char *name, int startb, int stopb, int starta, int stopa,
#endif
}

template <typename Function, typename T>
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 <typename Function, typename T>
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::Rank<2>>;
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 <typename Function, typename T>
void portableReduce(const char *name, int startz, int stopz, int starty,
int stopy, int startx, int stopx, Function function,
Expand Down

0 comments on commit 981d81a

Please sign in to comment.