https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
RestartableDataReader Class Reference

Reader for restartable data written by the RestartableDataWriter. More...

#include <RestartableDataReader.h>

Inheritance diagram for RestartableDataReader:
[legend]

Classes

struct  HeaderEntry
 Struct that describes data in the header. More...
 
struct  InputStreams
 Structure that contains the input streams for the reader. More...
 

Public Member Functions

 RestartableDataReader (MooseApp &app, RestartableDataMap &data, const bool force=false)
 
 RestartableDataReader (MooseApp &app, std::vector< RestartableDataMap > &data, const bool force=false)
 
void setInput (std::unique_ptr< std::stringstream > header_stream, std::unique_ptr< std::stringstream > data_stream)
 Sets the input stream for reading from the stringstreams header_stream and data_stream for the header and data, respectively.
 
void setInput (const std::filesystem::path &folder_base)
 Sets the input stream for reading to the file with the folder base folder_base.
 
bool isRestoring () const
 
bool restoreDataIfAvailable (RestartableDataValue &value, const THREAD_ID tid, Moose::PassKey< MooseApp >)
 Restores value in place from the open reader if it is present in the checkpoint and has not yet been loaded.
 
InputStreams clear ()
 Clears the contents of the reader (header stream, data stream, header)
 
void restore (const DataNames &filter_names={})
 Restores the restartable data.
 
template<typename T , typename... Args>
T & restoreData (const std::string &data_name, const THREAD_ID tid=0, void *const context=nullptr, Args &&... args)
 Restores the data with name data_name of type T.
 
template<typename T >
bool hasData (const std::string &data_name, const THREAD_ID tid=0) const
 
PerfGraphperfGraph ()
 Get the PerfGraph.
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 
void setErrorOnLoadWithDifferentNumberOfProcessors (bool value)
 

Static Public Member Functions

static bool isAvailable (const std::filesystem::path &folder_base)
 
static const std::string & getRestartableExt ()
 
static const std::string & restartableDataFile ()
 
static std::filesystem::path restartableDataFile (const std::filesystem::path &folder_base)
 
static const std::string & restartableHeaderFile ()
 
static std::filesystem::path restartableHeaderFile (const std::filesystem::path &folder_base)
 
static std::filesystem::path restartableDataFolder (const std::filesystem::path &folder_base)
 
static InputParameters validParams ()
 

Protected Types

typedef int COMPARE_HASH_CODE_TYPE
 The type to used for comparing hash codes (sanity checking)
 

Protected Member Functions

RestartableDataMapcurrentData (const THREAD_ID tid)
 
std::size_t dataSize () const
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level) const
 Call to register a named section for timing.
 
PerfID registerTimedSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true) const
 Call to register a named section for timing.
 
std::string timedSectionName (const std::string &section_name) const
 

Protected Attributes

const std::variant< RestartableDataMap *, std::vector< RestartableDataMap > * > _data
 The data we wish to act on This is a variant so that we can act on threaded and non-threaded data.
 
MooseApp_pg_moose_app
 The MooseApp that owns the PerfGraph.
 
const std::string _prefix
 A prefix to use for all sections.
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static const unsigned int CURRENT_BACKUP_FILE_VERSION = 4
 The current version for the backup file.
 

Private Member Functions

bool hasData (const std::string &data_name, const std::type_info &type, const THREAD_ID tid) const
 
std::vector< std::unordered_map< std::string, HeaderEntry > > readHeader (InputStream &header_input) const
 Internal method for reading the header (stored by RestartableDataWriter)
 
void deserializeValue (InputStream &data_input, RestartableDataValue &value, const HeaderEntry &header_entry) const
 Internal method for deserializing (restoring from backup into a value)
 
void requireRestoring () const
 Checks whether or not we're currently restoring and errors if not.
 
const HeaderEntryqueryHeader (const std::string &data_name, const THREAD_ID tid) const
 
const HeaderEntrygetHeader (const std::string &data_name, const THREAD_ID tid) const
 
bool isSameType (const HeaderEntry &header_entry, const std::type_info &type) const
 
