Skip to content

Commit

Permalink
Fix bounds error that caused memory access issue; likely the reason f…
Browse files Browse the repository at this point in the history
…or the debug prints of daynight indices. (#1584)
  • Loading branch information
AMLattanzi authored Apr 19, 2024
1 parent bac6f06 commit 5c816e6
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions Source/Radiation/Radiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ using yakl::fortran::SimpleBounds;
namespace internal {
void initial_fluxes (int nz, int nlay, int nbands, FluxesByband& fluxes)
{
fluxes.flux_up = real2d("flux_up", nz, nlay+1);
fluxes.flux_dn = real2d("flux_dn", nz, nlay+1);
fluxes.flux_net = real2d("flux_net", nz, nlay+1);
fluxes.flux_up = real2d("flux_up" , nz, nlay+1);
fluxes.flux_dn = real2d("flux_dn" , nz, nlay+1);
fluxes.flux_net = real2d("flux_net" , nz, nlay+1);
fluxes.flux_dn_dir = real2d("flux_dn_dir", nz, nlay+1);
fluxes.bnd_flux_up = real3d("flux_up", nz, nlay+1, nbands);
fluxes.bnd_flux_dn = real3d("flux_dn", nz, nlay+1, nbands);
fluxes.bnd_flux_net = real3d("flux_net", nz, nlay+1, nbands);

fluxes.bnd_flux_up = real3d("flux_up" , nz, nlay+1, nbands);
fluxes.bnd_flux_dn = real3d("flux_dn" , nz, nlay+1, nbands);
fluxes.bnd_flux_net = real3d("flux_net" , nz, nlay+1, nbands);
fluxes.bnd_flux_dn_dir = real3d("flux_dn_dir", nz, nlay+1, nbands);
}

Expand All @@ -54,8 +55,7 @@ namespace internal {
auto nlev = size(daytime_fluxes.bnd_flux_up, 2);
auto nbnds = size(daytime_fluxes.bnd_flux_up, 3);

int1d nday_1d("nday_1d", 1),
nday_host("nday_host",1);
int1d nday_1d("nday_1d", 1),nday_host("nday_host",1);
yakl::memset(nday_1d, 0);
parallel_for(SimpleBounds<1>(ncol), YAKL_LAMBDA (int icol)
{
Expand All @@ -71,15 +71,15 @@ namespace internal {
// auto icol = day_indices(iday);
auto icol = iday;
// Expand broadband fluxes
expanded_fluxes.flux_up(icol,ilev) = daytime_fluxes.flux_up(iday,ilev);
expanded_fluxes.flux_dn(icol,ilev) = daytime_fluxes.flux_dn(iday,ilev);
expanded_fluxes.flux_net(icol,ilev) = daytime_fluxes.flux_net(iday,ilev);
expanded_fluxes.flux_up(icol,ilev) = daytime_fluxes.flux_up(iday,ilev);
expanded_fluxes.flux_dn(icol,ilev) = daytime_fluxes.flux_dn(iday,ilev);
expanded_fluxes.flux_net(icol,ilev) = daytime_fluxes.flux_net(iday,ilev);
expanded_fluxes.flux_dn_dir(icol,ilev) = daytime_fluxes.flux_dn_dir(iday,ilev);

// Expand band-by-band fluxes
expanded_fluxes.bnd_flux_up(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_up(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_dn(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_dn(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_net(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_net(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_up(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_up(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_dn(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_dn(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_net(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_net(iday,ilev,ibnd);
expanded_fluxes.bnd_flux_dn_dir(icol,ilev,ibnd) = daytime_fluxes.bnd_flux_dn_dir(iday,ilev,ibnd);
});
}
Expand Down Expand Up @@ -309,8 +309,8 @@ void Radiation::run ()
if (do_short_wave_rad) {
// Radiative fluxes
FluxesByband fluxes_allsky, fluxes_clrsky;
internal::initial_fluxes(ncol, nlev, nlwbands, fluxes_allsky);
internal::initial_fluxes(ncol, nlev, nlwbands, fluxes_clrsky);
internal::initial_fluxes(ncol, nlev+1, nswbands, fluxes_allsky);
internal::initial_fluxes(ncol, nlev+1, nswbands, fluxes_clrsky);

// Get cosine solar zenith angle for current time step. ( still NOT YET implemented here)
// set_cosine_solar_zenith_angle(state, dt_avg, coszrs(1:ncol))
Expand Down

0 comments on commit 5c816e6

Please sign in to comment.