Skip to content
Snippets Groups Projects
Commit acca8a5f authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

Merge branch 'feature/checkpoint' into develop-threaded-fftw

parents 691741cf 4650c10c
Branches
Tags
2 merge requests!21Bugfix/nansampling,!3Bugfix/event manager show html
......@@ -52,15 +52,16 @@ class NSVorticityEquation(_fluid_particle_base):
simname = simname,
dtype = fluid_precision,
use_fftw_wisdom = use_fftw_wisdom)
self.parameters['nu'] = 0.1
self.parameters['nu'] = float(0.1)
self.parameters['fmode'] = 1
self.parameters['famplitude'] = 0.5
self.parameters['fk0'] = 2.0
self.parameters['fk1'] = 4.0
self.parameters['famplitude'] = float(0.5)
self.parameters['fk0'] = float(2.0)
self.parameters['fk1'] = float(4.0)
self.parameters['forcing_type'] = 'linear'
self.parameters['histogram_bins'] = 256
self.parameters['max_velocity_estimate'] = 1.0
self.parameters['max_vorticity_estimate'] = 1.0
self.parameters['histogram_bins'] = int(256)
self.parameters['max_velocity_estimate'] = float(1)
self.parameters['max_vorticity_estimate'] = float(1)
self.parameters['checkpoints_per_file'] = int(1)
self.file_datasets_grow = """
//begincpp
hid_t group;
......@@ -72,15 +73,7 @@ class NSVorticityEquation(_fluid_particle_base):
self.style = {}
self.statistics = {}
self.fluid_output = """
{
char file_name[512];
fs->fill_up_filename("cvorticity", file_name);
fs->cvorticity->io(
file_name,
"vorticity",
fs->iteration,
false);
}
fs->io_checkpoint(false);
"""
# vorticity_equation specific things
self.includes += '#include "vorticity_equation.hpp"\n'
......@@ -206,6 +199,22 @@ class NSVorticityEquation(_fluid_particle_base):
'fs->rvorticity->get_rdata()',
data_type = field_H5T)
self.stat_src += '}\n'
## checkpoint
self.stat_src += """
//begincpp
if (myrank == 0)
{
std::string fname = (
std::string("stop_") +
std::string(simname));
{
struct stat file_buffer;
stop_code_now = (stat(fname.c_str(), &file_buffer) == 0);
}
}
MPI_Bcast(&stop_code_now, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD);
//endcpp
"""
return None
def fill_up_fluid_code(self):
self.fluid_includes += '#include <cstring>\n'
......@@ -224,6 +233,43 @@ class NSVorticityEquation(_fluid_particle_base):
field_H5T = 'H5T_NATIVE_FLOAT'
elif self.dtype == np.float64:
field_H5T = 'H5T_NATIVE_DOUBLE'
self.variables += 'int checkpoint;\n'
self.variables += 'bool stop_code_now;\n'
self.read_checkpoint = """
//begincpp
if (myrank == 0)
{
hid_t dset = H5Dopen(stat_file, "checkpoint", H5P_DEFAULT);
H5Dread(
dset,
H5T_NATIVE_INT,
H5S_ALL,
H5S_ALL,
H5P_DEFAULT,
&checkpoint);
H5Dclose(dset);
}
MPI_Bcast(&checkpoint, 1, MPI_INT, 0, MPI_COMM_WORLD);
fs->checkpoint = checkpoint;
//endcpp
"""
self.store_checkpoint = """
//begincpp
checkpoint = fs->checkpoint;
if (myrank == 0)
{
hid_t dset = H5Dopen(stat_file, "checkpoint", H5P_DEFAULT);
H5Dwrite(
dset,
H5T_NATIVE_INT,
H5S_ALL,
H5S_ALL,
H5P_DEFAULT,
&checkpoint);
H5Dclose(dset);
}
//endcpp
"""
self.fluid_start += """
//begincpp
char fname[512];
......@@ -240,6 +286,7 @@ class NSVorticityEquation(_fluid_particle_base):
nx, ny, nz,
MPI_COMM_WORLD,
{1});
fs->checkpoints_per_file = checkpoints_per_file;
fs->nu = nu;
fs->fmode = fmode;
fs->famplitude = famplitude;
......@@ -247,31 +294,29 @@ class NSVorticityEquation(_fluid_particle_base):
fs->fk1 = fk1;
strncpy(fs->forcing_type, forcing_type, 128);
fs->iteration = iteration;
{{
char file_name[512];
fs->fill_up_filename("cvorticity", file_name);
fs->cvorticity->real_space_representation = false;
fs->cvorticity->io(
file_name,
"vorticity",
fs->iteration,
true);
#if (__GNUC_MINOR__ <= 7)
fs->kk->low_pass<{0}, THREE>(fs->cvorticity->get_cdata(), fs->kk->kM);
fs->kk->force_divfree<{0}>(fs->cvorticity->get_cdata());
#else
fs->kk->template low_pass<{0}, THREE>(fs->cvorticity->get_cdata(), fs->kk->kM);
fs->kk->template force_divfree<{0}>(fs->cvorticity->get_cdata());
#endif
}}
{2}
fs->cvorticity->real_space_representation = false;
fs->io_checkpoint();
//endcpp
""".format(self.C_dtype, self.fftw_plan_rigor, field_H5T)
""".format(
self.C_dtype,
self.fftw_plan_rigor,
self.read_checkpoint)
self.fluid_start += self.store_kspace
self.fluid_start += 'stop_code_now = false;\n'
self.fluid_loop = 'fs->step(dt);\n'
self.fluid_loop += ('if (fs->iteration % niter_out == 0)\n{\n' +
self.fluid_output + '\n}\n')
self.fluid_output +
self.store_checkpoint +
'\n}\n' +
'if (stop_code_now){\n' +
'iteration = fs->iteration;\n' +
'break;\n}\n')
self.fluid_end = ('if (fs->iteration % niter_out != 0)\n{\n' +
self.fluid_output + '\n}\n' +
self.fluid_output +
self.store_checkpoint +
'DEBUG_MSG("checkpoint value is %d\\n", checkpoint);\n' +
'\n}\n' +
'delete fs;\n' +
'delete tmp_vec_field;\n' +
'delete tmp_scal_field;\n')
......@@ -492,6 +537,7 @@ class NSVorticityEquation(_fluid_particle_base):
self.parameters['histogram_bins'],
4),
dtype = np.int64)
ofile['checkpoint'] = int(0)
return None
def specific_parser_arguments(
self,
......@@ -586,25 +632,23 @@ class NSVorticityEquation(_fluid_particle_base):
self.write_par()
init_condition_file = os.path.join(
self.work_dir,
self.simname + '_cvorticity_i{0:0>5x}.h5'.format(0))
self.simname + '_checkpoint_0.h5')
if not os.path.exists(init_condition_file):
f = h5py.File(init_condition_file, 'w')
if len(opt.src_simname) > 0:
src_file = os.path.join(
os.path.realpath(opt.src_work_dir),
opt.src_simname + '_cvorticity_i{0:0>5x}.h5'.format(opt.src_iteration))
f = h5py.File(init_condition_file, 'w')
f['vorticity/complex/{0}'.format(0)] = h5py.ExternalLink(
src_file,
'vorticity/complex/{0}'.format(opt.src_iteration))
f.close()
else:
data = self.generate_vector_field(
write_to_file = False,
spectra_slope = 2.0,
amplitude = 0.05)
f = h5py.File(init_condition_file, 'w')
f['vorticity/complex/{0}'.format(0)] = data
f.close()
f.close()
self.run(
nb_processes = opt.nb_processes,
nb_threads_per_process = opt.nb_threads_per_process,
......
......@@ -118,8 +118,15 @@ class _code(_base):
sprintf(fname, "%s.h5", simname);
parameter_file = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT);
Cdset = H5Dopen(parameter_file, "iteration", H5P_DEFAULT);
H5Dread(Cdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &iteration);
DEBUG_MSG("simname is %s and iteration is %d\\n", simname, iteration);
H5Dread(
Cdset,
H5T_NATIVE_INT,
H5S_ALL,
H5S_ALL,
H5P_DEFAULT,
&iteration);
DEBUG_MSG("simname is %s and iteration is %d\\n",
simname, iteration);
H5Dclose(Cdset);
H5Fclose(parameter_file);
read_parameters();
......
......@@ -46,6 +46,58 @@ void vorticity_equation<rnumber, be>::impose_zero_modes()
this->v[2]->impose_zero_mode();
}
template <class rnumber,
field_backend be>
void vorticity_equation<rnumber, be>::update_checkpoint()
{
std::string fname = this->get_current_fname();
bool file_exists = false;
{
struct stat file_buffer;
file_exists = (stat(fname.c_str(), &file_buffer) == 0);
}
if (file_exists)
{
// check how many fields there are in the checkpoint file
// increment checkpoint if needed
hsize_t fields_stored;
hid_t fid, group_id;
fid = H5Fopen(fname.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
group_id = H5Gopen(fid, "vorticity/complex", H5P_DEFAULT);
H5Gget_num_objs(
group_id,
&fields_stored);
H5Gclose(group_id);
H5Fclose(fid);
if (fields_stored >= this->checkpoints_per_file)
this->checkpoint++;
}
else if (this->cvelocity->myrank == 0)
{
// create file, create fields_stored dset
hid_t fid = H5Fcreate(
fname.c_str(),
H5F_ACC_EXCL,
H5P_DEFAULT,
H5P_DEFAULT);
hid_t gg = H5Gcreate(
fid,
"vorticity",
H5P_DEFAULT,
H5P_DEFAULT,
H5P_DEFAULT);
hid_t ggg = H5Gcreate(
gg,
"complex",
H5P_DEFAULT,
H5P_DEFAULT,
H5P_DEFAULT);
H5Gclose(ggg);
H5Gclose(gg);
H5Fclose(fid);
}
}
template <class rnumber,
field_backend be>
vorticity_equation<rnumber, be>::vorticity_equation(
......@@ -63,6 +115,7 @@ vorticity_equation<rnumber, be>::vorticity_equation(
strncpy(this->name, NAME, 256);
this->name[255] = '\0';
this->iteration = 0;
this->checkpoint = 0;
/* initialize fields */
this->cvorticity = new field<rnumber, be, THREE>(
......
......@@ -22,6 +22,7 @@
* *
**********************************************************************/
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
......@@ -52,6 +53,8 @@ class vorticity_equation
/* iteration */
int iteration;
int checkpoint;
int checkpoints_per_file;
/* fields */
field<rnumber, be, THREE> *cvorticity, *cvelocity;
......@@ -91,10 +94,37 @@ class vorticity_equation
void compute_vorticity(void);
void compute_velocity(field<rnumber, be, THREE> *vorticity);
/* binary I/O stuff */
inline void fill_up_filename(const char *base_name, char *full_name)
/* I/O stuff */
inline std::string get_current_fname()
{
sprintf(full_name, "%s_%s_i%.5x.h5", this->name, base_name, this->iteration);
return (
std::string(this->name) +
std::string("_checkpoint_") +
std::to_string(this->checkpoint) +
std::string(".h5"));
}
void update_checkpoint(void);
inline void io_checkpoint(bool read = true)
{
assert(!this->cvorticity->real_space_representation);
if (!read)
this->update_checkpoint();
std::string fname = this->get_current_fname();
this->cvorticity->io(
fname,
"vorticity",
this->iteration,
read);
if (read)
{
#if (__GNUC_MAJOR__ <= 4 && __GNUC_MINOR__ <= 7)
this->kk->low_pass<rnumber, THREE>(this->cvorticity->get_cdata(), this->kk->kM);
this->kk->force_divfree<rnumber>(this->cvorticity->get_cdata());
#else
this->kk->template low_pass<rnumber, THREE>(this->cvorticity->get_cdata(), this->kk->kM);
this->kk->template force_divfree<rnumber>(this->cvorticity->get_cdata());
#endif
}
}
/* statistics and general postprocessing */
......
......@@ -55,5 +55,5 @@ if __name__ == '__main__':
c.write_src()
c.write_par()
c.set_host_info(bfps.host_info)
c.run(ncpu = opt.ncpu)
c.run(opt.ncpu, 1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment