7#if __has_include (<filesystem>)
9namespace filesys_ns = std::filesystem;
11#elif __has_include (<experimental/filesystem>)
12#include <experimental/filesystem>
13namespace filesys_ns = std::experimental::filesystem;
16static_assert(0,
"Neither <filesystem> nor <experimental/filesystem> found!");
27template <
typename group>
28void checkpoint(
const GaugeField<group> &U,
const std::string &config_file,
int &n_trajectories,
29 int trajectory,
bool save_old =
true) {
33 if (save_old &&
hila::myrank() == 0 && filesys_ns::exists(config_file)) {
34 filesys_ns::rename(config_file, config_file +
".prev");
44 if (status.
open(
"run_status",
false,
false)) {
45 int ntraj = status.
get(
"trajectories");
46 if (ntraj != n_trajectories) {
47 hila::out0 <<
"* NUMBER OF TRAJECTORIES " << n_trajectories <<
" -> " << ntraj <<
'\n';
49 n_trajectories = ntraj;
54 std::fstream statfile;
55 statfile.open(
"run_status", std::ios::in);
58 outf.open(
"run_status", std::ios::out | std::ios::trunc);
59 outf <<
"trajectories " << n_trajectories
60 <<
" # CHANGE TO ADJUST NUMBER OF TRAJECTORIES IN THIS RUN\n";
61 outf <<
"trajectory " << trajectory + 1 <<
'\n';
62 outf <<
"seed " <<
static_cast<uint64_t
>(
hila::random() * (1UL << 61)) <<
'\n';
66 std::stringstream msg;
68 hila::timestamp(msg.str());
71template <
typename group>
72bool restore_checkpoint(
GaugeField<group> &U,
const std::string &config_file,
int &n_trajectories,
77 if (status.
open(
"run_status",
false,
false)) {
79 int traj = status.
get(
"trajectories");
80 if (traj != n_trajectories) {
81 hila::out0 <<
"Number of trajectories set in 'run_status' " << n_trajectories
82 <<
" -> " << traj <<
'\n';
83 n_trajectories = traj;
86 trajectory = status.
get(
"trajectory");
87 seed = status.
get(
"seed");
93 U.config_read(config_file);
98 bool exists =
hila::myrank() == 0 && filesys_ns::exists(config_file);
102 U.config_read(config_file);
void config_write(const std::string &filename) const
config_write writes the gauge field to file, with additional "verifying" header
int myrank()
rank of this node
double random()
Real valued uniform random number generator.
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...
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).