Skip to content

Commit

Permalink
Fix of performance issue in module_chemgrid().
Browse files Browse the repository at this point in the history
  • Loading branch information
lars2015 committed Sep 7, 2024
1 parent 8cc6759 commit 3b6a0e2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/mptrac.c
Original file line number Diff line number Diff line change
Expand Up @@ -2455,7 +2455,7 @@ void module_chemgrid(
double *restrict const press =
(double *) malloc((size_t) nz * sizeof(double));
double *restrict const mass =
(double *) malloc((size_t) ngrid * sizeof(double));
(double *) calloc((size_t) ngrid, sizeof(double));
double *restrict const area =
(double *) malloc((size_t) ny * sizeof(double));
double *restrict const lon =
Expand All @@ -2472,10 +2472,6 @@ void module_chemgrid(
const double dlon = (ctl->chemgrid_lon1 - ctl->chemgrid_lon0) / nx;
const double dlat = (ctl->chemgrid_lat1 - ctl->chemgrid_lat0) / ny;

/* Initialize mass... */// TODO: does not work on GPU?
for (int i = 0; i < ngrid; i++)
mass[i] = 0;

/* Set vertical coordinates... */
#ifdef _OPENACC
#pragma acc enter data create(ixs[0:np],iys[0:np],izs[0:np],z[0:nz],press[0:nz],mass[0:ngrid],area[0:ny],lon[0:nx],lat[0:ny])
Expand Down Expand Up @@ -2505,8 +2501,7 @@ void module_chemgrid(
izs[ip] = (int) ((Z(atm->p[ip]) - ctl->chemgrid_z0) / dz);
if (atm->time[ip] < t0 || atm->time[ip] > t1
|| ixs[ip] < 0 || ixs[ip] >= nx
|| iys[ip] < 0 || iys[ip] >= ny
|| izs[ip] < 0 || izs[ip] >= nz)
|| iys[ip] < 0 || iys[ip] >= ny || izs[ip] < 0 || izs[ip] >= nz)
izs[ip] = -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/trac.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ int main(
if (ctl.oh_chem_reaction != 0 || ctl.h2o2_chem_reaction != 0
|| (ctl.kpp_chem && fmod(t, ctl.dt_kpp) == 0))
module_chemgrid(&ctl, met0, met1, atm, t);

/* OH chemistry... */
if (ctl.oh_chem_reaction != 0)
module_oh_chem(&ctl, clim, met0, met1, atm, dt);
Expand Down

0 comments on commit 3b6a0e2

Please sign in to comment.