Skip to content

Commit

Permalink
Explicitly capture this in lambda function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rombur committed Jul 20, 2023
1 parent f448ac8 commit db1fa27
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ struct SomeCorrelation {

// With each team run a parallel_for with its threads
Kokkos::parallel_for(
Kokkos::TeamThreadRange(thread, data.extent(1)), [=](const int& j) {
Kokkos::TeamThreadRange(thread, data.extent(1)),
[=, *this](const int& j) {
int tsum;
// Run a vector loop reduction over the inner dimension of data
// Count how many values are multiples of 4
// Every vector lane gets the same reduction value (tsum) back, it is
// broadcast to all vector lanes
Kokkos::parallel_reduce(
Kokkos::ThreadVectorRange(thread, data.extent(2)),
[=](const int& k, int& vsum) {
[=, *this](const int& k, int& vsum) {
vsum += (data(i, j, k) % 4 == 0) ? 1 : 0;
},
tsum);
Expand Down Expand Up @@ -103,7 +104,7 @@ struct SomeCorrelation {
// Add with one thread and vectorlane of the team the team_sum to the global
// value
Kokkos::single(Kokkos::PerTeam(thread),
[=]() { Kokkos::atomic_add(&gsum(), team_sum); });
[=, *this]() { Kokkos::atomic_add(&gsum(), team_sum); });
}

// The functor needs to define how much shared memory it requests given a
Expand Down

0 comments on commit db1fa27

Please sign in to comment.