RestartableDataValuerestoreData (const std::string &data_name, std::unique_ptr< RestartableDataValue > value, const THREAD_ID tid)
 Internal method for restoring a new data value.
 

Private Attributes

InputStreams _streams
 The inputs for reading.
 
std::vector< std::unordered_map< std::string, HeaderEntry > > _header
 The loaded headers from the restart.
 
bool _is_restoring
 Whether or not we're currently restoring.
 
bool _error_on_different_number_of_processors
 Whether or not to error with a different number of processors.
 
const bool _force
 Whether or not to forcefully attempt to read despite incompatibilities.
 

Detailed Description

Reader for restartable data written by the RestartableDataWriter.

Definition at line 24 of file RestartableDataReader.h.

Member Typedef Documentation

◆ COMPARE_HASH_CODE_TYPE

typedef int RestartableDataIO::COMPARE_HASH_CODE_TYPE
protectedinherited

The type to used for comparing hash codes (sanity checking)

Definition at line 84 of file RestartableDataIO.h.

Constructor & Destructor Documentation

◆ RestartableDataReader() [1/2]

RestartableDataReader::RestartableDataReader ( MooseApp app,
RestartableDataMap data,
const bool  force = false 
)

Definition at line 25 of file RestartableDataReader.C.

28 : RestartableDataIO(app, data),
29 _is_restoring(false),
31 _force(force)
32{
33}
Class for doing restart.
bool _is_restoring
Whether or not we're currently restoring.
const bool _force
Whether or not to forcefully attempt to read despite incompatibilities.
bool _error_on_different_number_of_processors
Whether or not to error with a different number of processors.

◆ RestartableDataReader() [2/2]

RestartableDataReader::RestartableDataReader ( MooseApp app,
std::vector< RestartableDataMap > &  data,
const bool  force = false 
)

Definition at line 35 of file RestartableDataReader.C.

38 : RestartableDataIO(app, data),
39 _is_restoring(false),
41 _force(force)
42{
43}

Member Function Documentation

◆ clear()

RestartableDataReader::InputStreams RestartableDataReader::clear ( )

Clears the contents of the reader (header stream, data stream, header)

This returns ownership of the resulting input in the event that it should be retained

Definition at line 65 of file RestartableDataReader.C.

66{
67 _is_restoring = false;
68 _header.clear();
69 InputStreams streams;
70 std::swap(_streams, streams);
71 return streams;
72}
InputStreams _streams
The inputs for reading.
std::vector< std::unordered_map< std::string, HeaderEntry > > _header
The loaded headers from the restart.

Referenced by MooseApp::finalizeRestore().

◆ currentData()

RestartableDataMap & RestartableDataIO::currentData ( const THREAD_ID  tid)
protectedinherited
Returns
The restartable data for thread tid

This exists so that we can support threaded and non-threaded data in _data

Definition at line 33 of file RestartableDataIO.C.

34{
35 mooseAssert(dataSize() > tid, "Invalid thread");
36
37 if (std::holds_alternative<RestartableDataMap *>(_data))
38 return *std::get<RestartableDataMap *>(_data);
39 return (*std::get<std::vector<RestartableDataMap> *>(_data))[tid];
40}
const std::variant< RestartableDataMap *, std::vector< RestartableDataMap > * > _data
The data we wish to act on This is a variant so that we can act on threaded and non-threaded data.
std::size_t dataSize() const

Referenced by restore(), restoreData(), and RestartableDataWriter::write().

◆ dataSize()

std::size_t RestartableDataIO::dataSize ( ) const
protectedinherited
Returns
The size of _data

Definition at line 43 of file RestartableDataIO.C.

44{
45 return std::holds_alternative<RestartableDataMap *>(_data)
46 ? 1
47 : std::get<std::vector<RestartableDataMap> *>(_data)->size();
48}

Referenced by RestartableDataIO::currentData(), readHeader(), restore(), and RestartableDataWriter::write().

◆ deserializeValue()

void RestartableDataReader::deserializeValue ( InputStream data_input,
RestartableDataValue value,
const HeaderEntry header_entry 
) const
private

Internal method for deserializing (restoring from backup into a value)

