toutput_backup.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
toutput_backup.cc (2897B)
---
1 /* Copyright (C) 2017, 2019 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 "IceModel.hh"
21
22 #include "pism/util/pism_utilities.hh"
23 #include "pism/util/Profiling.hh"
24
25 namespace pism {
26
27 //! Initialize the backup (snapshot-on-wallclock-time) mechanism.
28 void IceModel::init_backups() {
29
30 std::string backup_file = m_config->get_string("output.file_name");
31 if (not backup_file.empty()) {
32 m_backup_filename = filename_add_suffix(backup_file, "_backup", "");
33 } else {
34 m_backup_filename = "pism_backup.nc";
35 }
36
37 m_backup_vars = output_variables(m_config->get_string("output.backup_size"));
38 m_last_backup_time = 0.0;
39 }
40
41 //! Write a backup (i.e. an intermediate result of a run).
42 void IceModel::write_backup() {
43
44 double backup_interval = m_config->get_number("output.backup_interval");
45
46 double wall_clock_hours = pism::wall_clock_hours(m_grid->com, m_start_time);
47
48 if (wall_clock_hours - m_last_backup_time < backup_interval) {
49 return;
50 }
51
52 const Profiling &profiling = m_ctx->profiling();
53
54 m_last_backup_time = wall_clock_hours;
55
56 // create a history string:
57
58 m_log->message(2,
59 " [%s] Saving an automatic backup to '%s' (%1.3f hours after the beginning of the run)\n",
60 timestamp(m_grid->com).c_str(), m_backup_filename.c_str(), wall_clock_hours);
61
62 double backup_start_time = get_time();
63 profiling.begin("io.backup");
64 {
65 File file(m_grid->com,
66 m_backup_filename,
67 string_to_backend(m_config->get_string("output.format")),
68 PISM_READWRITE_MOVE,
69 m_ctx->pio_iosys_id());
70
71 write_metadata(file, WRITE_MAPPING, PREPEND_HISTORY);
72 write_run_stats(file);
73
74 save_variables(file, INCLUDE_MODEL_STATE, m_backup_vars, m_time->current());
75 }
76 profiling.end("io.backup");
77 double backup_end_time = get_time();
78
79 // Also flush time-series:
80 flush_timeseries();
81
82 m_log->message(2,
83 " [%s] Done saving an automatic backup in %f seconds (%f minutes).\n",
84 timestamp(m_grid->com).c_str(),
85 backup_end_time - backup_start_time,
86 (backup_end_time - backup_start_time) / 60.0);
87
88 }
89
90 } // end of namespace pism