FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
FEAT::Control::CheckpointControl Class Reference

Checkpoint/Restart infrastructure. More...

#include <checkpoint_control.hpp>

Public Member Functions

 CheckpointControl (const Dist::Comm &comm, const LAFEM::SerialConfig &config=LAFEM::SerialConfig())
 Constructor. More...
 
 ~CheckpointControl ()
 Destructor. More...
 
template<typename OT_ >
void add_object (String identifier, OT_ &object)
 Register checkpointable object. More...
 
void clear_input ()
 Delete all read input. More...
 
String get_identifier_list ()
 Retrieve a list of all items stored in the checkpoint. More...
 
void load (BinaryStream &bs)
 Load checkpoint from stream. More...
 
void load (const String filename)
 Load checkpoint from disk. More...
 
void remove_object (String identifier)
 Remove checkpointable object. More...
 
template<typename OT_ >
void restore_object (String identifier, OT_ &object, bool add_to_checkpoint_control=true)
 Restore checkpointable object. More...
 
void save (BinaryStream &bs)
 Save checkpoint to a stream. More...
 
void save (const String filename)
 Write checkpoint file to disk. More...
 
void set_config (FEAT::LAFEM::SerialConfig &conf)
 Set a new serialize configuration. More...
 

Private Member Functions

std::uint64_t _collect_checkpoint_data (std::vector< char > &buffer)
 Build checkpoint buffer. More...
 
void _load (const String name)
 Load checkpoint from disk. More...
 
void _restore_checkpoint_data ()
 Extract input buffer. More...
 
void _save (const String name)
 Write checkpoint files to disk. More...
 

Private Attributes

std::map< String, std::shared_ptr< Checkpointable > > _checkpointable_by_identifier
 Mapping of identifier string to pointer to the checkpointable object. More...
 
const Dist::Comm_comm
 the mpi communicator identifying our mpi context More...
 
FEAT::LAFEM::SerialConfig _config
 The config class that controls the compression modes. More...
 
std::vector< char > _input_array
 Vector holding the array read from the input file during restore. More...
 
std::map< String, std::uint64_t > _offset_by_identifier
 Mapping of identifier string to the offset in the input file. More...
 

Detailed Description

Checkpoint/Restart infrastructure.

This class provides a general interface for checkpoint/restart usecases. Compatible objects can be summed up to a single checkpoint. This checkpoint can then be stored and restored via mpi io mechanics. Afterwards, any object can be restored from the recreated checkpoint.

Note
The checkpoint control class object is used on a per rank basis. The contents of all ranks objects will be written into one single file. Later on, the loaded objects will, again, be local objects in every rank with distinct contents.
Todo:
do we need extra handling for machines with no global acessible file servers?

Definition at line 140 of file checkpoint_control.hpp.

Constructor & Destructor Documentation

◆ CheckpointControl()

FEAT::Control::CheckpointControl::CheckpointControl ( const Dist::Comm comm,
const LAFEM::SerialConfig config = LAFEM::SerialConfig() 
)
inline

Constructor.

Initalize the input array as NULL pointer.

Parameters
[in]commThe communicator common to all stored objects
[in]configA config class, controlling the compression of the written out data

Definition at line 280 of file checkpoint_control.hpp.

References _input_array.

◆ ~CheckpointControl()

FEAT::Control::CheckpointControl::~CheckpointControl ( )
inline

Destructor.

Destroy the checkpoint control instance and delete the input array.

Definition at line 292 of file checkpoint_control.hpp.

Member Function Documentation

◆ _collect_checkpoint_data()

std::uint64_t FEAT::Control::CheckpointControl::_collect_checkpoint_data ( std::vector< char > &  buffer)
inlineprivate

Build checkpoint buffer.

Collect all data needed for a checkpoint from every object registered at the checkpoint control.

Parameters
[in]bufferbuffer containing the collected data
Returns
the size of the buffer

