Skip to content

Commit

Permalink
Merge pull request #452 from pdziekan/record_aux_const_arrays
Browse files Browse the repository at this point in the history
add functions to record aux const arrays
  • Loading branch information
pdziekan committed Apr 24, 2020
2 parents e14cb25 + 3101cf3 commit d6c8049
Showing 1 changed file with 56 additions and 32 deletions.
88 changes: 56 additions & 32 deletions libmpdata++/output/hdf5.hpp
Expand Up @@ -48,11 +48,11 @@ namespace libmpdataxx
// HDF types of host data
const H5::FloatType
flttype_solver =
sizeof(typename solver_t::real_t) == sizeof(long double)
? H5::PredType::NATIVE_LDOUBLE
: sizeof(typename solver_t::real_t) == sizeof(double)
? H5::PredType::NATIVE_DOUBLE :
H5::PredType::NATIVE_FLOAT,
sizeof(typename solver_t::real_t) == sizeof(long double)
? H5::PredType::NATIVE_LDOUBLE
: sizeof(typename solver_t::real_t) == sizeof(double)
? H5::PredType::NATIVE_DOUBLE :
H5::PredType::NATIVE_FLOAT,
flttype_output = H5::PredType::NATIVE_FLOAT; // using floats not to waste disk space

blitz::TinyVector<hsize_t, parent_t::n_dims> cshape, shape, chunk, srfcshape, srfcchunk, offst;
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace libmpdataxx
offst = 0;

for (int d = 0; d < parent_t::n_dims; ++d)
shape[d] = this->mem->distmem.grid_size[d];
shape[d] = this->mem->distmem.grid_size[d];

chunk = shape;

Expand All @@ -114,10 +114,10 @@ namespace libmpdataxx
#if defined(USE_MPI)
if (this->mem->distmem.size() > 1)
{
shape[0] = this->mem->grid_size[0].length();
cshape[0] = this->mem->grid_size[0].length();
shape[0] = this->mem->grid_size[0].length();
cshape[0] = this->mem->grid_size[0].length();

if (this->mem->distmem.rank() == this->mem->distmem.size() - 1)
if (this->mem->distmem.rank() == this->mem->distmem.size() - 1)
cshape[0] += 1;

offst[0] = this->mem->grid_size[0].first();
Expand All @@ -134,9 +134,9 @@ namespace libmpdataxx
srfcchunk = chunk;
*(srfcchunk.end()-1) = 1;

params.setChunk(parent_t::n_dims, chunk.data());
params.setChunk(parent_t::n_dims, chunk.data());
#if !defined(USE_MPI)
params.setDeflate(5); // TODO: move such constant to the header
params.setDeflate(5); // TODO: move such constant to the header
#endif

// creating variables
Expand Down Expand Up @@ -222,26 +222,26 @@ namespace libmpdataxx
assert(this->rank == 0);
//count[1] = 1; TODO

// creating the timestep file
hdfp.reset(new H5::H5File(this->outdir + "/" + hdf_name(), H5F_ACC_TRUNC
// creating the timestep file
hdfp.reset(new H5::H5File(this->outdir + "/" + hdf_name(), H5F_ACC_TRUNC
#if defined(USE_MPI)
, H5P_DEFAULT, fapl_id
#endif
));
));

{
std::map<int, H5::DataSet> vars;

for (const auto &v : this->outvars)
{
// creating the user-requested variables
vars[v.first] = (*hdfp).createDataSet(
v.second.name,
flttype_output,
sspace,
params
);
// TODO: units attribute
for (const auto &v : this->outvars)
{
// creating the user-requested variables
vars[v.first] = (*hdfp).createDataSet(
v.second.name,
flttype_output,
sspace,
params
);
// TODO: units attribute

record_dsc_helper(vars[v.first], this->out_data(v.first));
}
Expand Down Expand Up @@ -313,11 +313,11 @@ namespace libmpdataxx
}

// data is assumed to be contiguous and in the same layout as hdf variable
void record_aux(const std::string &name, typename solver_t::real_t *data)
void record_aux_hlpr(const std::string &name, typename solver_t::real_t *data, H5::H5File hdf)
{
assert(this->rank == 0);

auto aux = (*hdfp).createDataSet(
auto aux = hdf.createDataSet(
name,
flttype_output,
sspace,
Expand All @@ -328,16 +328,21 @@ namespace libmpdataxx
space.selectHyperslab(H5S_SELECT_SET, shape.data(), offst.data());
aux.write(data, flttype_solver, H5::DataSpace(parent_t::n_dims, shape.data()), space, dxpl_id);
}

void record_aux(const std::string &name, typename solver_t::real_t *data)
{
record_aux_hlpr(name, data, *hdfp);
}

// for discontiguous array with halos
void record_aux_dsc(const std::string &name, const typename solver_t::arr_t &arr, bool srfc = false)
void record_aux_dsc_hlpr(const std::string &name, const typename solver_t::arr_t &arr, H5::H5File hdf, bool srfc = false)
{
assert(this->rank == 0);

if(srfc)
params.setChunk(parent_t::n_dims, srfcchunk.data());
params.setChunk(parent_t::n_dims, srfcchunk.data());

auto aux = (*hdfp).createDataSet(
auto aux = hdf.createDataSet(
name,
flttype_output,
srfc ? srfcspace : sspace,
Expand All @@ -347,13 +352,19 @@ namespace libmpdataxx
if(srfc)
{
// revert to default chunk
params.setChunk(parent_t::n_dims, chunk.data());
params.setChunk(parent_t::n_dims, chunk.data());
record_dsc_srfc_helper(aux, arr);
}
else
record_dsc_helper(aux, arr);
}

void record_aux_dsc(const std::string &name, const typename solver_t::arr_t &arr, bool srfc = false)
{
record_aux_dsc_hlpr(name, arr, *hdfp, srfc);
}


void record_scalar_hlpr(const std::string &name, const std::string &group_name, typename solver_t::real_t data, H5::H5File hdf)
{
assert(this->rank == 0);
Expand All @@ -373,6 +384,19 @@ namespace libmpdataxx
}

// has to be called after const file was created (i.e. after start())
void record_aux_const(const std::string &name, typename solver_t::real_t *data)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR); // reopen the const file
record_aux_hlpr(name, data, hdfcp);
}

// has to be called after const file was created (i.e. after start())
void record_aux_dsc_const(const std::string &name, const typename solver_t::arr_t &arr)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR); // reopen the const file
record_aux_dsc_hlpr(name, arr, hdfcp);
}

void record_aux_const(const std::string &name, const std::string &group_name, typename solver_t::real_t data)
{
H5::H5File hdfcp(const_file, H5F_ACC_RDWR
Expand Down Expand Up @@ -593,8 +617,8 @@ namespace libmpdataxx

// ctor
hdf5(
typename parent_t::ctor_args_t args,
const typename parent_t::rt_params_t &p
typename parent_t::ctor_args_t args,
const typename parent_t::rt_params_t &p
) : parent_t(args, p)
{
#if defined(USE_MPI)
Expand Down

0 comments on commit d6c8049

Please sign in to comment.