Definition at line 257 of file RestartableDataReader.C.

261{
262 mooseAssert(!value.loaded(), value.name() + " is already loaded");
263
264 auto error = [&data_input, &value](auto... args)
265 {
266 std::stringstream err;
267 err << "While loading restartable data\n\n";
268 err << "From: ";
269 const auto filename = data_input.getFilename();
270 if (filename)
271 err << std::filesystem::absolute(filename->parent_path());
272 else
273 err << "memory";
274 err << "\nData name: " << value.name();
275 err << "\nData type: " << value.type();
276 err << "\n\n";
277 mooseError(err.str(), args...);
278 };
279
280 if (!isSameType(header_entry, value.typeId()))
281 error("The stored type of '", header_entry.type, "' does not match");
282
283 auto stream_ptr = data_input.get();
284 auto & stream = *stream_ptr;
285
286 stream.seekg(header_entry.position);
287 value.load(stream);
288
289 if (stream.tellg() == -1)
290 error("An error was encountered when reading from the stream");
291
292 const std::size_t loaded_size = stream.tellg() - header_entry.position;
293 if (loaded_size != header_entry.size)
294 error("The data read does not match the data stored\n\n",
295 "Stored size: ",
296 header_entry.size,
297 "\nLoaded size: ",
298 loaded_size);
299}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
virtual std::shared_ptr< std::istream > get() const =0
Gets an input stream to the underlying stream.
virtual std::optional< std::filesystem::path > getFilename() const
Gets the underlying filename, if any.
Definition InputStream.C:44
bool isSameType(const HeaderEntry &header_entry, const std::type_info &type) const
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
OStreamProxy err(std::cerr)

Referenced by restoreData(), and restoreDataIfAvailable().

◆ getHeader()

const RestartableDataReader::HeaderEntry & RestartableDataReader::getHeader ( const std::string &  data_name,
const THREAD_ID  tid 
) const
private
Returns
The header entry for the data with name data_name on thread tid.

Requires that restore() is called first to load the headers.

Definition at line 245 of file RestartableDataReader.C.

246{
247 const auto header = queryHeader(data_name, tid);
248 if (!header)
250 "RestartableDataReader::getHeader(): Failed to find a header entry for data with name '",
251 data_name,
252 "'");
253 return *header;
254}
const HeaderEntry * queryHeader(const std::string &data_name, const THREAD_ID tid) const

Referenced by restoreData().

◆ getRestartableExt()

const std::string & RestartableDataIO::getRestartableExt ( )
staticinherited
Returns
The common extension for restartable data folders

Definition at line 51 of file RestartableDataIO.C.

52{
53 static const std::string ext = ".rd";
54 return ext;
55}

Referenced by RestartableDataIO::restartableDataFolder().

◆ hasData() [1/2]

bool RestartableDataReader::hasData ( const std::string &  data_name,
const std::type_info &  type,
const THREAD_ID  tid 
) const
private
Returns
Whether or not data exists in the headers with the name data_name with type type on thread tid

Requires that restore() is called first to load the headers.

Definition at line 225 of file RestartableDataReader.C.

228{
229 if (const auto header = queryHeader(data_name, tid))
230 return isSameType(*header, type);
231 return false;
232}

◆ hasData() [2/2]

template<typename T >
bool RestartableDataReader::hasData ( const std::string &  data_name,
const THREAD_ID  tid = 0 
) const
inline
Returns
Whether or not data exists in the headers with the name data_name with type T on thread tid

Requires that restore() is called first to load the headers.

Definition at line 139 of file RestartableDataReader.h.

140 {
141 return hasData(data_name, typeid(T), tid);
142 }
bool hasData(const std::string &data_name, const THREAD_ID tid=0) const

Referenced by hasData().

◆ isAvailable()

bool RestartableDataReader::isAvailable ( const std::filesystem::path &  folder_base)
static
Returns
Whether or not restartable data is available in the folder folder_base

Will error if the header is available and the data is not, or if the data is and the header is not.

Definition at line 302 of file RestartableDataReader.C.

