* // Create some distributed datasets.
* // Note that the keyword template is used between data and create because
* // the function create_dataset returns a dependent template.
- * auto frequency_dataset = data.template create_dataset<double>("frequency", std::vector<hsize_t>{nb_frequency_points});
+ * auto frequency_dataset = data.create_dataset<double>("frequency", std::vector<hsize_t>{nb_frequency_points});
*
- * auto displacement = data.template create_dataset<std::complex<double>>("displacement",
+ * auto displacement = data.create_dataset<std::complex<double>>("displacement",
* std::vector<hsize_t>{nb_slice_points, nb_frequency_points}));
*
* // ... do some calculations ...
*
* @author Daniel Garcia-Sanchez, 2018
*/
- template <typename T>
class DataSet : public HDF5Object
{
friend class Group;
protected:
- DataSet(const std::string name,
- const hid_t & parent_group_id,
- std::vector<hsize_t> dimensions,
- bool mpi,
- const Mode mode);
+ DataSet(const std::string name,
+ const hid_t & parent_group_id,
+ std::vector<hsize_t> dimensions,
+ std::shared_ptr<hid_t> t_type,
+ bool mpi,
+ const Mode mode);
public:
~DataSet();
* Transfer: Datatype Conversion and Selection"</a> section in the HDF5
* User's Guide.
*/
+ template <typename T>
void
write_data(const std::vector<T> &data) const;
* Transfer: Datatype Conversion and Selection"</a> section in the HDF5
* User's Guide.
*/
+ template <typename T>
void
write_data(const FullMatrix<T> &data) const;
* Transfer: Datatype Conversion and Selection"</a> section in the HDF5
* User's Guide.
*/
+ template <typename T>
void
write_data_selection(const std::vector<T> & data,
const std::vector<hsize_t> coordinates) const;
* Transfer: Datatype Conversion and Selection"</a> section in the HDF5
* User's Guide.
*/
+ template <typename T>
void
write_data_hyperslab(const std::vector<T> & data,
const std::vector<hsize_t> offset,
* Transfer: Datatype Conversion and Selection"</a> section in the HDF5
* User's Guide.
*/
+ template <typename T>
void
write_data_hyperslab(const FullMatrix<T> & data,
const std::vector<hsize_t> offset,
const std::vector<hsize_t> count) const;
+
+ /**
+ * This function does not write any data, but can contribute to a collective
+ * write call. T can be double, int, unsigned int, bool or
+ * std::complex<double>.
+ *
+ * Datatype conversion takes place at the time of a read or write and is
+ * automatic. See the <a
+ * href="https://support.hdfgroup.org/HDF5/doc/UG/HDF5_Users_Guide-Responsive%20HTML5/index.html#t=HDF5_Users_Guide%2FDatatypes%2FHDF5_Datatypes.htm%23TOC_6_10_Data_Transferbc-26&rhtocid=6.5_2">"Data
+ * Transfer: Datatype Conversion and Selection"</a> section in the HDF5
+ * User's Guide.
+ */
+ template <typename T>
void
- write_data_none() const;
+ write_data_none() const;
+
const unsigned int rank;
const std::vector<hsize_t> dimensions;
private:
std::shared_ptr<hid_t> dataspace;
- std::shared_ptr<hid_t> t_type;
unsigned int total_size;
};
* Creates a dataset. T can be double, int, unsigned int, bool or
* std::complex<double>.
*
- * The keyword template has to be used between create_dataset and the name
- * of the object because the function create_dataset returns a dependent
- * template. See the example in HDF5.
- *
* Datatype conversion takes place at the time of a read or write and is
* automatic. See the <a
* href="https://support.hdfgroup.org/HDF5/doc/UG/HDF5_Users_Guide-Responsive%20HTML5/index.html#t=HDF5_Users_Guide%2FDatatypes%2FHDF5_Datatypes.htm%23TOC_6_10_Data_Transferbc-26&rhtocid=6.5_2">"Data
* User's Guide.
*/
template <typename T>
- DataSet<T>
+ DataSet
create_dataset(const std::string name,
const std::vector<hsize_t> dimensions) const;
H5Aclose(attr);
}
- template <typename T>
- DataSet<T>::DataSet(const std::string name,
- const hid_t & parent_group_id,
- std::vector<hsize_t> dimensions,
- const bool mpi,
- const Mode mode)
+
+ DataSet::DataSet(const std::string name,
+ const hid_t & parent_group_id,
+ std::vector<hsize_t> dimensions,
+ std::shared_ptr<hid_t> t_type,
+ const bool mpi,
+ const Mode mode)
: HDF5Object(name, mpi)
, rank(dimensions.size())
, dimensions(dimensions)
- , t_type(internal::get_hdf5_datatype<T>())
{
hdf5_reference = std::shared_ptr<hid_t>(new hid_t, [](auto pointer) {
// Relase the HDF5 resource
}
}
- template <typename T>
- DataSet<T>::~DataSet()
+
+ DataSet::~DataSet()
{
// Close first the dataset
hdf5_reference.reset();
template <typename T>
void
- DataSet<T>::write_data(const std::vector<T> &data) const
+ DataSet::write_data(const std::vector<T> &data) const
{
AssertDimension(total_size, data.size());
- hid_t plist;
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ hid_t plist;
if (mpi)
{
template <typename T>
void
- DataSet<T>::write_data(const FullMatrix<T> &data) const
+ DataSet::write_data(const FullMatrix<T> &data) const
{
AssertDimension(total_size, data.m() * data.n());
- hid_t plist;
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ hid_t plist;
if (mpi)
{
template <typename T>
void
- DataSet<T>::write_data_selection(const std::vector<T> & data,
- const std::vector<hsize_t> coordinates) const
+ DataSet::write_data_selection(const std::vector<T> & data,
+ const std::vector<hsize_t> coordinates) const
{
AssertDimension(coordinates.size(), data.size() * rank);
- hid_t memory_dataspace;
- hid_t plist;
- std::vector<hsize_t> data_dimensions = {data.size()};
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ std::vector<hsize_t> data_dimensions = {data.size()};
+
+ hid_t memory_dataspace;
+ hid_t plist;
+
memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL);
H5Sselect_elements(*dataspace,
template <typename T>
void
- DataSet<T>::write_data_hyperslab(const std::vector<T> & data,
- const std::vector<hsize_t> offset,
- const std::vector<hsize_t> count) const
+ DataSet::write_data_hyperslab(const std::vector<T> & data,
+ const std::vector<hsize_t> offset,
+ const std::vector<hsize_t> count) const
{
AssertDimension(std::accumulate(count.begin(),
count.end(),
1,
std::multiplies<unsigned int>()),
data.size());
- hid_t memory_dataspace;
- hid_t plist;
- std::vector<hsize_t> data_dimensions = {data.size()};
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ std::vector<hsize_t> data_dimensions = {data.size()};
+
+ hid_t memory_dataspace;
+ hid_t plist;
+
memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL);
H5Sselect_hyperslab(
template <typename T>
void
- DataSet<T>::write_data_hyperslab(const FullMatrix<T> & data,
- const std::vector<hsize_t> offset,
- const std::vector<hsize_t> count) const
+ DataSet::write_data_hyperslab(const FullMatrix<T> & data,
+ const std::vector<hsize_t> offset,
+ const std::vector<hsize_t> count) const
{
AssertDimension(std::accumulate(count.begin(),
count.end(),
1,
std::multiplies<unsigned int>()),
data.m() * data.n());
- hid_t memory_dataspace;
- hid_t plist;
- std::vector<hsize_t> data_dimensions = {data.m(), data.n()};
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ std::vector<hsize_t> data_dimensions = {data.m(), data.n()};
+
+ hid_t memory_dataspace;
+ hid_t plist;
memory_dataspace = H5Screate_simple(2, data_dimensions.data(), NULL);
H5Sselect_hyperslab(
template <typename T>
void
- DataSet<T>::write_data_none() const
+ DataSet::write_data_none() const
{
- hid_t memory_dataspace;
- hid_t plist;
- std::vector<hsize_t> data_dimensions = {0};
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ std::vector<hsize_t> data_dimensions = {0};
+
+ hid_t memory_dataspace;
+ hid_t plist;
memory_dataspace = H5Screate_simple(1, data_dimensions.data(), NULL);
H5Sselect_none(*dataspace);
}
template <typename T>
- DataSet<T>
+ DataSet
Group::create_dataset(const std::string name,
const std::vector<hsize_t> dimensions) const
{
- return DataSet<T>(
- name, *hdf5_reference, dimensions, mpi, DataSet<T>::Mode::create);
+ std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
+ return DataSet(
+ name, *hdf5_reference, dimensions, t_type, mpi, DataSet::Mode::create);
}
template <typename T>
{}
- // explicit instantiations of classes
- template class DataSet<float>;
- template class DataSet<double>;
- template class DataSet<long double>;
- template class DataSet<std::complex<float>>;
- template class DataSet<std::complex<double>>;
- template class DataSet<std::complex<long double>>;
- template class DataSet<int>;
- template class DataSet<unsigned int>;
-
-
// explicit instantiations of functions
template float
HDF5Object::attr<float>(const std::string attr_name) const;
HDF5Object::write_attr<unsigned int>(const std::string attr_name,
unsigned int value) const;
+ template void
+ DataSet::write_data_selection<float>(
+ const std::vector<float> & data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<double>(
+ const std::vector<double> &data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<long double>(
+ const std::vector<long double> &data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<std::complex<float>>(
+ const std::vector<std::complex<float>> &data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<std::complex<double>>(
+ const std::vector<std::complex<double>> &data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<std::complex<long double>>(
+ const std::vector<std::complex<long double>> &data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<int>(
+ const std::vector<int> & data,
+ const std::vector<hsize_t> coordinates) const;
+ template void
+ DataSet::write_data_selection<unsigned int>(
+ const std::vector<unsigned int> &data,
+ const std::vector<hsize_t> coordinates) const;
+
+ template void
+ DataSet::write_data_none<float>() const;
+ template void
+ DataSet::write_data_none<double>() const;
+ template void
+ DataSet::write_data_none<long double>() const;
+ template void
+ DataSet::write_data_none<std::complex<float>>() const;
+ template void
+ DataSet::write_data_none<std::complex<double>>() const;
+ template void
+ DataSet::write_data_none<std::complex<long double>>() const;
+ template void
+ DataSet::write_data_none<int>() const;
+ template void
+ DataSet::write_data_none<unsigned int>() const;
- template DataSet<float>
+ template DataSet
Group::create_dataset<float>(const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<double>
+ template DataSet
Group::create_dataset<double>(const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<long double>
+ template DataSet
Group::create_dataset<long double>(
const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<std::complex<float>>
+ template DataSet
Group::create_dataset<std::complex<float>>(
const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<std::complex<double>>
+ template DataSet
Group::create_dataset<std::complex<double>>(
const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<std::complex<long double>>
+ template DataSet
Group::create_dataset<std::complex<long double>>(
const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<int>
+ template DataSet
Group::create_dataset<int>(const std::string name,
const std::vector<hsize_t> dimensions) const;
- template DataSet<unsigned int>
+ template DataSet
Group::create_dataset<unsigned int>(
const std::string name,
const std::vector<hsize_t> dimensions) const;