summaryrefslogtreecommitdiffstats
path: root/src/H5Dchunk.c
diff options
context:
space:
mode:
authorMark Kittisopikul <mkitti@users.noreply.github.com>2022-08-16 21:59:55 (GMT)
committerGitHub <noreply@github.com>2022-08-16 21:59:55 (GMT)
commit0c1898d6f5707d1844cfcbb4db116ab6dcee77d2 (patch)
tree329d6d08307e21b85dca5c65a7b742419f94f5c5 /src/H5Dchunk.c
parentd9247ec17e8abe53af0a439e1a1b58ade6ae5310 (diff)
downloadhdf5-0c1898d6f5707d1844cfcbb4db116ab6dcee77d2.zip
hdf5-0c1898d6f5707d1844cfcbb4db116ab6dcee77d2.tar.gz
hdf5-0c1898d6f5707d1844cfcbb4db116ab6dcee77d2.tar.bz2
Backport H5Dchunk_iter to 1.12 branch (#1970)
* Revert "Revert H5Dchunk_iter changes in hdf5_1_12_1 (#733)" This reverts commit 10abe9a8b4985a18a0c88615686184d233d7b845. * Apply clang-format * Reincorporate spelling fix from #1166 * Incorporate H5Dchunk_iter changes from #161 * Backport to 1.12: Adds a quick for for some egregious chunk_info badness (#722) * Backport to 1.12: Converts testhdf5 macros to h5test macros in chunk_info.c (#1820) The two macro schemes were not designed to work together. Also quiets some MSVC warnings about comparing pointers and integers. * Backport to 1.12: H5Dchunk_iter now passes offsets in units of dataset elements, fix #1419 (#1969) * H5Dchunk_iter now passes chunk dimension scaled offsets, fix #1419 * Update docs for H5Dchunk_iter, H5Dget_chunk_info* Modified description for `H5Dchunk_iter`, `H5Dget_chunk_info`, and `H5Dget_chunk_info_by_coord` to the following * offset Logical position of the chunk’s first element in units of dataset elements * filter_mask Bitmask indicating the filters used when the chunk was written * size Chunk size in bytes, 0 if the chunk does not exist * Sync H5Dchunk_iter documentation with develop * Remove H5VL_DATASET_WAIT references from 1.12 * Backport to 1.12 #161, #1474, review comments Co-authored-by: Dana Robinson <43805+derobins@users.noreply.github.com>
Diffstat (limited to 'src/H5Dchunk.c')
-rw-r--r--src/H5Dchunk.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c
index f58f3ec..e0eaaeb 100644
--- a/src/H5Dchunk.c
+++ b/src/H5Dchunk.c
@@ -249,6 +249,12 @@ typedef struct H5D_chunk_coll_fill_info_t {
} H5D_chunk_coll_fill_info_t;
#endif /* H5_HAVE_PARALLEL */
+typedef struct H5D_chunk_iter_ud_t {
+ H5D_chunk_iter_op_t op; /* User defined callback */
+ void *op_data; /* User data for user defined callback */
+ H5O_layout_chunk_t *chunk; /* Chunk layout */
+} H5D_chunk_iter_ud_t;
+
/********************/
/* Local Prototypes */
/********************/
@@ -272,6 +278,7 @@ static herr_t H5D__chunk_dest(H5D_t *dset);
static int H5D__get_num_chunks_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata);
static int H5D__get_chunk_info_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata);
static int H5D__get_chunk_info_by_coord_cb(const H5D_chunk_rec_t *chunk_rec, void *_udata);
+static int H5D__chunk_iter_cb(const H5D_chunk_rec_t *chunk_rec, void *udata);
/* "Nonexistent" layout operation callback */
static ssize_t H5D__nonexistent_readvv(const H5D_io_info_t *io_info, size_t chunk_max_nseq,
@@ -7649,3 +7656,106 @@ H5D__get_chunk_info_by_coord(const H5D_t *dset, const hsize_t *offset, unsigned
done:
FUNC_LEAVE_NOAPI_TAG(ret_value)
} /* end H5D__get_chunk_info_by_coord() */
+
+/*-------------------------------------------------------------------------
+ * Function: H5D__chunk_iter_cb
+ *
+ * Purpose: Call the user-defined function with the chunk data. The iterator continues if
+ * the user-defined function returns H5_ITER_CONT, and stops if H5_ITER_STOP is
+ * returned.
+ *
+ * Return: Success: H5_ITER_CONT or H5_ITER_STOP
+ * Failure: Negative (H5_ITER_ERROR)
+ *
+ * Programmer: Gaute Hope
+ * August 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+H5D__chunk_iter_cb(const H5D_chunk_rec_t *chunk_rec, void *udata)
+{
+ const H5D_chunk_iter_ud_t *data = (H5D_chunk_iter_ud_t *)udata;
+ const H5O_layout_chunk_t *chunk = data->chunk;
+ int ret_value = H5_ITER_CONT;
+ hsize_t offset[H5O_LAYOUT_NDIMS];
+ unsigned ii; /* Match H5O_layout_chunk_t.ndims */
+
+ /* Similar to H5D__get_chunk_info */
+ for (ii = 0; ii < chunk->ndims; ii++)
+ offset[ii] = chunk_rec->scaled[ii] * chunk->dim[ii];
+
+ FUNC_ENTER_PACKAGE_NOERR
+
+ /* Check for callback failure and pass along return value */
+ if ((ret_value = (data->op)(offset, chunk_rec->filter_mask, chunk_rec->chunk_addr, chunk_rec->nbytes,
+ data->op_data)) < 0)
+ HERROR(H5E_DATASET, H5E_CANTNEXT, "iteration operator failed");
+
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5D__chunk_iter_cb */
+
+/*-------------------------------------------------------------------------
+ * Function: H5D__chunk_iter
+ *
+ * Purpose: Iterate over all the chunks in the dataset with given callback.
+ *
+ * Return: Success: Non-negative
+ * Failure: Negative
+ *
+ * Programmer: Gaute Hope
+ * August 2020
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5D__chunk_iter(H5D_t *dset, H5D_chunk_iter_op_t op, void *op_data)
+{
+ const H5D_rdcc_t *rdcc = NULL; /* Raw data chunk cache */
+ H5O_layout_t *layout = NULL; /* Dataset layout */
+ H5D_rdcc_ent_t *ent; /* Cache entry index */
+ H5D_chk_idx_info_t idx_info; /* Chunked index info */
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_PACKAGE_TAG(dset->oloc.addr)
+
+ /* Check args */
+ HDassert(dset);
+ HDassert(dset->shared);
+
+ /* Get dataset layout and raw data chunk cache */
+ layout = &(dset->shared->layout);
+ rdcc = &(dset->shared->cache.chunk);
+ HDassert(layout);
+ HDassert(rdcc);
+ HDassert(H5D_CHUNKED == layout->type);
+
+ /* Search for cached chunks that haven't been written out */
+ for (ent = rdcc->head; ent; ent = ent->next)
+ /* Flush the chunk out to disk, to make certain the size is correct later */
+ if (H5D__chunk_flush_entry(dset, ent, FALSE) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_CANTFLUSH, FAIL, "cannot flush indexed storage buffer")
+
+ /* Compose chunked index info struct */
+ idx_info.f = dset->oloc.file;
+ idx_info.pline = &dset->shared->dcpl_cache.pline;
+ idx_info.layout = &layout->u.chunk;
+ idx_info.storage = &layout->storage.u.chunk;
+
+ /* If the dataset is not written, return without errors */
+ if (H5F_addr_defined(idx_info.storage->idx_addr)) {
+ H5D_chunk_iter_ud_t ud;
+
+ /* Set up info for iteration callback */
+ ud.op = op;
+ ud.op_data = op_data;
+ ud.chunk = &dset->shared->layout.u.chunk;
+
+ /* Iterate over the allocated chunks calling the iterator callback */
+ if ((ret_value = (layout->storage.u.chunk.ops->iterate)(&idx_info, H5D__chunk_iter_cb, &ud)) < 0)
+ HERROR(H5E_DATASET, H5E_CANTNEXT, "chunk iteration failed");
+ } /* end if H5F_addr_defined */
+
+done:
+ FUNC_LEAVE_NOAPI_TAG(ret_value)
+} /* end H5D__chunk_iter() */