Skip to content

Commit d90282e

Browse files
committed
EAMxx: Using a regular range policy instead of MDRangePolicy, as it has been reported that the latter has performance issues. We can revert this commit once the Kokkos team addresses these concerns.
1 parent 22e635f commit d90282e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

components/eamxx/src/physics/mam/eamxx_mam_microphysics_process_interface.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void MAMMicrophysics::initialize_impl(const RunType run_type) {
463463
// ---------------------------------------------------------------
464464
populate_wet_atm(wet_atm_);
465465
populate_dry_atm(dry_atm_, buffer_);
466-
466+
467467
// FIXME: we are using cldfrac_tot in other mam4xx process.
468468
dry_atm_.cldfrac = get_field_in("cldfrac_liq").get_view<const Real **>();
469469
// FIXME: phis is not populated by populate_wet_and_dry_atm.
@@ -954,9 +954,11 @@ void MAMMicrophysics::run_impl(const double dt) {
954954
// Transpose extfrc_ from internal layout [ncol][nlev][extcnt]
955955
// to output layout [ncol][extcnt][nlev]
956956
// This aligns with expected field storage in the EAMxx infrastructure.
957-
Kokkos::parallel_for("transpose_extfrc",
958-
Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0,0,0}, {ncol, extcnt, nlev}),
959-
KOKKOS_LAMBDA(const int i, const int j, const int k) {
957+
Kokkos::parallel_for("transpose_extfrc", ncol * extcnt * nlev,
958+
KOKKOS_LAMBDA(const int linear_index) {
959+
const int k = linear_index / (ncol * extcnt);
960+
const int j = (linear_index / ncol) % extcnt;
961+
const int i = linear_index % ncol;
960962
const int pcnst_idx = extfrc_pcnst_index[j];
961963
const Real molar_mass_g_per_mol = molar_mass_g_per_mol_tmp[pcnst_idx]; // g/mol
962964
// Modify units to MKS units: [molec/cm3/s] to [kg/m3/s]

components/eamxx/src/physics/mam/eamxx_mam_optics_process_interface.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void MAMOptics::set_grids(
5252
FieldLayout scalar3d_int = grid_->get_3d_scalar_layout(false);
5353
add_tracers_wet_atm();
5454
add_fields_dry_atm();
55-
55+
5656
// cloud liquid number mixing ratio [1/kg]
5757
add_tracer<Required>("nc", grid_, n_unit);
5858

@@ -443,11 +443,14 @@ void MAMOptics::run_impl(const double dt) {
443443
Kokkos::fence();
444444

445445
// nswbands loop is using rrtmg indexing.
446+
const int ncol = ncol_;
447+
const int nswbands = nswbands_;
446448
Kokkos::parallel_for(
447-
"copying data from mam4xx to eamxx",
448-
Kokkos::MDRangePolicy<Kokkos::Rank<3>>({0, 0, 0},
449-
{ncol_, nswbands_, nlev_}),
450-
KOKKOS_LAMBDA(const int icol, const int iswband, const int kk) {
449+
"copying data from mam4xx to eamxx", ncol_*nswbands_*nlev_,
450+
KOKKOS_LAMBDA(const int linear_index) {
451+
const int kk = linear_index / (ncol * nswbands);
452+
const int iswband = (linear_index / ncol) % nswbands;
453+
const int icol = linear_index % ncol;
451454
// Extract single scattering albedo from the product-defined fields
452455
if(tau_sw(icol, iswband, kk + 1) > zero) {
453456
aero_ssa_sw_eamxx(icol, get_idx_rrtmgp_from_rrtmg_swbands(iswband),

0 commit comments

Comments
 (0)