Reader for restartable data written by the RestartableDataWriter. More...
#include <RestartableDataReader.h>
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 |
PerfGraph & | perfGraph () |
Get the PerfGraph. More... | |
const Parallel::Communicator & | comm () 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 | |
RestartableDataMap & | currentData (const THREAD_ID tid) |
std::size_t | dataSize () const |
PerfID | registerTimedSection (const std::string §ion_name, const unsigned int level) const |
Call to register a named section for timing. More... | |
PerfID | registerTimedSection (const std::string §ion_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 §ion_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 HeaderEntry * | queryHeader (const std::string &data_name, const THREAD_ID tid) const |
const HeaderEntry & | getHeader (const std::string &data_name, const THREAD_ID tid) const |
bool | isSameType (const HeaderEntry &header_entry, const std::type_info &type) const |
RestartableDataValue & | restoreData (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... | |
Reader for restartable data written by the RestartableDataWriter.
Definition at line 23 of file RestartableDataReader.h.
|
protectedinherited |
The type to used for comparing hash codes (sanity checking)
Definition at line 84 of file RestartableDataIO.h.
RestartableDataReader::RestartableDataReader | ( | MooseApp & | app, |
RestartableDataMap & | data, | ||
const bool | force = false |
||
) |
Definition at line 25 of file RestartableDataReader.C.
RestartableDataReader::RestartableDataReader | ( | MooseApp & | app, |
std::vector< RestartableDataMap > & | data, | ||
const bool | force = false |
||
) |
Definition at line 35 of file RestartableDataReader.C.
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().
|
protectedinherited |
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().
|
protectedinherited |
Definition at line 43 of file RestartableDataIO.C.
Referenced by RestartableDataIO::currentData(), readHeader(), restore(), and RestartableDataWriter::write().
|
private |
Internal method for deserializing (restoring from backup into a value)
Definition at line 257 of file RestartableDataReader.C.
Referenced by restore(), and restoreData().
|
private |
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().
|
staticinherited |
Definition at line 51 of file RestartableDataIO.C.
Referenced by RestartableDataIO::restartableDataFolder().
|
inline |
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.
|
private |
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.
|
static |
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().
|
inline |
Definition at line 55 of file RestartableDataReader.h.
Referenced by MooseApp::finalizeRestore().
|
private |
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().
|
inherited |
Get the PerfGraph.
Definition at line 78 of file PerfGraphInterface.C.
Referenced by CommonOutputAction::act(), PerfGraphData::finalize(), and PerfGraphOutput::output().
|
private |
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().
|
private |
Internal method for reading the header (stored by RestartableDataWriter)
Definition at line 75 of file RestartableDataReader.C.
Referenced by restore().
|
protectedinherited |
Call to register a named section for timing.
section_name | The name of the code section to be timed |
level | The importance of the timer - lower is more important (0 will always come out) |
Definition at line 53 of file PerfGraphInterface.C.
|
protectedinherited |
Call to register a named section for timing.
section_name | The name of the code section to be timed |
level | The importance of the timer - lower is more important (0 will always come out) |
live_message | The message to be printed to the screen during execution |
print_dots | Whether or not progress dots should be printed for this section |
Definition at line 64 of file PerfGraphInterface.C.
|
private |
Checks whether or not we're currently restoring and errors if not.
Definition at line 332 of file RestartableDataReader.C.
Referenced by queryHeader().
|
staticinherited |
Definition at line 58 of file RestartableDataIO.C.
Referenced by isAvailable(), RestartableDataIO::restartableDataFile(), setInput(), and RestartableDataWriter::write().
|
staticinherited |
folder_base
Does not append .rd to the folder base
Definition at line 80 of file RestartableDataIO.C.
|
staticinherited |
folder_base
This just appends .rd
Definition at line 72 of file RestartableDataIO.C.
Referenced by MooseApp::metaDataFolderBase(), and MooseApp::restartFolderBase().
|
staticinherited |
Definition at line 65 of file RestartableDataIO.C.
Referenced by RestartableDataIO::restartableHeaderFile(), setInput(), and RestartableDataWriter::write().
|
staticinherited |
folder_base
Does not append .rd to the folder base
Definition at line 86 of file RestartableDataIO.C.
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()!
filter_names | A 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().
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.
data_name | The name of the data |
tid | The thread |
context | The data context (if any) |
args | Arguments to forward to the constructor of the object |
Definition at line 220 of file RestartableDataReader.h.
|
private |
Internal method for restoring a new data value.
Definition at line 353 of file RestartableDataReader.C.
|
inline |
Definition at line 104 of file RestartableDataReader.h.
Referenced by MooseApp::possiblyLoadRestartableMetaData().
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().
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.
|
protectedinherited |
section_name
.Optionally adds a prefix if one is defined.
Definition at line 47 of file PerfGraphInterface.C.
Referenced by PerfGraphInterface::registerTimedSection().
|
staticinherited |
Definition at line 16 of file PerfGraphInterface.C.
Referenced by Convergence::validParams().
|
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().
|
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().
|
private |
Whether or not to forcefully attempt to read despite incompatibilities.
Definition at line 215 of file RestartableDataReader.h.
Referenced by readHeader().
|
private |
The loaded headers from the restart.
Definition at line 206 of file RestartableDataReader.h.
Referenced by clear(), queryHeader(), and restore().
|
private |
Whether or not we're currently restoring.
Definition at line 209 of file RestartableDataReader.h.
Referenced by clear(), requireRestoring(), and restore().
|
protectedinherited |
The MooseApp that owns the PerfGraph.
Definition at line 124 of file PerfGraphInterface.h.
Referenced by PerfGraphInterface::perfGraph().
|
protectedinherited |
A prefix to use for all sections.
Definition at line 127 of file PerfGraphInterface.h.
Referenced by PerfGraphInterface::timedSectionName().
|
private |
The inputs for reading.
Definition at line 203 of file RestartableDataReader.h.
Referenced by clear(), isRestoring(), requireRestoring(), restore(), restoreData(), and setInput().
|
staticprotectedinherited |
The current version for the backup file.
Definition at line 82 of file RestartableDataIO.h.
Referenced by readHeader(), and RestartableDataWriter::write().