303{
304 const auto header_path = restartableDataFile(folder_base);
305 const auto data_path = restartableDataFile(folder_base);
306
307 const auto available = [](const auto & filename)
308 { return MooseUtils::pathExists(filename) && MooseUtils::checkFileReadable(filename); };
309
310 const bool header_available = available(header_path);
311 const bool data_available = available(data_path);
312
313 if (header_available != data_available)
314 mooseError("The restart ",
315 header_available ? "header" : "data",
316 " is available but the corresponding ",
317 header_available ? "data" : "header",
318 " is not available\n\n",
319 "Header (",
320 header_available ? "available" : "missing",
321 "): ",
322 std::filesystem::absolute(header_path),
323 "\nData (",
324 data_available ? "available" : "missing",
325 "): ",
326 std::filesystem::absolute(header_path));
327
328 return header_available && data_available;
329}
static const std::string & restartableDataFile()
bool pathExists(const std::string &path)
Definition MooseUtils.C:258
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
Definition MooseUtils.C:265

Referenced by MooseUtils::getLatestCheckpointFilePrefix(), and MooseApp::possiblyLoadRestartableMetaData().

◆ isRestoring()

bool RestartableDataReader::isRestoring ( ) const
inline
Returns
Whether or not this reader is currently restoring

Definition at line 56 of file RestartableDataReader.h.

56{ return _streams.data != nullptr; }
std::unique_ptr< InputStream > data

Referenced by MooseApp::finalizeRestore(), and restoreDataIfAvailable().

◆ isSameType()

bool RestartableDataReader::isSameType ( const HeaderEntry header_entry,
const std::type_info &  type 
) const
private
Returns
Whether or not the type type is the same as the type in header_entry

We need this because this check depends on whether or not we do a string comparison

Definition at line 356 of file RestartableDataReader.C.

358{
359#ifndef RESTARTABLE_SKIP_CHECK_HASH_CODE
360 if (header_entry.type_hash_code == type.hash_code())
361 return true;
362#endif
363 return header_entry.type == type.name();
364}

Referenced by deserializeValue(), and hasData().

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 86 of file PerfGraphInterface.C.

87{
88 return _pg_moose_app.perfGraph();
89}
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition MooseApp.h:179
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.

Referenced by CommonOutputAction::act(), PerfGraphData::finalize(), PerfGraphReporter::finalize(), and PerfGraphOutput::output().

◆ queryHeader()

const RestartableDataReader::HeaderEntry * RestartableDataReader::queryHeader ( const std::string &  data_name,
const THREAD_ID  tid 
) const
private
Returns
The header entry for the data with name data_name on thread tid if it exists, and nullptr otherwise.

Requires that restore() is called first to load the headers.

Definition at line 235 of file RestartableDataReader.C.

236{
238 const auto it = _header[tid].find(data_name);
239 if (it == _header[tid].end())
240 return nullptr;
241 return &it->second;
242}
void requireRestoring() const
Checks whether or not we're currently restoring and errors if not.

Referenced by getHeader(), hasData(), and restoreDataIfAvailable().

◆ readHeader()

std::vector< std::unordered_map< std::string, RestartableDataReader::HeaderEntry > > RestartableDataReader::readHeader ( InputStream header_input) const
private

Internal method for reading the header (stored by RestartableDataWriter)

Definition at line 75 of file RestartableDataReader.C.

