PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
YacOutputWriter.hh
Go to the documentation of this file.
1/* Copyright (C) 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#ifndef PISM_YACOUTPUTWRITER_H
21#define PISM_YACOUTPUTWRITER_H
22
23#include <memory>
24#include <mpi.h>
25#include <string>
26
27#include "OutputWriter.hh"
28#include "pism/util/io/OutputWriter.hh"
29#include "pism/external/nlohmann/json.hpp"
30
31namespace pism {
32
33class File;
34
35namespace io {
36enum Backend : int;
37}
38
39// These have to match the actions which are defined on the server
56
57/*!
58 * Synchronous implementation of OutputWriter.
59 */
61public:
62 YacOutputWriter(MPI_Comm comm, const Config &config);
64
65private:
66 MPI_Comm m_intercomm;
67
68 //! True if the current MPI process is responsible for sending non-gridded data.
70
71 //! Length of the time dimension in a file
72 std::map<std::string, int> m_time_length;
73
74 //! last time value in an output file
75 std::map<std::string, double> m_last_time;
76
77 // Note (and possibly FIXME): these lists of variables and dimensions below are
78 // inaccurate for files that are opened for appending. This means that when appending to
79 // a file PISM will attempt to define variables *once*. The output server code is
80 // responsible for checking if a dimension (variable) exists and ignoring a request to
81 // define it.
82
83 //! List of all variables defined in a given file (used to avoid defining a variable
84 //! more than once)
85 std::map<std::string, std::map<std::string, bool> > m_defined_variable;
86
87 //! List of all dimensions defined in a given file (used to avoid defining a dimension
88 //! more than once)
89 std::map<std::string, std::map<std::string, bool> > m_defined_dimension;
90
91 // --- YAC Grid information
92
93 //! YAC point set ID corresponding to a grid name
94 std::map<std::string, int> m_point_set_id;
95
96 //! YAC field ID corresponding to a particular variable (by name)
97 std::map<std::string, int> m_field_ids;
98
99 // --- Buffers ---
100
101 //! buffers used to send text (write_text_impl())
102 std::vector<std::string> m_text_buffers;
103
104 //! buffers used to send arrays of double
105 std::vector<double *> m_buffers;
106
108 double *m_field_buffer = nullptr;
109
110 // --- MPI Communication
111
112 //! Tags for MPI messages sending non-gridded variable data
113
115 int tag(const std::string &variable_name, TagTreatment flag = GET_EXISTING_TAG);
116 std::map<std::string, int> m_variable_tags;
117
118 std::vector<MPI_Request> m_mpi_requests;
119
120 //! Call MPI_Waitall() to ensure that all buffers can be freed.
121 void waitall();
122
123 // --- Server-related subroutines ---
124 void create_intercomm();
125
126 void define_yac_grid(const VariableMetadata &variable);
127
128 void define_yac_field(const VariableMetadata &variable);
129
130 void end_yac_definitions();
131
132 void send_action(int action_id, const nlohmann::json &metadata);
133
134 // --- Interface implementation ---
135 void initialize_impl(const std::set<VariableMetadata> &array_variables);
136
137 void define_dimension_impl(const std::string &file_name, const std::string &name,
138 unsigned int length);
139
140 void define_variable_impl(const std::string &file_name, const std::string &variable_name,
141 const std::vector<std::string> &dims, io::Type type,
142 const VariableAttributes &attributes);
143
144 void set_global_attributes_impl(const std::string &file_name,
145 const std::map<std::string, std::string> &strings,
146 const std::map<std::string, std::vector<double> > &numbers);
147
148 void append_time_impl(const std::string &file_name, double time_seconds);
149
150 void append_history_impl(const std::string &file_name, const std::string &text);
151
152 unsigned int time_dimension_length_impl(const std::string &file_name);
153
154 double last_time_value_impl(const std::string &file_name);
155
156 void write_array_impl(const std::string &file_name, const std::string &variable_name,
157 const std::vector<unsigned int> &start,
158 const std::vector<unsigned int> &count, const double *data);
159
160 void write_text_impl(const std::string &file_name, const std::string &variable_name,
161 const std::vector<unsigned int> &start,
162 const std::vector<unsigned int> &count,
163 const std::string &input);
164
165 void write_distributed_array_impl(const std::string &file_name, const std::string &variable_name,
166 const double *data);
167
168 void append_impl(const std::string &file_name);
169 void sync_impl(const std::string &file_name);
170 void close_impl(const std::string &file_name);
171};
172
173} // namespace pism
174
175#endif /* PISM_YACOUTPUTWRITER_H */
A class for storing and accessing PISM configuration flags and parameters.
Definition Config.hh:56
MPI_Comm comm() const
std::vector< std::string > m_text_buffers
buffers used to send text (write_text_impl())
void initialize_impl(const std::set< VariableMetadata > &array_variables)
void define_yac_field(const VariableMetadata &variable)
void set_global_attributes_impl(const std::string &file_name, const std::map< std::string, std::string > &strings, const std::map< std::string, std::vector< double > > &numbers)
void define_variable_impl(const std::string &file_name, const std::string &variable_name, const std::vector< std::string > &dims, io::Type type, const VariableAttributes &attributes)
std::map< std::string, int > m_field_ids
YAC field ID corresponding to a particular variable (by name)
std::map< std::string, int > m_variable_tags
std::vector< double * > m_buffers
buffers used to send arrays of double
void define_dimension_impl(const std::string &file_name, const std::string &name, unsigned int length)
void define_yac_grid(const VariableMetadata &variable)
void write_distributed_array_impl(const std::string &file_name, const std::string &variable_name, const double *data)
std::vector< MPI_Request > m_mpi_requests
void close_impl(const std::string &file_name)
void append_impl(const std::string &file_name)
TagTreatment
Tags for MPI messages sending non-gridded variable data.
void write_text_impl(const std::string &file_name, const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, const std::string &input)
void write_array_impl(const std::string &file_name, const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, const double *data)
double last_time_value_impl(const std::string &file_name)
unsigned int time_dimension_length_impl(const std::string &file_name)
void waitall()
Call MPI_Waitall() to ensure that all buffers can be freed.
std::map< std::string, int > m_time_length
Length of the time dimension in a file.
bool m_leader
True if the current MPI process is responsible for sending non-gridded data.
void append_history_impl(const std::string &file_name, const std::string &text)
void append_time_impl(const std::string &file_name, double time_seconds)
std::map< std::string, int > m_point_set_id
YAC point set ID corresponding to a grid name.
void sync_impl(const std::string &file_name)
std::map< std::string, std::map< std::string, bool > > m_defined_variable
void send_action(int action_id, const nlohmann::json &metadata)
std::map< std::string, std::map< std::string, bool > > m_defined_dimension
int tag(const std::string &variable_name, TagTreatment flag=GET_EXISTING_TAG)
std::map< std::string, double > m_last_time
last time value in an output file
@ DEFINE_VARIABLE
@ DEFINE_YAC_GRID
@ DEFINE_YAC_FIELD
@ SET_FILE_ATTRIBUTES
@ DEFINE_DIMENSION
@ FINISH_YAC_INITIALIZATION
@ SEND_GRIDDED_VARIABLE
int count
Definition test_cube.c:16