20#ifdef DEAL_II_WITH_HDF5
371 template <
typename T>
387 template <
typename T>
434 DataSet(
const std::string &
name,
const hid_t &parent_group_id,
bool mpi);
441 const hid_t &parent_group_id,
443 const std::shared_ptr<hid_t> &t_type,
464 template <
typename Container>
501 template <
typename Container>
540 template <
typename Container>
543 const std::vector<hsize_t> &count);
577 template <
typename Container>
580 const std::vector<hsize_t> &offset,
581 const std::vector<hsize_t> &stride,
582 const std::vector<hsize_t> &count,
583 const std::vector<hsize_t> &block);
596 template <
typename number>
618 template <
typename Container>
650 template <
typename Container>
653 const std::vector<hsize_t> &coordinates);
682 template <
typename Container>
685 const std::vector<hsize_t> &offset,
686 const std::vector<hsize_t> &count);
720 template <
typename Container>
723 const std::vector<hsize_t> &data_dimensions,
724 const std::vector<hsize_t> &offset,
725 const std::vector<hsize_t> &stride,
726 const std::vector<hsize_t> &count,
727 const std::vector<hsize_t> &block);
746 template <
typename number>
808 H5D_mpio_actual_io_mode_t
1002 const Group &parent_group,
1042 template <
typename number>
1045 const std::vector<hsize_t> &dimensions)
const;
1065 template <
typename Container>
1136 template <
typename number>
1137 std::shared_ptr<hid_t>
1149 template <
typename number>
1150 std::vector<hsize_t>
1157 template <
typename number>
1158 std::vector<hsize_t>
1165 template <
typename number>
1166 std::vector<hsize_t>
1173 template <
typename number>
1181 template <
typename number>
1189 template <
typename number>
1211 template <
typename Container>
1213 std::is_same_v<Container, std::vector<typename Container::value_type>>,
1220 template <
typename Container>
1222 std::is_same_v<Container, Vector<typename Container::value_type>>,
1229 template <
typename Container>
1231 std::is_same_v<Container, FullMatrix<typename Container::value_type>>,
1242 set_plist(hid_t &plist,
const bool mpi);
1254 H5D_mpio_actual_io_mode_t &io_mode,
1255 std::uint32_t &local_no_collective_cause,
1256 std::uint32_t &global_no_collective_cause,
1258 const bool query_io_mode);
1273 template <
typename number>
1274 std::shared_ptr<hid_t>
1277 static_assert(std::is_same_v<number, float> ||
1278 std::is_same_v<number, double> ||
1279 std::is_same_v<number, int> ||
1280 std::is_same_v<number, bool> ||
1281 std::is_same_v<number, unsigned int> ||
1282 std::is_same_v<number, std::complex<float>> ||
1283 std::is_same_v<number, std::complex<double>>,
1284 "The data type you are trying to get the HDF5 tag for "
1285 "is not supported by this function.");
1287 if (std::is_same_v<number, float>)
1289 return std::make_shared<hid_t>(H5T_NATIVE_FLOAT);
1291 else if (std::is_same_v<number, double>)
1293 return std::make_shared<hid_t>(H5T_NATIVE_DOUBLE);
1295 else if (std::is_same_v<number, int>)
1297 return std::make_shared<hid_t>(H5T_NATIVE_INT);
1299 else if (std::is_same_v<number, unsigned int>)
1301 return std::make_shared<hid_t>(H5T_NATIVE_UINT);
1303 else if (std::is_same_v<number, bool>)
1305 return std::make_shared<hid_t>(H5T_NATIVE_HBOOL);
1307 else if (std::is_same_v<number, std::complex<float>>)
1309 std::shared_ptr<hid_t> t_type =
1310 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1312 const herr_t ret = H5Tclose(*pointer);
1318 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<float>));
1323 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_FLOAT);
1325 ret = H5Tinsert(*t_type,
"i",
sizeof(
float), H5T_NATIVE_FLOAT);
1330 else if (std::is_same_v<number, std::complex<double>>)
1332 std::shared_ptr<hid_t> t_type =
1333 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1335 const herr_t ret = H5Tclose(*pointer);
1340 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<double>));
1345 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_DOUBLE);
1347 ret = H5Tinsert(*t_type,
"i",
sizeof(
double), H5T_NATIVE_DOUBLE);
1360 template <
typename number>
1361 std::vector<hsize_t>
1364 std::vector<hsize_t> dimensions = {
data.size()};
1370 template <
typename number>
1371 std::vector<hsize_t>
1374 std::vector<hsize_t> dimensions = {
data.size()};
1380 template <
typename number>
1381 std::vector<hsize_t>
1384 std::vector<hsize_t> dimensions = {
data.m(),
data.n()};
1390 template <
typename number>
1394 return static_cast<unsigned int>(
data.size());
1399 template <
typename number>
1403 return static_cast<unsigned int>(
data.size());
1408 template <
typename number>
1412 return static_cast<unsigned int>(
data.m() *
data.n());
1417 template <
typename Container>
1419 std::is_same_v<Container, std::vector<typename Container::value_type>>,
1423 return Container(std::accumulate(
1424 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1429 template <
typename Container>
1431 std::is_same_v<Container, Vector<typename Container::value_type>>,
1435 return Container(std::accumulate(
1436 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1441 template <
typename Container>
1443 std::is_same_v<Container, FullMatrix<typename Container::value_type>>,
1451 std::vector<hsize_t> squeezed_dimensions;
1453 if (dimensions.size() > 2)
1455 for (
const auto &dimension : dimensions)
1458 squeezed_dimensions.push_back(dimension);
1463 squeezed_dimensions = dimensions;
1467 return Container(squeezed_dimensions[0], squeezed_dimensions[1]);
1476# ifdef DEAL_II_WITH_MPI
1477 plist = H5Pcreate(H5P_DATASET_XFER);
1479 const herr_t ret = H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE);
1488 plist = H5P_DEFAULT;
1498 H5D_mpio_actual_io_mode_t &io_mode,
1499 std::uint32_t &local_no_collective_cause,
1500 std::uint32_t &global_no_collective_cause,
1502 const bool query_io_mode)
1506# ifdef DEAL_II_WITH_MPI
1511 ret = H5Pget_mpio_actual_io_mode(plist, &io_mode);
1514 H5Pget_mpio_no_collective_cause(plist,
1515 &local_no_collective_cause,
1516 &global_no_collective_cause);
1519 ret = H5Pclose(plist);
1528 (void)local_no_collective_cause;
1529 (void)global_no_collective_cause;
1531 (void)query_io_mode;
1538 std::string message;
1540 auto append_to_message = [&message](
const char *p) {
1541 if (message.size() > 0)
1556 if (no_collective_cause == 0x00)
1558 append_to_message(
"H5D_MPIO_COLLECTIVE");
1561 if ((no_collective_cause & 0x01) == 0x01)
1563 append_to_message(
"H5D_MPIO_SET_INDEPENDENT");
1566 if ((no_collective_cause & 0x02) == 0x02)
1568 append_to_message(
"H5D_MPIO_DATATYPE_CONVERSION");
1571 if ((no_collective_cause & 0x04) == 0x04)
1573 append_to_message(
"H5D_MPIO_DATA_TRANSFORMS");
1576 if ((no_collective_cause & 0x10) == 0x10)
1578 append_to_message(
"H5D_MPIO_NOT_SIMPLE_OR_SCALAR_DATASPACES");
1581 if ((no_collective_cause & 0x20) == 0x20)
1583 append_to_message(
"H5D_MPIO_NOT_CONTIGUOUS_OR_CHUNKED_DATASET");
1586 if ((no_collective_cause & 0x40) == 0x40)
1588 append_to_message(
"H5D_MPIO_FILTERS");
1595 template <
typename T>
1599 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1607 ret = H5Aread(attr, *t_type, &value);
1610 ret = H5Aclose(attr);
1640 type = H5Tcopy(H5T_C_S1);
1644 ret = H5Tset_cset(type, H5T_CSET_UTF8);
1647 ret = H5Tset_size(type, H5T_VARIABLE);
1653 ret = H5Aread(attr, type, &string_out);
1656 std::string string_value(string_out);
1660 ret = H5Tclose(type);
1663 ret = H5Aclose(attr);
1667 return string_value;
1672 template <
typename T>
1680 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1686 aid = H5Screate(H5S_SCALAR);
1699 ret = H5Awrite(attr, *t_type, &value);
1702 ret = H5Sclose(aid);
1704 ret = H5Aclose(attr);
1715 const std::string value)
1728 t_type = H5Tcopy(H5T_C_S1);
1732 ret = H5Tset_cset(t_type, H5T_CSET_UTF8);
1735 ret = H5Tset_size(t_type, H5T_VARIABLE);
1741 aid = H5Screate(H5S_SCALAR);
1744 *
hdf5_reference, attr_name.data(), t_type, aid, H5P_DEFAULT, H5P_DEFAULT);
1753 const char *c_string_value = value.c_str();
1754 ret = H5Awrite(attr, t_type, &c_string_value);
1757 ret = H5Sclose(aid);
1759 ret = H5Aclose(attr);
1767 template <
typename Container>
1771 const std::shared_ptr<hid_t> t_type =
1772 internal::get_hdf5_datatype<typename Container::value_type>();
1776 Container
data = internal::initialize_container<Container>(
dimensions);
1802 template <
typename Container>
1808 "The dimension of coordinates has to be divisible by the rank"));
1809 const std::shared_ptr<hid_t> t_type =
1810 internal::get_hdf5_datatype<typename Container::value_type>();
1812 hid_t memory_dataspace;
1815 std::vector<hsize_t> data_dimensions{
1816 static_cast<hsize_t
>(coordinates.size() /
rank)};
1818 Container
data = internal::initialize_container<Container>(data_dimensions);
1820 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1825 coordinates.data());
1845 ret = H5Sclose(memory_dataspace);
1854 template <
typename Container>
1857 const std::vector<hsize_t> &count)
1859 const std::shared_ptr<hid_t> t_type =
1860 internal::get_hdf5_datatype<typename Container::value_type>();
1862 hid_t memory_dataspace;
1867 std::vector<hsize_t> data_dimensions = count;
1869 Container
data = internal::initialize_container<Container>(data_dimensions);
1872 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1899 ret = H5Sclose(memory_dataspace);
1908 template <
typename Container>
1911 const std::vector<hsize_t> &offset,
1912 const std::vector<hsize_t> &stride,
1913 const std::vector<hsize_t> &count,
1914 const std::vector<hsize_t> &block)
1916 const std::shared_ptr<hid_t> t_type =
1917 internal::get_hdf5_datatype<typename Container::value_type>();
1919 hid_t memory_dataspace;
1922 Container
data = internal::initialize_container<Container>(data_dimensions);
1925 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1952 ret = H5Sclose(memory_dataspace);
1961 template <
typename number>
1965 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
1966 const std::vector<hsize_t> data_dimensions = {0};
1968 hid_t memory_dataspace;
1972 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1993 ret = H5Sclose(memory_dataspace);
2001 template <
typename Container>
2006 const std::shared_ptr<hid_t> t_type =
2007 internal::get_hdf5_datatype<typename Container::value_type>();
2033 template <
typename Container>
2036 const std::vector<hsize_t> &coordinates)
2039 const std::shared_ptr<hid_t> t_type =
2040 internal::get_hdf5_datatype<typename Container::value_type>();
2041 const std::vector<hsize_t> data_dimensions =
2044 hid_t memory_dataspace;
2049 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2054 coordinates.data());
2074 ret = H5Sclose(memory_dataspace);
2082 template <
typename Container>
2085 const std::vector<hsize_t> &offset,
2086 const std::vector<hsize_t> &count)
2091 std::multiplies<unsigned int>()),
2093 const std::shared_ptr<hid_t> t_type =
2094 internal::get_hdf5_datatype<typename Container::value_type>();
2097 const std::vector<hsize_t> &data_dimensions = count;
2099 hid_t memory_dataspace;
2104 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2131 ret = H5Sclose(memory_dataspace);
2139 template <
typename Container>
2142 const std::vector<hsize_t> &data_dimensions,
2143 const std::vector<hsize_t> &offset,
2144 const std::vector<hsize_t> &stride,
2145 const std::vector<hsize_t> &count,
2146 const std::vector<hsize_t> &block)
2148 const std::shared_ptr<hid_t> t_type =
2149 internal::get_hdf5_datatype<typename Container::value_type>();
2151 hid_t memory_dataspace;
2156 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2183 ret = H5Sclose(memory_dataspace);
2191 template <
typename number>
2195 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2196 std::vector<hsize_t> data_dimensions = {0};
2198 hid_t memory_dataspace;
2202 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2223 ret = H5Sclose(memory_dataspace);
2231 template <
typename number>
2234 const std::vector<hsize_t> &dimensions)
const
2236 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2242 template <
typename Container>
2248 create_dataset<typename Container::value_type>(
name, dimensions);
2249 dataset.write(
data);
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
unsigned int get_rank() const
void write(const Container &data)
std::vector< hsize_t > get_dimensions() const
std::vector< hsize_t > dimensions
std::uint32_t get_local_no_collective_cause_as_hdf5_type()
void write_hyperslab(const Container &data, const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
unsigned int get_size() const
void write_selection(const Container &data, const std::vector< hsize_t > &coordinates)
std::shared_ptr< hid_t > dataspace
std::string get_local_no_collective_cause()
std::string get_io_mode()
std::uint32_t local_no_collective_cause
std::string get_global_no_collective_cause()
bool get_query_io_mode() const
std::uint32_t global_no_collective_cause
std::uint32_t get_global_no_collective_cause_as_hdf5_type()
Container read_selection(const std::vector< hsize_t > &coordinates)
H5D_mpio_actual_io_mode_t get_io_mode_as_hdf5_type()
void set_query_io_mode(const bool new_query_io_mode)
Container read_hyperslab(const std::vector< hsize_t > &offset, const std::vector< hsize_t > &count)
H5D_mpio_actual_io_mode_t io_mode
DataSet open_dataset(const std::string &name) const
Group open_group(const std::string &name) const
DataSet create_dataset(const std::string &name, const std::vector< hsize_t > &dimensions) const
Group create_group(const std::string &name) const
void write_dataset(const std::string &name, const Container &data) const
std::shared_ptr< hid_t > hdf5_reference
std::string get_name() const
T get_attribute(const std::string &attr_name) const
void set_attribute(const std::string &attr_name, const T value)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertNothrow(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
#define DEAL_II_ASSERT_UNREACHABLE()
std::vector< index_type > data
void release_plist(hid_t &plist, H5D_mpio_actual_io_mode_t &io_mode, std::uint32_t &local_no_collective_cause, std::uint32_t &global_no_collective_cause, const bool mpi, const bool query_io_mode)
std::string no_collective_cause_to_string(const std::uint32_t no_collective_cause)
std::enable_if_t< std::is_same_v< Container, std::vector< typename Container::value_type > >, Container > initialize_container(const std::vector< hsize_t > &dimensions)
unsigned int get_container_size(const std::vector< number > &data)
void set_plist(hid_t &plist, const bool mpi)
std::shared_ptr< hid_t > get_hdf5_datatype()
std::vector< hsize_t > get_container_dimensions(const std::vector< number > &data)