Definition at line 163 of file checkpoint_control.hpp.

References _checkpointable_by_identifier, and _config.

Referenced by _save(), and save().

◆ _load()

void FEAT::Control::CheckpointControl::_load ( const String  name)
inlineprivate

Load checkpoint from disk.

Read binary file [name].cp holding a safed state of all checkpointable objects and store it to _input_array.

Fill the _offset_by_identifier map with the data from the array.

Parameters
[in]nameString holding the name of the file (without the extension .zcp)
Warning
Reading another input file / stream will overwrite values in _input_array and _offset_by_identifier

Definition at line 260 of file checkpoint_control.hpp.

References _comm, _input_array, _restore_checkpoint_data(), and FEAT::DistFileIO::read_combined().

Referenced by load().

◆ _restore_checkpoint_data()

void FEAT::Control::CheckpointControl::_restore_checkpoint_data ( )
inlineprivate

Extract input buffer.

Extract the identifier string and offset for its data in the input array for every object in the read checkpoint, and store this information for restoration in this checkpoint control object.

Definition at line 208 of file checkpoint_control.hpp.

References _input_array, and _offset_by_identifier.

Referenced by _load(), and load().

◆ _save()

void FEAT::Control::CheckpointControl::_save ( const String  name)
inlineprivate

Write checkpoint files to disk.

Write one binary file: [name].cp: a uncompressed binary file holding the current status of all checkpointable objects added to the checkpoint control

Parameters
[in]nameString holding the name of the file (without the extension .cp)

Definition at line 240 of file checkpoint_control.hpp.

References _collect_checkpoint_data(), _comm, and FEAT::DistFileIO::write_combined().

Referenced by save().

◆ add_object()

template<typename OT_ >
void FEAT::Control::CheckpointControl::add_object ( String  identifier,
OT_ &  object 
)
inline

Register checkpointable object.

Adds a pointer to a checkpointable object to the checkpoint control.

The object will be internally identified by its indentifier string (especially during restoration).

Parameters
[in]identifierString used as identifier
[in]objectPointer to the checkpointable object

Definition at line 346 of file checkpoint_control.hpp.

References _checkpointable_by_identifier, and XASSERTM.

Referenced by restore_object().

◆ clear_input()

void FEAT::Control::CheckpointControl::clear_input ( )
inline

Delete all read input.

Clear the input read before from this checkpoint control object. Does not touch the map holding the pointers to the checkpointable objects included into the following written checkpoints.

Definition at line 313 of file checkpoint_control.hpp.

References _input_array, and _offset_by_identifier.

◆ get_identifier_list()

String FEAT::Control::CheckpointControl::get_identifier_list ( )
inline

Retrieve a list of all items stored in the checkpoint.

Definition at line 320 of file checkpoint_control.hpp.

References _checkpointable_by_identifier.

◆ load() [1/2]

void FEAT::Control::CheckpointControl::load ( BinaryStream bs)
inline

Load checkpoint from stream.

Read the BinaryStream, to restore the safed state of all objects registered to the checkpoint control and store it to _input_array.

Fill the _offset_by_identifier map with the data from the array.

Parameters
[in]bsBinaryStream that shall be read from
Warning
Reading another input file / stream will overwrite values in _input_array and _offset_by_identifier

Definition at line 488 of file checkpoint_control.hpp.

References _input_array, _restore_checkpoint_data(), FEAT::BinaryStream::data(), and XASSERTM.

◆ load() [2/2]

void FEAT::Control::CheckpointControl::load ( const String  filename)
inline

Load checkpoint from disk.

Read the [filename.cp] file, to restore the size of the checkpoint data per rank.

Read binary file [filename] holding a safed state of all checkpointable objects and store it to _input_array.

Fill the _offset_by_identifier map with the data from the array.

Parameters
[in]filenameString holding the name of the file
Warning
Reading another input file / stream will overwrite values in _input_array and _offset_by_identifier

