Skip to content

Commit

Permalink
Merge pull request #15 from lanl/brryan/1d_2d_reduce
Browse files Browse the repository at this point in the history
Add 1D and 2D parallel reduces
  • Loading branch information
Yurlungur authored Apr 3, 2023
2 parents 2319b01 + 981d81a commit caf6722
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 @@ -236,6 +236,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 caf6722

Please sign in to comment.