Skip to content

Commit 8b8b2c7

Browse files
committed
FEAT: start timing at end of initialization
1 parent f10b2f8 commit 8b8b2c7

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed

include/times.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class Times {
8282
**/
8383
double get_current();
8484

85+
/**************************************************************
86+
\brief Sets the start time at the start of the time loop
87+
**/
88+
void set_start_time_loop();
89+
8590
/**************************************************************
8691
\brief Returns the end time in seconds since ref date
8792
**/
@@ -237,6 +242,9 @@ class Times {
237242
/// This is the system time at the start of the simulation
238243
time_t sys_time_start;
239244

245+
/// This is the system time at the start of time loop
246+
time_t sys_time_start_time_loop;
247+
240248
/// This is the current system time of the simulation
241249
time_t sys_time_current;
242250

src/main/main.cpp

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,70 @@ int main() {
2424
try {
2525
// Create inputs (reading the input file):
2626
input = Inputs(time);
27+
2728
if (!input.is_ok())
2829
throw std::string("input initialization failed!");
2930

3031
if (input.get_is_student())
3132
report.print(-1, "Hello " +
32-
input.get_student_name() + " - welcome to Aether!");
33+
input.get_student_name() + " - welcome to Aether!");
3334

3435
Quadtree quadtree;
36+
3537
if (!quadtree.is_ok())
3638
throw std::string("quadtree initialization failed!");
37-
39+
3840
// Initialize MPI and parallel aspects of the code:
3941
didWork = init_parallel(quadtree);
42+
4043
if (!didWork)
4144
throw std::string("init_parallel failed!");
4245

4346
// Everything should be set for the inputs now, so write a restart file:
4447
didWork = input.write_restart();
48+
4549
if (!didWork)
4650
throw std::string("input.write_restart failed!");
4751

4852
// Initialize the EUV system:
4953
Euv euv;
54+
5055
if (!euv.is_ok())
5156
throw std::string("EUV initialization failed!");
5257

5358
// Initialize the planet:
5459
Planets planet;
5560
MPI_Barrier(aether_comm);
61+
5662
if (!planet.is_ok())
5763
throw std::string("planet initialization failed!");
5864

5965
// Initialize the indices, read the files, and perturb:
6066
Indices indices;
6167
didWork = read_and_store_indices(indices);
6268
MPI_Barrier(aether_comm);
69+
6370
if (!didWork)
6471
throw std::string("read_and_store_indices failed!");
65-
72+
6673
// Perturb the inputs if user has asked for this
6774
indices.perturb();
6875
MPI_Barrier(aether_comm);
69-
76+
7077
// Initialize Geographic grid:
7178
Grid gGrid(input.get_nLonsGeo(),
72-
input.get_nLatsGeo(),
73-
input.get_nAltsGeo(),
74-
nGeoGhosts);
79+
input.get_nLatsGeo(),
80+
input.get_nAltsGeo(),
81+
nGeoGhosts);
7582
didWork = gGrid.init_geo_grid(quadtree, planet);
7683
MPI_Barrier(aether_comm);
84+
7785
if (!didWork)
78-
throw std::string("init_geo_grid failed!");
86+
throw std::string("init_geo_grid failed!");
7987

8088
// Find interpolation coefs for the ghostcells if cubesphere grid
8189
didWork = find_ghostcell_interpolation_coefs(gGrid);
8290

83-
8491
// Calculate centripetal acceleration, since this is a constant
8592
// vector on the grid:
8693
if (input.get_cent_acc())
@@ -100,7 +107,7 @@ int main() {
100107
// Is simply adds nans and infinities in a few places, then
101108
// checks for them to make sure the checking is working
102109
// -----------------------------------------------------------------
103-
110+
104111
if (input.get_nan_test()) {
105112
neutrals.nan_test(input.get_nan_test_variable());
106113
ions.nan_test(input.get_nan_test_variable());
@@ -128,22 +135,25 @@ int main() {
128135
// Initialize electrodynamics and check if electrodynamics times
129136
// works with input time
130137
Electrodynamics electrodynamics(time);
138+
131139
if (!electrodynamics.is_ok())
132140
throw std::string("electrodynamics initialization failed!");
133141

134142
// If the user wants to restart, then get the time of the restart
135143
if (input.get_do_restart()) {
136144
report.print(1, "Restarting! Reading time file!");
137145
didWork = time.restart_file(input.get_restartin_dir(), DoRead);
146+
138147
if (!didWork)
139-
throw std::string("Reading Restart for time Failed!!!\n");
148+
throw std::string("Reading Restart for time Failed!!!\n");
140149
}
141150

142151
// This is for the initial output. If it is not a restart, this will go:
143152
if (time.check_time_gate(input.get_dt_output(0)))
144153
didWork = output(neutrals, ions, gGrid, time, planet);
154+
145155
if (!didWork)
146-
throw std::string("output failed!");
156+
throw std::string("output failed!");
147157

148158
// This is advancing now... We are not coupling, so set dt_couple to the
149159
// end of the simulation
@@ -158,26 +168,30 @@ int main() {
158168
// be made into a library and run externally.
159169

160170
Logfile logfile(indices);
171+
172+
time.set_start_time_loop();
173+
161174
while (time.get_current() < time.get_end()) {
162175

163176
time.increment_intermediate(dt_couple);
164177

165178
// Increment until the intermediate time:
166179
while (time.get_current() < time.get_intermediate()) {
167-
didWork = advance(planet,
168-
gGrid,
169-
time,
170-
euv,
171-
neutrals,
172-
ions,
173-
chemistry,
174-
electrodynamics,
175-
indices,
176-
logfile);
177-
if (!didWork)
178-
throw std::string("Error in advance!");
180+
didWork = advance(planet,
181+
gGrid,
182+
time,
183+
euv,
184+
neutrals,
185+
ions,
186+
chemistry,
187+
electrodynamics,
188+
indices,
189+
logfile);
190+
191+
if (!didWork)
192+
throw std::string("Error in advance!");
179193
}
180-
194+
181195
// Should write out some restart files every time we are done with
182196
// intermediate times. Just so when we restart, we know that we can
183197
// couple first thing and everything should be good. (Not sure if
@@ -189,19 +203,22 @@ int main() {
189203
// wrote out restart files, so we only need to do this if we
190204
// didn't just do it. So, check the negative here:
191205
if (!time.check_time_gate(input.get_dt_write_restarts())) {
192-
report.print(3, "Writing restart files");
206+
report.print(3, "Writing restart files");
193207

194-
didWork = neutrals.restart_file(input.get_restartout_dir(), DoWrite);
195-
if (!didWork)
196-
throw std::string("Writing Restart for Neutrals Failed!!!\n");
208+
didWork = neutrals.restart_file(input.get_restartout_dir(), DoWrite);
197209

198-
didWork = ions.restart_file(input.get_restartout_dir(), DoWrite);
199-
if (!didWork)
200-
throw std::string("Writing Restart for Ions Failed!!!\n");
210+
if (!didWork)
211+
throw std::string("Writing Restart for Neutrals Failed!!!\n");
201212

202-
didWork = time.restart_file(input.get_restartout_dir(), DoWrite);
203-
if (!didWork)
204-
throw std::string("Writing Restart for time Failed!!!\n");
213+
didWork = ions.restart_file(input.get_restartout_dir(), DoWrite);
214+
215+
if (!didWork)
216+
throw std::string("Writing Restart for Ions Failed!!!\n");
217+
218+
didWork = time.restart_file(input.get_restartout_dir(), DoWrite);
219+
220+
if (!didWork)
221+
throw std::string("Writing Restart for time Failed!!!\n");
205222
}
206223

207224
// Do some coupling here. But we have no coupling to do. Sad.
@@ -213,13 +230,14 @@ int main() {
213230

214231
} catch (std::string error) {
215232
report.report_errors();
233+
216234
if (iProc == 0) {
217235
std::cout << error << "\n";
218236
std::cout << "---- Must Exit! ----\n";
219237
}
220238
}
221239

222-
240+
223241
// End parallel tasks:
224242
iErr = MPI_Finalize();
225243

src/time.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Times::Times() {
3030
time(&sys_time_start);
3131
}
3232

33+
// -----------------------------------------------------------------------------
34+
// This sets the end of the initialization time
35+
// -----------------------------------------------------------------------------
36+
37+
void Times::set_start_time_loop() {
38+
time(&sys_time_start_time_loop);
39+
}
40+
3341
// -----------------------------------------------------------------------------
3442
// This is for restarting the code. Either write or read the time.
3543
// -----------------------------------------------------------------------------
@@ -279,7 +287,7 @@ void Times::display() {
279287
time(&sys_time_current);
280288
walltime =
281289
static_cast<double>(sys_time_current) -
282-
static_cast<double>(sys_time_start);
290+
static_cast<double>(sys_time_start_time_loop);
283291

284292
double elapsed_simulation_time = current - restart;
285293
double total_simulation_time = end - restart;

0 commit comments

Comments
 (0)