76{
77 std::vector<std::unordered_map<std::string, RestartableDataReader::HeaderEntry>> header;
78
79 auto stream_ptr = header_input.get();
80 auto & stream = *stream_ptr;
81
82 stream.seekg(0);
83
84 const auto error = [&header_input](auto... args)
85 {
86 std::stringstream err_prefix;
87 err_prefix << "While reading restartable data in ";
88 const auto filename = header_input.getFilename();
89 if (filename)
90 err_prefix << std::filesystem::absolute(filename->parent_path());
91 else
92 err_prefix << "memory";
93 err_prefix << ":\n\n";
94
95 mooseError(err_prefix.str(), args...);
96 };
97
98 // ID
99 char this_id[2];
100 stream.read(this_id, 2);
101 if (this_id[0] != 'R' || this_id[1] != 'D')
102 error("The data is invalid or corrupted (unexpected header)");
103
104 // File version
105 std::remove_const<decltype(CURRENT_BACKUP_FILE_VERSION)>::type this_file_version;
106 dataLoad(stream, this_file_version, nullptr);
107 if (this_file_version != CURRENT_BACKUP_FILE_VERSION)
108 error("There is a mismatch in the backup version\n\n",
109 "Current backup version: ",
111 "\nLoaded backup version: ",
112 this_file_version);
113
114 // Type id for a basic type
115 std::size_t this_compare_hash_code;
116 dataLoad(stream, this_compare_hash_code, nullptr);
117#ifndef RESTARTABLE_SKIP_CHECK_HASH_CODE
118 if (this_compare_hash_code != typeid(COMPARE_HASH_CODE_TYPE).hash_code() && !_force)
119 error("The backup is not compatible\n\nThe hash code check for a basic type (",
120 MooseUtils::prettyCppType<COMPARE_HASH_CODE_TYPE>(),
121 ") failed.\nIt is possible that this backup was stored with a different architecture or "
122 "operating system.\n\nTo forcefully attempt loading the backup, use the command line "
123 "option --force-restart");
124#else
125 (void)_force;
126#endif
127
128 // Number of procs
129 decltype(n_processors()) this_n_procs = 0;
130 dataLoad(stream, this_n_procs, nullptr);
132 error("The number of MPI ranks is not consistent\n\nCurrent MPI ranks: ",
133 n_processors(),
134 "\nLoaded MPI ranks: ",
135 this_n_procs);
136
137 // Number of data
138 decltype(dataSize()) this_num_data = 0;
139 dataLoad(stream, this_num_data, nullptr);
140 if (this_num_data != dataSize())
141 error("The number of threads is not consistent\n\nCurrent threads: ",
142 dataSize(),
143 "\nLoaded threads: ",
144 this_num_data);
145
146 header.resize(dataSize());
147
148 // Size of data for each thread
149 std::vector<std::size_t> tid_n_data(dataSize());
150 for (const auto tid : make_range(dataSize()))
151 dataLoad(stream, tid_n_data[tid], nullptr);
152
153 // The position of the current data that we're loading
154 std::size_t current_data_position = 0;
155
156 // Load the data header for each thread
157 for (const auto tid : make_range(dataSize()))
158 for (const auto i : make_range(tid_n_data[tid]))
159 {
160 std::ignore = i;
161
162 std::string name;
163 dataLoad(stream, name, nullptr);
164 mooseAssert(name.size(), "Empty name");
165
166 mooseAssert(!header[tid].count(name), "Data '" + name + "' is already inserted");
167 auto & entry = header[tid][name];
168
169 dataLoad(stream, entry.size, nullptr);
170 dataLoad(stream, entry.type_hash_code, nullptr);
171 dataLoad(stream, entry.type, nullptr);
172 dataLoad(stream, entry.has_context, nullptr);
173 entry.position = current_data_position;
174
175 current_data_position += entry.size;
176 }
177
178 stream.seekg(0);
179
180 return header;
181}
void dataLoad(std::istream &stream, LineSegment &l, void *context)
unsigned int count
Definition MortarUtils.C:53
for(PetscInt i=0;i< nvars;++i)
static const unsigned int CURRENT_BACKUP_FILE_VERSION
The current version for the backup file.
int COMPARE_HASH_CODE_TYPE
The type to used for comparing hash codes (sanity checking)
processor_id_type n_processors() const
std::string name(const ElemQuality q)
IntRange< T > make_range(T beg, T end)

◆ registerTimedSection() [1/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 61 of file PerfGraphInterface.C.

63{
64 const auto timed_section_name = timedSectionName(section_name);
65 if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
66 return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
67 else
68 return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
69}
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID @section_name The name of the section.
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ registerTimedSection() [2/2]

PerfID PerfGraphInterface::registerTimedSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
) const
protectedinherited

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
live_messageThe message to be printed to the screen during execution
print_dotsWhether or not progress dots should be printed for this section
Returns
The ID of the section - use when starting timing

Definition at line 72 of file PerfGraphInterface.C.

