Commit 29bb158a authored by Lukas Weber's avatar Lukas Weber

make dump reads work

parent 444aec0d
......@@ -87,13 +87,13 @@ iodump::group::iterator::iterator(hid_t group, uint64_t idx) : group_(group), id
std::string iodump::group::iterator::operator*() {
ssize_t name_size =
H5Lget_name_by_idx(group_, "/", H5_INDEX_NAME, H5_ITER_INC, idx_, nullptr, 0, H5P_DEFAULT);
H5Lget_name_by_idx(group_, ".", H5_INDEX_NAME, H5_ITER_INC, idx_, nullptr, 0, H5P_DEFAULT);
if(name_size < 0) {
throw iodump_exception{"H5Lget_name_by_idx"};
}
std::vector<char> buf(name_size + 1);
name_size = H5Lget_name_by_idx(group_, "/", H5_INDEX_NAME, H5_ITER_INC, idx_, buf.data(),
name_size = H5Lget_name_by_idx(group_, ".", H5_INDEX_NAME, H5_ITER_INC, idx_, buf.data(),
buf.size(), H5P_DEFAULT);
if(name_size < 0) {
throw iodump_exception{"H5Lget_name_by_idx"};
......
......@@ -261,6 +261,7 @@ template<class T>
void iodump::group::read(const std::string &name, T &value) const {
std::vector<T> buf;
read(name, buf);
assert(buf.size() == 1);
value = buf.at(0);
}
}
......@@ -85,7 +85,7 @@ static bool file_exists(const std::string &path) {
}
bool mc::_read(const std::string &dir) {
if(!file_exists(dir)) {
if(!file_exists(dir + ".dump.h5")) {
return false;
}
......@@ -94,8 +94,10 @@ bool mc::_read(const std::string &dir) {
iodump dump_file = iodump::open_readonly(dir + ".dump.h5");
auto g = dump_file.get_root();
measure.checkpoint_read(g.open_group("measurements"));
rng.reset(new random_number_generator());
rng->checkpoint_read(g.open_group("random_number_generator"));
measure.checkpoint_read(g.open_group("measurements"));
checkpoint_read(g.open_group("simulation"));
g.read("sweeps", sweep_);
......
......@@ -48,13 +48,12 @@ public:
}
void checkpoint_write(const iodump::group &d) {
static_cast<base *>(this)->backend_checkpoint_write(d);
d.write("seed", seed_);
d.write("type", type());
static_cast<base *>(this)->backend_checkpoint_write(d);
}
void checkpoint_read(const iodump::group &d) {
static_cast<base *>(this)->backend_checkpoint_read(d);
d.read("seed", seed_);
std::string read_type;
d.read("type", read_type);
......@@ -64,6 +63,7 @@ public:
"loadleveller was built with backend '{}'",
read_type, type()));
}
static_cast<base *>(this)->backend_checkpoint_read(d);
}
// implemented by base:
......@@ -95,11 +95,11 @@ public:
std::stringstream buf;
buf << generator_;
buf << real_dist_;
dump_file.write("rng_state", buf.str());
dump_file.write("state", buf.str());
}
void backend_checkpoint_read(const iodump::group &dump_file) {
std::string state;
dump_file.read("rng_state", state);
dump_file.read("state", state);
std::stringstream buf(state);
buf >> generator_;
buf >> real_dist_;
......
......@@ -303,6 +303,9 @@ void runner_slave::start() {
if(!sys_->_read(job_.rundir(task_id_, run_id_))) {
sys_->_init();
// checkpointing();
job_.log(fmt::format("* initialized {}", job_.rundir(task_id_, run_id_)));
} else {
job_.log(fmt::format("* read {}", job_.rundir(task_id_, run_id_)));
}
} else {
if(!sys_) {
......
......@@ -28,8 +28,12 @@ int runner_single::start() {
sys_ = std::unique_ptr<mc>{mccreator_(job_.jobfile["tasks"][job_.task_names.at(task_id_)])};
if(!sys_->_read(job_.rundir(task_id_, 1))) {
sys_->_init();
job_.log(fmt::format("* initialized {}", job_.rundir(task_id_, 1)));
} else {
job_.log(fmt::format("* read {}", job_.rundir(task_id_, 1)));
}
while(!tasks_[task_id_].is_done() && !time_is_up()) {
sys_->_do_update();
tasks_[task_id_].sweeps++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment