Skip to content

Commit

Permalink
Build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfouca committed Oct 7, 2024
1 parent 88d8ecc commit d3d549a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
65 changes: 31 additions & 34 deletions components/eamxx/src/physics/rrtmgp/scream_rrtmgp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ using MDRP = typename conv::MDRP<LayoutT>;
template <typename T>
using view_t = Kokkos::View<T, LayoutT, DeviceT>;

template <typename T>
using oview_t = Kokkos::Experimental::OffsetView<T, LayoutT, DeviceT>;

template <typename T>
using hview_t = Kokkos::View<T, LayoutT, HostDevice>;

Expand Down Expand Up @@ -565,6 +562,25 @@ static void rrtmgp_sw(
int ngpt = k_dist.get_ngpt();
int ngas = gas_concs.get_num_gases();

// Get daytime indices
auto dayIndices = pool_t::template alloc<int>(ncol);
Kokkos::deep_copy(dayIndices, -1);

int nday = 0;
// Serialized for now.
Kokkos::parallel_reduce(1, KOKKOS_LAMBDA(int, int& nday_inner) {
for (int icol = 0; icol < ncol; ++icol) {
if (mu0(icol) > 0) {
dayIndices(nday_inner++) = icol;
}
}
}, Kokkos::Sum<int>(nday));

if (nday == 0) {
// No daytime columns in this chunk, skip the rest of this routine
return;
}

// Allocate temporaries from pool
const int size1 = nday;
const int size2 = nday*nlay; // 4
Expand Down Expand Up @@ -641,25 +657,6 @@ static void rrtmgp_sw(
bnd_flux_dn_dir(icol,ilev,ibnd) = 0;
});

// Get daytime indices
auto dayIndices = view_t<int*>("dayIndices", ncol);
Kokkos::deep_copy(dayIndices, -1);

int nday = 0;
// Serialized for now.
Kokkos::parallel_reduce(1, KOKKOS_LAMBDA(int, int& nday_inner) {
for (int icol = 0; icol < ncol; ++icol) {
if (mu0(icol) > 0) {
dayIndices(nday_inner++) = icol;
}
}
}, Kokkos::Sum<int>(nday));

if (nday == 0) {
// No daytime columns in this chunk, skip the rest of this routine
return;
}

// Subset mu0
Kokkos::parallel_for(nday, KOKKOS_LAMBDA(int iday) {
mu0_day(iday) = mu0(dayIndices(iday));
Expand Down Expand Up @@ -824,6 +821,7 @@ static void rrtmgp_sw(
}

pool_t::dealloc(data, dcurr - data);
pool_t::dealloc(dayIndices);
}

/*
Expand Down Expand Up @@ -857,7 +855,7 @@ static void rrtmgp_lw(
view_t<RealT**> gauss_wts (dcurr, max_gauss_pts,max_gauss_pts); dcurr += size3;
view_t<RealT**> t_lay_limited(dcurr, ncol, nlay); dcurr += size4;
view_t<RealT**> t_lev_limited(dcurr, ncol, nlay+1); dcurr += size5;
view_t<RealT***> col_gas (dcurr, std::make_pair(0, ncol-1), std::make_pair(0, nlay-1), std::make_pair(-1, k_dist.get_ngas()-1)); dcurr += size6;
view_t<RealT***> col_gas (dcurr, ncol, nlay, k_dist.get_ngas()+1); dcurr += size6;

// Associate local pointers for fluxes
auto &flux_up = fluxes.flux_up;
Expand Down Expand Up @@ -984,7 +982,8 @@ static void rrtmgp_lw(
/*
* Return a subcolumn mask consistent with a specified overlap assumption
*/
static void get_subcolumn_mask(const int ncol, const int nlay, const int ngpt, const real2dk &cldf, const int overlap_option, int1dk &seeds, int3dk& subcolumn_mask)
template <typename CldfT, typename SeedsT, typename SubcT>
static void get_subcolumn_mask(const int ncol, const int nlay, const int ngpt, const CldfT &cldf, const int overlap_option, const SeedsT &seeds, const SubcT& subcolumn_mask)
{
// Subcolumn generators are a means for producing a variable x(i,j,k), where
//
Expand Down Expand Up @@ -1054,8 +1053,6 @@ static void get_subcolumn_mask(const int ncol, const int nlay, const int ngpt, c
});

pool_t::dealloc(cldx);

return subcolumn_mask;
}