76{
77 const auto timed_section_name = timedSectionName(section_name);
78 if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
80 timedSectionName(section_name), level, live_message, print_dots);
81 else
82 return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
83}

◆ requireRestoring()

void RestartableDataReader::requireRestoring ( ) const
private

Checks whether or not we're currently restoring and errors if not.

Definition at line 332 of file RestartableDataReader.C.

333{
334 if (!_is_restoring)
336 "The RestartableDataReader is not available for querying as it is not currently restoring");
337 mooseAssert(_streams.header, "Header not available");
338 mooseAssert(_streams.data, "Data not available");
339}
std::unique_ptr< InputStream > header

Referenced by queryHeader().

◆ restartableDataFile() [1/2]

const std::string & RestartableDataIO::restartableDataFile ( )
staticinherited
Returns
The filename for the restartable data

Definition at line 58 of file RestartableDataIO.C.

59{
60 static const std::string file = "data";
61 return file;
62}

Referenced by isAvailable(), RestartableDataIO::restartableDataFile(), setInput(), and RestartableDataWriter::write().

◆ restartableDataFile() [2/2]

std::filesystem::path RestartableDataIO::restartableDataFile ( const std::filesystem::path &  folder_base)
staticinherited
Returns
The path to the restartable data file with base folder_base

Does not append .rd to the folder base

Definition at line 80 of file RestartableDataIO.C.

81{
82 return folder_base / restartableDataFile();
83}

◆ restartableDataFolder()

std::filesystem::path RestartableDataIO::restartableDataFolder ( const std::filesystem::path &  folder_base)
staticinherited
Returns
The path to the restartable data folder with base folder_base

This just appends .rd

Definition at line 72 of file RestartableDataIO.C.

73{
74 auto folder = folder_base;
75 folder += getRestartableExt();
76 return folder;
77}
static const std::string & getRestartableExt()

Referenced by MooseApp::metaDataFolderBase(), and MooseApp::restartFolderBase().

◆ restartableHeaderFile() [1/2]

const std::string & RestartableDataIO::restartableHeaderFile ( )
staticinherited
Returns
The filename for the restartable header

Definition at line 65 of file RestartableDataIO.C.

66{
67 static const std::string file = "header";
68 return file;
69}

Referenced by RestartableDataIO::restartableHeaderFile(), setInput(), and RestartableDataWriter::write().

◆ restartableHeaderFile() [2/2]

std::filesystem::path RestartableDataIO::restartableHeaderFile ( const std::filesystem::path &  folder_base)
staticinherited
Returns
The path to the restartable header file with base folder_base

Does not append .rd to the folder base

Definition at line 86 of file RestartableDataIO.C.

87{
88 return folder_base / restartableHeaderFile();
89}
static const std::string & restartableHeaderFile()

◆ restore()

void RestartableDataReader::restore ( const DataNames filter_names = {})

Restores the restartable data.

The input must be set via setInput() first.

A handle to the input is still kept after this restore is called! In order to remove that handle, you must call clear()!

Parameters
filter_namesA list of data names to only restore. If not provided, restores all.

Definition at line 184 of file RestartableDataReader.C.

185{
186 if (!_streams.header || !_streams.data)
187 mooseError("RestartableDataReader::restore(): Cannot restore because an input was not set");
188
189 _is_restoring = true;
190
191 // Set everything as not loaded
192 for (const auto tid : make_range(dataSize()))
193 for (auto & value : currentData(tid))
194 value.setNotLoaded({});
195
196 // Read the header
198
199 for (const auto tid : index_range(_header))
200 {
201 auto & data = currentData(tid);
202 const auto & header = _header[tid];
203
204 // TODO: Think about what to do with missing data
205 // Load the data in the order that it was requested
206 for (auto & value : data)
207 {
208 const auto & name = value.name();
209
210 auto find_header = header.find(name);
211 if (find_header == header.end())
212 continue;
213
214 auto & header_entry = find_header->second;
215
216 // Only restore values if we're either recovering or the data isn't filtered out
217 const auto is_data_in_filter = filter_names.find(name) != filter_names.end();
218 if (!is_data_in_filter)
219 deserializeValue(*_streams.data, value, header_entry);
220 }
221 }
222}
RestartableDataMap & currentData(const THREAD_ID tid)
std::vector< std::unordered_map< std::string, HeaderEntry > > readHeader(InputStream &header_input) const
Internal method for reading the header (stored by RestartableDataWriter)
void deserializeValue(InputStream &data_input, RestartableDataValue &value, const HeaderEntry &header_entry) const
Internal method for deserializing (restoring from backup into a value)
auto index_range(const T &sizable)

