Closed hmenke closed 2 years ago
Possible patch:
diff --git a/c++/h5/array_interface.cpp b/c++/h5/array_interface.cpp
index 79d4c1c..6254d6d 100644
--- a/c++/h5/array_interface.cpp
+++ b/c++/h5/array_interface.cpp
@@ -78,7 +78,10 @@ namespace h5::array_interface {
if (compress and (v.rank() != 0)) {
int n_dims = v.rank();
std::vector<hsize_t> chunk_dims(n_dims);
- for (int i = 0; i < v.rank(); ++i) chunk_dims[i] = std::max(v.slab.count[i], hsize_t{1});
+ hsize_t const dtype_size = H5Tget_size(v.ty);
+ hsize_t const chunk_max = hsize_t{1UL << 32} - hsize_t{1}; // 2^32 - 1 = 4 GB
+ hsize_t const root_dim = std::pow(chunk_max / dtype_size, 1. / n_dims);
+ for (int i = 0; i < v.rank(); ++i) chunk_dims[i] = std::clamp(v.slab.count[i], hsize_t{1}, root_dim);
cparms = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(cparms, n_dims, chunk_dims.data());
H5Pset_deflate(cparms, 1);
Prerequisites
Description
For very large data like lattice susceptibilities the chunk size of the HDF5 data may exceed 4 GB which is not allowed and will crash.
See also https://support.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetChunk
Steps to Reproduce
Expected behavior: No error.
Actual behavior:
Versions
d6081913d2d42b258dfe362d17933b3d178764d3
Formatting
Please use markdown in your issue message. A useful summary of commands can be found here.
Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.