46 met_t *met0TMP, *met1TMP, *mets;
52 char dirname[
LEN], filename[2 *
LEN];
56 int ntask = -1, rank = 0, size = 1;
64 MPI_Init(&argc, &argv);
65 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
66 MPI_Comm_size(MPI_COMM_WORLD, &size);
72 if (acc_get_num_devices(acc_device_nvidia) <= 0)
73 ERRMSG(
"Not running on a GPU device!");
74 acc_set_device_num(rank % acc_get_num_devices(acc_device_nvidia),
76 acc_device_t device_type = acc_get_device_type();
77 acc_init(device_type);
82 ERRMSG(
"Give parameters: <dirlist> <ctl> <atm_in>");
85 if (!(dirlist = fopen(argv[1],
"r")))
86 ERRMSG(
"Cannot open directory list!");
89 while (fscanf(dirlist,
"%4999s", dirname) != EOF) {
92 if ((++ntask) % size != rank)
95 LOG(1,
"Parallelization: ntask= %d | rank= %d | size= %d | acc_dev= %d",
96 ntask, rank, size, acc_get_device_num(device_type));
98 LOG(1,
"Parallelization: ntask= %d | rank= %d | size= %d | acc_dev= nan",
126#pragma acc enter data create(atm[:1], cache[:1], clim[:1], ctl, ctlTMP, met0[:1], met1[:1], met0TMP[:1], met1TMP[:1], dt[:NP], rs[:3 * NP])
128#pragma acc enter data create(atm[:1], cache[:1], clim[:1], ctl, met0[:1], met1[:1], dt[:NP], rs[:3 * NP])
133 sprintf(filename,
"%s/%s", dirname, argv[2]);
134 read_ctl(filename, argc, argv, &ctl);
140 sprintf(filename,
"%s/%s", dirname, argv[3]);
142 ERRMSG(
"Cannot open file!");
155 if (ctl.
dt_mod > fabs(met0->
lon[1] - met0->
lon[0]) * 111132. / 150.)
156 WARN(
"Violation of CFL criterion! Check DT_MOD!");
174#pragma acc update device(atm[:1], cache[:1], clim[:1], ctl)
184 int ompTrdnum = omp_get_max_threads();
190#pragma omp parallel num_threads(2)
205 if (omp_get_thread_num() == 0) {
220 get_met(&ctl, clim, t, &met0, &met1);
308 ERRMSG(
"Code was compiled without KPP!");
330 omp_set_num_threads(ompTrdnum);
341 omp_set_num_threads(ompTrdnum);
352 LOG(1,
"SIZE_NP = %d", atm->
np);
353 LOG(1,
"SIZE_MPI_TASKS = %d", size);
354 LOG(1,
"SIZE_OMP_THREADS = %d", omp_get_max_threads());
356 LOG(1,
"SIZE_ACC_DEVICES = %d", acc_get_num_devices(acc_device_nvidia));
358 LOG(1,
"SIZE_ACC_DEVICES = %d", 0);
362 LOG(1,
"MEMORY_ATM = %g MByte",
sizeof(
atm_t) / 1024. / 1024.);
363 LOG(1,
"MEMORY_CACHE = %g MByte",
sizeof(
cache_t) / 1024. / 1024.);
364 LOG(1,
"MEMORY_CLIM = %g MByte",
sizeof(
clim_t) / 1024. / 1024.);
365 LOG(1,
"MEMORY_METEO = %g MByte", 2 *
sizeof(
met_t) / 1024. / 1024.);
366 LOG(1,
"MEMORY_DYNAMIC = %g MByte", (3 *
NP *
sizeof(
int)
367 + 4 *
NP *
sizeof(
double)
368 +
EX *
EY *
EP *
sizeof(
float)) /
370 LOG(1,
"MEMORY_STATIC = %g MByte", (
EX *
EY *
EP *
sizeof(
float)) /
377#pragma acc exit data delete (ctl, atm, cache, clim, met0, met1, dt, rs, met0TMP, met1TMP)
379#pragma acc exit data delete (ctl, atm, cache, clim, met0, met1, dt, rs)
void get_met(ctl_t *ctl, clim_t *clim, const double t, met_t **met0, met_t **met1)
Retrieves meteorological data for the specified time.
void module_advect(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Performs the advection of atmospheric particles using meteorological data.
void module_chem_init(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm)
Initializes the chemistry modules by setting atmospheric composition.
void module_convection(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt, double *rs)
Simulate convective processes for atmospheric particles.
void module_diffusion_meso(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, cache_t *cache, const double *dt, double *rs)
Simulate mesoscale diffusion for atmospheric particles.
void module_sedi(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Simulate sedimentation of particles in the atmosphere.
void module_timesteps_init(ctl_t *ctl, const atm_t *atm)
Initialize start time and time interval for time-stepping.
void module_mixing(const ctl_t *ctl, const clim_t *clim, atm_t *atm, const double t)
Update atmospheric properties through interparcel mixing.
void module_oh_chem(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Perform hydroxyl chemistry calculations for atmospheric particles.
void module_chemgrid(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double tt)
Calculate grid data for chemistry modules.
void module_isosurf(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, cache_t *cache, const double *dt)
Apply the isosurface module to adjust atmospheric properties.
void module_timesteps(const ctl_t *ctl, met_t *met0, atm_t *atm, double *dt, const double t)
Calculate time steps for air parcels based on specified conditions.
void module_isosurf_init(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, cache_t *cache)
Initialize the isosurface module based on atmospheric data.
void module_position(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Update the positions and pressure levels of atmospheric particles.
void module_diffusion_turb(const ctl_t *ctl, const clim_t *clim, atm_t *atm, const double *dt, double *rs)
Simulate turbulent diffusion for atmospheric particles.
void module_advect_init(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm)
Initializes the advection module by setting up pressure fields.
void module_decay(const ctl_t *ctl, const clim_t *clim, atm_t *atm, const double *dt)
Simulate exponential decay processes for atmospheric particles.
void module_rng_init(const int ntask)
Initialize random number generators for parallel tasks.
void module_wet_deposition(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Perform wet deposition calculations for air parcels.
void module_h2o2_chem(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Perform chemical reactions involving H2O2 within cloud particles.
void module_meteo(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Update atmospheric properties using meteorological data.
void write_output(const char *dirname, const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double t)
Writes various types of output data to files in a specified directory.
void read_ctl(const char *filename, int argc, char *argv[], ctl_t *ctl)
Reads control parameters from a configuration file and populates the given structure.
void module_bound_cond(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Apply boundary conditions to particles based on meteorological and climatological data.
void module_tracer_chem(const ctl_t *ctl, const clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Simulate chemical reactions involving long-lived atmospheric tracers.
void module_sort(const ctl_t *ctl, met_t *met0, atm_t *atm)
Sort particles according to box index.
int read_atm(const char *filename, const ctl_t *ctl, atm_t *atm)
Reads air parcel data from a specified file into the given atmospheric structure.
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
void module_dry_deposition(const ctl_t *ctl, met_t *met0, met_t *met1, atm_t *atm, const double *dt)
Simulate dry deposition of atmospheric particles.
MPTRAC library declarations.
#define LEN
Maximum length of ASCII data lines.
void module_kpp_chem(ctl_t *ctl, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm, double *dt)
KPP chemistry module.
#define PARTICLE_LOOP(ip0, ip1, check_dt,...)
Loop over particle indices with OpenACC acceleration.
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
#define EY
Maximum number of latitudes for meteo data.
#define EX
Maximum number of longitudes for meteo data.
#define WARN(...)
Print a warning message with contextual information.
#define ALLOC(ptr, type, n)
Allocate memory for a pointer with error handling.
#define START_TIMERS
Starts a timer for tracking.
#define NP
Maximum number of atmospheric data points.
#define SELECT_TIMER(id, group, color)
Select and start a timer with specific attributes.
#define PRINT_TIMERS
Print the current state of all timers.
#define LOG(level,...)
Print a log message with a specified logging level.
#define EP
Maximum number of pressure levels for meteo data.
#define STOP_TIMERS
Stop the current timer.
int np
Number of air parcels.
double q[NQ][NP]
Quantity data (for various, user-defined attributes).
double wet_depo_ic_a
Coefficient A for wet deposition in cloud (exponential form).
int qnt_rhop
Quantity array index for particle density.
double mixing_trop
Interparcel exchange parameter for mixing in the troposphere.
double sort_dt
Time step for sorting of particle data [s].
double wet_depo_bc_a
Coefficient A for wet deposition below cloud (exponential form).
double conv_cape
CAPE threshold for convection module [J/kg].
int direction
Direction flag (1=forward calculation, -1=backward calculation).
double met_dt_out
Time step for sampling of meteo data along trajectories [s].
double turb_dz_trop
Vertical turbulent diffusion coefficient (troposphere) [m^2/s].
double turb_mesoz
Vertical scaling factor for mesoscale wind fluctuations.
int qnt_loss_rate
Quantity array index for total loss rate.
double turb_dx_strat
Horizontal turbulent diffusion coefficient (stratosphere) [m^2/s].
double bound_lat1
Boundary conditions maximum longitude [deg].
double turb_dx_trop
Horizontal turbulent diffusion coefficient (troposphere) [m^2/s].
int isosurf
Isosurface parameter (0=none, 1=pressure, 2=density, 3=theta, 4=balloon).
double bound_p1
Boundary conditions top pressure [hPa].
double turb_mesox
Horizontal scaling factor for mesoscale wind fluctuations.
int qnt_rp
Quantity array index for particle radius.
double mixing_strat
Interparcel exchange parameter for mixing in the stratosphere.
double dt_kpp
Time step for KPP chemistry [s].
double t_stop
Stop time of simulation [s].
double conv_dt
Time interval for convection module [s].
double bound_lat0
Boundary conditions minimum longitude [deg].
int tracer_chem
Switch for first order tracer chemistry module (0=off, 1=on).
double dt_mod
Time step of simulation [s].
int oh_chem_reaction
Reaction type for OH chemistry (0=none, 2=bimolecular, 3=termolecular).
double wet_depo_ic_h[3]
Coefficients for wet deposition in cloud (Henry's law: Hb, Cb, pH).
double tdec_strat
Life time of particles in the stratosphere [s].
int advect
Advection scheme (0=off, 1=Euler, 2=midpoint, 4=Runge-Kutta).
int kpp_chem
Switch for KPP chemistry module (0=off, 1=on).
double wet_depo_bc_h[2]
Coefficients for wet deposition below cloud (Henry's law: Hb, Cb).
double bound_p0
Boundary conditions bottom pressure [hPa].
int h2o2_chem_reaction
Reaction type for H2O2 chemistry (0=none, 1=SO2).
double dry_depo_vdep
Dry deposition velocity [m/s].
double mixing_dt
Time interval for mixing [s].
double turb_dz_strat
Vertical turbulent diffusion coefficient (stratosphere) [m^2/s].
double t_start
Start time of simulation [s].
double tdec_trop
Life time of particles in the troposphere [s].
double lon[EX]
Longitude [deg].
int main(int argc, char *argv[])