Commit 6ddcee26 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

Merge branch 'bugfix/kraichnan_checkpointing' into develop

parents 82f9568b 93bfe5a8
Pipeline #67559 passed with stage
in 12 minutes and 12 seconds
...@@ -104,26 +104,17 @@ int kraichnan_field<rnumber>::initialize(void) ...@@ -104,26 +104,17 @@ int kraichnan_field<rnumber>::initialize(void)
DEBUG_MSG("Coefficient: %g\n", DEBUG_MSG("Coefficient: %g\n",
this->spectrum_coefficient); this->spectrum_coefficient);
this->generate_random_velocity();
// is this the first iteration? // is this the first iteration?
if ((this->iteration == 0) and (this->output_velocity == 1)) if ((this->iteration == 0) and (this->output_velocity == 1))
{ {
// if yes, generate random field and save it // if yes, generate random field and save it
this->generate_random_velocity();
this->velocity->io( this->velocity->io(
this->get_current_fname(), this->get_current_fname(),
"velocity", "velocity",
this->iteration, this->iteration,
false); false);
} }
else
{
// if not, read the random field that exists in the checkpoint file
this->velocity->io(
this->get_current_fname(),
"velocity",
this->iteration,
true);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
...@@ -336,14 +327,23 @@ void kraichnan_field<rnumber>::update_checkpoint() ...@@ -336,14 +327,23 @@ void kraichnan_field<rnumber>::update_checkpoint()
hsize_t fields_stored; hsize_t fields_stored;
hid_t fid, group_id; hid_t fid, group_id;
fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT); fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
group_id = H5Gopen(fid, "velocity/real", H5P_DEFAULT); group_id = H5Gopen(fid, "tracers0/state", H5P_DEFAULT);
H5Gget_num_objs( bool dset_exists;
if (group_id > 0)
{
H5Gget_num_objs(
group_id, group_id,
&fields_stored); &fields_stored);
bool dset_exists = H5Lexists( dset_exists = H5Lexists(
group_id, group_id,
std::to_string(this->iteration).c_str(), std::to_string(this->iteration).c_str(),
H5P_DEFAULT); H5P_DEFAULT);
}
else
{
fields_stored = 0;
dset_exists = false;
}
H5Gclose(group_id); H5Gclose(group_id);
H5Fclose(fid); H5Fclose(fid);
if ((int(fields_stored) >= this->checkpoints_per_file) && if ((int(fields_stored) >= this->checkpoints_per_file) &&
...@@ -360,13 +360,13 @@ void kraichnan_field<rnumber>::update_checkpoint() ...@@ -360,13 +360,13 @@ void kraichnan_field<rnumber>::update_checkpoint()
H5P_DEFAULT); H5P_DEFAULT);
hid_t gg = H5Gcreate( hid_t gg = H5Gcreate(
fid, fid,
"velocity", "tracers0",
H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT); H5P_DEFAULT);
hid_t ggg = H5Gcreate( hid_t ggg = H5Gcreate(
gg, gg,
"real", "state",
H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT); H5P_DEFAULT);
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <hdf5.h> #include <hdf5.h>
#include <sys/stat.h>
#include "abstract_particles_output.hpp" #include "abstract_particles_output.hpp"
#include "scope_timer.hpp" #include "scope_timer.hpp"
...@@ -140,10 +141,23 @@ public: ...@@ -140,10 +141,23 @@ public:
if(Parent::isInvolved()){ if(Parent::isInvolved()){
if (Parent::getMyRank() == 0) if (Parent::getMyRank() == 0)
{ {
hid_t file_id = H5Fopen( bool file_exists = false;
{
struct stat file_buffer;
file_exists = (stat(filename.c_str(), &file_buffer) == 0);
}
hid_t file_id;
if (file_exists)
file_id = H5Fopen(
filename.c_str(), filename.c_str(),
H5F_ACC_RDWR | H5F_ACC_DEBUG, H5F_ACC_RDWR | H5F_ACC_DEBUG,
H5P_DEFAULT); H5P_DEFAULT);
else
file_id = H5Fcreate(
filename.c_str(),
H5F_ACC_EXCL | H5F_ACC_DEBUG,
H5P_DEFAULT,
H5P_DEFAULT);
assert(file_id >= 0); assert(file_id >= 0);
bool group_exists = H5Lexists( bool group_exists = H5Lexists(
file_id, file_id,
......
Supports Markdown
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