PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
output_checkpoint.cc
Go to the documentation of this file.
1/* Copyright (C) 2017, 2019, 2022, 2023, 2024, 2025, 2026 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "pism/icemodel/IceModel.hh"
21
22#include "pism/util/pism_utilities.hh"
23#include "pism/util/Profiling.hh"
24#include "pism/util/io/io_helpers.hh"
25
26namespace pism {
27
28//! Initialize checkpointing (snapshot-on-wallclock-time) mechanism.
50
51//! Write a checkpoint (i.e. an intermediate result of a run).
52/*!
53 * Returns `true` if PISM has to stop, `false` otherwise.
54 */
56
57 double checkpoint_interval = m_config->get_number("output.checkpoint.interval");
58
60
61 if (wall_clock_hours - m_last_checkpoint_time < checkpoint_interval) {
62 return false;
63 }
64
65 const Profiling &profiling = m_ctx->profiling();
66
68
69 // create a history string:
70
71 m_log->message(2,
72 " [%s] Saving a checkpoint to '%s' (%1.3f hours after the beginning of the run)\n",
74
75 double checkpoint_start_time = get_time(m_grid->com);
76 profiling.begin("io.checkpoint");
77 {
79 // Ensure that the checkpoint file is closed to force PISM to open a new file every
80 // time we write a checkpoint, moving the old file aside if it exists.
81 file.close();
82
83 {
84 // define time dimension *without* time bounds
85 define_time(file);
87 }
88
89 {
90 io::write_config(*m_config, "pism_config", file);
91 file.append_time(m_time->current());
92 write_state(file);
95 write_run_stats(file);
96 }
97 }
98 profiling.end("io.checkpoint");
99 double checkpoint_end_time = get_time(m_grid->com);
100
101 // Also flush time-series:
103
104 m_log->message(2,
105 " [%s] Done saving a checkpoint in %f seconds (%f minutes).\n",
106 timestamp(m_grid->com).c_str(),
107 checkpoint_end_time - checkpoint_start_time,
108 (checkpoint_end_time - checkpoint_start_time) / 60.0);
109
110 return m_config->get_flag("output.checkpoint.exit");
111}
112
113} // end of namespace pism
double m_start_time
Definition IceModel.hh:524
void init_checkpoints()
Initialize checkpointing (snapshot-on-wallclock-time) mechanism.
void define_variables(const OutputFile &file, const std::set< VariableMetadata > &variables) const
Definition output.cc:206
std::set< std::string > m_spatial_vars
Definition IceModel.hh:494
std::shared_ptr< Config > m_config
Configuration flags and parameters.
Definition IceModel.hh:278
void define_time(const OutputFile &file, bool with_bounds=false) const
Definition output.cc:73
void write_run_stats(const OutputFile &file) const
Definition output.cc:182
std::shared_ptr< Context > m_ctx
Execution context.
Definition IceModel.hh:280
std::shared_ptr< Logger > m_log
Logger.
Definition IceModel.hh:284
double m_last_checkpoint_time
Definition IceModel.hh:506
virtual std::set< VariableMetadata > diagnostic_variables(const std::set< std::string > &variable_names) const
std::set< VariableMetadata > state_variables_diagnostics(const std::set< std::string > &variable_names) const
virtual std::set< VariableMetadata > state_variables() const
Definition output.cc:217
std::shared_ptr< Time > m_time
Time manager.
Definition IceModel.hh:286
bool write_checkpoint()
Write a checkpoint (i.e. an intermediate result of a run).
std::set< std::string > m_checkpoint_vars
Definition IceModel.hh:507
std::set< VariableMetadata > common_metadata() const
Definition output.cc:81
void write_state_diagnostics(const OutputFile &file, const std::set< std::string > &variable_names) const
void write_diagnostics(const OutputFile &file, const std::set< std::string > &variable_names) const
Writes variables listed in variable_names to file.
virtual std::set< std::string > output_variables(const std::string &keyword)
Assembles a list of diagnostics corresponding to an output file size.
std::string m_checkpoint_filename
Definition IceModel.hh:505
std::shared_ptr< OutputWriter > m_output_writer
Definition IceModel.hh:288
void scalar_diagnostics_flush_buffers()
Flush scalar time-series.
std::string m_output_filename
Name of the output file.
Definition IceModel.hh:233
virtual void write_state(const OutputFile &file) const
Definition output.cc:240
std::set< VariableMetadata > m_checkpoint_file_contents
set of variables that will be written to checkpoint files
Definition IceModel.hh:509
const std::shared_ptr< Grid > m_grid
Computational grid.
Definition IceModel.hh:276
void append_time(double time_seconds) const
Definition OutputFile.cc:41
void begin(const char *name) const
Definition Profiling.cc:75
void end(const char *name) const
Definition Profiling.cc:91
void write_config(const Config &config, const std::string &variable_name, const OutputFile &file)
double get_time(MPI_Comm comm)
double wall_clock_hours(MPI_Comm com, double start_time)
Return time since the beginning of the run, in hours.
std::string filename_add_suffix(const std::string &filename, const std::string &separator, const std::string &suffix)
Adds a suffix to a filename.
std::string timestamp(MPI_Comm com)
Creates a time-stamp used for the history NetCDF attribute.
T combine(const T &a, const T &b)