Referenced by MooseApp::possiblyLoadRestartableMetaData(), MooseApp::restore(), and MooseApp::restore().

◆ restoreData() [1/2]

template<typename T , typename... Args>
T & RestartableDataReader::restoreData ( const std::string &  data_name,
const THREAD_ID  tid = 0,
void *const  context = nullptr,
Args &&...  args 
)

Restores the data with name data_name of type T.

This is used to restore data that was never declared in the restart, but was stored in the backup. You cannot call this if the data has already been declared or restored.

Requires that restore() is called first to load the headers.

Parameters
data_nameThe name of the data
tidThe thread
contextThe data context (if any)
argsArguments to forward to the constructor of the object
Returns
The restored data

Definition at line 234 of file RestartableDataReader.h.

238{
239 std::unique_ptr<RestartableDataValue> T_data =
240 std::make_unique<RestartableData<T>>(data_name, context, std::forward<Args>(args)...);
241 auto & value = restoreData(data_name, std::move(T_data), tid);
242 auto T_value = dynamic_cast<RestartableData<T> *>(&value);
243 mooseAssert(T_value, "Bad cast");
244 return T_value->set();
245}
T & restoreData(const std::string &data_name, const THREAD_ID tid=0, void *const context=nullptr, Args &&... args)
Restores the data with name data_name of type T.
Concrete definition of a parameter value for a specified type.

Referenced by restoreData().

◆ restoreData() [2/2]

RestartableDataValue & RestartableDataReader::restoreData ( const std::string &  data_name,
std::unique_ptr< RestartableDataValue value,
const THREAD_ID  tid 
)
private

Internal method for restoring a new data value.

Definition at line 367 of file RestartableDataReader.C.

370{
371 auto & data_map = currentData(tid);
372 if (data_map.hasData(data_name))
373 mooseError("RestartableDataReader::restoreData(): Cannot declare restartable data '",
374 data_name,
375 "' because it has already been declared");
376
377 const auto & header = getHeader(data_name, tid);
378 auto & added_value = currentData(tid).addData(std::move(value));
379 deserializeValue(*_streams.data, added_value, header);
380 return added_value;
381}
RestartableDataValue & addData(std::unique_ptr< RestartableDataValue > data)
Adds the restartable data data to the map.
const HeaderEntry & getHeader(const std::string &data_name, const THREAD_ID tid) const

◆ restoreDataIfAvailable()

bool RestartableDataReader::restoreDataIfAvailable ( RestartableDataValue value,
const THREAD_ID  tid,
Moose::PassKey< MooseApp  
)

Restores value in place from the open reader if it is present in the checkpoint and has not yet been loaded.

Used to recover data (e.g. reporter values) that is declared after the bulk restore pass while the reader window is still open.

Requires that restore() has been called.

Returns
Whether or not the value was restored

Definition at line 342 of file RestartableDataReader.C.

345{
346 if (!isRestoring() || value.loaded())
347 return false;
348 const auto * const header_entry = queryHeader(value.name(), tid);
349 if (!header_entry)
350 return false;
351 deserializeValue(*_streams.data, value, *header_entry);
352 return true;
353}

Referenced by MooseApp::restoreDataIfAvailable().

◆ setErrorOnLoadWithDifferentNumberOfProcessors()

void RestartableDataReader::setErrorOnLoadWithDifferentNumberOfProcessors ( bool  value)
inline

◆ setInput() [1/2]

void RestartableDataReader::setInput ( const std::filesystem::path &  folder_base)

Sets the input stream for reading to the file with the folder base folder_base.

Definition at line 56 of file RestartableDataReader.C.

