From eb0f0ad28736bf01b57cfb65e41a6a43690f1774 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sat, 8 May 2004 14:10:01 -0500 Subject: [svn-r8497] Purpose: Code optimization Description: Further reduce the number of copies we make of a hyperslab selection for chunked I/O, especially when we are only going to throw the old selection away for a new one. Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.9 (sleipnir) w/parallel --- src/H5A.c | 6 +++--- src/H5D.c | 4 ++-- src/H5Dio.c | 18 +++++++++--------- src/H5S.c | 12 ++++++++---- src/H5Shyper.c | 17 ++++++++++++++--- src/H5Spkg.h | 2 +- src/H5Sprivate.h | 4 ++-- src/H5Sselect.c | 11 ++++++++--- 8 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index e7f0cf2..aa786da 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -244,7 +244,7 @@ H5A_create(const H5G_entry_t *ent, const char *name, const H5T_t *type, HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, FAIL, "invalid VL location"); /* Copy the dataspace for the attribute */ - attr->ds=H5S_copy(space); + attr->ds=H5S_copy(space, FALSE); /* Mark it initially set to initialized */ attr->initialized = TRUE; /*for now, set to false later*/ @@ -865,7 +865,7 @@ H5Aget_space(hid_t attr_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute"); /* Copy the attribute's dataspace */ - if (NULL==(dst=H5S_copy (attr->ds))) + if (NULL==(dst=H5S_copy (attr->ds, FALSE))) HGOTO_ERROR (H5E_ATTR, H5E_CANTINIT, FAIL, "unable to copy dataspace"); /* Atomize */ @@ -1499,7 +1499,7 @@ H5A_copy(const H5A_t *old_attr) /* Copy the guts of the attribute */ new_attr->name=HDstrdup(old_attr->name); new_attr->dt=H5T_copy(old_attr->dt, H5T_COPY_ALL); - new_attr->ds=H5S_copy(old_attr->ds); + new_attr->ds=H5S_copy(old_attr->ds, FALSE); if(old_attr->data) { if (NULL==(new_attr->data=H5MM_malloc(old_attr->data_size))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); diff --git a/src/H5D.c b/src/H5D.c index e0076de..1eb550f 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -1232,7 +1232,7 @@ H5Dget_space(hid_t dset_id) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataset"); /* Read the data space message and return a data space object */ - if (NULL==(space=H5S_copy (dset->space))) + if (NULL==(space=H5S_copy (dset->space, FALSE))) HGOTO_ERROR (H5E_DATASET, H5E_CANTINIT, FAIL, "unable to get data space"); /* Create an atom */ @@ -1965,7 +1965,7 @@ H5D_create(H5G_entry_t *loc, const char *name, hid_t type_id, const H5S_t *space HGOTO_ERROR(H5E_DATATYPE, H5E_CANTINIT, NULL, "invalid VL location"); /* Copy dataspace for dataset */ - if((new_dset->space = H5S_copy(space))==NULL) + if((new_dset->space = H5S_copy(space, FALSE))==NULL) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy dataspace"); /* Set the dataset's dataspace to 'all' selection */ diff --git a/src/H5Dio.c b/src/H5Dio.c index 37e95a3..10845c9 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -2393,7 +2393,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp size_t elmt_size; /* Memory datatype size */ /* Make a copy of equivalent memory space */ - if((tmp_mspace = H5S_copy(equiv_mspace))==NULL) + if((tmp_mspace = H5S_copy(equiv_mspace,TRUE))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") /* De-select the mem space copy */ @@ -2633,8 +2633,8 @@ H5D_create_chunk_file_map_hyper(const fm_map *fm) hssize_t schunk_points; /* Number of elements in chunk selection */ /* Create "temporary" chunk for selection operations (copy file space) */ - if((tmp_fchunk = H5S_copy(fm->file_space))==NULL) - HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space"); + if((tmp_fchunk = H5S_copy(fm->file_space,TRUE))==NULL) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") /* Make certain selections are stored in span tree form (not "optimized hyperslab" or "all") */ if(H5S_hyper_convert(tmp_fchunk)<0) @@ -2804,7 +2804,7 @@ H5D_create_chunk_mem_map_hyper(const fm_map *fm) /* Check if it's OK to share dataspace */ if(fm->mem_space_copy) { /* Copy the memory dataspace & selection to be the chunk's dataspace & selection */ - if((chunk_info->mspace = H5S_copy(fm->mem_space))==NULL) + if((chunk_info->mspace = H5S_copy(fm->mem_space,FALSE))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") } /* end if */ else { @@ -2857,16 +2857,16 @@ H5D_create_chunk_mem_map_hyper(const fm_map *fm) /* Copy the information */ /* Copy the memory dataspace */ - if((chunk_info->mspace = H5S_copy(fm->mem_space))==NULL) - HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space"); + if((chunk_info->mspace = H5S_copy(fm->mem_space,TRUE))==NULL) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") /* Release the current selection */ if(H5S_select_release(chunk_info->mspace)<0) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection"); /* Copy the file chunk's selection */ - if(H5S_select_copy(chunk_info->mspace,chunk_info->fspace)<0) - HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy selection"); + if(H5S_select_copy(chunk_info->mspace,chunk_info->fspace,FALSE)<0) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy selection") /* Compensate for the chunk offset */ for(u=0; uf_ndims; u++) { @@ -3103,7 +3103,7 @@ H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_ /* Check if the chunk already has a memory space */ if(chunk_info->mspace==NULL) { /* Copy the template memory chunk dataspace */ - if((chunk_info->mspace = H5S_copy(fm->mchunk_tmpl))==NULL) + if((chunk_info->mspace = H5S_copy(fm->mchunk_tmpl,FALSE))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy file space") } /* end else */ diff --git a/src/H5S.c b/src/H5S.c index c5385a5..1ee34fb 100644 --- a/src/H5S.c +++ b/src/H5S.c @@ -566,7 +566,7 @@ H5Scopy(hid_t space_id) HGOTO_ERROR (H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space"); /* Copy */ - if (NULL==(dst=H5S_copy (src))) + if (NULL==(dst=H5S_copy (src, FALSE))) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy data space"); /* Atomize */ @@ -690,7 +690,11 @@ done: * Function: H5S_copy * * Purpose: Copies a data space, by copying the extent and selection through - * H5S_extent_copy and H5S_select_copy + * H5S_extent_copy and H5S_select_copy. If the SHARE_SELECTION flag + * is set, then the selection can be shared between the source and + * destination dataspaces. (This should only occur in situations + * where the destination dataspace will immediately change to a new + * selection) * * Return: Success: A pointer to a new copy of SRC * @@ -704,7 +708,7 @@ done: *------------------------------------------------------------------------- */ H5S_t * -H5S_copy(const H5S_t *src) +H5S_copy(const H5S_t *src, hbool_t share_selection) { H5S_t *dst = NULL; H5S_t *ret_value; /* Return value */ @@ -724,7 +728,7 @@ H5S_copy(const H5S_t *src) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy extent"); /* Copy the source dataspace's selection */ - if (H5S_select_copy(dst,src)<0) + if (H5S_select_copy(dst,src,share_selection)<0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy select"); /* Set the return value */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 8168694..d559066 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -1553,13 +1553,18 @@ done: DESCRIPTION Copies all the hyperslab selection information from the source dataspace to the destination dataspace. + + If the SHARE_SELECTION flag is set, then the selection can be shared + between the source and destination dataspaces. (This should only occur in + situations where the destination dataspace will immediately change to a new + selection) GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_hyper_copy (H5S_t *dst, const H5S_t *src) +H5S_hyper_copy (H5S_t *dst, const H5S_t *src, hbool_t share_selection) { herr_t ret_value=SUCCEED; /* return value */ @@ -1571,8 +1576,14 @@ H5S_hyper_copy (H5S_t *dst, const H5S_t *src) /* Check if there is hyperslab span information to copy */ /* (Regular hyperslab information is copied with the selection structure) */ if(src->select.sel_info.hslab.span_lst!=NULL) { - /* Copy the hyperslab span information */ - dst->select.sel_info.hslab.span_lst=H5S_hyper_copy_span(src->select.sel_info.hslab.span_lst); + if(share_selection) { + /* Share the source's span tree by incrementing the reference count on it */ + dst->select.sel_info.hslab.span_lst=src->select.sel_info.hslab.span_lst; + dst->select.sel_info.hslab.span_lst->count++; + } /* end if */ + else + /* Copy the hyperslab span information */ + dst->select.sel_info.hslab.span_lst=H5S_hyper_copy_span(src->select.sel_info.hslab.span_lst); } /* end if */ done: diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 313c206..706f8a7 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -217,7 +217,7 @@ H5_DLL herr_t H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); /* Hyperslab selection functions */ H5_DLL herr_t H5S_hyper_release(H5S_t *space); H5_DLL hsize_t H5S_hyper_npoints(const H5S_t *space); -H5_DLL herr_t H5S_hyper_copy(H5S_t *dst, const H5S_t *src); +H5_DLL herr_t H5S_hyper_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); H5_DLL htri_t H5S_hyper_is_valid(const H5S_t *space); H5_DLL hssize_t H5S_hyper_serial_size(const H5S_t *space); H5_DLL herr_t H5S_hyper_serialize(const H5S_t *space, uint8_t *buf); diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 343fa2a..947c34b 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -173,7 +173,7 @@ typedef struct H5S_conv_t { } H5S_conv_t; /* Operations on dataspaces */ -H5_DLL H5S_t *H5S_copy(const H5S_t *src); +H5_DLL H5S_t *H5S_copy(const H5S_t *src, hbool_t share_selection); H5_DLL herr_t H5S_close(H5S_t *ds); H5_DLL H5S_conv_t *H5S_find(const H5S_t *mem_space, const H5S_t *file_space, unsigned flags, hbool_t *use_par_opt_io); @@ -228,7 +228,7 @@ H5_DLL htri_t H5S_select_valid(const H5S_t *space); H5_DLL hssize_t H5S_get_select_npoints(const H5S_t *space); H5_DLL herr_t H5S_get_select_bounds(const H5S_t *space, hssize_t *start, hssize_t *end); H5_DLL herr_t H5S_select_offset(H5S_t *space, const hssize_t *offset); -H5_DLL herr_t H5S_select_copy(H5S_t *dst, const H5S_t *src); +H5_DLL herr_t H5S_select_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); H5_DLL htri_t H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2); H5_DLL herr_t H5S_select_release(H5S_t *ds); diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 2a017b1..d20c3a7 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -113,13 +113,18 @@ done: DESCRIPTION Copies all the selection information (include offset) from the source dataspace to the destination dataspace. + + If the SHARE_SELECTION flag is set, then the selection can be shared + between the source and destination dataspaces. (This should only occur in + situations where the destination dataspace will immediately change to a new + selection) GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_select_copy (H5S_t *dst, const H5S_t *src) +H5S_select_copy (H5S_t *dst, const H5S_t *src, hbool_t share_selection) { herr_t ret_value=SUCCEED; /* return value */ @@ -132,7 +137,7 @@ H5S_select_copy (H5S_t *dst, const H5S_t *src) /* Copy regular fields */ HDmemcpy(&dst->select,&src->select,sizeof(H5S_select_t)); -/* Need to copy order information still */ +/* Need to copy permutation order information still */ /* Copy offset information */ if(src->extent.u.simple.rank>0) { @@ -165,7 +170,7 @@ H5S_select_copy (H5S_t *dst, const H5S_t *src) break; case H5S_SEL_HYPERSLABS: - ret_value=H5S_hyper_copy(dst,src); + ret_value=H5S_hyper_copy(dst,src,share_selection); break; default: -- cgit v0.12