MPTRAC
Functions
trac.c File Reference

Lagrangian particle dispersion model. More...

#include "mptrac.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

Lagrangian particle dispersion model.

Definition in file trac.c.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 31 of file trac.c.

33 {
34
35 ctl_t *ctl;
36
37 atm_t *atm;
38
39 cache_t *cache;
40
41 clim_t *clim;
42
43 met_t *met0, *met1;
44
45 FILE *dirlist;
46
47 char dirname[LEN], filename[2 * LEN];
48
49 int ntask = -1, rank = 0, size = 1;
50
51 /* Start timers... */
53
54 /* Initialize MPI... */
55#ifdef MPI
56 SELECT_TIMER("MPI_INIT", "INIT", NVTX_CPU);
57 MPI_Init(&argc, &argv);
58 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
59 MPI_Comm_size(MPI_COMM_WORLD, &size);
60#endif
61
62 /* Check arguments... */
63 if (argc < 4)
64 ERRMSG("Give parameters: <dirlist> <ctl> <atm_in>");
65
66 /* Open directory list... */
67 if (!(dirlist = fopen(argv[1], "r")))
68 ERRMSG("Cannot open directory list!");
69
70 /* Loop over directories... */
71 while (fscanf(dirlist, "%4999s", dirname) != EOF) {
72
73 /* MPI parallelization... */
74 if ((++ntask) % size != rank)
75 continue;
76
77 /* ------------------------------------------------------------
78 Initialize model run...
79 ------------------------------------------------------------ */
80
81 /* Allocate memory... */
82 mptrac_alloc(&ctl, &cache, &clim, &met0, &met1, &atm);
83
84 /* Write info... */
85#ifdef _OPENACC
86 acc_device_t device_type = acc_get_device_type();
87 LOG(1, "Parallelization: ntask= %d | rank= %d | size= %d | acc_dev= %d",
88 ntask, rank, size, acc_get_device_num(device_type));
89#else
90 LOG(1, "Parallelization: ntask= %d | rank= %d | size= %d | acc_dev= nan",
91 ntask, rank, size);
92#endif
93
94 /* Read control parameters... */
95 sprintf(filename, "%s/%s", dirname, argv[2]);
96 read_ctl(filename, argc, argv, ctl);
97
98 /* Read climatological data... */
99 read_clim(ctl, clim);
100
101 /* Read atmospheric data... */
102 sprintf(filename, "%s/%s", dirname, argv[3]);
103 if (!read_atm(filename, ctl, atm))
104 ERRMSG("Cannot open file!");
105
106 /* Initialize timesteps... */
107 module_timesteps_init(ctl, atm);
108
109 /* Initialize random number generator... */
110 module_rng_init(ntask);
111
112 /* Initialize meteo data... */
113 get_met(ctl, clim, ctl->t_start, &met0, &met1);
114
115 /* Check time step... */
116 if (ctl->dt_mod > fabs(met0->lon[1] - met0->lon[0]) * 111132. / 150.)
117 WARN("Violation of CFL criterion! Check DT_MOD!");
118
119 /* Initialize isosurface data... */
120 if (ctl->isosurf >= 1 && ctl->isosurf <= 4)
121 module_isosurf_init(ctl, cache, met0, met1, atm);
122
123 /* Initialize advection... */
124 module_advect_init(ctl, met0, met1, atm);
125
126 /* Initialize chemistry... */
127 module_chem_init(ctl, clim, met0, met1, atm);
128
129 /* Update GPU... */
130#ifdef _OPENACC
131 SELECT_TIMER("UPDATE_DEVICE", "MEMORY", NVTX_H2D);
132#pragma acc update device(atm[:1], cache[:1], clim[:1], ctl[:1])
133#endif
134
135 /* ------------------------------------------------------------
136 Loop over timesteps...
137 ------------------------------------------------------------ */
138
139 /* Loop over timesteps... */
140 for (double t = ctl->t_start;
141 ctl->direction * (t - ctl->t_stop) < ctl->dt_mod;
142 t += ctl->direction * ctl->dt_mod) {
143
144 /* Adjust length of final time step... */
145 if (ctl->direction * (t - ctl->t_stop) > 0)
146 t = ctl->t_stop;
147
148 /* Run a single time step... */
149 mptrac_run_timestep(ctl, cache, clim, &met0, &met1, atm, t);
150
151 /* Write output... */
152 write_output(dirname, ctl, met0, met1, atm, t);
153 }
154
155 /* ------------------------------------------------------------
156 Finalize model run...
157 ------------------------------------------------------------ */
158
159 /* Flush output buffer... */
160 fflush(NULL);
161
162 /* Report problem size... */
163 LOG(1, "SIZE_NP = %d", atm->np);
164 LOG(1, "SIZE_MPI_TASKS = %d", size);
165 LOG(1, "SIZE_OMP_THREADS = %d", omp_get_max_threads());
166#ifdef _OPENACC
167 LOG(1, "SIZE_ACC_DEVICES = %d", acc_get_num_devices(acc_device_nvidia));
168#else
169 LOG(1, "SIZE_ACC_DEVICES = %d", 0);
170#endif
171
172 /* Report memory usage... */
173 LOG(1, "MEMORY_ATM = %g MByte", sizeof(atm_t) / 1024. / 1024.);
174 LOG(1, "MEMORY_CACHE = %g MByte", sizeof(cache_t) / 1024. / 1024.);
175 LOG(1, "MEMORY_CLIM = %g MByte", sizeof(clim_t) / 1024. / 1024.);
176 LOG(1, "MEMORY_METEO = %g MByte", sizeof(met_t) / 1024. / 1024.);
177
178 /* Free memory... */
179 mptrac_free(ctl, cache, clim, met0, met1, atm);
180 }
181
182 /* Report timers... */
184
185 /* Finalize MPI... */
186#ifdef MPI
187 MPI_Finalize();
188#endif
189
190 /* Stop timers... */
192
193 return EXIT_SUCCESS;
194}
void mptrac_alloc(ctl_t **ctl, cache_t **cache, clim_t **clim, met_t **met0, met_t **met1, atm_t **atm)
Allocates and initializes memory resources for MPTRAC.
Definition: mptrac.c:4320
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.
Definition: mptrac.c:1003
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.
Definition: mptrac.c:2639
void module_timesteps_init(ctl_t *ctl, const atm_t *atm)
Initialize start time and time interval for time-stepping.
Definition: mptrac.c:4084
void module_isosurf_init(const ctl_t *ctl, cache_t *cache, met_t *met0, met_t *met1, atm_t *atm)
Initialize the isosurface module based on atmospheric data.
Definition: mptrac.c:3192
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.
Definition: mptrac.c:2370
void module_rng_init(const int ntask)
Initialize random number generators for parallel tasks.
Definition: mptrac.c:3787
void mptrac_free(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t *met0, met_t *met1, atm_t *atm)
Frees memory resources allocated for MPTRAC.
Definition: mptrac.c:4367
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.
Definition: mptrac.c:10578
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.
Definition: mptrac.c:5156
void mptrac_run_timestep(ctl_t *ctl, cache_t *cache, clim_t *clim, met_t **met0, met_t **met1, atm_t *atm, double t)
Executes a single timestep of the MPTRAC model simulation.
Definition: mptrac.c:4393
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.
Definition: mptrac.c:4566
void read_clim(const ctl_t *ctl, clim_t *clim)
Reads various climatological data and populates the given climatology structure.
Definition: mptrac.c:4824
#define LEN
Maximum length of ASCII data lines.
Definition: mptrac.h:241
#define ERRMSG(...)
Print an error message with contextual information and terminate the program.
Definition: mptrac.h:1916
#define WARN(...)
Print a warning message with contextual information.
Definition: mptrac.h:1883
#define START_TIMERS
Starts a timer for tracking.
Definition: mptrac.h:2015
#define SELECT_TIMER(id, group, color)
Select and start a timer with specific attributes.
Definition: mptrac.h:1996
#define PRINT_TIMERS
Print the current state of all timers.
Definition: mptrac.h:1975
#define LOG(level,...)
Print a log message with a specified logging level.
Definition: mptrac.h:1846
#define STOP_TIMERS
Stop the current timer.
Definition: mptrac.h:2030
Air parcel data.
Definition: mptrac.h:3147
int np
Number of air parcels.
Definition: mptrac.h:3150
Cache data structure.
Definition: mptrac.h:3175
Climatological data.
Definition: mptrac.h:3315
Control parameters.
Definition: mptrac.h:2170
int direction
Direction flag (1=forward calculation, -1=backward calculation).
Definition: mptrac.h:2465
int isosurf
Isosurface parameter (0=none, 1=pressure, 2=density, 3=theta, 4=balloon).
Definition: mptrac.h:2645
double t_stop
Stop time of simulation [s].
Definition: mptrac.h:2471
double dt_mod
Time step of simulation [s].
Definition: mptrac.h:2474
double t_start
Start time of simulation [s].
Definition: mptrac.h:2468
Meteo data structure.
Definition: mptrac.h:3374
double lon[EX]
Longitude [deg].
Definition: mptrac.h:3392
Here is the call graph for this function: