Skip to content

Commit 3a85062

Browse files
committed
Use kokkos scratch pad for local per-team bools
1 parent 9438a98 commit 3a85062

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

components/eamxx/src/physics/p3/impl/p3_main_impl.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ ::p3_main_internal(
8787
const physics::P3_Constants<S> & p3constants)
8888
{
8989
using ExeSpace = typename KT::ExeSpace;
90+
using ScratchViewType = Kokkos::View<bool*, typename ExeSpace::scratch_memory_space>;
9091

9192
const Int nk_pack = ekat::npack<Spack>(nk);
92-
const auto policy = ekat::ExeSpaceUtils<ExeSpace>::get_default_team_policy(nj, nk_pack);
93+
const auto scratch_size = ScratchViewType::shmem_size(2);
94+
const auto policy = ekat::ExeSpaceUtils<ExeSpace>::get_default_team_policy(nj, nk_pack).set_scratch_size(0, Kokkos::PerTeam(scratch_size));
9395

9496
// load constants into local vars
9597
const Scalar inv_dt = 1 / infrastructure.dt;
@@ -98,9 +100,6 @@ ::p3_main_internal(
98100
const Int kbot = kdir == -1 ? nk-1 : 0;
99101
constexpr bool debug_ABORT = false;
100102

101-
// per-column bools
102-
view_2d<bool> bools("bools", nj, 2);
103-
104103
// we do not want to measure init stuff
105104
auto start = std::chrono::steady_clock::now();
106105

@@ -201,9 +200,11 @@ ::p3_main_internal(
201200
const auto oqv_prev = ekat::subview(diagnostic_inputs.qv_prev, i);
202201
const auto ot_prev = ekat::subview(diagnostic_inputs.t_prev, i);
203202

204-
// Need to watch out for race conditions with these shared variables
205-
bool &nucleationPossible = bools(i, 0);
206-
bool &hydrometeorsPresent = bools(i, 1);
203+
// Use Kokkos' scratch pad for allocating 2 bools
204+
// per team to determine early exits
205+
ScratchViewType bools(team.team_scratch(0), 2);
206+
bool &nucleationPossible = bools(0);
207+
bool &hydrometeorsPresent = bools(1);
207208

208209
view_1d_ptr_array<Spack, 36> zero_init = {
209210
&mu_r, &lamr, &logn0r, &nu, &cdist, &cdist1, &cdistr,

0 commit comments

Comments
 (0)