Definition at line 440 of file checkpoint_control.hpp.

References _input_array, _load(), XABORTM, and XASSERTM.

◆ remove_object()

void FEAT::Control::CheckpointControl::remove_object ( String  identifier)
inline

Remove checkpointable object.

Remove pointer to a checkpointable object from the checkpoint control.

Parameters
[in]identifierIdentifier of the object to remove

Definition at line 361 of file checkpoint_control.hpp.

References _checkpointable_by_identifier, and XASSERTM.

◆ restore_object()

template<typename OT_ >
void FEAT::Control::CheckpointControl::restore_object ( String  identifier,
OT_ &  object,
bool  add_to_checkpoint_control = true 
)
inline

Restore checkpointable object.

Restore a checkpointable object from the checkpoint control. The objects contents will be found by its identifier string and restored.

Parameters
[in]identifierIdentifier of the object to restore
[out]objectReference to object
[in]add_to_checkpoint_controlIf true the restored object is added to the checkpoint control, default true
Warning
The user has to load an input file before and has to ensure proper size/data/whatsover type layout.

Definition at line 380 of file checkpoint_control.hpp.

References _input_array, _offset_by_identifier, add_object(), and XASSERTM.

◆ save() [1/2]

void FEAT::Control::CheckpointControl::save ( BinaryStream bs)
inline

Save checkpoint to a stream.

Save a checkpoint, holding the current status of all registered objects, in a BinaryStream

Parameters
[in]bsBinaryStream that shall be written to

Definition at line 467 of file checkpoint_control.hpp.

References _collect_checkpoint_data().

◆ save() [2/2]

void FEAT::Control::CheckpointControl::save ( const String  filename)
inline

Write checkpoint file to disk.

Write one uncompressed binary file: filename: [name.cp]: holding the current status of all checkpointable objects added to the checkpoint control

Parameters
[in]filenameString holding the complete name of the file with extension .cp

Definition at line 407 of file checkpoint_control.hpp.

References _save(), and XASSERTM.

◆ set_config()

void FEAT::Control::CheckpointControl::set_config ( FEAT::LAFEM::SerialConfig conf)
inline

Set a new serialize configuration.

Parameters
[in]confLAFEM::SerialConfig, a config class holding information about the compression parameters.

Set a new SerialConfig object.

Definition at line 303 of file checkpoint_control.hpp.

References _config.

Member Data Documentation

◆ _checkpointable_by_identifier

std::map<String, std::shared_ptr<Checkpointable> > FEAT::Control::CheckpointControl::_checkpointable_by_identifier
private

Mapping of identifier string to pointer to the checkpointable object.

Definition at line 144 of file checkpoint_control.hpp.

Referenced by _collect_checkpoint_data(), add_object(), get_identifier_list(), and remove_object().

◆ _comm

const Dist::Comm& FEAT::Control::CheckpointControl::_comm
private

the mpi communicator identifying our mpi context

Definition at line 150 of file checkpoint_control.hpp.

Referenced by _load(), and _save().

◆ _config

FEAT::LAFEM::SerialConfig FEAT::Control::CheckpointControl::_config
private

The config class that controls the compression modes.

Definition at line 152 of file checkpoint_control.hpp.

Referenced by _collect_checkpoint_data(), and set_config().

◆ _input_array

std::vector<char> FEAT::Control::CheckpointControl::_input_array
private

Vector holding the array read from the input file during restore.

Definition at line 146 of file checkpoint_control.hpp.

Referenced by CheckpointControl(), _load(), _restore_checkpoint_data(), clear_input(), load(), and restore_object().

◆ _offset_by_identifier

std::map<String, std::uint64_t> FEAT::Control::CheckpointControl::_offset_by_identifier
private

Mapping of identifier string to the offset in the input file.

Definition at line 148 of file checkpoint_control.hpp.

Referenced by _restore_checkpoint_data(), clear_input(), and restore_object().


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