https://mooseframework.inl.gov
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. More...
 
void setInput (const std::filesystem::path &folder_base)
 Sets the input stream for reading to the file with the folder base folder_base. More...
 
bool isRestoring () const
 
InputStreams clear ()
 Clears the contents of the reader (header stream, data stream, header) More...
 
void restore (const DataNames &filter_names={})
 Restores the restartable data. More...
 
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. More...
 
template<typename T >
bool hasData (const std::string &data_name, const THREAD_ID tid=0) const
 
PerfGraphperfGraph ()
 Get the PerfGraph. More...
 
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) More...
 

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. More...
 
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. More...
 
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. More...
 
MooseApp_pg_moose_app
 The MooseApp that owns the PerfGraph. More...
 
const std::string _prefix
 A prefix to use for all sections. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

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

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) More...
 
void deserializeValue (InputStream &data_input, RestartableDataValue &value, const HeaderEntry &header_entry) const
 Internal method for deserializing (restoring from backup into a value) More...
 
void requireRestoring () const
 Checks whether or not we're currently restoring and errors if not. More...
 
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. More...
 

Private Attributes

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

Detailed Description

Reader for restartable data written by the RestartableDataWriter.

Definition at line 23 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 }
RestartableDataIO(MooseApp &app, RestartableDataMap &data)
bool _is_restoring
Whether or not we&#39;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 }
RestartableDataIO(MooseApp &app, RestartableDataMap &data)
bool _is_restoring
Whether or not we&#39;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.

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.

Referenced by MooseApp::finalizeRestore().

66 {
67  _is_restoring = false;
68  _header.clear();
69  InputStreams streams;
70  std::swap(_streams, streams);
71  return streams;
72 }
void swap(std::vector< T > &data, const std::size_t idx0, const std::size_t idx1, const libMesh::Parallel::Communicator &comm)
Swap function for serial or distributed vector of data.
Definition: Shuffle.h:494
bool _is_restoring
Whether or not we&#39;re currently restoring.
InputStreams _streams
The inputs for reading.
std::vector< std::unordered_map< std::string, HeaderEntry > > _header
The loaded headers from the restart.

◆ 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.

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

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
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155

◆ dataSize()

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

Definition at line 43 of file RestartableDataIO.C.

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

44 {
45  return std::holds_alternative<RestartableDataMap *>(_data)
46  ? 1
47  : std::get<std::vector<RestartableDataMap> *>(_data)->size();
48 }
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...
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155

◆ 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.

Referenced by restore(), and restoreData().

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 }
OStreamProxy err
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool isSameType(const HeaderEntry &header_entry, const std::type_info &type) const
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

◆ 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.

Referenced by restoreData().

