21#ifdef DEAL_II_WITH_HDF5
372 template <
typename T>
388 template <
typename T>
435 DataSet(
const std::string &
name,
const hid_t &parent_group_id,
bool mpi);
442 const hid_t & parent_group_id,
444 const std::shared_ptr<hid_t> &t_type,
465 template <
typename Container>
502 template <
typename Container>
541 template <
typename Container>
544 const std::vector<hsize_t> &count);
578 template <
typename Container>
581 const std::vector<hsize_t> &offset,
582 const std::vector<hsize_t> &stride,
583 const std::vector<hsize_t> &count,
584 const std::vector<hsize_t> &block);
597 template <
typename number>
619 template <
typename Container>
621 write(
const Container &data);
651 template <
typename Container>
654 const std::vector<hsize_t> &coordinates);
683 template <
typename Container>
686 const std::vector<hsize_t> &offset,
687 const std::vector<hsize_t> &count);
721 template <
typename Container>
724 const std::vector<hsize_t> &data_dimensions,
725 const std::vector<hsize_t> &offset,
726 const std::vector<hsize_t> &stride,
727 const std::vector<hsize_t> &count,
728 const std::vector<hsize_t> &block);
747 template <
typename number>
809 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>
1107 const MPI_Comm & mpi_communicator);
1120 const MPI_Comm & mpi_communicator);
1135 template <
typename number>
1136 std::shared_ptr<hid_t>
1147 template <
typename number>
1148 std::vector<hsize_t>
1154 template <
typename number>
1155 std::vector<hsize_t>
1161 template <
typename number>
1162 std::vector<hsize_t>
1168 template <
typename number>
1175 template <
typename number>
1182 template <
typename number>
1203 template <
typename Container>
1204 typename std::enable_if<
1205 std::is_same<Container,
1206 std::vector<typename Container::value_type>>::value,
1212 template <
typename Container>
1213 typename std::enable_if<
1214 std::is_same<Container, Vector<typename Container::value_type>>::value,
1220 template <
typename Container>
1221 typename std::enable_if<
1222 std::is_same<Container,
1233 set_plist(hid_t &plist,
const bool mpi);
1244 H5D_mpio_actual_io_mode_t &io_mode,
1245 uint32_t & local_no_collective_cause,
1246 uint32_t & global_no_collective_cause,
1248 const bool query_io_mode);
1262 template <
typename number>
1263 std::shared_ptr<hid_t>
1266 static_assert(std::is_same<number, float>::value ||
1267 std::is_same<number, double>::value ||
1268 std::is_same<number, int>::value ||
1269 std::is_same<number, bool>::value ||
1270 std::is_same<number, unsigned int>::value ||
1271 std::is_same<number, std::complex<float>>::value ||
1272 std::is_same<number, std::complex<double>>::value,
1273 "The data type you are trying to get the HDF5 tag for "
1274 "is not supported by this function.");
1276 if (std::is_same<number, float>::value)
1278 return std::make_shared<hid_t>(H5T_NATIVE_FLOAT);
1280 else if (std::is_same<number, double>::value)
1282 return std::make_shared<hid_t>(H5T_NATIVE_DOUBLE);
1284 else if (std::is_same<number, int>::value)
1286 return std::make_shared<hid_t>(H5T_NATIVE_INT);
1288 else if (std::is_same<number, unsigned int>::value)
1290 return std::make_shared<hid_t>(H5T_NATIVE_UINT);
1292 else if (std::is_same<number, bool>::value)
1294 return std::make_shared<hid_t>(H5T_NATIVE_HBOOL);
1296 else if (std::is_same<number, std::complex<float>>::value)
1298 std::shared_ptr<hid_t> t_type =
1299 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1301 const herr_t ret = H5Tclose(*pointer);
1307 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<float>));
1312 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_FLOAT);
1314 ret = H5Tinsert(*t_type,
"i",
sizeof(
float), H5T_NATIVE_FLOAT);
1319 else if (std::is_same<number, std::complex<double>>::value)
1321 std::shared_ptr<hid_t> t_type =
1322 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1324 const herr_t ret = H5Tclose(*pointer);
1329 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<double>));
1334 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_DOUBLE);
1336 ret = H5Tinsert(*t_type,
"i",
sizeof(
double), H5T_NATIVE_DOUBLE);
1349 template <
typename number>
1350 std::vector<hsize_t>
1353 std::vector<hsize_t> dimensions = {data.size()};
1359 template <
typename number>
1360 std::vector<hsize_t>
1363 std::vector<hsize_t> dimensions = {data.
size()};
1369 template <
typename number>
1370 std::vector<hsize_t>
1373 std::vector<hsize_t> dimensions = {data.m(), data.n()};
1379 template <
typename number>
1383 return static_cast<unsigned int>(data.size());
1388 template <
typename number>
1392 return static_cast<unsigned int>(data.
size());
1397 template <
typename number>
1401 return static_cast<unsigned int>(data.m() * data.n());
1406 template <
typename Container>
1407 typename std::enable_if<
1408 std::is_same<Container,
1409 std::vector<typename Container::value_type>>::value,
1413 return Container(std::accumulate(
1414 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1419 template <
typename Container>
1420 typename std::enable_if<
1421 std::is_same<Container, Vector<typename Container::value_type>>::value,
1425 return Container(std::accumulate(
1426 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1431 template <
typename Container>
1432 typename std::enable_if<
1433 std::is_same<Container,
1442 std::vector<hsize_t> squeezed_dimensions;
1444 if (dimensions.size() > 2)
1446 for (
const auto &dimension : dimensions)
1449 squeezed_dimensions.push_back(dimension);
1454 squeezed_dimensions = dimensions;
1458 return Container(squeezed_dimensions[0], squeezed_dimensions[1]);
1467# ifdef DEAL_II_WITH_MPI
1468 plist = H5Pcreate(H5P_DATASET_XFER);
1470 const herr_t ret = H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE);
1479 plist = H5P_DEFAULT;
1489 H5D_mpio_actual_io_mode_t &io_mode,
1490 uint32_t & local_no_collective_cause,
1491 uint32_t & global_no_collective_cause,
1493 const bool query_io_mode)
1497# ifdef DEAL_II_WITH_MPI
1502 ret = H5Pget_mpio_actual_io_mode(plist, &io_mode);
1505 H5Pget_mpio_no_collective_cause(plist,
1506 &local_no_collective_cause,
1507 &global_no_collective_cause);
1510 ret = H5Pclose(plist);
1519 (void)local_no_collective_cause;
1520 (void)global_no_collective_cause;
1522 (void)query_io_mode;
1529 std::string message;
1531 auto append_to_message = [&message](
const char *p) {
1532 if (message.length() > 0)
1547 if (no_collective_cause == 0x00)
1549 append_to_message(
"H5D_MPIO_COLLECTIVE");
1552 if ((no_collective_cause & 0x01) == 0x01)
1554 append_to_message(
"H5D_MPIO_SET_INDEPENDENT");
1557 if ((no_collective_cause & 0x02) == 0x02)
1559 append_to_message(
"H5D_MPIO_DATATYPE_CONVERSION");
1562 if ((no_collective_cause & 0x04) == 0x04)
1564 append_to_message(
"H5D_MPIO_DATA_TRANSFORMS");
1567 if ((no_collective_cause & 0x10) == 0x10)
1569 append_to_message(
"H5D_MPIO_NOT_SIMPLE_OR_SCALAR_DATASPACES");
1572 if ((no_collective_cause & 0x20) == 0x20)
1574 append_to_message(
"H5D_MPIO_NOT_CONTIGUOUS_OR_CHUNKED_DATASET");
1577 if ((no_collective_cause & 0x40) == 0x40)
1579 append_to_message(
"H5D_MPIO_FILTERS");
1586 template <
typename T>
1590 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1598 ret = H5Aread(attr, *t_type, &value);
1601 ret = H5Aclose(attr);
1631 type = H5Tcopy(H5T_C_S1);
1635 ret = H5Tset_cset(type, H5T_CSET_UTF8);
1638 ret = H5Tset_size(type, H5T_VARIABLE);
1644 ret = H5Aread(attr, type, &string_out);
1647 std::string string_value(string_out);
1651 ret = H5Tclose(type);
1654 ret = H5Aclose(attr);
1658 return string_value;
1663 template <
typename T>
1671 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1677 aid = H5Screate(H5S_SCALAR);
1690 ret = H5Awrite(attr, *t_type, &value);
1693 ret = H5Sclose(aid);
1695 ret = H5Aclose(attr);
1706 const std::string value)
1719 t_type = H5Tcopy(H5T_C_S1);
1723 ret = H5Tset_cset(t_type, H5T_CSET_UTF8);
1726 ret = H5Tset_size(t_type, H5T_VARIABLE);
1732 aid = H5Screate(H5S_SCALAR);
1735 *
hdf5_reference, attr_name.data(), t_type, aid, H5P_DEFAULT, H5P_DEFAULT);
1744 const char *c_string_value = value.c_str();
1745 ret = H5Awrite(attr, t_type, &c_string_value);
1748 ret = H5Sclose(aid);
1750 ret = H5Aclose(attr);
1758 template <
typename Container>
1762 const std::shared_ptr<hid_t> t_type =
1763 internal::get_hdf5_datatype<typename Container::value_type>();
1767 Container data = internal::initialize_container<Container>(
dimensions);
1793 template <
typename Container>
1799 "The dimension of coordinates has to be divisible by the rank"));
1800 const std::shared_ptr<hid_t> t_type =
1801 internal::get_hdf5_datatype<typename Container::value_type>();
1803 hid_t memory_dataspace;
1806 std::vector<hsize_t> data_dimensions{
1807 static_cast<hsize_t
>(coordinates.size() /
rank)};
1809 Container data = internal::initialize_container<Container>(data_dimensions);
1811 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1816 coordinates.data());
1836 ret = H5Sclose(memory_dataspace);
1845 template <
typename Container>
1848 const std::vector<hsize_t> &count)
1850 const std::shared_ptr<hid_t> t_type =
1851 internal::get_hdf5_datatype<typename Container::value_type>();
1853 hid_t memory_dataspace;
1858 std::vector<hsize_t> data_dimensions = count;
1860 Container data = internal::initialize_container<Container>(data_dimensions);
1863 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1890 ret = H5Sclose(memory_dataspace);
1899 template <
typename Container>
1902 const std::vector<hsize_t> &offset,
1903 const std::vector<hsize_t> &stride,
1904 const std::vector<hsize_t> &count,
1905 const std::vector<hsize_t> &block)
1907 const std::shared_ptr<hid_t> t_type =
1908 internal::get_hdf5_datatype<typename Container::value_type>();
1910 hid_t memory_dataspace;
1913 Container data = internal::initialize_container<Container>(data_dimensions);
1916 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1943 ret = H5Sclose(memory_dataspace);
1952 template <
typename number>
1956 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
1957 const std::vector<hsize_t> data_dimensions = {0};
1959 hid_t memory_dataspace;
1963 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1984 ret = H5Sclose(memory_dataspace);
1992 template <
typename Container>
1997 const std::shared_ptr<hid_t> t_type =
1998 internal::get_hdf5_datatype<typename Container::value_type>();
2024 template <
typename Container>
2027 const std::vector<hsize_t> &coordinates)
2030 const std::shared_ptr<hid_t> t_type =
2031 internal::get_hdf5_datatype<typename Container::value_type>();
2032 const std::vector<hsize_t> data_dimensions =
2035 hid_t memory_dataspace;
2040 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2045 coordinates.data());
2065 ret = H5Sclose(memory_dataspace);
2073 template <
typename Container>
2076 const std::vector<hsize_t> &offset,
2077 const std::vector<hsize_t> &count)
2082 std::multiplies<unsigned int>()),
2084 const std::shared_ptr<hid_t> t_type =
2085 internal::get_hdf5_datatype<typename Container::value_type>();
2088 const std::vector<hsize_t> &data_dimensions = count;
2090 hid_t memory_dataspace;
2095 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2122 ret = H5Sclose(memory_dataspace);
2130 template <
typename Container>
2133 const std::vector<hsize_t> &data_dimensions,
2134 const std::vector<hsize_t> &offset,
2135 const std::vector<hsize_t> &stride,
2136 const std::vector<hsize_t> &count,
2137 const std::vector<hsize_t> &block)
2139 const std::shared_ptr<hid_t> t_type =
2140 internal::get_hdf5_datatype<typename Container::value_type>();
2142 hid_t memory_dataspace;
2147 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2174 ret = H5Sclose(memory_dataspace);
2182 template <
typename number>
2186 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2187 std::vector<hsize_t> data_dimensions = {0};
2189 hid_t memory_dataspace;
2193 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2214 ret = H5Sclose(memory_dataspace);
2222 template <
typename number>
2225 const std::vector<hsize_t> &dimensions)
const
2227 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2233 template <
typename Container>
2239 create_dataset<typename Container::value_type>(
name, dimensions);
2240 dataset.write(data);
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
unsigned int get_rank() const
void write(const Container &data)
uint32_t local_no_collective_cause
std::vector< hsize_t > get_dimensions() const
std::vector< hsize_t > dimensions
uint32_t get_global_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
DataSet(const std::string &name, const hid_t &parent_group_id, bool mpi)
std::string get_local_no_collective_cause()
std::string get_io_mode()
std::string get_global_no_collective_cause()
bool get_query_io_mode() const
uint32_t global_no_collective_cause
Container read_selection(const std::vector< hsize_t > &coordinates)
uint32_t get_local_no_collective_cause_as_hdf5_type()
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
File(const std::string &name, const FileAccessMode mode)
DataSet open_dataset(const std::string &name) const
Group open_group(const std::string &name) const
Group(const std::string &name, const Group &parent_group, const bool mpi, const GroupAccessMode mode)
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)
HDF5Object(const std::string &name, const bool mpi)
#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)
std::enable_if< std::is_same< Container, std::vector< typenameContainer::value_type > >::value, Container >::type initialize_container(const std::vector< hsize_t > &dimensions)
std::string no_collective_cause_to_string(const uint32_t no_collective_cause)
unsigned int get_container_size(const std::vector< number > &data)
void release_plist(hid_t &plist, H5D_mpio_actual_io_mode_t &io_mode, uint32_t &local_no_collective_cause, uint32_t &global_no_collective_cause, const bool mpi, const bool query_io_mode)
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)