From 869910c1372547c34d365669fe6ce3e3b2d7bf27 Mon Sep 17 00:00:00 2001 From: Luca Bertagna Date: Thu, 9 May 2024 18:17:53 -0600 Subject: [PATCH] EAMxx: only init timestep in IO if this will be an output step --- .../eamxx/src/control/atmosphere_driver.cpp | 2 +- .../src/share/io/scream_output_manager.cpp | 19 +++++++++++++------ .../src/share/io/scream_output_manager.hpp | 2 +- .../eamxx/src/share/io/tests/io_diags.cpp | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/components/eamxx/src/control/atmosphere_driver.cpp b/components/eamxx/src/control/atmosphere_driver.cpp index 875f9878764..fc7ae4f8bce 100644 --- a/components/eamxx/src/control/atmosphere_driver.cpp +++ b/components/eamxx/src/control/atmosphere_driver.cpp @@ -1604,7 +1604,7 @@ void AtmosphereDriver::run (const int dt) { // the timestamp at the beginning of the timestep, so that we can compute // dt at the end. for (auto it : m_output_managers) { - it.init_timestep(m_current_ts); + it.init_timestep(m_current_ts,dt); } // The class AtmosphereProcessGroup will take care of dispatching arguments to diff --git a/components/eamxx/src/share/io/scream_output_manager.cpp b/components/eamxx/src/share/io/scream_output_manager.cpp index af5b67b12f6..7a96ddb8ae6 100644 --- a/components/eamxx/src/share/io/scream_output_manager.cpp +++ b/components/eamxx/src/share/io/scream_output_manager.cpp @@ -267,7 +267,7 @@ setup (const ekat::Comm& io_comm, const ekat::ParameterList& params, m_output_control.next_write_ts = m_run_t0; // This is in case some diags need to init the timestep. Most likely, their output // is meaningless at t0, but they may still require the start-of-step timestamp to be valid - init_timestep(m_run_t0); + init_timestep(m_run_t0,0); this->run(m_run_t0); } @@ -285,13 +285,24 @@ add_global (const std::string& name, const ekat::any& global) { } /*===============================================================================================*/ -void OutputManager::init_timestep (const util::TimeStamp& start_of_step) +void OutputManager::init_timestep (const util::TimeStamp& start_of_step, const Real dt) { // In case output is disabled, no point in doing anything else if (not m_output_control.output_enabled()) { return; } + // Update counters + ++m_output_control.nsamples_since_last_write; + ++m_checkpoint_control.nsamples_since_last_write; + + // Check if the end of this timestep will correspond to an output step. If not, there's nothing to do + const auto& end_of_step = start_of_step+dt; + const bool will_be_output_step = m_output_control.is_write_step(end_of_step) || end_of_step==m_case_t0; + if (not will_be_output_step) { + return; + } + if (m_atm_logger) { m_atm_logger->debug("[OutputManager::init_timestep] filename_prefix: " + m_filename_prefix + "\n"); } @@ -317,10 +328,6 @@ void OutputManager::run(const util::TimeStamp& timestamp) std::string timer_root = m_is_model_restart_output ? "EAMxx::IO::restart" : "EAMxx::IO::standard"; start_timer(timer_root); - // Check if we need to open a new file - ++m_output_control.nsamples_since_last_write; - ++m_checkpoint_control.nsamples_since_last_write; - // Check if this is a write step (and what kind) // Note: a full checkpoint not only writes globals in the restart file, but also all the history variables. // Since we *always* write a history restart file, we can have a non-full checkpoint, if the average diff --git a/components/eamxx/src/share/io/scream_output_manager.hpp b/components/eamxx/src/share/io/scream_output_manager.hpp index df54f614970..e1f58d93fed 100644 --- a/components/eamxx/src/share/io/scream_output_manager.hpp +++ b/components/eamxx/src/share/io/scream_output_manager.hpp @@ -113,7 +113,7 @@ class OutputManager } void add_global (const std::string& name, const ekat::any& global); - void init_timestep (const util::TimeStamp& start_of_step); + void init_timestep (const util::TimeStamp& start_of_step, const Real dt); void run (const util::TimeStamp& current_ts); void finalize(); diff --git a/components/eamxx/src/share/io/tests/io_diags.cpp b/components/eamxx/src/share/io/tests/io_diags.cpp index b9477413a21..3b67e9419d5 100644 --- a/components/eamxx/src/share/io/tests/io_diags.cpp +++ b/components/eamxx/src/share/io/tests/io_diags.cpp @@ -207,7 +207,7 @@ void write (const int seed, const ekat::Comm& comm) f.get_header().get_tracking().update_time_stamp(t0+dt); f.update(one,1.0,1.0); } - om.init_timestep(t0); + om.init_timestep(t0,dt); om.run (t0+dt); // Close file and cleanup