Commit b5b3de9b authored by Chichi Lalescu's avatar Chichi Lalescu
Browse files

put iteration in .h5 file

parent cfc81c10
......@@ -121,13 +121,13 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
fs->fk0 = fk0;
fs->fk1 = fk1;
strncpy(fs->forcing_type, forcing_type, 128);
fs->iteration = iter0;
fs->iteration = iteration;
fs->read('v', 'c');
if (myrank == 0)
{
sprintf(fname, "%s_stats.bin", simname);
stat_file = fopen(fname, "ab");
sprintf(fname, "%s_time_i%.5x", simname, iter0);
sprintf(fname, "%s_time_i%.5x", simname, iteration);
FILE *time_file = fopen(fname, "rb");
fread((void*)&t, sizeof(double), 1, time_file);
fclose(time_file);
......@@ -184,7 +184,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base):
'nparticles, neighbours{0}, smoothness{0}, integration_steps{0},\n' +
'fs->ru);\n' +
'ps{0}->dt = dt;\n' +
'ps{0}->iteration = iter0;\n' +
'ps{0}->iteration = iteration;\n' +
update_field +
'ps{0}->read();\n' +
'if (myrank == 0)\n' +
......@@ -386,9 +386,7 @@ def launch(
if opt.run:
if opt.iteration == 0 and opt.initialize:
c.generate_initial_condition()
for nrun in range(opt.njobs):
c.run(ncpu = opt.ncpu,
iter0 = opt.iteration + nrun*opt.nsteps)
c.run(ncpu = opt.ncpu, njobs = opt.njobs)
return c
def test(opt):
......
......@@ -57,13 +57,12 @@ class base(object):
+ '\n{\n'
+ 'char fname[{0}];\n'.format(self.string_length)
+ 'sprintf(fname, "%s.h5", simname);\n'
+ 'H5::H5File par_file(fname, H5F_ACC_RDONLY);\n'
+ 'H5::DataSet dset;\n'
+ 'H5::StrType strdtype(0, H5T_VARIABLE);\n'
+ 'H5::DataSpace strdspace(H5S_SCALAR);\n'
+ 'std::string tempstr;')
for i in range(len(key)):
src_txt += 'dset = par_file.openDataSet("parameters/{0}");\n'.format(key[i])
src_txt += 'dset = data_file.openDataSet("parameters/{0}");\n'.format(key[i])
if type(self.parameters[key[i]]) == int:
src_txt += 'dset.read(&{0}, H5::PredType::NATIVE_INT);\n'.format(key[i])
elif type(self.parameters[key[i]]) == str:
......@@ -100,13 +99,13 @@ class base(object):
ofile = h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'w-')
for k in self.parameters.keys():
ofile['parameters/' + k] = self.parameters[k]
ofile['iteration'] = int(0)
ofile.close()
return None
def read_parameters(self):
ifile = h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r')
for k in ifile['parameters'].keys():
self.parameters[k] = ifile['parameters/' + k].value
ifile.close()
self.data_file = h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r')
for k in self.data_file['parameters'].keys():
self.parameters[k] = self.data_file['parameters/' + k].value
return None
def get_coord(self, direction):
assert(direction == 'x' or direction == 'y' or direction == 'z')
......
......@@ -42,12 +42,15 @@ class code(base):
#include "fluid_solver.hpp"
#include <iostream>
#include <H5Cpp.h>
#include <string>
#include <fftw3-mpi.h>
//endcpp
"""
self.variables = 'int myrank, nprocs;\n'
self.variables += 'int iter0;\n'
self.variables += 'int iteration;\n'
self.variables += 'char simname[256];\n'
self.variables += ('H5::H5File data_file;\n' +
'H5::DataSet H5dset;\n')
self.definitions = ''
self.main_start = """
//begincpp
......@@ -56,7 +59,7 @@ class code(base):
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
if (argc != 3)
if (argc != 2)
{
std::cerr << "Wrong number of command line arguments. Stopping." << std::endl;
MPI_Finalize();
......@@ -65,10 +68,10 @@ class code(base):
else
{
strcpy(simname, argv[1]);
iter0 = atoi(argv[2]);
std::cerr << "myrank = " << myrank <<
", simulation name is " << simname <<
" and iter0 is " << iter0 << std::endl;
data_file.openFile(std::string(simname) + std::string(".h5"), H5F_ACC_RDWR);
H5dset = data_file.openDataSet("iteration");
H5dset.read(&iteration, H5::PredType::NATIVE_INT);
DEBUG_MSG("simname is %s and iteration is %d\\n", simname, iteration);
}
read_parameters();
//endcpp
......@@ -78,6 +81,9 @@ class code(base):
self.main_end = """
//begincpp
// clean up
H5dset = data_file.openDataSet("iteration");
H5dset.write(&iteration, H5::PredType::NATIVE_INT);
data_file.close();
fftwf_mpi_cleanup();
fftw_mpi_cleanup();
MPI_Finalize();
......@@ -128,12 +134,13 @@ class code(base):
return None
def run(self,
ncpu = 2,
iter0 = 0,
out_file = 'out_file',
err_file = 'err_file',
hours = 1,
minutes = 0,
njobs = 1):
self.read_parameters()
iter0 = self.data_file['iteration'].value
assert(self.compile_code() == 0)
current_dir = os.getcwd()
if not os.path.isdir(self.work_dir):
......@@ -148,8 +155,7 @@ class code(base):
'-np',
'{0}'.format(ncpu),
'./' + self.name,
self.simname,
'{0}'.format(iter0)]
self.simname]
if self.host_info['type'] == 'cluster':
job_name_list = []
for j in range(njobs):
......@@ -175,7 +181,6 @@ class code(base):
os.chdir(self.work_dir)
os.environ['LD_LIBRARY_PATH'] += ':{0}'.format(bfps.lib_dir)
for j in range(njobs):
command_atoms[-1] = '{0}'.format(iter0 + j*self.parameters['niter_todo'])
subprocess.call(command_atoms,
stdout = open(out_file + '_' + self.simname, 'w'),
stderr = open(err_file + '_' + self.simname, 'w'))
......
......@@ -79,7 +79,7 @@ class fluid_particle_base(bfps.code):
self.main = self.fluid_start
if self.particle_species > 0:
self.main += self.particle_start
self.main += 'for (int iteration = iter0; iteration < iter0 + niter_todo; iteration++)\n{\n'
self.main += 'for (int max_iter = iteration+niter_todo; iteration < max_iter; iteration++)\n{\n'
if self.particle_species > 0:
self.main += self.particle_loop
self.main += self.fluid_loop
......
......@@ -65,7 +65,7 @@ class fluid_converter(bfps.fluid_base.fluid_particle_base):
fluid_name,
nx, ny, nz,
dkx, dky, dkz);
fs->iteration = iter0;
fs->iteration = iteration;
do_conversion(fs);
//endcpp
"""
......
......@@ -58,7 +58,7 @@ class fluid_resize(bfps.fluid_base.fluid_particle_base):
dst_simname,
dst_nx, dst_ny, dst_nz,
dst_dkx, dst_dky, dst_dkz);
fs0->iteration = iter0;
fs0->iteration = iteration;
fs1->iteration = 0;
fs0->read('v', 'c');
double a, b;
......
......@@ -149,7 +149,6 @@ def double(opt):
opt.work_dir + '/' + old_simname, opt.iteration, opt.work_dir + '/resize', old_simname))
subprocess.call([cp_command], shell = True)
c.run(ncpu = opt.ncpu,
iter0 = opt.iteration,
err_file = 'err_' + old_simname + '_' + new_simname,
out_file = 'out_' + old_simname + '_' + new_simname)
if not os.path.isdir(os.path.join(opt.work_dir, new_simname)):
......@@ -206,7 +205,6 @@ def NSlaunch(
testing = True,
rseed = 3284)
c.run(ncpu = opt.ncpu,
iter0 = opt.iteration,
njobs = opt.njobs)
return c
......@@ -255,8 +253,7 @@ def convergence_test(opt):
converter.parameters['niter_todo'] = 0
converter.write_par()
converter.run(
ncpu = 2,
iter0 = c.parameters['niter_todo'])
ncpu = 2)
c.transpose_frame(iteration = c.parameters['niter_todo'])
# read data
c0.compute_statistics()
......@@ -460,6 +457,5 @@ if __name__ == '__main__':
c.write_src()
c.write_par()
c.set_host_info({'type' : 'pc'})
c.run(ncpu = opt.ncpu,
iter0 = opt.iteration)
c.run(ncpu = opt.ncpu)
[tox]
envlist = py27
[testenv]
whitelist_externals =
echo
cp
passenv = LD_LIBRARY_PATH
changedir =
{envtmpdir}
commands =
cp {toxinidir}/test.py {envtmpdir}
python test.py -n 32 --run --initialize --ncpu 2 --plain
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