/*
Expand Down Expand Up @@ -1324,8 +1321,8 @@ static optical_props1_t get_cloud_optics_lw(
cloud_optics.set_ice_roughness(2);

// Limit effective radii to be within bounds of lookup table
auto rel_limited = pool_t::alloc(ncol, nlay);
auto rei_limited = pool_t::alloc(ncol, nlay);
auto rel_limited = pool_t::template alloc<RealT>(ncol, nlay);
auto rei_limited = pool_t::template alloc<RealT>(ncol, nlay);
limit_to_bounds_k(rel, cloud_optics.radliq_lwr, cloud_optics.radliq_upr, rel_limited);
limit_to_bounds_k(rei, cloud_optics.radice_lwr, cloud_optics.radice_upr, rei_limited);

Expand All @@ -1348,7 +1345,7 @@ static optical_props2_t get_subsampled_clouds(
subsampled_optics.alloc_2str(ncol, nlay);

// Subcolumn mask with values of 0 indicating no cloud, 1 indicating cloud
auto cldmask = pool_t::alloc<int>(ncol, nlay, ngpt);
auto cldmask = pool_t::template alloc<int>(ncol, nlay, ngpt);

// Check that we do not have clouds with no optical properties; this would get corrected
// when we assign optical props, but we want to use a "radiative cloud fraction"
Expand All @@ -1357,7 +1354,7 @@ static optical_props2_t get_subsampled_clouds(
// the vertical correlation of cloudy layers. I.e., cloudy layers might look maximally overlapped
// even when separated by layers with no cloud properties, when in fact those layers should be
// randomly overlapped.
auto cldfrac_rad = pool_t::alloc<RealT>(ncol, nlay);
auto cldfrac_rad = pool_t::template alloc<RealT>(ncol, nlay);
Kokkos::parallel_for(MDRP::template get<3>({nbnd,nlay,ncol}), KOKKOS_LAMBDA (int ibnd, int ilay, int icol) {
if (cloud_optics.tau(icol,ilay,ibnd) > 0) {
cldfrac_rad(icol,ilay) = cld(icol,ilay);
Expand All @@ -1371,7 +1368,7 @@ static optical_props2_t get_subsampled_clouds(
int overlap = 1;
// Get unique seeds for each column that are reproducible across different MPI rank layouts;
// use decimal part of pressure for this, consistent with the implementation in EAM
auto seeds = pool_t::alloc<int>(ncol);
auto seeds = pool_t::template alloc<int>(ncol);
Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol) {
seeds(icol) = 1e9 * (p_lay(icol,nlay-1) - int(p_lay(icol,nlay-1)));
});
Expand Down Expand Up @@ -1408,7 +1405,7 @@ static optical_props1_t get_subsampled_clouds(
subsampled_optics.alloc_1scl(ncol, nlay);

// Subcolumn mask with values of 0 indicating no cloud, 1 indicating cloud
auto cldmask = pool_t::alloc<int>(ncol, nlay, ngpt);
auto cldmask = pool_t::template alloc<int>(ncol, nlay, ngpt);

// Check that we do not have clouds with no optical properties; this would get corrected
// when we assign optical props, but we want to use a "radiative cloud fraction"
Expand All @@ -1417,7 +1414,7 @@ static optical_props1_t get_subsampled_clouds(
// the vertical correlation of cloudy layers. I.e., cloudy layers might look maximally overlapped
// even when separated by layers with no cloud properties, when in fact those layers should be
// randomly overlapped.
auto cldfrac_rad = pool_t::alloc<RealT>(ncol, nlay);
auto cldfrac_rad = pool_t::template alloc<RealT>(ncol, nlay);
Kokkos::parallel_for(MDRP::template get<3>({nbnd,nlay,ncol}), KOKKOS_LAMBDA (int ibnd, int ilay, int icol) {
if (cloud_optics.tau(icol,ilay,ibnd) > 0) {
cldfrac_rad(icol,ilay) = cld(icol,ilay);
Expand All @@ -1428,7 +1425,7 @@ static optical_props1_t get_subsampled_clouds(
// Get unique seeds for each column that are reproducible across different MPI rank layouts;
// use decimal part of pressure for this, consistent with the implementation in EAM; use different
// seed values for longwave and shortwave
auto seeds = pool_t::alloc<int>(ncol);
auto seeds = pool_t::template alloc<int>(ncol);
Kokkos::parallel_for(ncol, KOKKOS_LAMBDA(int icol) {
seeds(icol) = 1e9 * (p_lay(icol,nlay-2) - int(p_lay(icol,nlay-2)));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ TEST_CASE("rrtmgp_test_subcol_gen_k") {
for (unsigned seed = 0; seed < 10; seed++) {
auto seeds = int1dk("seeds", ncol);
Kokkos::deep_copy(seeds, seed);
cldmask = interface_t::get_subcolumn_mask(ncol, nlay, ngpt, cldfrac, 1, seeds);
interface_t::get_subcolumn_mask(ncol, nlay, ngpt, cldfrac, 1, seeds, cldmask);
// Check answers by computing new cldfrac from mask
Kokkos::deep_copy(cldfrac_from_mask, 0.0);
Kokkos::parallel_for(MDRP::template get<2>({nlay,ncol}), KOKKOS_LAMBDA(int ilay, int icol) {
Expand Down Expand Up @@ -1325,7 +1325,7 @@ TEST_CASE("rrtmgp_test_subcol_gen_k") {
for (unsigned seed = 0; seed < 10; seed++) {
auto seeds = int1dk("seeds", ncol);
Kokkos::deep_copy(seeds, seed);
cldmask = interface_t::get_subcolumn_mask(ncol, nlay, ngpt, cldfrac, 1, seeds);
interface_t::get_subcolumn_mask(ncol, nlay, ngpt, cldfrac, 1, seeds, cldmask);
auto cldmask_h = chc(cldmask);
for (int igpt = 0; igpt < ngpt; igpt++) {
if (cldmask_h(0,0,igpt) == 1) {
Expand Down

0 comments on commit d3d549a

Please sign in to comment.