class Checkpoint

Save the state of a class in memory by writing to disk, such that the checkpoint file can be later read to restart the simulation. Note that for OMP or parallel simulations, the number of hours is multiplied by the number of threads.

Public Functions

double num_hours() const

Return number of hours between writing file.

template<typename T>
void write(const T &obj, const std::string append_backup = ".bak") const

Write the checkpoint to file. If the file exists, create backup.

template<typename T>
void check(const T &obj)

Write object to checkpoint_file if num_hours has passed since previous.

template<typename T>
void read(T *obj)

Initialize object by reading from file.

void serialize(std::ostream &ostr) const

Serialize object.

Checkpoint(std::istream &istr)

Deserialize object.


  • num_hours: Number of hours between printing of checkpoint file (default: 1).

  • num_hours_terminate: Terminate after this many hours. If -1, do not terminate (default: -1). Termination may be detected in Bash shell using “$? != 0”.

  • checkpoint_file: The default is one space (e.g., ” “). Do not checkpoint if checkpoint_file is empty or is one space.

  • writes_per_backup: Create a unique checkpoint file name every this many times that a checkpoint is written (default: -1). If -1, only backup the previous file by appending its name with “.bak”. Otherwise, if > 0, append each backup with an integer count beginning with 0.