Skip to content

Commit 7baa889

Browse files
authored
Output better timing information with each step (#1714)
1 parent 5caa9b1 commit 7baa889

File tree

4 files changed

+43
-15
lines changed

4 files changed

+43
-15
lines changed

amr-wind/core/SimTime.H

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ public:
177177
m_stop_time = -1.;
178178
}
179179

180+
/** Return true if TinyProfiler output should be sent to the log file at
181+
* this timestep
182+
*/
183+
bool output_profiling_info() const;
184+
180185
private:
181186
//! Timestep sizes
182187
amrex::Vector<amrex::Real> m_dt =
@@ -287,6 +292,9 @@ private:
287292
//! Time interval for regridding
288293
int m_regrid_interval{-1};
289294

295+
//! Time step interval for profiling output
296+
int m_profiling_interval{-1};
297+
290298
//! Verbosity
291299
int m_verbose{0};
292300

amr-wind/core/SimTime.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void SimTime::parse_parameters()
3939
pp.query("plot_start", m_plt_start_index);
4040
pp.query("checkpoint_start", m_chkpt_start_index);
4141
pp.query("use_force_cfl", m_use_force_cfl);
42+
pp.query("profiling_interval", m_profiling_interval);
4243

4344
// Tolerances
4445
pp.query("plot_time_interval_reltol", m_plt_t_tol);
@@ -418,4 +419,11 @@ void SimTime::calculate_minimum_enforce_dt_abs_tol()
418419
}
419420
}
420421

422+
bool SimTime::output_profiling_info() const
423+
{
424+
return (
425+
(m_profiling_interval > 0) &&
426+
(m_time_index % m_profiling_interval == 0));
427+
}
428+
421429
} // namespace amr_wind

amr-wind/incflo.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ incflo::incflo()
2323
// constructor. No valid BoxArray and DistributionMapping have been defined.
2424
// But the arrays for them have been resized.
2525

26-
amrex::Print() << std::endl
27-
<< "Initializing AMR-Wind." << std::endl
28-
<< std::endl;
29-
3026
// Check if dry run is requested and set up if so
3127
CheckAndSetUpDryRun();
3228

@@ -287,8 +283,10 @@ void incflo::Evolve()
287283
{
288284
BL_PROFILE("amr-wind::incflo::Evolve()");
289285

286+
const amrex::Real init_time = amrex::ParallelDescriptor::second();
287+
290288
while (m_time.new_timestep()) {
291-
amrex::Real time0 = amrex::ParallelDescriptor::second();
289+
const amrex::Real time0 = amrex::ParallelDescriptor::second();
292290

293291
regrid_and_update();
294292

@@ -302,7 +300,7 @@ void incflo::Evolve()
302300
pre_advance_stage2();
303301
}
304302

305-
amrex::Real time1 = amrex::ParallelDescriptor::second();
303+
const amrex::Real time1 = amrex::ParallelDescriptor::second();
306304
// Advance to time t + dt
307305
for (int fixed_point_iteration = 0;
308306
fixed_point_iteration < m_fixed_point_iterations;
@@ -311,22 +309,27 @@ void incflo::Evolve()
311309
}
312310

313311
amrex::Print() << std::endl;
314-
amrex::Real time2 = amrex::ParallelDescriptor::second();
312+
const amrex::Real time2 = amrex::ParallelDescriptor::second();
315313
post_advance_work();
316-
amrex::Real time3 = amrex::ParallelDescriptor::second();
314+
const amrex::Real time3 = amrex::ParallelDescriptor::second();
317315

318-
amrex::Print() << "WallClockTime: " << m_time.time_index()
319-
<< " Pre: " << std::setprecision(3) << (time1 - time0)
316+
amrex::Print() << "WallClockTime in Evolve() for step "
317+
<< m_time.time_index()
318+
<< ": Pre: " << std::setprecision(3) << (time1 - time0)
320319
<< " Solve: " << std::setprecision(4) << (time2 - time1)
321320
<< " Post: " << std::setprecision(3) << (time3 - time2)
322321
<< " Total: " << std::setprecision(4) << (time3 - time0)
323322
<< std::endl;
324-
325-
amrex::Print() << "Solve time per cell: " << std::setprecision(4)
326-
<< amrex::ParallelDescriptor::NProcs() *
327-
(time2 - time1) /
328-
static_cast<amrex::Real>(m_cell_count)
323+
amrex::Print() << "Cumulative WallClockTime in Evolve(): "
324+
<< std::setprecision(4) << (time3 - init_time)
329325
<< std::endl;
326+
327+
#ifdef AMREX_TINY_PROFILING
328+
if (m_time.output_profiling_info()) {
329+
amrex::Print() << "\nCumulative times reported by TinyProfiler:";
330+
amrex::TinyProfiler::Finalize(true);
331+
}
332+
#endif
330333
}
331334
amrex::Print() << "\n======================================================"
332335
"========================\n"

docs/sphinx/user/inputs_time.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,12 @@ This section also addresses the time-dependent nature of checkpoint files, plot
263263
When :input_param:`time.enforce_checkpoint_time_dt` is true, a tolerance is needed to determine when
264264
it is necessary to shrink the time step size. This tolerance is relative to the checkpoint time interval.
265265
In most cases, this parameter need not be modified, but it can be changed by the user.
266+
267+
.. input_param:: time.profiling_interval
268+
269+
**type:** Integer, optional, default = -1
270+
271+
If this value is greater than zero, it indicates the frequency (in
272+
timesteps) at which profiling information is written to the log
273+
file. This will only work if the code was compiled with
274+
``AMR_WIND_ENABLE_TINY_PROFILE`` set to ``ON``.

0 commit comments

Comments
 (0)