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
1003 const Group & parent_group,
1043 template <
typename number>
1046 const std::vector<hsize_t> &dimensions)
const;
1066 template <
typename Container>
1108 const MPI_Comm & mpi_communicator);
1121 const MPI_Comm & mpi_communicator);
1137 template <
typename number>
1138 std::shared_ptr<hid_t>
1150 template <
typename number>
1151 std::vector<hsize_t>
1158 template <
typename number>
1159 std::vector<hsize_t>
1166 template <
typename number>
1167 std::vector<hsize_t>
1174 template <
typename number>
1182 template <
typename number>
1190 template <
typename number>
1212 template <
typename Container>
1213 typename std::enable_if<
1214 std::is_same<Container,
1215 std::vector<typename Container::value_type>>::value,
1222 template <
typename Container>
1223 typename std::enable_if<
1224 std::is_same<Container, Vector<typename Container::value_type>>::value,
1231 template <
typename Container>
1232 typename std::enable_if<
1233 std::is_same<Container,
1245 set_plist(hid_t &plist,
const bool mpi);
1257 H5D_mpio_actual_io_mode_t &io_mode,
1258 std::uint32_t & local_no_collective_cause,
1259 std::uint32_t & global_no_collective_cause,
1261 const bool query_io_mode);
1276 template <
typename number>
1277 std::shared_ptr<hid_t>
1280 static_assert(std::is_same<number, float>::value ||
1281 std::is_same<number, double>::value ||
1282 std::is_same<number, int>::value ||
1283 std::is_same<number, bool>::value ||
1284 std::is_same<number, unsigned int>::value ||
1285 std::is_same<number, std::complex<float>>::value ||
1286 std::is_same<number, std::complex<double>>::value,
1287 "The data type you are trying to get the HDF5 tag for "
1288 "is not supported by this function.");
1290 if (std::is_same<number, float>::value)
1292 return std::make_shared<hid_t>(H5T_NATIVE_FLOAT);
1294 else if (std::is_same<number, double>::value)
1296 return std::make_shared<hid_t>(H5T_NATIVE_DOUBLE);
1298 else if (std::is_same<number, int>::value)
1300 return std::make_shared<hid_t>(H5T_NATIVE_INT);
1302 else if (std::is_same<number, unsigned int>::value)
1304 return std::make_shared<hid_t>(H5T_NATIVE_UINT);
1306 else if (std::is_same<number, bool>::value)
1308 return std::make_shared<hid_t>(H5T_NATIVE_HBOOL);
1310 else if (std::is_same<number, std::complex<float>>::value)
1312 std::shared_ptr<hid_t> t_type =
1313 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1315 const herr_t ret = H5Tclose(*pointer);
1321 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<float>));
1326 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_FLOAT);
1328 ret = H5Tinsert(*t_type,
"i",
sizeof(
float), H5T_NATIVE_FLOAT);
1333 else if (std::is_same<number, std::complex<double>>::value)
1335 std::shared_ptr<hid_t> t_type =
1336 std::shared_ptr<hid_t>(
new hid_t, [](hid_t *pointer) {
1338 const herr_t ret = H5Tclose(*pointer);
1343 *t_type = H5Tcreate(H5T_COMPOUND,
sizeof(std::complex<double>));
1348 herr_t ret = H5Tinsert(*t_type,
"r", 0, H5T_NATIVE_DOUBLE);
1350 ret = H5Tinsert(*t_type,
"i",
sizeof(
double), H5T_NATIVE_DOUBLE);
1363 template <
typename number>
1364 std::vector<hsize_t>
1367 std::vector<hsize_t> dimensions = {data.size()};
1373 template <
typename number>
1374 std::vector<hsize_t>
1377 std::vector<hsize_t> dimensions = {data.
size()};
1383 template <
typename number>
1384 std::vector<hsize_t>
1387 std::vector<hsize_t> dimensions = {data.
m(), data.
n()};
1393 template <
typename number>
1397 return static_cast<unsigned int>(data.size());
1402 template <
typename number>
1406 return static_cast<unsigned int>(data.
size());
1411 template <
typename number>
1415 return static_cast<unsigned int>(data.
m() * data.
n());
1420 template <
typename Container>
1421 typename std::enable_if<
1422 std::is_same<Container,
1423 std::vector<typename Container::value_type>>::value,
1427 return Container(std::accumulate(
1428 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1433 template <
typename Container>
1434 typename std::enable_if<
1435 std::is_same<Container, Vector<typename Container::value_type>>::value,
1439 return Container(std::accumulate(
1440 dimensions.begin(), dimensions.end(), 1, std::multiplies<int>()));
1445 template <
typename Container>
1446 typename std::enable_if<
1447 std::is_same<Container,
1456 std::vector<hsize_t> squeezed_dimensions;
1458 if (dimensions.size() > 2)
1460 for (
const auto &dimension : dimensions)
1463 squeezed_dimensions.push_back(dimension);
1468 squeezed_dimensions = dimensions;
1472 return Container(squeezed_dimensions[0], squeezed_dimensions[1]);
1481# ifdef DEAL_II_WITH_MPI
1482 plist = H5Pcreate(H5P_DATASET_XFER);
1484 const herr_t ret = H5Pset_dxpl_mpio(plist, H5FD_MPIO_COLLECTIVE);
1493 plist = H5P_DEFAULT;
1503 H5D_mpio_actual_io_mode_t &io_mode,
1504 std::uint32_t & local_no_collective_cause,
1505 std::uint32_t & global_no_collective_cause,
1507 const bool query_io_mode)
1511# ifdef DEAL_II_WITH_MPI
1516 ret = H5Pget_mpio_actual_io_mode(plist, &io_mode);
1519 H5Pget_mpio_no_collective_cause(plist,
1520 &local_no_collective_cause,
1521 &global_no_collective_cause);
1524 ret = H5Pclose(plist);
1533 (void)local_no_collective_cause;
1534 (void)global_no_collective_cause;
1536 (void)query_io_mode;
1543 std::string message;
1545 auto append_to_message = [&message](
const char *p) {
1546 if (message.size() > 0)
1561 if (no_collective_cause == 0x00)
1563 append_to_message(
"H5D_MPIO_COLLECTIVE");
1566 if ((no_collective_cause & 0x01) == 0x01)
1568 append_to_message(
"H5D_MPIO_SET_INDEPENDENT");
1571 if ((no_collective_cause & 0x02) == 0x02)
1573 append_to_message(
"H5D_MPIO_DATATYPE_CONVERSION");
1576 if ((no_collective_cause & 0x04) == 0x04)
1578 append_to_message(
"H5D_MPIO_DATA_TRANSFORMS");
1581 if ((no_collective_cause & 0x10) == 0x10)
1583 append_to_message(
"H5D_MPIO_NOT_SIMPLE_OR_SCALAR_DATASPACES");
1586 if ((no_collective_cause & 0x20) == 0x20)
1588 append_to_message(
"H5D_MPIO_NOT_CONTIGUOUS_OR_CHUNKED_DATASET");
1591 if ((no_collective_cause & 0x40) == 0x40)
1593 append_to_message(
"H5D_MPIO_FILTERS");
1600 template <
typename T>
1604 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1612 ret = H5Aread(attr, *t_type, &value);
1615 ret = H5Aclose(attr);
1645 type = H5Tcopy(H5T_C_S1);
1649 ret = H5Tset_cset(type, H5T_CSET_UTF8);
1652 ret = H5Tset_size(type, H5T_VARIABLE);
1658 ret = H5Aread(attr, type, &string_out);
1661 std::string string_value(string_out);
1665 ret = H5Tclose(type);
1668 ret = H5Aclose(attr);
1672 return string_value;
1677 template <
typename T>
1685 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<T>();
1691 aid = H5Screate(H5S_SCALAR);
1704 ret = H5Awrite(attr, *t_type, &value);
1707 ret = H5Sclose(aid);
1709 ret = H5Aclose(attr);
1720 const std::string value)
1733 t_type = H5Tcopy(H5T_C_S1);
1737 ret = H5Tset_cset(t_type, H5T_CSET_UTF8);
1740 ret = H5Tset_size(t_type, H5T_VARIABLE);
1746 aid = H5Screate(H5S_SCALAR);
1749 *
hdf5_reference, attr_name.data(), t_type, aid, H5P_DEFAULT, H5P_DEFAULT);
1758 const char *c_string_value = value.c_str();
1759 ret = H5Awrite(attr, t_type, &c_string_value);
1762 ret = H5Sclose(aid);
1764 ret = H5Aclose(attr);
1772 template <
typename Container>
1776 const std::shared_ptr<hid_t> t_type =
1777 internal::get_hdf5_datatype<typename Container::value_type>();
1781 Container data = internal::initialize_container<Container>(
dimensions);
1807 template <
typename Container>
1813 "The dimension of coordinates has to be divisible by the rank"));
1814 const std::shared_ptr<hid_t> t_type =
1815 internal::get_hdf5_datatype<typename Container::value_type>();
1817 hid_t memory_dataspace;
1820 std::vector<hsize_t> data_dimensions{
1821 static_cast<hsize_t
>(coordinates.size() /
rank)};
1823 Container data = internal::initialize_container<Container>(data_dimensions);
1825 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1830 coordinates.data());
1850 ret = H5Sclose(memory_dataspace);
1859 template <
typename Container>
1862 const std::vector<hsize_t> &count)
1864 const std::shared_ptr<hid_t> t_type =
1865 internal::get_hdf5_datatype<typename Container::value_type>();
1867 hid_t memory_dataspace;
1872 std::vector<hsize_t> data_dimensions = count;
1874 Container data = internal::initialize_container<Container>(data_dimensions);
1877 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1904 ret = H5Sclose(memory_dataspace);
1913 template <
typename Container>
1916 const std::vector<hsize_t> &offset,
1917 const std::vector<hsize_t> &stride,
1918 const std::vector<hsize_t> &count,
1919 const std::vector<hsize_t> &block)
1921 const std::shared_ptr<hid_t> t_type =
1922 internal::get_hdf5_datatype<typename Container::value_type>();
1924 hid_t memory_dataspace;
1927 Container data = internal::initialize_container<Container>(data_dimensions);
1930 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
1957 ret = H5Sclose(memory_dataspace);
1966 template <
typename number>
1970 const std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
1971 const std::vector<hsize_t> data_dimensions = {0};
1973 hid_t memory_dataspace;
1977 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
1998 ret = H5Sclose(memory_dataspace);
2006 template <
typename Container>
2011 const std::shared_ptr<hid_t> t_type =
2012 internal::get_hdf5_datatype<typename Container::value_type>();
2038 template <
typename Container>
2041 const std::vector<hsize_t> &coordinates)
2044 const std::shared_ptr<hid_t> t_type =
2045 internal::get_hdf5_datatype<typename Container::value_type>();
2046 const std::vector<hsize_t> data_dimensions =
2049 hid_t memory_dataspace;
2054 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2059 coordinates.data());
2079 ret = H5Sclose(memory_dataspace);
2087 template <
typename Container>
2090 const std::vector<hsize_t> &offset,
2091 const std::vector<hsize_t> &count)
2096 std::multiplies<unsigned int>()),
2098 const std::shared_ptr<hid_t> t_type =
2099 internal::get_hdf5_datatype<typename Container::value_type>();
2102 const std::vector<hsize_t> &data_dimensions = count;
2104 hid_t memory_dataspace;
2109 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2136 ret = H5Sclose(memory_dataspace);
2144 template <
typename Container>
2147 const std::vector<hsize_t> &data_dimensions,
2148 const std::vector<hsize_t> &offset,
2149 const std::vector<hsize_t> &stride,
2150 const std::vector<hsize_t> &count,
2151 const std::vector<hsize_t> &block)
2153 const std::shared_ptr<hid_t> t_type =
2154 internal::get_hdf5_datatype<typename Container::value_type>();
2156 hid_t memory_dataspace;
2161 H5Screate_simple(data_dimensions.size(), data_dimensions.data(),
nullptr);
2188 ret = H5Sclose(memory_dataspace);
2196 template <
typename number>
2200 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2201 std::vector<hsize_t> data_dimensions = {0};
2203 hid_t memory_dataspace;
2207 memory_dataspace = H5Screate_simple(1, data_dimensions.data(),
nullptr);
2228 ret = H5Sclose(memory_dataspace);
2236 template <
typename number>
2239 const std::vector<hsize_t> &dimensions)
const
2241 std::shared_ptr<hid_t> t_type = internal::get_hdf5_datatype<number>();
2247 template <
typename Container>
2253 create_dataset<typename Container::value_type>(
name, dimensions);
2254 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)
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)
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< std::is_same< Container, std::vector< typenameContainer::value_type > >::value, Container >::type 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)