@@ -16,8 +16,22 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array) {
16
16
hid_t fspace = H5Screate_simple (1 , (hsize_t []){array .size }, NULL );
17
17
hid_t lcpl = H5Pcreate (H5P_LINK_CREATE );
18
18
19
- hid_t dset = H5Dcreate2 (f , label , hdf5_standard_type , fspace , lcpl ,
20
- H5P_DEFAULT , H5P_DEFAULT );
19
+ hid_t dcpl = H5Pcreate (H5P_DATASET_CREATE );
20
+
21
+ // Choose 1 MiB, the default chunk cache size, as our chunk size.
22
+ size_t chunk_size = 1024 * 1024 / bsp_type_size (array .type );
23
+
24
+ // If the dataset is smaller than the chunk size, cap the chunk size.
25
+ if (array .size < chunk_size ) {
26
+ chunk_size = array .size ;
27
+ }
28
+
29
+ H5Pset_chunk (dcpl , 1 , (hsize_t []){chunk_size });
30
+
31
+ H5Pset_deflate (dcpl , 9 );
32
+
33
+ hid_t dset =
34
+ H5Dcreate2 (f , label , hdf5_standard_type , fspace , lcpl , dcpl , H5P_DEFAULT );
21
35
22
36
if (dset == H5I_INVALID_HID ) {
23
37
return -1 ;
@@ -34,6 +48,7 @@ int bsp_write_array(hid_t f, char* label, bsp_array_t array) {
34
48
35
49
H5Sclose (fspace );
36
50
H5Pclose (lcpl );
51
+ H5Pclose (dcpl );
37
52
38
53
return 0 ;
39
54
}
0 commit comments