57{
58 mooseAssert(!_streams.header, "Header input already set");
59 mooseAssert(!_streams.data, "Data stream already set");
60 _streams.header = std::make_unique<FileInputStream>(restartableHeaderFile(folder_base));
61 _streams.data = std::make_unique<FileInputStream>(restartableDataFile(folder_base));
62}

◆ setInput() [2/2]

void RestartableDataReader::setInput ( std::unique_ptr< std::stringstream >  header_stream,
std::unique_ptr< std::stringstream >  data_stream 
)

Sets the input stream for reading from the stringstreams header_stream and data_stream for the header and data, respectively.

Definition at line 46 of file RestartableDataReader.C.

48{
49 mooseAssert(!_streams.header, "Header input already set");
50 mooseAssert(!_streams.data, "Data stream already set");
51 _streams.header = std::make_unique<StringInputStream>(std::move(header_stream));
52 _streams.data = std::make_unique<StringInputStream>(std::move(data_stream));
53}

Referenced by MooseApp::possiblyLoadRestartableMetaData(), MooseApp::restore(), and MooseApp::restore().

◆ timedSectionName()

std::string PerfGraphInterface::timedSectionName ( const std::string &  section_name) const
protectedinherited
Returns
The name of the timed section with the name section_name.

Optionally adds a prefix if one is defined.

Definition at line 55 of file PerfGraphInterface.C.

56{
57 return _prefix.empty() ? "" : (_prefix + "::") + section_name;
58}
const std::string _prefix
A prefix to use for all sections.

Referenced by PerfGraphInterface::registerTimedSection(), and PerfGraphInterface::registerTimedSection().

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

17{
19 return params;
20}
InputParameters emptyInputParameters()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.

Referenced by Convergence::validParams().

Member Data Documentation

◆ _data

const std::variant<RestartableDataMap *, std::vector<RestartableDataMap> *> RestartableDataIO::_data
protectedinherited

The data we wish to act on This is a variant so that we can act on threaded and non-threaded data.

Definition at line 79 of file RestartableDataIO.h.

Referenced by RestartableDataIO::currentData(), and RestartableDataIO::dataSize().

◆ _error_on_different_number_of_processors

bool RestartableDataReader::_error_on_different_number_of_processors
private

Whether or not to error with a different number of processors.

Definition at line 226 of file RestartableDataReader.h.

Referenced by readHeader(), and setErrorOnLoadWithDifferentNumberOfProcessors().

◆ _force

const bool RestartableDataReader::_force
private

Whether or not to forcefully attempt to read despite incompatibilities.

Definition at line 229 of file RestartableDataReader.h.

Referenced by readHeader().

◆ _header

std::vector<std::unordered_map<std::string, HeaderEntry> > RestartableDataReader::_header
private

The loaded headers from the restart.

Definition at line 220 of file RestartableDataReader.h.

Referenced by clear(), and queryHeader().

◆ _is_restoring

bool RestartableDataReader::_is_restoring
private

Whether or not we're currently restoring.

Definition at line 223 of file RestartableDataReader.h.

Referenced by clear(), requireRestoring(), and restore().

◆ _pg_moose_app

MooseApp& PerfGraphInterface::_pg_moose_app
protectedinherited

The MooseApp that owns the PerfGraph.

Definition at line 135 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::perfGraph().

◆ _prefix

const std::string PerfGraphInterface::_prefix
protectedinherited

A prefix to use for all sections.

Definition at line 138 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::timedSectionName().

◆ _streams

InputStreams RestartableDataReader::_streams
private

The inputs for reading.

Definition at line 217 of file RestartableDataReader.h.

Referenced by clear(), isRestoring(), requireRestoring(), restore(), restoreData(), restoreDataIfAvailable(), setInput(), and setInput().

◆ CURRENT_BACKUP_FILE_VERSION

const unsigned int RestartableDataIO::CURRENT_BACKUP_FILE_VERSION = 4
staticprotectedinherited

The current version for the backup file.

Definition at line 82 of file RestartableDataIO.h.

Referenced by readHeader().


The documentation for this class was generated from the following files: