@@ -201,6 +201,8 @@ H5D__init_package(void)
201
201
H5D_def_dset .type_id = H5I_INVALID_HID ;
202
202
H5D_def_dset .dapl_id = H5I_INVALID_HID ;
203
203
H5D_def_dset .dcpl_id = H5I_INVALID_HID ;
204
+ /* By default, do not copy layout immediately */
205
+ H5D_def_dset .layout_copied_to_dcpl = false;
204
206
205
207
/* Get the default dataset creation property list values and initialize the
206
208
* default dataset with them.
@@ -485,13 +487,19 @@ H5D__new(hid_t dcpl_id, hid_t dapl_id, bool creating, bool vl_type)
485
487
if (H5I_inc_ref (dcpl_id , false) < 0 )
486
488
HGOTO_ERROR (H5E_DATASET , H5E_CANTINC , NULL , "can't increment default DCPL ID" );
487
489
new_dset -> dcpl_id = dcpl_id ;
490
+
491
+ new_dset -> layout_copied_to_dcpl = true;
488
492
} /* end if */
489
493
else {
490
494
/* Get the property list */
491
495
if (NULL == (plist = (H5P_genplist_t * )H5I_object (dcpl_id )))
492
496
HGOTO_ERROR (H5E_ARGS , H5E_BADTYPE , NULL , "not a property list" );
493
497
494
498
new_dset -> dcpl_id = H5P_copy_plist (plist , false);
499
+
500
+ /* If a specific DCPL was provided, then the dset's internal DCPL now has an accurate layout */
501
+ if (creating )
502
+ new_dset -> layout_copied_to_dcpl = true;
495
503
} /* end else */
496
504
497
505
if (!vl_type && creating && dapl_id == H5P_DATASET_ACCESS_DEFAULT ) {
@@ -1261,6 +1269,9 @@ H5D__create(H5F_t *file, hid_t type_id, const H5S_t *space, hid_t dcpl_id, hid_t
1261
1269
HGOTO_ERROR (H5E_ARGS , H5E_CANTINIT , NULL , "H5Z_has_optional_filter() failed" );
1262
1270
1263
1271
if (false == ignore_filters ) {
1272
+ /* Layout only exists on DCPL at this point in dset creation */
1273
+ assert (new_dset -> shared -> layout_copied_to_dcpl );
1274
+
1264
1275
/* Check if the filters in the DCPL can be applied to this dataset */
1265
1276
if (H5Z_can_apply (new_dset -> shared -> dcpl_id , new_dset -> shared -> type_id ) < 0 )
1266
1277
HGOTO_ERROR (H5E_ARGS , H5E_CANTINIT , NULL , "I/O filters can't operate on this dataset" );
@@ -3020,6 +3031,10 @@ H5D__check_filters(H5D_t *dataset)
3020
3031
if (fill_status == H5D_FILL_VALUE_DEFAULT || fill_status == H5D_FILL_VALUE_USER_DEFINED ) {
3021
3032
if (fill -> fill_time == H5D_FILL_TIME_ALLOC ||
3022
3033
(fill - > fill_time == H5D_FILL_TIME_IFSET && fill_status == H5D_FILL_VALUE_USER_DEFINED )) {
3034
+ /* Flush layout to DCPL before reading */
3035
+ if (H5D_flush_layout_to_dcpl (dataset ) < 0 )
3036
+ HGOTO_ERROR (H5E_DATASET , H5E_CANTSET , FAIL , "unable to flush layout ");
3037
+
3023
3038
/* Filters must have encoding enabled. Ensure that all filters can be applied */
3024
3039
if (H5Z_can_apply (dataset - > shared - > dcpl_id , dataset - > shared - > type_id ) < 0 )
3025
3040
HGOTO_ERROR (H5E_PLINE , H5E_CANAPPLY , FAIL , "can 't apply filters");
@@ -3631,6 +3646,11 @@ H5D_get_create_plist(const H5D_t *dset)
3631
3646
if (NULL == (dcpl_plist = (H5P_genplist_t * )H5I_object (dset -> shared -> dcpl_id )))
3632
3647
HGOTO_ERROR (H5E_DATASET , H5E_BADTYPE , FAIL , "can 't get property list");
3633
3648
3649
+ /* If necessary, flush virtual layout changes to the DCPL before copying */
3650
+ if (H5D_flush_layout_to_dcpl (dset ) < 0 ) {
3651
+ HGOTO_ERROR (H5E_DATASET , H5E_CANTSET , FAIL , "can't flush layout to DCPL" );
3652
+ }
3653
+
3634
3654
/* Copy the creation property list */
3635
3655
if ((new_dcpl_id = H5P_copy_plist (dcpl_plist , true)) < 0 )
3636
3656
HGOTO_ERROR (H5E_DATASET , H5E_CANTGET , FAIL , "unable to copy the creation property list" );
@@ -4057,3 +4077,55 @@ H5D_get_dcpl_id(const H5D_obj_create_t *d)
4057
4077
4058
4078
FUNC_LEAVE_NOAPI (d -> dcpl_id );
4059
4079
} /* end H5D_get_dcpl_id() */
4080
+
4081
+ /*-------------------------------------------------------------------------
4082
+ * Function: H5D_flush_layout_to_dcpl
4083
+ *
4084
+ * Purpose: Copy the dataset's creation-time layout to the internal DCPL,
4085
+ * if this has not yet been done.
4086
+ *
4087
+ * Return: Success: non-negative
4088
+ *
4089
+ * Failure: negative
4090
+ *-------------------------------------------------------------------------
4091
+ */
4092
+ herr_t
4093
+ H5D_flush_layout_to_dcpl (const H5D_t * dset )
4094
+ {
4095
+ herr_t ret_value = SUCCEED ;
4096
+ H5P_genplist_t * dcpl = NULL;
4097
+ bool ndims_modified = false;
4098
+
4099
+ FUNC_ENTER_NOAPI (FAIL )
4100
+
4101
+ if ((dcpl = H5P_object_verify (dset -> shared -> dcpl_id , H5P_DATASET_CREATE , true )) == NULL ) {
4102
+ HGOTO_ERROR (H5E_DATASET , H5E_BADID , FAIL , "invalid DCPL ID" );
4103
+ }
4104
+
4105
+ if (!dset -> shared -> layout_copied_to_dcpl ) {
4106
+ /* Don't modify default DCPL; short-circuit success */
4107
+ if (H5P_is_default_plist (dset -> shared -> dcpl_id )) {
4108
+ HGOTO_DONE (ret_value );
4109
+ }
4110
+
4111
+ /* Adjust chunk dimensions to omit datatype size (in last dimension) for creation property */
4112
+ if (H5D_CHUNKED == dset -> shared -> layout .type ) {
4113
+ dset -> shared -> layout .u .chunk .ndims -- ;
4114
+ ndims_modified = true;
4115
+ }
4116
+
4117
+ /* Copy layout property to DCPL from dataset */
4118
+ if (H5P_set (dcpl , H5D_CRT_LAYOUT_NAME , (void * )& dset -> shared -> layout ) < 0 ) {
4119
+ HGOTO_ERROR (H5E_DATASET , H5E_CANTSET , FAIL , "can't set layout property" );
4120
+ }
4121
+ }
4122
+
4123
+ done :
4124
+ if (ret_value == SUCCEED )
4125
+ dset -> shared -> layout_copied_to_dcpl = true;
4126
+
4127
+ if (ndims_modified )
4128
+ dset -> shared -> layout .u .chunk .ndims ++ ;
4129
+
4130
+ FUNC_LEAVE_NOAPI (ret_value );
4131
+ } /* end H5D_flush_layout_to_dcpl() */
0 commit comments