246 {
247  const auto header = queryHeader(data_name, tid);
248  if (!header)
249  mooseError(
250  "RestartableDataReader::getHeader(): Failed to find a header entry for data with name '",
251  data_name,
252  "'");
253  return *header;
254 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const HeaderEntry * queryHeader(const std::string &data_name, const THREAD_ID tid) const

◆ getRestartableExt()

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

Definition at line 51 of file RestartableDataIO.C.

Referenced by RestartableDataIO::restartableDataFolder().

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

◆ hasData() [1/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 125 of file RestartableDataReader.h.

126  {
127  return hasData(data_name, typeid(T), tid);
128  }
bool hasData(const std::string &data_name, const THREAD_ID tid=0) const

◆ hasData() [2/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 }
const HeaderEntry * queryHeader(const std::string &data_name, const THREAD_ID tid) const
bool isSameType(const HeaderEntry &header_entry, const std::type_info &type) const

◆ 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.

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

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()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:250
bool pathExists(const std::string &path)
Definition: MooseUtils.C:243

◆ isRestoring()

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

Definition at line 55 of file RestartableDataReader.h.

Referenced by MooseApp::finalizeRestore().

55 { return _streams.data != nullptr; }
std::unique_ptr< InputStream > data
InputStreams _streams
The inputs for reading.

◆ 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 342 of file RestartableDataReader.C.

Referenced by deserializeValue(), and hasData().

344 {
345 #ifndef RESTARTABLE_SKIP_CHECK_HASH_CODE
346  if (header_entry.type_hash_code == type.hash_code())
347  return true;
348 #endif
349  return header_entry.type == type.name();
350 }

◆ perfGraph()

PerfGraph & PerfGraphInterface::perfGraph ( )
inherited

Get the PerfGraph.

Definition at line 78 of file PerfGraphInterface.C.

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

79 {
80  return _pg_moose_app.perfGraph();
81 }
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:161

◆ 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.

Referenced by getHeader(), and hasData().

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&#39;re currently restoring and errors if not.
std::vector< std::unordered_map< std::string, HeaderEntry > > _header
The loaded headers from the restart.

◆ 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.

Referenced by restore().

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 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
static const unsigned int CURRENT_BACKUP_FILE_VERSION
The current version for the backup file.
std::size_t dataSize() const
void dataLoad(std::istream &stream, PenetrationInfo *&pinfo, void *context)
int COMPARE_HASH_CODE_TYPE
The type to used for comparing hash codes (sanity checking)
processor_id_type n_processors() const
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
const bool _force
Whether or not to forcefully attempt to read despite incompatibilities.
class infix_ostream_iterator if void
Definition: InfixIterator.h:26
bool _error_on_different_number_of_processors
Whether or not to error with a different number of processors.
for(PetscInt i=0;i< nvars;++i)
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

◆ 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 53 of file PerfGraphInterface.C.

55 {
56  const auto timed_section_name = timedSectionName(section_name);
57  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
58  return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
59  else
60  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
61 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
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 64 of file PerfGraphInterface.C.

68 {
69  const auto timed_section_name = timedSectionName(section_name);
70  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
72  timedSectionName(section_name), level, live_message, print_dots);
73  else
74  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
75 }
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.

◆ 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.

Referenced by queryHeader().

333 {
334  if (!_is_restoring)
335  mooseError(
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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::unique_ptr< InputStream > header
bool _is_restoring
Whether or not we&#39;re currently restoring.
std::unique_ptr< InputStream > data
InputStreams _streams
The inputs for reading.

◆ restartableDataFile() [1/2]

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

Definition at line 58 of file RestartableDataIO.C.

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

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

◆ 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 }
static const std::string & restartableDataFile()

◆ 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.

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

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

◆ restartableHeaderFile() [1/2]

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

Definition at line 65 of file RestartableDataIO.C.

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

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

◆ 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.

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

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 }
std::string name(const ElemQuality q)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
std::size_t dataSize() const
std::unique_ptr< InputStream > header
std::vector< std::unordered_map< std::string, HeaderEntry > > readHeader(InputStream &header_input) const
Internal method for reading the header (stored by RestartableDataWriter)
RestartableDataMap & currentData(const THREAD_ID tid)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool _is_restoring
Whether or not we&#39;re currently restoring.
std::unique_ptr< InputStream > data
void deserializeValue(InputStream &data_input, RestartableDataValue &value, const HeaderEntry &header_entry) const
Internal method for deserializing (restoring from backup into a value)
IntRange< T > make_range(T beg, T end)
InputStreams _streams
The inputs for reading.
auto index_range(const T &sizable)
std::vector< std::unordered_map< std::string, HeaderEntry > > _header
The loaded headers from the restart.

◆ 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 220 of file RestartableDataReader.h.

224 {
225  std::unique_ptr<RestartableDataValue> T_data =
226  std::make_unique<RestartableData<T>>(data_name, context, std::forward<Args>(args)...);
227  auto & value = restoreData(data_name, std::move(T_data), tid);
228  auto T_value = dynamic_cast<RestartableData<T> *>(&value);
229  mooseAssert(T_value, "Bad cast");
230  return T_value->set();
231 }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
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.

◆ 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 353 of file RestartableDataReader.C.

356 {
357  auto & data_map = currentData(tid);
358  if (data_map.hasData(data_name))
359  mooseError("RestartableDataReader::restoreData(): Cannot declare restartable data '",
360  data_name,
361  "' because it has already been declared");
362 
363  const auto & header = getHeader(data_name, tid);
364  auto & added_value = currentData(tid).addData(std::move(value));
365  deserializeValue(*_streams.data, added_value, header);
366  return added_value;
367 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const HeaderEntry & getHeader(const std::string &data_name, const THREAD_ID tid) const
RestartableDataValue & addData(std::unique_ptr< RestartableDataValue > data)
Adds the restartable data data to the map.
RestartableDataMap & currentData(const THREAD_ID tid)
std::unique_ptr< InputStream > data
void deserializeValue(InputStream &data_input, RestartableDataValue &value, const HeaderEntry &header_entry) const
Internal method for deserializing (restoring from backup into a value)
InputStreams _streams
The inputs for reading.

◆ setErrorOnLoadWithDifferentNumberOfProcessors()

void RestartableDataReader::setErrorOnLoadWithDifferentNumberOfProcessors ( bool  value)
inline

Definition at line 104 of file RestartableDataReader.h.

Referenced by MooseApp::possiblyLoadRestartableMetaData().

105  {
107  }
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
bool _error_on_different_number_of_processors
Whether or not to error with a different number of processors.

◆ setInput() [1/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.

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

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 }
std::unique_ptr< InputStream > header
std::unique_ptr< InputStream > data
InputStreams _streams
The inputs for reading.

◆ setInput() [2/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 }
static const std::string & restartableDataFile()
std::unique_ptr< InputStream > header
static const std::string & restartableHeaderFile()
std::unique_ptr< InputStream > data
InputStreams _streams
The inputs for reading.

◆ 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 47 of file PerfGraphInterface.C.

Referenced by PerfGraphInterface::registerTimedSection().

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

◆ validParams()

InputParameters PerfGraphInterface::validParams ( )
staticinherited

Definition at line 16 of file PerfGraphInterface.C.

Referenced by Convergence::validParams().

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

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 212 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 215 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 206 of file RestartableDataReader.h.

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

◆ _is_restoring

bool RestartableDataReader::_is_restoring
private

Whether or not we're currently restoring.

Definition at line 209 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 124 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 127 of file PerfGraphInterface.h.

Referenced by PerfGraphInterface::timedSectionName().

◆ _streams

InputStreams RestartableDataReader::_streams
private

The inputs for reading.

Definition at line 203 of file RestartableDataReader.h.

Referenced by clear(), isRestoring(), requireRestoring(), restore(), restoreData(), 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(), and RestartableDataWriter::write().


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