From 36695b3b04424d3674448f591b0387bd7e7b7e1f Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Mon, 29 Oct 2018 20:19:26 +0100 Subject: [PATCH] Add read_hyperslab() --- include/deal.II/base/hdf5.h | 40 +++++++++++++++++ source/base/hdf5.cc | 85 +++++++++++++++++++++++++++++++++++++ source/base/hdf5.inst.in | 19 +++++++++ 3 files changed, 144 insertions(+) diff --git a/include/deal.II/base/hdf5.h b/include/deal.II/base/hdf5.h index 8787327df1..1c1de3405e 100644 --- a/include/deal.II/base/hdf5.h +++ b/include/deal.II/base/hdf5.h @@ -506,6 +506,46 @@ namespace HDF5 read_hyperslab(const std::vector &offset, const std::vector &count); + /** + * * Writes a data hyperslab to the dataset. The parameters are summarized + * below: + * - Dataset_dimensions: the dimensions of the data memory block. + * - Offset: The starting location for the hyperslab. + * - Stride: The number of elements to separate each element or block to be + * selected. + * - Count: The number of elements or blocks to select along each + * dimension. + * - Block: The size of the block selected from the dataspace. + * + * See the Dataspaces + * and Data Transfer section in the HDF5 User's Guide. See as well the + * H5Sselect_hyperslab + * definition. + * + * Datatype conversion takes place at the time of a read or write and is + * automatic. See the Data + * Transfer: Datatype Conversion and Selection section in the HDF5 + * User's Guide. + * + * `Container` can be `std::vector`, `std::vector`, + * `std::vector>`, `std::vector>`, + * `std::vector`, `std::vector`, `Vector`, + * `Vector`, `Vector>`, + * `Vector>`, `FullMatrix`, + * `FullMatrix`, `FullMatrix>` or + * `FullMatrix>`. + */ + template + Container + read_hyperslab(const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + /** * This function does not read any data, but it can contribute to a * collective read call. @p number can be `float`, `double`, diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index cc507af1c4..3517b607a8 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -882,6 +882,76 @@ namespace HDF5 + template + Container + DataSet::read_hyperslab(const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block) + { + const std::shared_ptr t_type = + internal::get_hdf5_datatype(); + hid_t plist; + hid_t memory_dataspace; + + Container data = internal::initialize_container(data_dimensions); + + memory_dataspace = + H5Screate_simple(data_dimensions.size(), data_dimensions.data(), NULL); + Assert(memory_dataspace >= 0, ExcMessage("Error at H5Screate_simple")); + ret = H5Sselect_hyperslab(*dataspace, + H5S_SELECT_SET, + offset.data(), + stride.data(), + count.data(), + block.data()); + Assert(ret >= 0, ExcMessage("Error at H5Sselect_hyperslab")); + + if (mpi) + { + plist = H5Pcreate(H5P_DATASET_XFER); + Assert(plist >= 0, ExcMessage("Error at H5Pcreate")); + ret = H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE); + Assert(ret >= 0, ExcMessage("Error at H5Pset_dxpl_mpio")); + } + else + { + plist = H5P_DEFAULT; + } + + ret = H5Dread(*hdf5_reference, + *t_type, + memory_dataspace, + *dataspace, + plist, + internal::get_container_pointer(data)); + Assert(ret >= 0, ExcMessage("Error at H5Dread")); + + if (mpi) + { + if (query_io_mode) + { + ret = H5Pget_mpio_actual_io_mode(plist, &io_mode); + Assert(ret >= 0, ExcMessage("Error at H5Pget_mpio_actual_io_mode")); + ret = H5Pget_mpio_no_collective_cause(plist, + &local_no_collective_cause, + &global_no_collective_cause); + Assert(ret >= 0, + ExcMessage("Error at H5Pget_mpio_no_collective_cause")); + } + ret = H5Pclose(plist); + Assert(ret >= 0, ExcMessage("Error at H5Pclose")); + } + + ret = H5Sclose(memory_dataspace); + Assert(ret >= 0, ExcMessage("Error at H5SClose")); + + return data; + } + + + template void DataSet::read_none() @@ -1565,6 +1635,21 @@ namespace HDF5 const std::vector &offset, const std::vector &count); + template std::vector + DataSet::read_hyperslab>( + const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + template std::vector + DataSet::read_hyperslab>( + const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + template void DataSet::read_none(); template void diff --git a/source/base/hdf5.inst.in b/source/base/hdf5.inst.in index d082f7562d..87bf2c2a28 100644 --- a/source/base/hdf5.inst.in +++ b/source/base/hdf5.inst.in @@ -35,6 +35,25 @@ for (number : REAL_AND_COMPLEX_SCALARS) template FullMatrix DataSet::read_hyperslab>( const std::vector &offset, const std::vector &count); + template std::vector DataSet::read_hyperslab>( + const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + template Vector DataSet::read_hyperslab>( + const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + template FullMatrix DataSet::read_hyperslab>( + const std::vector &data_dimensions, + const std::vector &offset, + const std::vector &stride, + const std::vector &count, + const std::vector &block); + template void DataSet::read_none(); template void DataSet::write>( -- 2.39.5