summaryrefslogtreecommitdiffstats
path: root/src/H5Dio.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2012-11-07 17:08:46 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2012-11-07 17:08:46 (GMT)
commitb7041a91cd7b322007e87ee3b37729ce0319a56c (patch)
tree17b06d4659ecd7add14830d8e9ca3569544aca8e /src/H5Dio.c
parent0cf58a4755eb6f3e7be64b0f05f2bb8ef6f7ad0d (diff)
downloadhdf5-b7041a91cd7b322007e87ee3b37729ce0319a56c.zip
hdf5-b7041a91cd7b322007e87ee3b37729ce0319a56c.tar.gz
hdf5-b7041a91cd7b322007e87ee3b37729ce0319a56c.tar.bz2
[svn-r23017] I added a prototype function H5DOwrite_chunk in HL library for Dectris people to test performance. The library's API function H5PSIdirect_write
is still in. I reorganized the internal library by adding H5D__pre_write function. Tested on koala.
Diffstat (limited to 'src/H5Dio.c')
-rw-r--r--src/H5Dio.c184
1 files changed, 145 insertions, 39 deletions
diff --git a/src/H5Dio.c b/src/H5Dio.c
index 7852b3e..e5a9ccc 100644
--- a/src/H5Dio.c
+++ b/src/H5Dio.c
@@ -58,6 +58,8 @@ static herr_t H5D__read(H5D_t *dataset, hid_t mem_type_id,
static herr_t H5D__write(H5D_t *dataset, hid_t mem_type_id,
const H5S_t *mem_space, const H5S_t *file_space, hid_t dset_xfer_plist,
const void *buf);
+static herr_t H5D__pre_write(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
+ hid_t file_space_id, hid_t dxpl_id, const void *buf);
/* Setup/teardown routines */
static herr_t H5D__ioinfo_init(H5D_t *dset, const H5D_dxpl_cache_t *dxpl_cache,
@@ -215,37 +217,51 @@ herr_t
H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t dxpl_id, const void *buf)
{
- H5D_t *dset = NULL;
- const H5S_t *mem_space = NULL;
- const H5S_t *file_space = NULL;
- char fake_char;
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_API(FAIL)
H5TRACE6("e", "iiiii*x", dset_id, mem_type_id, mem_space_id, file_space_id,
dxpl_id, buf);
+ if(!dset_id)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
+
+ if(H5D__pre_write(dset_id, mem_type_id, mem_space_id, file_space_id, dxpl_id, buf) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't prepare for writing data")
+
+done:
+ FUNC_LEAVE_API(ret_value)
+} /* end H5Dwrite() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5D__pre_write
+ *
+ * Purpose: Preparation for writing data.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Raymond Lu
+ * 2 November 2012
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+H5D__pre_write(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
+ hid_t file_space_id, hid_t dxpl_id, const void *buf)
+{
+ H5D_t *dset = NULL;
+ H5P_genplist_t *plist; /* Property list pointer */
+ htri_t direct_write = FALSE;
+ herr_t ret_value = SUCCEED; /* Return value */
+
+ FUNC_ENTER_NOAPI(FAIL)
+
/* check arguments */
if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
if(NULL == dset->oloc.file)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
- if(H5S_ALL != mem_space_id) {
- if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space")
-
- /* Check for valid selection */
- if(H5S_SELECT_VALID(mem_space) != TRUE)
- HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "memory selection+offset not within extent")
- } /* end if */
- if(H5S_ALL != file_space_id) {
- if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE)))
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space")
-
- /* Check for valid selection */
- if(H5S_SELECT_VALID(file_space) != TRUE)
- HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "file selection+offset not within extent")
- } /* end if */
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Get the default dataset transfer property list if the user didn't provide one */
if(H5P_DEFAULT == dxpl_id)
@@ -253,23 +269,107 @@ H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id,
else
if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms")
- if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0))
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer")
- /* If the buffer is nil, and 0 element is selected, make a fake buffer.
- * This is for some MPI package like ChaMPIon on NCSA's tungsten which
- * doesn't support this feature.
- */
- if(!buf)
- buf = &fake_char;
-
- /* write raw data */
- if(H5D__write(dset, mem_type_id, mem_space, file_space, dxpl_id, buf) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data")
+ /* Get the plist structure */
+ if(NULL == (plist = H5P_object_verify(dxpl_id, H5P_DATASET_XFER)))
+ HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID")
+
+ if(H5P_get(plist, H5D_XFER_DIRECT_CHUNK_WRITE_FLAG_NAME, &direct_write) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting flag for direct chunk write")
+
+ /* Direct chunk write */
+ if(direct_write) {
+ uint32_t direct_filters = 0;
+ hsize_t *direct_offset;
+ size_t direct_datasize = 0;
+ int ndims = 0;
+ hsize_t *dims = NULL;
+ hsize_t *internal_offset = NULL;
+ int i;
+
+ if(H5D_CHUNKED != dset->shared->layout.type)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset")
+
+
+ if(H5P_get(plist, H5D_XFER_DIRECT_CHUNK_WRITE_FILTERS_NAME, &direct_filters) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting filter info for direct chunk write")
+
+ if(H5P_get(plist, H5D_XFER_DIRECT_CHUNK_WRITE_OFFSET_NAME, &direct_offset) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting offset info for direct chunk write")
+
+ if(H5P_get(plist, H5D_XFER_DIRECT_CHUNK_WRITE_DATASIZE_NAME, &direct_datasize) < 0)
+ HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "error getting data size for direct chunk write")
+
+ /* The library's chunking code requires the offset terminates with a zero. So transfer the
+ * offset array to an internal offset array */
+ ndims = (int)H5S_GET_EXTENT_NDIMS(dset->shared->space);
+ if(NULL == (dims = (hsize_t *)H5MM_malloc(ndims*sizeof(hsize_t))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for dimensions")
+
+ if(NULL == (internal_offset = (hsize_t *)H5MM_malloc((ndims+1)*sizeof(hsize_t))))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed for offset")
+
+ if(H5S_get_simple_extent_dims(dset->shared->space, dims, NULL) < 0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't retrieve dataspace extent dims")
+
+ for(i=0; i<ndims; i++) {
+ /* Make sure the offset doesn't exceed the dataset's dimensions */
+ if(direct_offset[i] > dims[i])
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "offset exceeds dimensions of dataset")
+
+ /* Make sure the offset fall right on a chunk's boundary */
+ if(direct_offset[i] % dset->shared->layout.u.chunk.dim[i])
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "offset doesn't fall on chunks's boundary")
+
+ internal_offset[i] = direct_offset[i];
+ }
+
+ /* Terminate the offset with a zero */
+ internal_offset[ndims] = 0;
+
+ /* write raw data */
+ if(H5D__chunk_direct_write(dset, dxpl_id, direct_filters, internal_offset, direct_datasize, buf) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write chunk directly")
+ } else { /* Normal write */
+ const H5S_t *mem_space = NULL;
+ const H5S_t *file_space = NULL;
+ char fake_char;
+
+ if(H5S_ALL != mem_space_id) {
+ if(NULL == (mem_space = (const H5S_t *)H5I_object_verify(mem_space_id, H5I_DATASPACE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space")
+
+ /* Check for valid selection */
+ if(H5S_SELECT_VALID(mem_space) != TRUE)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "memory selection+offset not within extent")
+ } /* end if */
+ if(H5S_ALL != file_space_id) {
+ if(NULL == (file_space = (const H5S_t *)H5I_object_verify(file_space_id, H5I_DATASPACE)))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space")
+
+ /* Check for valid selection */
+ if(H5S_SELECT_VALID(file_space) != TRUE)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "file selection+offset not within extent")
+ } /* end if */
+
+ if(!buf && (NULL == file_space || H5S_GET_SELECT_NPOINTS(file_space) != 0))
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer")
+
+ /* If the buffer is nil, and 0 element is selected, make a fake buffer.
+ * This is for some MPI package like ChaMPIon on NCSA's tungsten which
+ * doesn't support this feature.
+ */
+ if(!buf)
+ buf = &fake_char;
+
+ /* write raw data */
+ if(H5D__write(dset, mem_type_id, mem_space, file_space, dxpl_id, buf) < 0)
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data")
+ }
done:
- FUNC_LEAVE_API(ret_value)
-} /* end H5Dwrite() */
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5D__pre_write() */
/*-------------------------------------------------------------------------
@@ -286,7 +386,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offset,
+H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, uint32_t filters, hsize_t *offset,
size_t data_size, const void *buf)
{
H5D_t *dset = NULL;
@@ -302,7 +402,7 @@ H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offse
if(NULL == (dset = (H5D_t *)H5I_object_verify(dset_id, H5I_DATASET)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
if(NULL == dset->oloc.file)
- HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
if(H5D_CHUNKED != dset->shared->layout.type)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a chunked dataset")
@@ -314,8 +414,14 @@ H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offse
if(TRUE != H5P_isa_class(dxpl_id, H5P_DATASET_XFER))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not xfer parms")
+ if(!offset)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no offset")
+
+ if(!data_size)
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no data size")
+
if(!buf)
- HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no output buffer")
+ HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no data buffer")
ndims = (int)H5S_GET_EXTENT_NDIMS(dset->shared->space);
if(NULL == (dims = (hsize_t *)H5MM_malloc(ndims*sizeof(hsize_t))))
@@ -344,7 +450,7 @@ H5PSIdirect_write(hid_t dset_id, hid_t dxpl_id, unsigned filters, hsize_t *offse
/* write raw data */
if(H5D__chunk_direct_write(dset, dxpl_id, filters, internal_offset, data_size, buf) < 0)
- HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write data")
+ HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't write chunk directly")
done:
if(dims)