From 253ee36580536cb1ebcc51876ee841538d0a83eb Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 22 Apr 2004 15:21:51 -0500 Subject: [svn-r8409] Purpose: Code optimization Description: Instead of dynamicly allocating various arrays for various pieces of information about a selection or selection iterator, just use fixed size array of size H5S_MAX_RANK (as the rest of the library does). Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.9 (sleipnir) h5committest --- src/H5S.c | 13 ++- src/H5Shyper.c | 319 +++++++++++++++---------------------------------------- src/H5Spkg.h | 19 +--- src/H5Sprivate.h | 20 ++-- src/H5Sselect.c | 12 +-- 5 files changed, 119 insertions(+), 264 deletions(-) diff --git a/src/H5S.c b/src/H5S.c index 7b7354e..6f9b03a 100644 --- a/src/H5S.c +++ b/src/H5S.c @@ -645,11 +645,14 @@ H5S_extent_copy(H5S_extent_t *dst, const H5S_extent_t *src) FUNC_ENTER_NOAPI(H5S_extent_copy, FAIL); /* Copy the regular fields */ - *dst=*src; + dst->type=src->type; + dst->nelem=src->nelem; + dst->u.simple.rank=src->u.simple.rank; switch (src->type) { case H5S_SCALAR: - /*nothing needed */ + dst->u.simple.size=NULL; + dst->u.simple.max=NULL; break; case H5S_SIMPLE: @@ -658,11 +661,15 @@ H5S_extent_copy(H5S_extent_t *dst, const H5S_extent_t *src) for (u = 0; u < src->u.simple.rank; u++) dst->u.simple.size[u] = src->u.simple.size[u]; } + else + dst->u.simple.size=NULL; if (src->u.simple.max) { dst->u.simple.max = H5FL_ARR_MALLOC(hsize_t,src->u.simple.rank); for (u = 0; u < src->u.simple.rank; u++) dst->u.simple.max[u] = src->u.simple.max[u]; } + else + dst->u.simple.max=NULL; break; case H5S_COMPLEX: @@ -707,8 +714,10 @@ H5S_copy(const H5S_t *src) if (NULL==(dst = H5FL_MALLOC(H5S_t))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed"); +#ifdef LATER /* Copy the field in the struct */ *dst = *src; +#endif /* LATER */ /* Copy the source dataspace's extent */ if (H5S_extent_copy(&(dst->extent),&(src->extent))<0) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index ea51475..9c0dcf6 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -71,21 +71,9 @@ static const hsize_t _block[H5O_LAYOUT_NDIMS]={ /* Default block size ar /* Declare a free list to manage the H5S_hyper_span_t struct */ H5FL_DEFINE_STATIC(H5S_hyper_span_t); -/* Declare a free list to manage arrays of H5S_hyper_span_t */ -H5FL_ARR_DEFINE_STATIC(H5S_hyper_span_t,H5S_MAX_RANK); - /* Declare a free list to manage the H5S_hyper_span_info_t struct */ H5FL_DEFINE_STATIC(H5S_hyper_span_info_t); -/* Declare external the free list for hssize_t arrays */ -H5FL_ARR_EXTERN(hssize_t); - -/* Declare a free list to manage arrays of hsize_t */ -H5FL_ARR_EXTERN(hsize_t); - -/* Declare a free list to manage arrays of H5S_hyper_dim_t */ -H5FL_ARR_DEFINE_STATIC(H5S_hyper_dim_t,H5S_MAX_RANK); - /* #define H5S_HYPER_DEBUG */ #ifdef H5S_HYPER_DEBUG static herr_t @@ -160,7 +148,7 @@ H5S_hyper_print_diminfo(FILE *f, const H5S_t *space) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_print_diminfo); - H5S_hyper_print_diminfo_helper(f,"diminfo",space->extent.u.simple.rank,space->select.sel_info.hslab.diminfo); + H5S_hyper_print_diminfo_helper(f,"opt_diminfo",space->extent.u.simple.rank,space->select.sel_info.hslab.opt_diminfo); H5S_hyper_print_diminfo_helper(f,"app_diminfo",space->extent.u.simple.rank,space->select.sel_info.hslab.app_diminfo); FUNC_LEAVE_NOAPI(SUCCEED); @@ -212,10 +200,10 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size) rank=space->extent.u.simple.rank; /* Set the temporary pointer to the dimension information */ - tdiminfo=space->select.sel_info.hslab.diminfo; + tdiminfo=space->select.sel_info.hslab.opt_diminfo; /* Check for the special case of just one H5Sselect_hyperslab call made */ - if(tdiminfo!=NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* Initialize the information needed for regular hyperslab I/O */ const hsize_t *mem_size; /* Temporary pointer to dataspace extent's dimension sizes */ hsize_t acc; /* Accumulator for "flattened" dimension's sizes */ @@ -251,16 +239,6 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size) /* Set the iterator's rank to the contiguous dimensions */ iter->u.hyp.iter_rank=flat_rank; - /* Allocate the position & initialize to initial location */ - iter->u.hyp.off = H5FL_ARR_MALLOC(hsize_t,flat_rank); - assert(iter->u.hyp.off); - iter->u.hyp.diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,flat_rank); - assert(iter->u.hyp.diminfo); - iter->u.hyp.size = H5FL_ARR_MALLOC(hsize_t,flat_rank); - assert(iter->u.hyp.size); - iter->u.hyp.sel_off = H5FL_ARR_MALLOC(hssize_t,flat_rank); - assert(iter->u.hyp.sel_off); - /* "Flatten" dataspace extent and selection information */ curr_dim=flat_rank-1; for(i=rank-1, acc=1; i>=0; i--) { @@ -311,14 +289,6 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size) iter->u.hyp.off[u]=iter->u.hyp.diminfo[u].start; } /* end if */ else { - /* Allocate the position & initialize to initial location */ - iter->u.hyp.off = H5FL_ARR_MALLOC(hsize_t,rank); - assert(iter->u.hyp.off); - - /* Allocate the storage for the regular selection information */ - iter->u.hyp.diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,rank); - assert(iter->u.hyp.diminfo); - /* Initialize position to initial location */ /* Also make local copy of the regular selection information */ for(u=0; uu.hyp.off[u]=tdiminfo[u].start; } /* end if */ - - /* Initialize other regular region information also (for release) */ - iter->u.hyp.size = NULL; - iter->u.hyp.sel_off = NULL; } /* end else */ + /* Flag the diminfo information as valid in the iterator */ + iter->u.hyp.diminfo_valid=TRUE; + /* Initialize irregular region information also (for release) */ iter->u.hyp.spans=NULL; - iter->u.hyp.span=NULL; } /* end if */ else { /* Initialize the information needed for non-regular hyperslab I/O */ @@ -349,12 +317,6 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size) /* Set the nelem & pstride values according to the element size */ H5S_hyper_span_precompute(iter->u.hyp.spans,elmt_size); - /* Allocate the span tree pointers, span pointers and positions */ - iter->u.hyp.span = H5FL_ARR_MALLOC(H5S_hyper_span_t,rank); - assert(iter->u.hyp.span); - iter->u.hyp.off = H5FL_ARR_MALLOC(hsize_t,rank); - assert(iter->u.hyp.off); - /* Initialize the starting span_info's and spans */ spans=iter->u.hyp.spans; for(u=0; uhead->down; } /* end for */ - /* Initialize regular region information also (for release) */ - iter->u.hyp.diminfo = NULL; - iter->u.hyp.size = NULL; - iter->u.hyp.sel_off = NULL; + /* Flag the diminfo information as not valid in the iterator */ + iter->u.hyp.diminfo_valid=FALSE; + } /* end else */ /* Initialize methods for selection iterator */ @@ -419,7 +380,7 @@ H5S_hyper_iter_coords (const H5S_sel_iter_t *iter, hssize_t *coords) /* Copy the offset of the current point */ /* Check for a single "regular" hyperslab */ - if(iter->u.hyp.diminfo!=NULL) { + if(iter->u.hyp.diminfo_valid) { /* Check if this is a "flattened" regular hyperslab selection */ if(iter->u.hyp.iter_rank!=0 && iter->u.hyp.iter_rankrank) { unsigned flat_dim; /* The rank of the flattened dimension */ @@ -477,7 +438,7 @@ H5S_hyper_iter_block (const H5S_sel_iter_t *iter, hssize_t *start, hssize_t *end /* Copy the offset of the current point */ /* Check for a single "regular" hyperslab */ - if(iter->u.hyp.diminfo!=NULL) { + if(iter->u.hyp.diminfo_valid) { /* Copy the current iterator offset as the start */ HDmemcpy(start,iter->u.hyp.off,sizeof(hssize_t)*iter->rank); @@ -554,7 +515,7 @@ H5S_hyper_iter_has_next_block(const H5S_sel_iter_t *iter) assert (iter); /* Check for a single "regular" hyperslab */ - if(iter->u.hyp.diminfo!=NULL) { + if(iter->u.hyp.diminfo_valid) { const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ const hssize_t *toff; /* Temporary offset in selection */ @@ -611,7 +572,7 @@ H5S_hyper_iter_next(H5S_sel_iter_t *iter, size_t nelem) /* Check for the special case of just one H5Sselect_hyperslab call made */ /* (i.e. a regular hyperslab selection */ - if(iter->u.hyp.diminfo!=NULL) { + if(iter->u.hyp.diminfo_valid) { const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ hsize_t iter_offset[H5O_LAYOUT_NDIMS]; hsize_t iter_count[H5O_LAYOUT_NDIMS]; @@ -826,7 +787,7 @@ H5S_hyper_iter_next_block(H5S_sel_iter_t *iter) /* Check for the special case of just one H5Sselect_hyperslab call made */ /* (i.e. a regular hyperslab selection */ - if(iter->u.hyp.diminfo!=NULL) { + if(iter->u.hyp.diminfo_valid) { const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ hsize_t iter_offset[H5O_LAYOUT_NDIMS]; hsize_t iter_count[H5O_LAYOUT_NDIMS]; @@ -1009,32 +970,11 @@ H5S_hyper_iter_release (H5S_sel_iter_t *iter) /* Check args */ assert (iter); - /* Release the common array of offsets/positions */ - if(iter->u.hyp.off!=NULL) - H5FL_ARR_FREE(hsize_t,iter->u.hyp.off); - -/* Release the information needed for "flattened" regular hyperslab I/O */ - /* Free the "flattened" dataspace extent */ - if(iter->u.hyp.size!=NULL) - H5FL_ARR_FREE(hsize_t,iter->u.hyp.size); - - /* Free the "flattened" regular hyperslab selection */ - if(iter->u.hyp.diminfo!=NULL) - H5FL_ARR_FREE(H5S_hyper_dim_t,iter->u.hyp.diminfo); - - /* Free the "flattened" selection offset */ - if(iter->u.hyp.sel_off!=NULL) - H5FL_ARR_FREE(hssize_t,iter->u.hyp.sel_off); - /* Release the information needed for non-regular hyperslab I/O */ /* Free the copy of the selections span tree */ if(iter->u.hyp.spans!=NULL) H5S_hyper_free_span_info(iter->u.hyp.spans); - /* Release the array of pointers to span nodes */ - if(iter->u.hyp.span!=NULL) - H5FL_ARR_FREE(H5S_hyper_span_t,iter->u.hyp.span); - FUNC_LEAVE_NOAPI(SUCCEED); } /* H5S_hyper_iter_release() */ @@ -1625,8 +1565,6 @@ done: herr_t H5S_hyper_copy (H5S_t *dst, const H5S_t *src) { - H5S_hyper_dim_t *new_diminfo=NULL; /* New per-dimension info array[rank] */ - unsigned u; /* Counters */ herr_t ret_value=SUCCEED; /* return value */ FUNC_ENTER_NOAPI(H5S_hyper_copy, FAIL); @@ -1634,40 +1572,8 @@ H5S_hyper_copy (H5S_t *dst, const H5S_t *src) assert(src); assert(dst); - /* Check if there is regular hyperslab information to copy */ - if(src->select.sel_info.hslab.diminfo!=NULL) { - /* Create the per-dimension selection info */ - if((new_diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,src->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension array"); - - /* Copy the per-dimension selection info */ - for(u=0; uextent.u.simple.rank; u++) { - new_diminfo[u].start = src->select.sel_info.hslab.diminfo[u].start; - new_diminfo[u].stride = src->select.sel_info.hslab.diminfo[u].stride; - new_diminfo[u].count = src->select.sel_info.hslab.diminfo[u].count; - new_diminfo[u].block = src->select.sel_info.hslab.diminfo[u].block; - } /* end for */ - dst->select.sel_info.hslab.diminfo = new_diminfo; - - /* Create the per-dimension selection info */ - if((new_diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,src->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension array"); - - /* Copy the per-dimension selection info */ - for(u=0; uextent.u.simple.rank; u++) { - new_diminfo[u].start = src->select.sel_info.hslab.app_diminfo[u].start; - new_diminfo[u].stride = src->select.sel_info.hslab.app_diminfo[u].stride; - new_diminfo[u].count = src->select.sel_info.hslab.app_diminfo[u].count; - new_diminfo[u].block = src->select.sel_info.hslab.app_diminfo[u].block; - } /* end for */ - dst->select.sel_info.hslab.app_diminfo = new_diminfo; - } /* end if */ - else { - dst->select.sel_info.hslab.diminfo = new_diminfo; - dst->select.sel_info.hslab.app_diminfo = new_diminfo; - } /* end else */ - /* 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); @@ -1775,8 +1681,8 @@ H5S_hyper_is_valid (const H5S_t *space) assert(space); /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo != NULL) { - const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab.diminfo; /* local alias for diminfo */ + if(space->select.sel_info.hslab.diminfo_valid) { + const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab.opt_diminfo; /* local alias for diminfo */ hssize_t end; /* The high bound of a region in a dimension */ /* Check each dimension */ @@ -1888,7 +1794,7 @@ H5S_get_select_hyper_nblocks(H5S_t *space) assert(space); /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* Check each dimension */ for(ret_value=1,u=0; uextent.u.simple.rank; u++) ret_value*=space->select.sel_info.hslab.app_diminfo[u].count; @@ -1976,10 +1882,10 @@ H5S_hyper_serial_size (const H5S_t *space) ret_value=24; /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* Check each dimension */ for(block_count=1,u=0; uextent.u.simple.rank; u++) - block_count*=space->select.sel_info.hslab.diminfo[u].count; + block_count*=space->select.sel_info.hslab.opt_diminfo[u].count; ret_value+=8*block_count*space->extent.u.simple.rank; } /* end if */ else { @@ -2093,7 +1999,7 @@ done: herr_t H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) { - H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ + const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ hsize_t tmp_count[H5O_LAYOUT_NDIMS]; /* Temporary hyperslab counts */ hssize_t offset[H5O_LAYOUT_NDIMS]; /* Offset of element in dataspace */ hssize_t start[H5O_LAYOUT_NDIMS]; /* Location of start of hyperslab */ @@ -2125,11 +2031,11 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) len+=4; /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* Set some convienence values */ ndims=space->extent.u.simple.rank; fast_dim=ndims-1; - diminfo=space->select.sel_info.hslab.diminfo; + diminfo=space->select.sel_info.hslab.opt_diminfo; /* Check each dimension */ for(block_count=1,i=0; iselect.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* Set some convienence values */ ndims=space->extent.u.simple.rank; fast_dim=ndims-1; @@ -2497,7 +2384,7 @@ H5S_get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startbloc * Use the "optimized dimension information" to pass back information * on the blocks set, not the "application information". */ - diminfo=space->select.sel_info.hslab.diminfo; + diminfo=space->select.sel_info.hslab.opt_diminfo; else /* * Use the "application dimension information" to pass back to the user @@ -2757,8 +2644,8 @@ H5S_hyper_bounds(const H5S_t *space, hssize_t *start, hssize_t *end) } /* end for */ /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo!=NULL) { - const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab.diminfo; /* local alias for diminfo */ + if(space->select.sel_info.hslab.diminfo_valid) { + const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab.opt_diminfo; /* local alias for diminfo */ /* Check each dimension */ for(i=0; iselect.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { + const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab.opt_diminfo; /* local alias for diminfo */ + /* * For a regular hyperslab to be contiguous, it must have only one * block (i.e. count==1 in all dimensions) and the block size must be @@ -2832,11 +2721,11 @@ H5S_hyper_is_contiguous(const H5S_t *space) /* Check for a "large contigous" block */ for(u=0; uextent.u.simple.rank; u++) { - if(space->select.sel_info.hslab.diminfo[u].count>1) { + if(diminfo[u].count>1) { large_contiguous=FALSE; break; } /* end if */ - if(u>0 && space->select.sel_info.hslab.diminfo[u].block!=space->extent.u.simple.size[u]) { + if(u>0 && diminfo[u].block!=space->extent.u.simple.size[u]) { large_contiguous=FALSE; break; } /* end if */ @@ -2846,11 +2735,11 @@ H5S_hyper_is_contiguous(const H5S_t *space) if(large_contiguous==FALSE) { small_contiguous=TRUE; for(u=0; uextent.u.simple.rank; u++) { - if(space->select.sel_info.hslab.diminfo[u].count>1) { + if(diminfo[u].count>1) { small_contiguous=FALSE; break; } /* end if */ - if(u<(space->extent.u.simple.rank-1) && space->select.sel_info.hslab.diminfo[u].block!=1) { + if(u<(space->extent.u.simple.rank-1) && diminfo[u].block!=1) { small_contiguous=FALSE; break; } /* end if */ @@ -2993,7 +2882,7 @@ H5S_hyper_is_single(const H5S_t *space) assert(space); /* Check for a "single" hyperslab selection */ - if(space->select.sel_info.hslab.diminfo != NULL) { + if(space->select.sel_info.hslab.diminfo_valid) { /* * For a regular hyperslab to be single, it must have only one * block (i.e. count==1 in all dimensions) @@ -3004,7 +2893,7 @@ H5S_hyper_is_single(const H5S_t *space) /* Check for a single block */ for(u=0; uextent.u.simple.rank; u++) { - if(space->select.sel_info.hslab.diminfo[u].count>1) { + if(space->select.sel_info.hslab.opt_diminfo[u].count>1) { ret_value=FALSE; break; } /* end if */ @@ -3072,7 +2961,7 @@ H5S_hyper_is_regular(const H5S_t *space) assert(space); /* Only simple check for regular hyperslabs for now... */ - if(space->select.sel_info.hslab.diminfo != NULL) + if(space->select.sel_info.hslab.diminfo_valid) ret_value=TRUE; else ret_value=FALSE; @@ -3117,13 +3006,8 @@ H5S_hyper_release (H5S_t *space) /* Reset the number of points selected */ space->select.num_elem=0; - /* Release the regular selection info */ - if(space->select.sel_info.hslab.diminfo!=NULL) { - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.diminfo); - space->select.sel_info.hslab.diminfo = NULL; - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.app_diminfo); - space->select.sel_info.hslab.app_diminfo = NULL; - } /* end if */ + /* Reset the regular selection info flag */ + space->select.sel_info.hslab.diminfo_valid=FALSE; /* Release irregular hyperslab information */ if(space->select.sel_info.hslab.span_lst!=NULL) { @@ -3496,9 +3380,8 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, hssize_t *coords) /* Set selection type */ space->select.type=H5S_SEL_HYPERSLABS; - /* Reset "regular" hyperslab fields */ - space->select.sel_info.hslab.diminfo = NULL; - space->select.sel_info.hslab.app_diminfo = NULL; + /* Reset "regular" hyperslab flag */ + space->select.sel_info.hslab.diminfo_valid=FALSE; /* Set selection methods */ space->select.get_seq_list=H5S_hyper_get_seq_list; @@ -3966,10 +3849,10 @@ H5S_hyper_adjust(H5S_t *space, const hssize_t *offset) assert(offset); /* Subtract the offset from the "regular" coordinates, if they exist */ - if(space->select.sel_info.hslab.diminfo) { + if(space->select.sel_info.hslab.diminfo_valid) { for(u=0; uextent.u.simple.rank; u++) { - space->select.sel_info.hslab.diminfo[u].start-=offset[u]; - assert(space->select.sel_info.hslab.diminfo[u].start>=0); + space->select.sel_info.hslab.opt_diminfo[u].start-=offset[u]; + assert(space->select.sel_info.hslab.opt_diminfo[u].start>=0); } /* end for */ } /* end if */ @@ -4081,10 +3964,10 @@ H5S_hyper_move(H5S_t *space, const hssize_t *offset) assert(offset); /* Move to the offset with the "regular" coordinates, if they exist */ - if(space->select.sel_info.hslab.diminfo) { + if(space->select.sel_info.hslab.diminfo_valid) { for(u=0; uextent.u.simple.rank; u++) { - space->select.sel_info.hslab.diminfo[u].start=offset[u]; - assert(space->select.sel_info.hslab.diminfo[u].start>=0); + space->select.sel_info.hslab.opt_diminfo[u].start=offset[u]; + assert(space->select.sel_info.hslab.opt_diminfo[u].start>=0); } /* end for */ } /* end if */ @@ -5372,7 +5255,7 @@ H5S_hyper_rebuild (H5S_t *space) unsigned curr_dim; /* Current dimension being worked on */ herr_t ret_value=SUCCEED; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5S_hyper_rebuild); + FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5S_hyper_rebuild); /* Check args */ assert (space); @@ -5383,16 +5266,10 @@ H5S_hyper_rebuild (H5S_t *space) /* Protect against empty tree */ if(span!=NULL) { - /* Allocate space for the optimized hyperslab information */ - if((diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); - - /* Allocate space for the optimized hyperslab information */ - if((app_diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); - /* Iterate down the span tree */ curr_dim=0; + diminfo=space->select.sel_info.hslab.opt_diminfo; + app_diminfo=space->select.sel_info.hslab.app_diminfo; while(span!=NULL) { /* Sanity check */ assert(curr_dimextent.u.simple.rank); @@ -5413,12 +5290,10 @@ H5S_hyper_rebuild (H5S_t *space) break; } /* end while */ - /* Set the dataspace's pointers to the new optimized information */ - space->select.sel_info.hslab.diminfo = diminfo; - space->select.sel_info.hslab.app_diminfo = app_diminfo; + /* Indicate that the diminfo is valid */ + space->select.sel_info.hslab.diminfo_valid=TRUE; } /* end if */ -done: FUNC_LEAVE_NOAPI(ret_value); } /* H5S_hyper_rebuild() */ @@ -5822,24 +5697,17 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, if((*space->select.release)(space)<0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release hyperslab"); - /* Copy all the application per-dimension selection info into the space descriptor */ - if((diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); + /* Save the diminfo */ + diminfo=space->select.sel_info.hslab.opt_diminfo; for(u=0; uextent.u.simple.rank; u++) { - diminfo[u].start = start[u]; - diminfo[u].stride = stride[u]; - diminfo[u].count = count[u]; - diminfo[u].block = block[u]; - } /* end for */ - space->select.sel_info.hslab.app_diminfo = diminfo; + space->select.sel_info.hslab.app_diminfo[u].start = start[u]; + space->select.sel_info.hslab.app_diminfo[u].stride = stride[u]; + space->select.sel_info.hslab.app_diminfo[u].count = count[u]; + space->select.sel_info.hslab.app_diminfo[u].block = block[u]; - /* Allocate room for the optimized per-dimension selection info */ - if((diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); + /* Optimize the hyperslab selection to detect contiguously selected block/stride information */ + /* Modify the stride, block & count for contiguous hyperslab selections */ - /* Optimize the hyperslab selection to detect contiguously selected block/stride information */ - /* Modify the stride, block & count for contiguous hyperslab selections */ - for(u=0; uextent.u.simple.rank; u++) { /* Starting location doesn't get optimized */ diminfo[u].start = start[u]; @@ -5860,7 +5728,9 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, diminfo[u].block=block[u]; } /* end else */ } /* end for */ - space->select.sel_info.hslab.diminfo = diminfo; + + /* Indicate that the dimension information is valid */ + space->select.sel_info.hslab.diminfo_valid=TRUE; /* Build the hyperslab information also */ if(H5S_generate_hyperslab (space, H5S_SELECT_SET, start, stride, count, block)<0) @@ -5870,16 +5740,8 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Sanity check */ assert(space->select.type==H5S_SEL_HYPERSLABS); - /* Is this the first operation? */ - if(space->select.sel_info.hslab.diminfo != NULL) { - /* Remove the 'diminfo' information, since we're adding to it */ - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.diminfo); - space->select.sel_info.hslab.diminfo = NULL; - - /* Remove the 'app_diminfo' information also, since we're adding to it */ - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.app_diminfo); - space->select.sel_info.hslab.app_diminfo = NULL; - } /* end if */ + /* Indicate that the regular dimensions are no longer valid */ + space->select.sel_info.hslab.diminfo_valid=FALSE; /* Add in the new hyperslab information */ if(H5S_generate_hyperslab (space, op, start, stride, count, block)<0) @@ -6422,24 +6284,17 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, if((*space->select.release)(space)<0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release hyperslab"); - /* Copy all the application per-dimension selection info into the space descriptor */ - if((diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); + /* Save the diminfo */ + diminfo=space->select.sel_info.hslab.diminfo; for(u=0; uextent.u.simple.rank; u++) { - diminfo[u].start = start[u]; - diminfo[u].stride = stride[u]; - diminfo[u].count = count[u]; - diminfo[u].block = block[u]; - } /* end for */ - space->select.sel_info.hslab.app_diminfo = diminfo; + space->select.sel_info.hslab.app_diminfo[u].start = start[u]; + space->select.sel_info.hslab.app_diminfo[u].stride = stride[u]; + space->select.sel_info.hslab.app_diminfo[u].count = count[u]; + space->select.sel_info.hslab.app_diminfo[u].block = block[u]; - /* Allocate room for the optimized per-dimension selection info */ - if((diminfo = H5FL_ARR_MALLOC(H5S_hyper_dim_t,space->extent.u.simple.rank))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate per-dimension vector"); + /* Optimize the hyperslab selection to detect contiguously selected block/stride information */ + /* Modify the stride, block & count for contiguous hyperslab selections */ - /* Optimize the hyperslab selection to detect contiguously selected block/stride information */ - /* Modify the stride, block & count for contiguous hyperslab selections */ - for(u=0; uextent.u.simple.rank; u++) { /* Starting location doesn't get optimized */ diminfo[u].start = start[u]; @@ -6460,7 +6315,9 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, diminfo[u].block=block[u]; } /* end else */ } /* end for */ - space->select.sel_info.hslab.diminfo = diminfo; + + /* Indicate that the dimension information is valid */ + space->select.sel_info.hslab.diminfo_valid=TRUE; /* Build the hyperslab information also */ if(H5S_generate_hyperslab (space, H5S_SELECT_SET, start, stride, count, block)<0) @@ -6470,16 +6327,8 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Sanity check */ assert(space->select.type==H5S_SEL_HYPERSLABS); - /* Is this the first 'or' operation? */ - if(space->select.sel_info.hslab.diminfo != NULL) { - /* Remove the 'diminfo' information, since we're adding to it */ - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.diminfo); - space->select.sel_info.hslab.diminfo = NULL; - - /* Remove the 'app_diminfo' information also, since we're adding to it */ - H5FL_ARR_FREE(H5S_hyper_dim_t,space->select.sel_info.hslab.app_diminfo); - space->select.sel_info.hslab.app_diminfo = NULL; - } /* end if */ + /* Indicate that the regular dimensions are no longer valid */ + space->select.sel_info.hslab.diminfo_valid=FALSE; /* Add in the new hyperslab information */ if(H5S_generate_hyperslab (space, op, start, stride, count, block)<0) @@ -7874,7 +7723,7 @@ H5S_hyper_get_seq_list(const H5S_t *space, unsigned UNUSED flags, H5S_sel_iter_t assert(len); /* Check for the special case of just one H5Sselect_hyperslab call made */ - if(space->select.sel_info.hslab.diminfo!=NULL) + if(space->select.sel_info.hslab.diminfo_valid) /* Use optimized call to generate sequence list */ ret_value=H5S_hyper_get_seq_list_opt(space,iter,elem_size,maxseq,maxbytes,nseq,nbytes,off,len); else diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 5d73fa2..5ce7535 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -98,23 +98,12 @@ struct H5S_hyper_span_info_t { struct H5S_hyper_span_t *head; /* Pointer to list of spans in next dimension down */ }; -/* Information about one dimension in a hyperslab selection */ -struct H5S_hyper_dim_t { - hssize_t start; - hsize_t stride; - hsize_t count; - hsize_t block; -}; - /* Information about new-style hyperslab selection */ typedef struct { - H5S_hyper_dim_t *diminfo; /* ->[rank] of per-dim selection info */ - /* diminfo only points to one array, which holds the information - * for one hyperslab selection. Perhaps this might need to be - * expanded into a list of arrays when the H5Sselect_hyperslab's - * restriction to H5S_SELECT_SET is removed. */ - H5S_hyper_dim_t *app_diminfo;/* ->[rank] of per-dim selection info */ - /* 'diminfo' points to a [potentially] optimized version of the user's + hbool_t diminfo_valid; /* Whether the dataset has valid diminfo */ + H5S_hyper_dim_t opt_diminfo[H5S_MAX_RANK]; /* per-dim selection info */ + H5S_hyper_dim_t app_diminfo[H5S_MAX_RANK]; /* per-dim selection info */ + /* 'opt_diminfo' points to a [potentially] optimized version of the user's * hyperslab information. 'app_diminfo' points to the actual parameters * that the application used for setting the hyperslab selection. These * are only used for re-gurgitating the original values used to set the diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 94510b2..d350738 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -42,7 +42,14 @@ typedef struct H5S_t H5S_t; typedef struct H5S_pnt_node_t H5S_pnt_node_t; typedef struct H5S_hyper_span_t H5S_hyper_span_t; typedef struct H5S_hyper_span_info_t H5S_hyper_span_info_t; -typedef struct H5S_hyper_dim_t H5S_hyper_dim_t; + +/* Information about one dimension in a hyperslab selection */ +typedef struct H5S_hyper_dim_t { + hssize_t start; + hsize_t stride; + hsize_t count; + hsize_t block; +} H5S_hyper_dim_t; /* Point selection iteration container */ typedef struct { @@ -52,22 +59,23 @@ typedef struct { /* Hyperslab selection iteration container */ typedef struct { /* Common fields for all hyperslab selections */ - hssize_t *off; /* Offset in span node (used as position for regular hyperslabs) */ + hssize_t off[H5S_MAX_RANK]; /* Offset in span node (used as position for regular hyperslabs) */ unsigned iter_rank; /* Rank of iterator information */ /* (This should always be the same as the dataspace * rank, except for regular hyperslab selections in * which there are contiguous regions in the lower * dimensions which have been "flattened" out */ + hbool_t diminfo_valid; /* Whether the dimension information is valid */ /* "Flattened" regular hyperslab selection fields */ - H5S_hyper_dim_t *diminfo; /* "Flattened" regular selection information */ - hsize_t *size; /* "Flattened" dataspace extent information */ - hssize_t *sel_off; /* "Flattened" selection offset information */ + H5S_hyper_dim_t diminfo[H5S_MAX_RANK]; /* "Flattened" regular selection information */ + hsize_t size[H5S_MAX_RANK]; /* "Flattened" dataspace extent information */ + hssize_t sel_off[H5S_MAX_RANK]; /* "Flattened" selection offset information */ /* Irregular hyperslab selection fields */ H5S_hyper_span_info_t *spans; /* Pointer to copy of the span tree */ - H5S_hyper_span_t **span;/* Array of pointers to span nodes */ + H5S_hyper_span_t *span[H5S_MAX_RANK];/* Array of pointers to span nodes */ } H5S_hyper_iter_t; /* "All" selection iteration container */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 902530f..10774d2 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -130,7 +130,7 @@ H5S_select_copy (H5S_t *dst, const H5S_t *src) assert(src); /* Copy regular fields */ - dst->select=src->select; + HDmemcpy(&dst->select,&src->select,sizeof(H5S_select_t)); /* Need to copy order information still */ @@ -1147,16 +1147,16 @@ HDfprintf(stderr,"%s: Entering\n",FUNC); else if(space1->select.type==H5S_SEL_NONE || space2->select.type==H5S_SEL_NONE) { HGOTO_DONE(TRUE); } /* end if */ - else if((space1->select.type==H5S_SEL_HYPERSLABS && space1->select.sel_info.hslab.diminfo) - && (space2->select.type==H5S_SEL_HYPERSLABS && space2->select.sel_info.hslab.diminfo)) { + else if((space1->select.type==H5S_SEL_HYPERSLABS && space1->select.sel_info.hslab.diminfo_valid) + && (space2->select.type==H5S_SEL_HYPERSLABS && space2->select.sel_info.hslab.diminfo_valid)) { /* Check that the shapes are the same */ for (u=0; uextent.u.simple.rank; u++) { - if(space1->select.sel_info.hslab.diminfo[u].stride!=space2->select.sel_info.hslab.diminfo[u].stride) + if(space1->select.sel_info.hslab.opt_diminfo[u].stride!=space2->select.sel_info.hslab.opt_diminfo[u].stride) HGOTO_DONE(FALSE); - if(space1->select.sel_info.hslab.diminfo[u].count!=space2->select.sel_info.hslab.diminfo[u].count) + if(space1->select.sel_info.hslab.opt_diminfo[u].count!=space2->select.sel_info.hslab.opt_diminfo[u].count) HGOTO_DONE(FALSE); - if(space1->select.sel_info.hslab.diminfo[u].block!=space2->select.sel_info.hslab.diminfo[u].block) + if(space1->select.sel_info.hslab.opt_diminfo[u].block!=space2->select.sel_info.hslab.opt_diminfo[u].block) HGOTO_DONE(FALSE); } /* end for */ } /* end if */ -- cgit v0.12