HILA
Loading...
Searching...
No Matches
src/checkpoint.h
1#ifndef CHECKPOINT_H
2#define CHECKPOINT_H
3
4#include "hila.h"
5#include "parameters.h"
6
7template <typename group>
8void checkpoint(const GaugeField<group> &U, int iteration, const parameters &p) {
9
10 double t = hila::gettime();
11 // save config
12 U.config_write(p.config_file);
13
14 // write run_status file
15 if (hila::myrank() == 0) {
16 std::ofstream outf;
17 outf.open("run_status", std::ios::out | std::ios::trunc);
18 outf << "iteration " << iteration + 1 << '\n';
19 outf << "seed " << static_cast<uint64_t>(hila::random() * (1UL << 61)) << '\n';
20 outf << "time " << hila::gettime() << '\n';
21 outf.close();
22 }
23
24 std::stringstream msg;
25 msg << "Checkpointing, time " << hila::gettime() - t;
26 hila::timestamp(msg.str().c_str());
27}
28
29template <typename group>
30bool restore_checkpoint(GaugeField<group> &U, int &trajectory, parameters &p) {
31
32 uint64_t seed;
33 bool ok = true;
34 p.time_offset = 0;
35
36 hila::input status;
37 if (status.open("run_status", false, false)) {
38
39 hila::out0 << "RESTORING FROM CHECKPOINT:\n";
40
41 trajectory = status.get("iteration");
42 seed = status.get("seed");
43 p.time_offset = status.get("time");
44 status.close();
45
47
48 U.config_read(p.config_file);
49
50 ok = true;
51 } else {
52
53 std::ifstream in;
54 in.open(p.config_file, std::ios::in | std::ios::binary);
55
56 if (in.is_open()) {
57 in.close();
58
59 hila::out0 << "READING initial config\n";
60
61 U.config_read(p.config_file);
62
63 ok = true;
64 } else {
65
66 ok = false;
67 }
68 }
69
70 return ok;
71}
72
73#endif
Gauge field class.
Definition gaugefield.h:22
void config_write(const std::string &filename) const
config_write writes the gauge field to file, with additional "verifying" header
Definition gaugefield.h:155
hila::input - Class for parsing runtime parameter files.
Definition input.h:52
void close()
Closes input parameter file.
Definition input.cpp:79
returntype get(const std::string &key)
Get next value in stack of read in input string from parameters file.
Definition input.h:269
bool open(const std::string &fname, bool use_cmdline=true, bool exit_on_error=true)
Open file that parameters are read from.
Definition input.cpp:22
int myrank()
rank of this node
Definition com_mpi.cpp:235
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:120
std::ostream out0
This writes output only from main process (node 0)
void seed_random(uint64_t seed, bool device_rng=true)
Seed random generators with 64-bit unsigned value. On MPI shuffles the seed so that different MPI ran...
Definition random.cpp:86
double gettime()
Definition timing.cpp:163