12#if __has_include(<filesystem>)
14namespace filesys_ns = std::filesystem;
16#elif __has_include(<experimental/filesystem>)
17#include <experimental/filesystem>
18namespace filesys_ns = std::experimental::filesystem;
21static_assert(0,
"Neither <filesystem> nor <experimental/filesystem> found!");
32template <
typename group>
34 int trajectory,
bool save_old =
true) {
38 if (save_old &&
hila::myrank() == 0 && filesys_ns::exists(config_file)) {
39 filesys_ns::rename(config_file, config_file +
".prev");
49 if (status.
open(
"run_status",
false,
false)) {
50 int ntraj = status.
get(
"trajectories");
51 if (ntraj != n_trajectories) {
52 hila::out0 <<
"* NUMBER OF TRAJECTORIES " << n_trajectories <<
" -> " << ntraj <<
'\n';
54 n_trajectories = ntraj;
59 std::fstream statfile;
60 statfile.open(
"run_status", std::ios::in);
63 outf.open(
"run_status", std::ios::out | std::ios::trunc);
64 outf <<
"trajectories " << n_trajectories
65 <<
" # CHANGE TO ADJUST NUMBER OF TRAJECTORIES IN THIS RUN\n";
66 outf <<
"trajectory " << trajectory + 1 <<
'\n';
67 outf <<
"seed " <<
static_cast<uint64_t
>(
hila::random() * (1UL << 61)) <<
'\n';
71 std::stringstream msg;
73 hila::timestamp(msg.str());
76template <
typename group>
77bool restore_checkpoint(
GaugeField<group> &U,
const std::string &config_file,
int &n_trajectories,
82 if (status.
open(
"run_status",
false,
false)) {
84 int traj = status.
get(
"trajectories");
85 if (traj != n_trajectories) {
86 hila::out0 <<
"Number of trajectories set in 'run_status' " << n_trajectories <<
" -> "
88 n_trajectories = traj;
91 trajectory = status.
get(
"trajectory");
92 seed = status.
get(
"seed");
98 U.config_read(config_file);
103 bool exists =
hila::myrank() == 0 && filesys_ns::exists(config_file);
107 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
double random()
Real valued uniform random number generator.
int myrank()
rank of this node
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).