From 9d86314f8b71f090b71d7edec8014935f5cd3cc7 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 15 Mar 2019 20:14:41 -0500 Subject: [PATCH 01/32] Core changes to selection code from the hyperslab_updates branch. --- src/H5Dchunk.c | 372 ++- src/H5Dfill.c | 4 +- src/H5Dmpio.c | 22 +- src/H5Dpkg.h | 8 +- src/H5Dscatgath.c | 79 +- src/H5Dselect.c | 8 +- src/H5Sall.c | 94 +- src/H5Shyper.c | 5777 +++++++++++++++++++++++++++++---------------- src/H5Smpio.c | 438 ++-- src/H5Snone.c | 63 +- src/H5Spkg.h | 129 +- src/H5Spoint.c | 499 ++-- src/H5Sprivate.h | 28 +- src/H5Spublic.h | 17 + src/H5Sselect.c | 207 +- src/H5Stest.c | 284 ++- src/H5TS.c | 12 + src/H5TSprivate.h | 1 + src/H5err.txt | 1 + test/tselect.c | 1398 ++++++++++- 20 files changed, 6676 insertions(+), 2765 deletions(-) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index dcd3a8d49c..e7d1b15126 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -276,6 +276,8 @@ static hbool_t H5D__chunk_cinfo_cache_found(const H5D_chunk_cached_t *last, static herr_t H5D__free_chunk_info(void *item, void *key, void *opdata); static herr_t H5D__create_chunk_map_single(H5D_chunk_map_t *fm, const H5D_io_info_t *io_info); +static herr_t H5D__create_chunk_file_map_all(H5D_chunk_map_t *fm, + const H5D_io_info_t *io_info); static herr_t H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t *io_info); static herr_t H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm); @@ -1044,7 +1046,6 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf hbool_t iter_init = FALSE; /* Selection iteration info has been initialized */ unsigned f_ndims; /* The number of dimensions of the file's dataspace */ int sm_ndims; /* The number of dimensions of the memory buffer's dataspace (signed) */ - H5SL_node_t *curr_node; /* Current node in skip list */ char bogus; /* "bogus" buffer to pass to selection iterator */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1168,25 +1169,17 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* Check if file selection is a not a hyperslab selection */ if(sel_hyper_flag) { /* Build the file selection for each chunk */ - if(H5D__create_chunk_file_map_hyper(fm, io_info) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create file chunk selections") + if(H5S_SEL_ALL == fm->fsel_type) { + if(H5D__create_chunk_file_map_all(fm, io_info) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create file chunk selections") + } /* end if */ + else { + /* Sanity check */ + HDassert(fm->fsel_type == H5S_SEL_HYPERSLABS); - /* Clean file chunks' hyperslab span "scratch" information */ - curr_node = H5SL_first(fm->sel_chunks); - while(curr_node) { - H5D_chunk_info_t *chunk_info; /* Pointer chunk information */ - - /* Get pointer to chunk's information */ - chunk_info = (H5D_chunk_info_t *)H5SL_item(curr_node); - HDassert(chunk_info); - - /* Clean hyperslab span's "scratch" information */ - if(H5S_hyper_reset_scratch(chunk_info->fspace) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "unable to reset span scratch info") - - /* Get the next chunk node in the skip list */ - curr_node = H5SL_next(curr_node); - } /* end while */ + if(H5D__create_chunk_file_map_hyper(fm, io_info) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create file chunk selections") + } /* end else */ } /* end if */ else { H5S_sel_iter_op_t iter_op; /* Operator for iteration */ @@ -1248,7 +1241,7 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* Create selection iterator for memory selection */ if(0 == (elmt_size = H5T_get_size(mem_type))) HGOTO_ERROR(H5E_DATATYPE, H5E_BADSIZE, FAIL, "datatype size invalid") - if(H5S_select_iter_init(&(fm->mem_iter), mem_space, elmt_size) < 0) + if(H5S_select_iter_init(&(fm->mem_iter), mem_space, elmt_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -1258,26 +1251,6 @@ H5D__chunk_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* Spaces aren't the same shape, iterate over the memory selection directly */ if(H5S_select_iterate(&bogus, file_type, file_space, &iter_op, fm) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to create memory chunk selections") - - /* Clean up hyperslab stuff, if necessary */ - if(fm->msel_type != H5S_SEL_POINTS) { - /* Clean memory chunks' hyperslab span "scratch" information */ - curr_node = H5SL_first(fm->sel_chunks); - while(curr_node) { - H5D_chunk_info_t *chunk_info; /* Pointer chunk information */ - - /* Get pointer to chunk's information */ - chunk_info = (H5D_chunk_info_t *)H5SL_item(curr_node); - HDassert(chunk_info); - - /* Clean hyperslab span's "scratch" information */ - if(H5S_hyper_reset_scratch(chunk_info->mspace) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTFREE, FAIL, "unable to reset span scratch info") - - /* Get the next chunk node in the skip list */ - curr_node = H5SL_next(curr_node); - } /* end while */ - } /* end if */ } /* end else */ } /* end else */ @@ -1531,6 +1504,211 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__create_chunk_map_single() */ + +/*------------------------------------------------------------------------- + * Function: H5D__create_chunk_file_map_all + * + * Purpose: Create all chunk selections in file, for an "all" selection. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Monday, January 21, 2019 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D__create_chunk_file_map_all(H5D_chunk_map_t *fm, const H5D_io_info_t +#ifndef H5_HAVE_PARALLEL + H5_ATTR_UNUSED +#endif /* H5_HAVE_PARALLEL */ + *io_info) +{ + H5S_t *tmp_fchunk = NULL; /* Temporary file dataspace */ + hsize_t file_dims[H5S_MAX_RANK]; /* File dataspace dims */ + hsize_t sel_points; /* Number of elements in file selection */ + hsize_t zeros[H5S_MAX_RANK]; /* All zero vector (for start parameter to setting hyperslab on partial chunks) */ + hsize_t coords[H5S_MAX_RANK]; /* Current coordinates of chunk */ + hsize_t end[H5S_MAX_RANK]; /* Final coordinates of chunk */ + hsize_t scaled[H5S_MAX_RANK]; /* Scaled coordinates for this chunk */ + hsize_t chunk_index; /* "Index" of chunk */ + hsize_t curr_partial_clip[H5S_MAX_RANK]; /* Current partial dimension sizes to clip against */ + hsize_t partial_dim_size[H5S_MAX_RANK]; /* Size of a partial dimension */ + hbool_t is_partial_dim[H5S_MAX_RANK]; /* Whether a dimension is currently a partial chunk */ + unsigned num_partial_dims; /* Current number of partial dimensions */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(fm->f_ndims > 0); + + /* Get number of elements selected in file */ + sel_points = fm->nelmts; + + /* Get dataspace dimensions */ + if(H5S_get_simple_extent_dims(fm->file_space, file_dims, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection bound info") + + /* Set initial chunk location, partial dimensions, etc */ + num_partial_dims = 0; + HDmemset(zeros, 0, sizeof(zeros)); + for(u = 0; u < fm->f_ndims; u++) { + /* Validate this chunk dimension */ + if(fm->layout->u.chunk.dim[u] == 0) + HGOTO_ERROR(H5E_DATASET, H5E_BADVALUE, FAIL, "chunk size must be > 0, dim = %u ", u) + + /* Set up start / end coordinates for first chunk */ + scaled[u] = 0; + coords[u] = 0; + end[u] = fm->chunk_dim[u] - 1; + + /* Iniitialize partial chunk dimension information */ + partial_dim_size[u] = file_dims[u] % fm->chunk_dim[u]; + if(file_dims[u] < fm->chunk_dim[u]) { + curr_partial_clip[u] = partial_dim_size[u]; + is_partial_dim[u] = TRUE; + num_partial_dims++; + } /* end if */ + else { + curr_partial_clip[u] = fm->chunk_dim[u]; + is_partial_dim[u] = FALSE; + } /* end else */ + } /* end for */ + + /* Set the index of this chunk */ + chunk_index = 0; + + /* Create "temporary" chunk for selection operations (copy file space) */ + if(NULL == (tmp_fchunk = H5S_create_simple(fm->f_ndims, fm->chunk_dim, NULL))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, "unable to create dataspace for chunk") + + /* Iterate through each chunk in the dataset */ + while(sel_points) { + H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into skip list */ + hssize_t schunk_points; /* Number of elements in chunk selection */ + + /* Add temporary chunk to the list of chunks */ + + /* Allocate the file & memory chunk information */ + if(NULL == (new_chunk_info = H5FL_MALLOC(H5D_chunk_info_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk info") + + /* Initialize the chunk information */ + + /* Set the chunk index */ + new_chunk_info->index = chunk_index; + +#ifdef H5_HAVE_PARALLEL + /* Store chunk selection information, for multi-chunk I/O */ + if(io_info->using_mpi_vfd) + fm->select_chunk[chunk_index] = new_chunk_info; +#endif /* H5_HAVE_PARALLEL */ + + /* Set the file chunk dataspace */ + if(NULL == (new_chunk_info->fspace = H5S_copy(tmp_fchunk, TRUE, FALSE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy chunk dataspace") + new_chunk_info->fspace_shared = FALSE; + + /* If there are partial dimensions for this chunk, set the hyperslab for them */ + if(num_partial_dims > 0) + if(H5S_select_hyperslab(new_chunk_info->fspace, H5S_SELECT_SET, zeros, NULL, curr_partial_clip, NULL) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSELECT, FAIL, "can't create chunk selection") + + /* Set the memory chunk dataspace */ + new_chunk_info->mspace = NULL; + new_chunk_info->mspace_shared = FALSE; + + /* Copy the chunk's scaled coordinates */ + HDmemcpy(new_chunk_info->scaled, scaled, sizeof(hsize_t) * fm->f_ndims); + new_chunk_info->scaled[fm->f_ndims] = 0; + + /* Insert the new chunk into the skip list */ + if(H5SL_insert(fm->sel_chunks, new_chunk_info, &new_chunk_info->index) < 0) { + H5D__free_chunk_info(new_chunk_info, NULL, NULL); + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert chunk into skip list") + } /* end if */ + + /* Get number of elements selected in chunk */ + if((schunk_points = H5S_GET_SELECT_NPOINTS(new_chunk_info->fspace)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements") + H5_CHECKED_ASSIGN(new_chunk_info->chunk_points, uint32_t, schunk_points, hssize_t); + + /* Decrement # of points left in file selection */ + sel_points -= (hsize_t)schunk_points; + + /* Advance to next chunk if we are not done */ + if(sel_points > 0) { + int curr_dim; /* Current dimension to increment */ + + /* Increment chunk index */ + chunk_index++; + + /* Set current increment dimension */ + curr_dim = (int)fm->f_ndims - 1; + + /* Increment chunk location in fastest changing dimension */ + coords[curr_dim] += fm->chunk_dim[curr_dim]; + scaled[curr_dim]++; + end[curr_dim] += fm->chunk_dim[curr_dim]; + + /* Bring chunk location back into bounds, if necessary */ + if(coords[curr_dim] >= file_dims[curr_dim]) { + do { + /* Reset current dimension's location to 0 */ + coords[curr_dim] = 0; + scaled[curr_dim] = 0; + end[curr_dim] = fm->chunk_dim[curr_dim] - 1; + + /* Check for previous partial chunk in this dimension */ + if(is_partial_dim[curr_dim] && end[curr_dim] < file_dims[curr_dim]) { + /* Sanity check */ + HDassert(num_partial_dims > 0); + + /* Reset partial chunk information for this dimension */ + curr_partial_clip[curr_dim] = fm->chunk_dim[curr_dim]; + is_partial_dim[curr_dim] = FALSE; + num_partial_dims--; + } /* end if */ + + /* Decrement current dimension */ + curr_dim--; + + /* Check for valid current dim */ + if(curr_dim >= 0) { + /* Increment chunk location in current dimension */ + coords[curr_dim] += fm->chunk_dim[curr_dim]; + scaled[curr_dim]++; + end[curr_dim] = (coords[curr_dim] + fm->chunk_dim[curr_dim]) - 1; + } /* end if */ + } while(curr_dim >= 0 && (coords[curr_dim] >= file_dims[curr_dim])); + } /* end if */ + + /* Check for valid current dim */ + if(curr_dim >= 0) { + /* Check for partial chunk in this dimension */ + if(!is_partial_dim[curr_dim] && file_dims[curr_dim] <= end[curr_dim]) { + /* Set partial chunk information for this dimension */ + curr_partial_clip[curr_dim] = partial_dim_size[curr_dim]; + is_partial_dim[curr_dim] = TRUE; + num_partial_dims++; + + /* Sanity check */ + HDassert(num_partial_dims <= fm->f_ndims); + } /* end if */ + } /* end if */ + } /* end if */ + } /* end while */ + +done: + /* Clean up */ + if(tmp_fchunk && H5S_close(tmp_fchunk) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't release temporary dataspace") + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D__create_chunk_file_map_all() */ + /*------------------------------------------------------------------------- * Function: H5D__create_chunk_file_map_hyper @@ -1551,6 +1729,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t #endif /* H5_HAVE_PARALLEL */ *io_info) { + H5S_t *tmp_fchunk = NULL; /* Temporary file dataspace */ hsize_t sel_start[H5O_LAYOUT_NDIMS]; /* Offset of low bound of file selection */ hsize_t sel_end[H5O_LAYOUT_NDIMS]; /* Offset of high bound of file selection */ hsize_t sel_points; /* Number of elements in file selection */ @@ -1594,45 +1773,28 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t /* Check for intersection of current chunk and file selection */ /* (Casting away const OK - QAK) */ if(TRUE == H5S_hyper_intersect_block((H5S_t *)fm->file_space, coords, end)) { - H5S_t *tmp_fchunk; /* Temporary file dataspace */ H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into skip list */ hssize_t schunk_points; /* Number of elements in chunk selection */ - /* Create "temporary" chunk for selection operations (copy file space) */ - if(NULL == (tmp_fchunk = H5S_copy(fm->file_space, TRUE, FALSE))) - 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) { - (void)H5S_close(tmp_fchunk); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to convert selection to span trees") - } /* end if */ - - /* "AND" temporary chunk and current chunk */ - if(H5S_select_hyperslab(tmp_fchunk,H5S_SELECT_AND,coords,NULL,fm->chunk_dim,NULL) < 0) { - (void)H5S_close(tmp_fchunk); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't create chunk selection") - } /* end if */ + /* Create dataspace for chunk, 'AND'ing the overall selection with + * the current chunk. + */ + if(H5S_combine_hyperslab(fm->file_space, H5S_SELECT_AND, coords, NULL, fm->chunk_dim, NULL, &tmp_fchunk) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to combine file space selection with chunk block") /* Resize chunk's dataspace dimensions to size of chunk */ - if(H5S_set_extent_real(tmp_fchunk,fm->chunk_dim) < 0) { - (void)H5S_close(tmp_fchunk); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't adjust chunk dimensions") - } /* end if */ + if(H5S_set_extent_real(tmp_fchunk, fm->chunk_dim) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSELECT, FAIL, "can't adjust chunk dimensions") /* Move selection back to have correct offset in chunk */ - if(H5S_SELECT_ADJUST_U(tmp_fchunk, coords) < 0) { - (void)H5S_close(tmp_fchunk); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't adjust chunk selection") - } + if(H5S_SELECT_ADJUST_U(tmp_fchunk, coords) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSELECT, FAIL, "can't adjust chunk selection") /* Add temporary chunk to the list of chunks */ /* Allocate the file & memory chunk information */ - if(NULL == (new_chunk_info = H5FL_MALLOC(H5D_chunk_info_t))) { - (void)H5S_close(tmp_fchunk); - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate chunk info") - } /* end if */ + if(NULL == (new_chunk_info = H5FL_MALLOC(H5D_chunk_info_t))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk info") /* Initialize the chunk information */ @@ -1648,6 +1810,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t /* Set the file chunk dataspace */ new_chunk_info->fspace = tmp_fchunk; new_chunk_info->fspace_shared = FALSE; + tmp_fchunk = NULL; /* Set the memory chunk dataspace */ new_chunk_info->mspace = NULL; @@ -1664,7 +1827,7 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t } /* end if */ /* Get number of elements selected in chunk */ - if((schunk_points = H5S_GET_SELECT_NPOINTS(tmp_fchunk)) < 0) + if((schunk_points = H5S_GET_SELECT_NPOINTS(new_chunk_info->fspace)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements") H5_CHECKED_ASSIGN(new_chunk_info->chunk_points, uint32_t, schunk_points, hssize_t); @@ -1713,6 +1876,11 @@ H5D__create_chunk_file_map_hyper(H5D_chunk_map_t *fm, const H5D_io_info_t } /* end while */ done: + /* Clean up on failure */ + if(ret_value < 0) + if(tmp_fchunk && H5S_close(tmp_fchunk) < 0) + HDONE_ERROR(H5E_DATASET, H5E_CANTRELEASE, FAIL, "can't release temporary dataspace") + FUNC_LEAVE_NOAPI(ret_value) } /* end H5D__create_chunk_file_map_hyper() */ @@ -1736,13 +1904,13 @@ done: static herr_t H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm) { + H5D_chunk_info_t *chunk_info; /* Pointer to chunk information */ H5SL_node_t *curr_node; /* Current node in skip list */ hsize_t file_sel_start[H5S_MAX_RANK]; /* Offset of low bound of file selection */ hsize_t file_sel_end[H5S_MAX_RANK]; /* Offset of high bound of file selection */ hsize_t mem_sel_start[H5S_MAX_RANK]; /* Offset of low bound of file selection */ hsize_t mem_sel_end[H5S_MAX_RANK]; /* Offset of high bound of file selection */ hssize_t adjust[H5S_MAX_RANK]; /* Adjustment to make to all file chunks */ - hssize_t chunk_adjust[H5S_MAX_RANK]; /* Adjustment to make to a particular chunk */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1753,8 +1921,6 @@ H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm) /* Check for all I/O going to a single chunk */ if(H5SL_count(fm->sel_chunks)==1) { - H5D_chunk_info_t *chunk_info; /* Pointer to chunk information */ - /* Get the node */ curr_node = H5SL_first(fm->sel_chunks); @@ -1789,41 +1955,61 @@ H5D__create_chunk_mem_map_hyper(const H5D_chunk_map_t *fm) /* Iterate over each chunk in the chunk list */ curr_node = H5SL_first(fm->sel_chunks); while(curr_node) { - H5D_chunk_info_t *chunk_info; /* Pointer to chunk information */ + hsize_t coords[H5S_MAX_RANK]; /* Current coordinates of chunk */ + hssize_t chunk_adjust[H5S_MAX_RANK]; /* Adjustment to make to a particular chunk */ + H5S_sel_type chunk_sel_type; /* Chunk's selection type */ /* Get pointer to chunk's information */ chunk_info = (H5D_chunk_info_t *)H5SL_item(curr_node); HDassert(chunk_info); + /* Compute the chunk coordinates from the scaled coordinates */ + for(u = 0; u < fm->f_ndims; u++) + coords[u] = chunk_info->scaled[u] * fm->layout->u.chunk.dim[u]; + /* Copy the information */ /* Copy the memory dataspace */ if((chunk_info->mspace = H5S_copy(fm->mem_space, TRUE, FALSE)) == 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") + /* Get the chunk's selection type */ + if((chunk_sel_type = H5S_GET_SELECT_TYPE(chunk_info->fspace)) < H5S_SEL_NONE) + HGOTO_ERROR(H5E_DATASET, H5E_BADSELECT, FAIL, "unable to get type of selection") - /* Copy the file chunk's selection */ - if(H5S_select_copy(chunk_info->mspace,chunk_info->fspace,FALSE) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy selection") + /* Set memory selection for "all" chunk selections */ + if(H5S_SEL_ALL == chunk_sel_type) { + /* Adjust the chunk coordinates */ + for(u = 0; u < fm->f_ndims; u++) + coords[u] -= adjust[u]; - /* Compute the adjustment for this chunk */ - for(u = 0; u < fm->f_ndims; u++) { - hsize_t coords[H5O_LAYOUT_NDIMS]; /* Current coordinates of chunk */ + /* Set to same shape as chunk */ + if(H5S_select_hyperslab(chunk_info->mspace, H5S_SELECT_SET, coords, NULL, fm->chunk_dim, NULL) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSELECT, FAIL, "can't create chunk memory selection") + } /* end if */ + else { + /* Sanity check */ + HDassert(H5S_SEL_HYPERSLABS == chunk_sel_type); - /* Compute the chunk coordinates from the scaled coordinates */ - coords[u] = chunk_info->scaled[u] * fm->layout->u.chunk.dim[u]; + /* Release the current selection */ + if(H5S_SELECT_RELEASE(chunk_info->mspace) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection") - /* Compensate for the chunk offset */ - H5_CHECK_OVERFLOW(coords[u], hsize_t, hssize_t); - chunk_adjust[u] = adjust[u] - (hssize_t)coords[u]; /*lint !e771 The adjust array will always be initialized */ - } /* end for */ + /* Copy the file chunk's selection */ + if(H5S_select_copy(chunk_info->mspace, chunk_info->fspace, FALSE) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy selection") - /* Adjust the selection */ - if(H5S_hyper_adjust_s(chunk_info->mspace, chunk_adjust) < 0) - HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to adjust selection") + /* Compute the adjustment for this chunk */ + for(u = 0; u < fm->f_ndims; u++) { + /* Compensate for the chunk offset */ + H5_CHECK_OVERFLOW(coords[u], hsize_t, hssize_t); + chunk_adjust[u] = adjust[u] - (hssize_t)coords[u]; /*lint !e771 The adjust array will always be initialized */ + } /* end for */ + + /* Adjust the selection */ + if(H5S_hyper_adjust_s(chunk_info->mspace, chunk_adjust) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, FAIL, "unable to adjust selection") + } /* end else */ /* Get the next chunk node in the skip list */ curr_node = H5SL_next(curr_node); @@ -4821,12 +5007,12 @@ H5D__chunk_prune_fill(H5D_chunk_it_ud1_t *udata, hbool_t new_unfilt_chunk) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate chunk selection iterator") /* Create a selection iterator for scattering the elements to memory buffer */ - if(H5S_select_iter_init(chunk_iter, udata->chunk_space, layout->u.chunk.dim[rank]) < 0) + if(H5S_select_iter_init(chunk_iter, udata->chunk_space, layout->u.chunk.dim[rank], 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize chunk selection information") chunk_iter_init = TRUE; /* Scatter the data into memory */ - if(H5D__scatter_mem(udata->fb_info.fill_buf, udata->chunk_space, chunk_iter, (size_t)sel_nelmts, chunk/*out*/) < 0) + if(H5D__scatter_mem(udata->fb_info.fill_buf, chunk_iter, (size_t)sel_nelmts, chunk/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "scatter failed") diff --git a/src/H5Dfill.c b/src/H5Dfill.c index 619f6994af..61ce822689 100644 --- a/src/H5Dfill.c +++ b/src/H5Dfill.c @@ -275,12 +275,12 @@ H5D__fill(const void *fill, const H5T_t *fill_type, void *buf, HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate memory selection iterator") /* Create a selection iterator for scattering the elements to memory buffer */ - if(H5S_select_iter_init(mem_iter, space, dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, space, dst_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /* Scatter the data into memory */ - if(H5D__scatter_mem(tmp_buf, space, mem_iter, (size_t)nelmts, buf/*out*/) < 0) + if(H5D__scatter_mem(tmp_buf, mem_iter, (size_t)nelmts, buf/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "scatter failed") } /* end if */ else { diff --git a/src/H5Dmpio.c b/src/H5Dmpio.c index 2a6c05fb6a..d1c70b03e0 100644 --- a/src/H5Dmpio.c +++ b/src/H5Dmpio.c @@ -2864,12 +2864,12 @@ H5D__chunk_redistribute_shared_chunks(const H5D_io_info_t *io_info, const H5D_ty HGOTO_ERROR(H5E_DATASET, H5E_CANTENCODE, FAIL, "unable to encode dataspace") /* Initialize iterator for memory selection */ - if(H5S_select_iter_init(mem_iter, chunk_info->mspace, type_info->src_type_size) < 0) + if(H5S_select_iter_init(mem_iter, chunk_info->mspace, type_info->src_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /* Collect the modification data into the buffer */ - if(0 == H5D__gather_mem(io_info->u.wbuf, chunk_info->mspace, mem_iter, (size_t)iter_nelmts, mod_data_p)) + if(0 == H5D__gather_mem(io_info->u.wbuf, mem_iter, (size_t)iter_nelmts, mod_data_p)) HGOTO_ERROR(H5E_IO, H5E_CANTGATHER, FAIL, "couldn't gather from write buffer") /* Send modification data to new owner */ @@ -3170,7 +3170,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk if (NULL == (mem_iter = (H5S_sel_iter_t *) H5MM_malloc(sizeof(H5S_sel_iter_t)))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate memory iterator") - if(H5S_select_iter_init(mem_iter, chunk_info->mspace, type_info->src_type_size) < 0) + if(H5S_select_iter_init(mem_iter, chunk_info->mspace, type_info->src_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; @@ -3185,7 +3185,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk if(NULL == (file_iter = (H5S_sel_iter_t *) H5MM_malloc(sizeof(H5S_sel_iter_t)))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate file iterator") - if(H5S_select_iter_init(file_iter, chunk_info->fspace, type_info->src_type_size) < 0) + if(H5S_select_iter_init(file_iter, chunk_info->fspace, type_info->src_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") file_iter_init = TRUE; @@ -3195,13 +3195,13 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk if(NULL == (tmp_gath_buf = H5MM_malloc((hsize_t) iter_nelmts * type_info->src_type_size))) HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate temporary gather buffer") - if(!H5D__gather_mem(chunk_entry->buf, chunk_info->fspace, file_iter, (size_t) iter_nelmts, tmp_gath_buf)) + if(!H5D__gather_mem(chunk_entry->buf, file_iter, (size_t) iter_nelmts, tmp_gath_buf)) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "couldn't gather from chunk buffer") if((iter_nelmts = H5S_GET_SELECT_NPOINTS(chunk_info->mspace)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "dataspace is invalid") - if(H5D__scatter_mem(tmp_gath_buf, chunk_info->mspace, mem_iter, (size_t) iter_nelmts, io_info->u.rbuf) < 0) + if(H5D__scatter_mem(tmp_gath_buf, mem_iter, (size_t) iter_nelmts, io_info->u.rbuf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "couldn't scatter to read buffer") break; @@ -3214,7 +3214,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "couldn't allocate temporary gather buffer") /* Gather modification data from the application write buffer into a temporary buffer */ - if(0 == H5D__gather_mem(io_info->u.wbuf, chunk_info->mspace, mem_iter, (size_t) iter_nelmts, tmp_gath_buf)) + if(0 == H5D__gather_mem(io_info->u.wbuf, mem_iter, (size_t) iter_nelmts, tmp_gath_buf)) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "couldn't gather from write buffer") if(H5S_SELECT_ITER_RELEASE(mem_iter) < 0) @@ -3222,7 +3222,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk mem_iter_init = FALSE; /* Initialize iterator for file selection */ - if(H5S_select_iter_init(mem_iter, chunk_info->fspace, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, chunk_info->fspace, type_info->dst_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information") mem_iter_init = TRUE; @@ -3232,7 +3232,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk /* Scatter the owner's modification data into the chunk data buffer according to * the file space. */ - if(H5D__scatter_mem(tmp_gath_buf, chunk_info->fspace, mem_iter, (size_t) iter_nelmts, chunk_entry->buf) < 0) + if(H5D__scatter_mem(tmp_gath_buf, mem_iter, (size_t) iter_nelmts, chunk_entry->buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "couldn't scatter to chunk data buffer") if(H5S_SELECT_ITER_RELEASE(mem_iter) < 0) @@ -3254,7 +3254,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk if(NULL == (dataspace = H5S_decode(&mod_data_p))) HGOTO_ERROR(H5E_DATASET, H5E_CANTDECODE, FAIL, "unable to decode dataspace") - if(H5S_select_iter_init(mem_iter, dataspace, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, dataspace, type_info->dst_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; @@ -3262,7 +3262,7 @@ H5D__filtered_collective_chunk_entry_io(H5D_filtered_collective_io_info_t *chunk HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "dataspace is invalid") /* Update the chunk data with the received modification data */ - if(H5D__scatter_mem(mod_data_p, dataspace, mem_iter, (size_t) iter_nelmts, chunk_entry->buf) < 0) + if(H5D__scatter_mem(mod_data_p, mem_iter, (size_t) iter_nelmts, chunk_entry->buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "couldn't scatter to write buffer") if(H5S_SELECT_ITER_RELEASE(mem_iter) < 0) diff --git a/src/H5Dpkg.h b/src/H5Dpkg.h index 2767aa162d..fb74c1c16f 100644 --- a/src/H5Dpkg.h +++ b/src/H5Dpkg.h @@ -591,10 +591,10 @@ H5_DLL herr_t H5D__select_write(const H5D_io_info_t *io_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space); /* Functions that perform scatter-gather serial I/O operations */ -H5_DLL herr_t H5D__scatter_mem(const void *_tscat_buf, const H5S_t *space, - H5S_sel_iter_t *iter, size_t nelmts, void *_buf); -H5_DLL size_t H5D__gather_mem(const void *_buf, const H5S_t *space, - H5S_sel_iter_t *iter, size_t nelmts, void *_tgath_buf/*out*/); +H5_DLL herr_t H5D__scatter_mem(const void *_tscat_buf, H5S_sel_iter_t *iter, + size_t nelmts, void *_buf); +H5_DLL size_t H5D__gather_mem(const void *_buf, H5S_sel_iter_t *iter, + size_t nelmts, void *_tgath_buf/*out*/); H5_DLL herr_t H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space); diff --git a/src/H5Dscatgath.c b/src/H5Dscatgath.c index 266f5f5896..829356217e 100644 --- a/src/H5Dscatgath.c +++ b/src/H5Dscatgath.c @@ -43,13 +43,11 @@ /* Local Prototypes */ /********************/ static herr_t H5D__scatter_file(const H5D_io_info_t *io_info, - const H5S_t *file_space, H5S_sel_iter_t *file_iter, size_t nelmts, - const void *buf); + H5S_sel_iter_t *file_iter, size_t nelmts, const void *buf); static size_t H5D__gather_file(const H5D_io_info_t *io_info, - const H5S_t *file_space, H5S_sel_iter_t *file_iter, size_t nelmts, - void *buf); -static herr_t H5D__compound_opt_read(size_t nelmts, const H5S_t *mem_space, - H5S_sel_iter_t *iter, const H5D_type_info_t *type_info, void *user_buf/*out*/); + H5S_sel_iter_t *file_iter, size_t nelmts, void *buf); +static herr_t H5D__compound_opt_read(size_t nelmts, H5S_sel_iter_t *iter, + const H5D_type_info_t *type_info, void *user_buf/*out*/); static herr_t H5D__compound_opt_write(size_t nelmts, const H5D_type_info_t *type_info); @@ -90,9 +88,8 @@ H5FL_SEQ_EXTERN(hsize_t); *------------------------------------------------------------------------- */ static herr_t -H5D__scatter_file(const H5D_io_info_t *_io_info, - const H5S_t *space, H5S_sel_iter_t *iter, size_t nelmts, - const void *_buf) +H5D__scatter_file(const H5D_io_info_t *_io_info, H5S_sel_iter_t *iter, + size_t nelmts, const void *_buf) { H5D_io_info_t tmp_io_info; /* Temporary I/O info object */ hsize_t *off = NULL; /* Pointer to sequence offsets */ @@ -111,7 +108,6 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, /* Check args */ HDassert(_io_info); - HDassert(space); HDassert(iter); HDassert(nelmts > 0); HDassert(_buf); @@ -138,7 +134,7 @@ H5D__scatter_file(const H5D_io_info_t *_io_info, /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Reset the current sequence information */ @@ -191,9 +187,8 @@ done: *------------------------------------------------------------------------- */ static size_t -H5D__gather_file(const H5D_io_info_t *_io_info, - const H5S_t *space, H5S_sel_iter_t *iter, size_t nelmts, - void *_buf/*out*/) +H5D__gather_file(const H5D_io_info_t *_io_info, H5S_sel_iter_t *iter, + size_t nelmts, void *_buf/*out*/) { H5D_io_info_t tmp_io_info; /* Temporary I/O info object */ hsize_t *off = NULL; /* Pointer to sequence offsets */ @@ -214,7 +209,6 @@ H5D__gather_file(const H5D_io_info_t *_io_info, HDassert(_io_info); HDassert(_io_info->dset); HDassert(_io_info->store); - HDassert(space); HDassert(iter); HDassert(nelmts > 0); HDassert(_buf); @@ -241,7 +235,7 @@ H5D__gather_file(const H5D_io_info_t *_io_info, /* Loop until all elements are read */ while(nelmts > 0) { /* Get list of sequences for selection to read */ - if(H5S_SELECT_GET_SEQ_LIST(space, H5S_GET_SEQ_LIST_SORTED, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Reset the current sequence information */ @@ -288,8 +282,8 @@ done: *------------------------------------------------------------------------- */ herr_t -H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, - H5S_sel_iter_t *iter, size_t nelmts, void *_buf/*out*/) +H5D__scatter_mem(const void *_tscat_buf, H5S_sel_iter_t *iter, size_t nelmts, + void *_buf/*out*/) { uint8_t *buf = (uint8_t *)_buf; /* Get local copies for address arithmetic */ const uint8_t *tscat_buf = (const uint8_t *)_tscat_buf; @@ -307,7 +301,6 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, /* Check args */ HDassert(tscat_buf); - HDassert(space); HDassert(iter); HDassert(nelmts > 0); HDassert(buf); @@ -329,7 +322,7 @@ H5D__scatter_mem (const void *_tscat_buf, const H5S_t *space, /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -376,8 +369,8 @@ done: *------------------------------------------------------------------------- */ size_t -H5D__gather_mem(const void *_buf, const H5S_t *space, - H5S_sel_iter_t *iter, size_t nelmts, void *_tgath_buf/*out*/) +H5D__gather_mem(const void *_buf, H5S_sel_iter_t *iter, size_t nelmts, + void *_tgath_buf/*out*/) { const uint8_t *buf = (const uint8_t *)_buf; /* Get local copies for address arithmetic */ uint8_t *tgath_buf = (uint8_t *)_tgath_buf; @@ -395,7 +388,6 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, /* Check args */ HDassert(buf); - HDassert(space); HDassert(iter); HDassert(nelmts > 0); HDassert(tgath_buf); @@ -417,7 +409,7 @@ H5D__gather_mem(const void *_buf, const H5S_t *space, /* Loop until all elements are written */ while(nelmts > 0) { /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, vec_size, nelmts, &nseq, &nelem, off, len) < 0) HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -495,13 +487,13 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") /* Figure out the strip mine size. */ - if(H5S_select_iter_init(file_iter, file_space, type_info->src_type_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, type_info->src_type_size, H5S_SEL_ITER_GET_SEQ_LIST_SORTED) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information") file_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(mem_iter, mem_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, type_info->dst_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(bkg_iter, mem_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(bkg_iter, mem_space, type_info->dst_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize background selection information") bkg_iter_init = TRUE; /*file selection iteration info has been initialized */ @@ -522,7 +514,7 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf /* * Gather data */ - n = H5D__gather_file(io_info, file_space, file_iter, smine_nelmts, type_info->tconv_buf/*out*/); + n = H5D__gather_file(io_info, file_iter, smine_nelmts, type_info->tconv_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file gather failed") @@ -531,12 +523,12 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf * bypass the rest of steps. */ if(type_info->cmpd_subset && H5T_SUBSET_FALSE != type_info->cmpd_subset->subset) { - if(H5D__compound_opt_read(smine_nelmts, mem_space, mem_iter, type_info, buf /*out*/) < 0) + if(H5D__compound_opt_read(smine_nelmts, mem_iter, type_info, buf /*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "datatype conversion failed") } /* end if */ else { if(H5T_BKG_YES == type_info->need_bkg) { - n = H5D__gather_mem(buf, mem_space, bkg_iter, smine_nelmts, type_info->bkg_buf/*out*/); + n = H5D__gather_mem(buf, bkg_iter, smine_nelmts, type_info->bkg_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "mem gather failed") } /* end if */ @@ -562,7 +554,7 @@ H5D__scatgath_read(const H5D_io_info_t *io_info, const H5D_type_info_t *type_inf } /* Scatter the data into memory */ - if(H5D__scatter_mem(type_info->tconv_buf, mem_space, mem_iter, smine_nelmts, buf/*out*/) < 0) + if(H5D__scatter_mem(type_info->tconv_buf, mem_iter, smine_nelmts, buf/*out*/) < 0) HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "scatter failed") } /* end else */ } /* end for */ @@ -635,13 +627,13 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") /* Figure out the strip mine size. */ - if(H5S_select_iter_init(file_iter, file_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, type_info->dst_type_size, H5S_SEL_ITER_GET_SEQ_LIST_SORTED) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information") file_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(mem_iter, mem_space, type_info->src_type_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, type_info->src_type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize memory selection information") mem_iter_init = TRUE; /*file selection iteration info has been initialized */ - if(H5S_select_iter_init(bkg_iter, file_space, type_info->dst_type_size) < 0) + if(H5S_select_iter_init(bkg_iter, file_space, type_info->dst_type_size, H5S_SEL_ITER_GET_SEQ_LIST_SORTED) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize background selection information") bkg_iter_init = TRUE; /*file selection iteration info has been initialized */ @@ -658,7 +650,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in * buffer. Also gather data from the file into the background buffer * if necessary. */ - n = H5D__gather_mem(buf, mem_space, mem_iter, smine_nelmts, type_info->tconv_buf/*out*/); + n = H5D__gather_mem(buf, mem_iter, smine_nelmts, type_info->tconv_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "mem gather failed") @@ -675,7 +667,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in } /* end if */ else { if(H5T_BKG_YES == type_info->need_bkg) { - n = H5D__gather_file(io_info, file_space, bkg_iter, smine_nelmts, type_info->bkg_buf/*out*/); + n = H5D__gather_file(io_info, bkg_iter, smine_nelmts, type_info->bkg_buf/*out*/); if(n != smine_nelmts) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "file gather failed") } /* end if */ @@ -705,7 +697,7 @@ H5D__scatgath_write(const H5D_io_info_t *io_info, const H5D_type_info_t *type_in /* * Scatter the data out to the file. */ - if(H5D__scatter_file(io_info, file_space, file_iter, smine_nelmts, type_info->tconv_buf) < 0) + if(H5D__scatter_file(io_info, file_iter, smine_nelmts, type_info->tconv_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "scatter failed") } /* end for */ @@ -761,7 +753,7 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5D__compound_opt_read(size_t nelmts, const H5S_t *space, H5S_sel_iter_t *iter, +H5D__compound_opt_read(size_t nelmts, H5S_sel_iter_t *iter, const H5D_type_info_t *type_info, void *user_buf/*out*/) { uint8_t *ubuf = (uint8_t *)user_buf; /* Cast for pointer arithmetic */ @@ -777,7 +769,6 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, H5S_sel_iter_t *iter, /* Check args */ HDassert(nelmts > 0); - HDassert(space); HDassert(iter); HDassert(type_info); HDassert(type_info->cmpd_subset); @@ -814,7 +805,7 @@ H5D__compound_opt_read(size_t nelmts, const H5S_t *space, H5S_sel_iter_t *iter, size_t elmtno; /* Element counter */ /* Get list of sequences for selection to write */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, vec_size, nelmts, &nseq, &elmtno, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, vec_size, nelmts, &nseq, &elmtno, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, 0, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -981,7 +972,7 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") /* Initialize selection iterator */ - if(H5S_select_iter_init(iter, dst_space, type_size) < 0) + if(H5S_select_iter_init(iter, dst_space, type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information") iter_init = TRUE; @@ -1005,7 +996,7 @@ H5Dscatter(H5D_scatter_func_t op, void *op_data, hid_t type_id, HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "callback returned more elements than in selection") /* Scatter data */ - if(H5D__scatter_mem(src_buf, dst_space, iter, nelmts_scatter, dst_buf) < 0) + if(H5D__scatter_mem(src_buf, iter, nelmts_scatter, dst_buf) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCOPY, FAIL, "scatter failed") nelmts -= (hssize_t)nelmts_scatter; @@ -1091,14 +1082,14 @@ H5Dgather(hid_t src_space_id, const void *src_buf, hid_t type_id, HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") /* Initialize selection iterator */ - if(H5S_select_iter_init(iter, src_space, type_size) < 0) + if(H5S_select_iter_init(iter, src_space, type_size, 0) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize selection iterator information") iter_init = TRUE; /* Loop until all data has been scattered */ while(nelmts > 0) { /* Gather data */ - if(0 == (nelmts_gathered = H5D__gather_mem(src_buf, src_space, iter, MIN(dst_buf_nelmts, (size_t)nelmts), dst_buf))) + if(0 == (nelmts_gathered = H5D__gather_mem(src_buf, iter, MIN(dst_buf_nelmts, (size_t)nelmts), dst_buf))) HGOTO_ERROR(H5E_IO, H5E_CANTCOPY, FAIL, "gather failed") HDassert(nelmts_gathered == MIN(dst_buf_nelmts, (size_t)nelmts)); diff --git a/src/H5Dselect.c b/src/H5Dselect.c index 0ec34233cc..2f2ed66ca6 100644 --- a/src/H5Dselect.c +++ b/src/H5Dselect.c @@ -175,12 +175,12 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "can't allocate file iterator") /* Initialize file iterator */ - if(H5S_select_iter_init(file_iter, file_space, elmt_size) < 0) + if(H5S_select_iter_init(file_iter, file_space, elmt_size, H5S_SEL_ITER_GET_SEQ_LIST_SORTED) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") file_iter_init = 1; /* File selection iteration info has been initialized */ /* Initialize memory iterator */ - if(H5S_select_iter_init(mem_iter, mem_space, elmt_size) < 0) + if(H5S_select_iter_init(mem_iter, mem_space, elmt_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") mem_iter_init = 1; /* Memory selection iteration info has been initialized */ @@ -193,7 +193,7 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Check if more file sequences are needed */ if(curr_file_seq >= file_nseq) { /* Get sequences for file selection */ - if(H5S_SELECT_GET_SEQ_LIST(file_space, H5S_GET_SEQ_LIST_SORTED, file_iter, vec_size, nelmts, &file_nseq, &file_nelem, file_off, file_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(file_iter, vec_size, nelmts, &file_nseq, &file_nelem, file_off, file_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Start at the beginning of the sequences again */ @@ -203,7 +203,7 @@ H5D__select_io(const H5D_io_info_t *io_info, size_t elmt_size, /* Check if more memory sequences are needed */ if(curr_mem_seq >= mem_nseq) { /* Get sequences for memory selection */ - if(H5S_SELECT_GET_SEQ_LIST(mem_space, 0, mem_iter, vec_size, nelmts, &mem_nseq, &mem_nelem, mem_off, mem_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(mem_iter, vec_size, nelmts, &mem_nseq, &mem_nelem, mem_off, mem_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Start at the beginning of the sequences again */ diff --git a/src/H5Sall.c b/src/H5Sall.c index 0aa2f05449..083410a594 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -51,9 +51,6 @@ /* Selection callbacks */ static herr_t H5S__all_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); -static herr_t H5S__all_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__all_release(H5S_t *space); static htri_t H5S__all_is_valid(const H5S_t *space); static hssize_t H5S__all_serial_size(const H5S_t *space); @@ -66,10 +63,11 @@ static int H5S__all_unlim_dim(const H5S_t *space); static htri_t H5S__all_is_contiguous(const H5S_t *space); static htri_t H5S__all_is_single(const H5S_t *space); static htri_t H5S__all_is_regular(const H5S_t *space); +static htri_t H5S__all_shape_same(const H5S_t *space1, const H5S_t *space2); static herr_t H5S__all_adjust_u(H5S_t *space, const hsize_t *offset); static herr_t H5S__all_project_scalar(const H5S_t *space, hsize_t *offset); static herr_t H5S__all_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); -static herr_t H5S__all_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); +static herr_t H5S__all_iter_init(const H5S_t *space, H5S_sel_iter_t *iter); /* Selection iteration callbacks */ static herr_t H5S__all_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); @@ -78,6 +76,8 @@ static hsize_t H5S__all_iter_nelmts(const H5S_sel_iter_t *iter); static htri_t H5S__all_iter_has_next_block(const H5S_sel_iter_t *iter); static herr_t H5S__all_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); static herr_t H5S__all_iter_next_block(H5S_sel_iter_t *sel_iter); +static herr_t H5S__all_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__all_iter_release(H5S_sel_iter_t *sel_iter); @@ -96,7 +96,6 @@ const H5S_select_class_t H5S_sel_all[1] = {{ /* Methods on selection */ H5S__all_copy, - H5S__all_get_seq_list, H5S__all_release, H5S__all_is_valid, H5S__all_serial_size, @@ -109,6 +108,7 @@ const H5S_select_class_t H5S_sel_all[1] = {{ H5S__all_is_contiguous, H5S__all_is_single, H5S__all_is_regular, + H5S__all_shape_same, H5S__all_adjust_u, H5S__all_project_scalar, H5S__all_project_simple, @@ -131,6 +131,7 @@ static const H5S_sel_iter_class_t H5S_sel_iter_all[1] = {{ H5S__all_iter_has_next_block, H5S__all_iter_next, H5S__all_iter_next_block, + H5S__all_iter_get_seq_list, H5S__all_iter_release, }}; @@ -149,7 +150,7 @@ static const H5S_sel_iter_class_t H5S_sel_iter_all[1] = {{ *------------------------------------------------------------------------- */ static herr_t -H5S__all_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) +H5S__all_iter_init(const H5S_t H5_ATTR_UNUSED *space, H5S_sel_iter_t *iter) { FUNC_ENTER_STATIC_NOERR @@ -157,9 +158,6 @@ H5S__all_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) HDassert(space && H5S_SEL_ALL == H5S_GET_SELECT_TYPE(space)); HDassert(iter); - /* Initialize the number of elements to iterate over */ - iter->elmt_left = H5S_GET_SELECT_NPOINTS(space); - /* Start at the upper left location */ iter->u.all.elmt_offset = 0; iter->u.all.byte_offset = 0; @@ -362,13 +360,11 @@ H5S__all_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter) /*-------------------------------------------------------------------------- NAME - H5S__all_get_seq_list + H5S__all_iter_get_seq_list PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S__all_get_seq_list(space,flags,iter,maxseq,maxelem,nseq,nelem,off,len) - H5S_t *space; IN: Dataspace containing selection to use. - unsigned flags; IN: Flags for extra information about operation + herr_t H5S__all_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. size_t maxseq; IN: Maximum number of sequences to generate @@ -392,16 +388,14 @@ H5S__all_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__all_get_seq_list(const H5S_t H5_ATTR_UNUSED *space, unsigned H5_ATTR_UNUSED flags, H5S_sel_iter_t *iter, - size_t H5_ATTR_UNUSED maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__all_iter_get_seq_list(H5S_sel_iter_t *iter, size_t H5_ATTR_UNUSED maxseq, + size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { size_t elem_used; /* The number of elements used */ FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -431,7 +425,7 @@ H5S__all_get_seq_list(const H5S_t H5_ATTR_UNUSED *space, unsigned H5_ATTR_UNUSED iter->u.all.byte_offset += len[0]; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__all_get_seq_list() */ +} /* end H5S__all_iter_get_seq_list() */ /*-------------------------------------------------------------------------- @@ -889,6 +883,70 @@ H5S__all_is_regular(const H5S_t H5_ATTR_UNUSED *space) FUNC_LEAVE_NOAPI(TRUE) } /* end H5S__all_is_regular() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__all_shape_same + PURPOSE + Check if a two "all" selections are the same shape + USAGE + htri_t H5S__all_shape_same(space1, space2) + const H5S_t *space1; IN: First dataspace to check + const H5S_t *space2; IN: Second dataspace to check + RETURNS + TRUE / FALSE / FAIL + DESCRIPTION + Checks to see if the current selection in each dataspace are the same + shape. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static htri_t +H5S__all_shape_same(const H5S_t *space1, const H5S_t *space2) +{ + int space1_dim; /* Current dimension in first dataspace */ + int space2_dim; /* Current dimension in second dataspace */ + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Check args */ + HDassert(space1); + HDassert(space2); + + /* Initialize dataspace dims */ + space1_dim = (int)space1->extent.rank - 1; + space2_dim = (int)space2->extent.rank - 1; + + /* Recall that space1_rank >= space2_rank. + * + * In the following while loop, we test to see if space1 and space2 + * have identical size in all dimensions they have in common. + */ + while(space2_dim >= 0) { + if(space1->extent.size[space1_dim] != space2->extent.size[space2_dim]) + HGOTO_DONE(FALSE) + + space1_dim--; + space2_dim--; + } /* end while */ + + /* Since we are selecting the entire space, we must also verify that space1 + * has size 1 in all dimensions that it does not share with space2. + */ + while(space1_dim >= 0) { + if(space1->extent.size[space1_dim] != 1) + HGOTO_DONE(FALSE) + + space1_dim--; + } /* end while */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__all_shape_same() */ + /*-------------------------------------------------------------------------- NAME diff --git a/src/H5Shyper.c b/src/H5Shyper.c index c9fab38eac..2857e13ca3 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -40,46 +40,132 @@ /* Local Macros */ /****************/ +/* Macro for checking if two ranges overlap one another */ +/* + * Three possible conditions for overlapping: + * 1. The lower bound of range #1 is between the lower and + * higher bounds of range #2. In other words, the low + * part of range #1 will at least overlap with range #2. + * 2. The higher bound of range #1 is between the lower and + * higher bounds of range #2. In other words, the upper + * part of range #1 will at least overlap with range #2. + * 3. Range #1 includes range #2, i.e. the lower bound + * is smaller than that of range #2 and the higher bound + * is larger than that of range #2. + */ +/* (Assumes that low & high bounds are _inclusive_) */ +#define H5S_RANGE_OVERLAP(L1, H1, L2, H2) \ + /* condition 1 */ \ + (((L1) >= (L2) && (L1) <= (H2)) || \ + /* condition 2 */ \ + ((H1) >= (L2) && (H1) <= (H2)) || \ + /* condition 3 */ \ + ((L1) <= (L2) && (H1) >= (H2))) + +/* Flags for which hyperslab fragments to compute */ +#define H5S_HYPER_COMPUTE_B_NOT_A 0x01 +#define H5S_HYPER_COMPUTE_A_AND_B 0x02 +#define H5S_HYPER_COMPUTE_A_NOT_B 0x04 + +/* Macro to advance a span, possibly recycling it first */ +#define H5S_HYPER_ADVANCE_SPAN(recover, curr_span, next_span) \ + do { \ + H5S_hyper_span_t *saved_next_span = (next_span); \ + \ + /* Check if the span should be recovered */ \ + if(recover) { \ + H5S__hyper_free_span(curr_span); \ + (recover) = FALSE; \ + } /* end if */ \ + \ + /* Set the current span to saved next span */ \ + (curr_span) = saved_next_span; \ + } while(0) + +#ifdef H5_HAVE_THREADSAFE +/* + * The per-thread operation generation. pthread_once() initializes a special + * key that will be used by all threads to create a stack specific to + * each thread individually. The association of operation generations to threads + * will be handled by the pthread library. + * + * In order for this macro to work, H5S_hyper_get_my_op_gen() must be preceeded + * by "uint64_t *gen =". + */ +#define H5S_hyper_get_my_op_gen() H5S__hyper_op_gen() +#else /* H5_HAVE_THREADSAFE */ +/* + * The current operation generation. + */ +#define H5S_hyper_get_my_op_gen() (&H5S_hyper_op_gen_g) +#endif /* H5_HAVE_THREADSAFE */ + /******************/ /* Local Typedefs */ /******************/ +/* Define alias for hsize_t, for allocating H5S_hyper_span_info_t + bounds objects */ +/* (Makes it easier to understand the alloc / free calls) */ +typedef hsize_t hbounds_t; + /********************/ /* Local Prototypes */ /********************/ +#ifdef H5_HAVE_THREADSAFE +static uint64_t *H5S__hyper_op_gen(void); +#endif /* H5_HAVE_THREADSAFE */ static H5S_hyper_span_t *H5S__hyper_new_span(hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, H5S_hyper_span_t *next); -static herr_t H5S__hyper_span_precompute(H5S_hyper_span_info_t *spans, size_t elmt_size); -static void H5S__hyper_span_scratch(H5S_hyper_span_info_t *spans); -static H5S_hyper_span_info_t *H5S__hyper_copy_span(H5S_hyper_span_info_t *spans); +static H5S_hyper_span_info_t *H5S__hyper_new_span_info(unsigned rank); +static H5S_hyper_span_info_t *H5S__hyper_copy_span(H5S_hyper_span_info_t *spans, + unsigned rank); static hbool_t H5S__hyper_cmp_spans(const H5S_hyper_span_info_t *span_info1, const H5S_hyper_span_info_t *span_info2); -static herr_t H5S__hyper_free_span_info(H5S_hyper_span_info_t *span_info); -static herr_t H5S__hyper_free_span(H5S_hyper_span_t *span); -static hbool_t H5S__hyper_is_valid_helper(const H5S_hyper_span_info_t *spans, - const hssize_t *offset, const hsize_t *size); -static herr_t H5S__hyper_recover_span(hbool_t *recover, - H5S_hyper_span_t **curr_span, H5S_hyper_span_t *next_span); -static H5S_hyper_span_t *H5S__hyper_coord_to_span(unsigned rank, - const hsize_t *coords); -static herr_t H5S__hyper_append_span(H5S_hyper_span_t **prev_span, - H5S_hyper_span_info_t **span_tree, hsize_t low, hsize_t high, - H5S_hyper_span_info_t *down, H5S_hyper_span_t *next); +static void H5S__hyper_free_span_info(H5S_hyper_span_info_t *span_info); +static void H5S__hyper_free_span(H5S_hyper_span_t *span); +static herr_t H5S__hyper_span_blocklist(const H5S_hyper_span_info_t *spans, + hsize_t start[], hsize_t end[], hsize_t rank, hsize_t *startblock, hsize_t *numblocks, + hsize_t **buf); +static herr_t H5S__get_select_hyper_blocklist(H5S_t *space, hsize_t startblock, + hsize_t numblocks, hsize_t *buf); +static H5S_hyper_span_t *H5S__hyper_coord_to_span(unsigned rank, const hsize_t *coords); +static herr_t H5S__hyper_append_span(H5S_hyper_span_info_t **span_tree, + unsigned ndims, hsize_t low, hsize_t high, H5S_hyper_span_info_t *down); static herr_t H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, - H5S_hyper_span_info_t *b_spans, H5S_hyper_span_info_t **a_not_b, + H5S_hyper_span_info_t *b_spans, unsigned selector, + unsigned ndims, H5S_hyper_span_info_t **a_not_b, H5S_hyper_span_info_t **a_and_b, H5S_hyper_span_info_t **b_not_a); -static herr_t H5S__hyper_merge_spans(H5S_t *space, - H5S_hyper_span_info_t *new_spans, hbool_t can_own); -static hsize_t H5S__hyper_spans_nelem(const H5S_hyper_span_info_t *spans); +static herr_t H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans); +static hsize_t H5S__hyper_spans_nelem(H5S_hyper_span_info_t *spans); +static herr_t H5S__hyper_add_disjoint_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans); static H5S_hyper_span_info_t *H5S__hyper_make_spans(unsigned rank, - const hsize_t *start, const hsize_t *stride, const hsize_t *count, - const hsize_t *block); + const hsize_t *start, const hsize_t *stride, + const hsize_t *count, const hsize_t *block); +static herr_t H5S__hyper_update_diminfo(H5S_t *space, H5S_seloper_t op, + const H5S_hyper_dim_t *new_hyper_diminfo); static herr_t H5S__hyper_generate_spans(H5S_t *space); +static hbool_t H5S__check_spans_overlap(const H5S_hyper_span_info_t *spans1, + const H5S_hyper_span_info_t *spans2); +static herr_t H5S__fill_in_new_space(H5S_t *space1, H5S_seloper_t op, + H5S_hyper_span_info_t *space2_span_lst, hbool_t can_own_span2, + hbool_t *span2_owned, hbool_t *updated_spans, H5S_t **result); static herr_t H5S__generate_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], const hsize_t stride[], const hsize_t count[], const hsize_t block[]); +static herr_t H5S__set_regular_hyperslab(H5S_t *space, const hsize_t start[], + const hsize_t *app_stride, const hsize_t app_count[], const hsize_t *app_block, + const hsize_t *opt_stride, const hsize_t opt_count[], const hsize_t *opt_block); +static herr_t H5S__fill_in_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2, + H5S_t **result); +static H5S_t *H5S__combine_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2); +static herr_t H5S__hyper_iter_get_seq_list_gen(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len); +static herr_t H5S__hyper_iter_get_seq_list_opt(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len); +static herr_t H5S__hyper_iter_get_seq_list_single(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len); static void H5S__hyper_get_clip_diminfo(hsize_t start, hsize_t stride, hsize_t *count, hsize_t *block, hsize_t clip_size); static hsize_t H5S__hyper_get_clip_extent_real(const H5S_t *clip_space, @@ -87,11 +173,9 @@ static hsize_t H5S__hyper_get_clip_extent_real(const H5S_t *clip_space, /* Selection callbacks */ static herr_t H5S__hyper_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); -static herr_t H5S__hyper_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__hyper_release(H5S_t *space); static htri_t H5S__hyper_is_valid(const H5S_t *space); +static hsize_t H5S__hyper_span_nblocks(H5S_hyper_span_info_t *spans); static hssize_t H5S__hyper_serial_size(const H5S_t *space); static herr_t H5S__hyper_serialize(const H5S_t *space, uint8_t **p); static herr_t H5S__hyper_deserialize(H5S_t *space, uint32_t version, uint8_t flags, @@ -104,10 +188,11 @@ static herr_t H5S__hyper_num_elem_non_unlim(const H5S_t *space, static htri_t H5S__hyper_is_contiguous(const H5S_t *space); static htri_t H5S__hyper_is_single(const H5S_t *space); static htri_t H5S__hyper_is_regular(const H5S_t *space); +static htri_t H5S__hyper_shape_same(const H5S_t *space1, const H5S_t *space2); static herr_t H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset); static herr_t H5S__hyper_project_scalar(const H5S_t *space, hsize_t *offset); static herr_t H5S__hyper_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); -static herr_t H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); +static herr_t H5S__hyper_iter_init(const H5S_t *space, H5S_sel_iter_t *iter); /* Selection iteration callbacks */ static herr_t H5S__hyper_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); @@ -116,12 +201,10 @@ static hsize_t H5S__hyper_iter_nelmts(const H5S_sel_iter_t *iter); static htri_t H5S__hyper_iter_has_next_block(const H5S_sel_iter_t *sel_iter); static herr_t H5S__hyper_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); static herr_t H5S__hyper_iter_next_block(H5S_sel_iter_t *sel_iter); +static herr_t H5S__hyper_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__hyper_iter_release(H5S_sel_iter_t *sel_iter); -/* Static function for optimizing hyperslab */ -static hbool_t H5S__hyper_rebuild_helper(const H5S_hyper_span_t *span, - H5S_hyper_dim_t span_slab_info[], unsigned rank); -static hbool_t H5S__hyper_rebuild(H5S_t *space); /*****************************/ /* Library Private Variables */ @@ -138,7 +221,6 @@ const H5S_select_class_t H5S_sel_hyper[1] = {{ /* Methods on selection */ H5S__hyper_copy, - H5S__hyper_get_seq_list, H5S__hyper_release, H5S__hyper_is_valid, H5S__hyper_serial_size, @@ -151,6 +233,7 @@ const H5S_select_class_t H5S_sel_hyper[1] = {{ H5S__hyper_is_contiguous, H5S__hyper_is_single, H5S__hyper_is_regular, + H5S__hyper_shape_same, H5S__hyper_adjust_u, H5S__hyper_project_scalar, H5S__hyper_project_simple, @@ -173,11 +256,10 @@ static const H5S_sel_iter_class_t H5S_sel_iter_hyper[1] = {{ H5S__hyper_iter_has_next_block, H5S__hyper_iter_next, H5S__hyper_iter_next_block, + H5S__hyper_iter_get_seq_list, H5S__hyper_iter_release, }}; -/* Static variables */ - /* Arrays for default stride, block, etc. */ static const hsize_t H5S_hyper_zeros_g[H5S_MAX_RANK] = { 0,0,0,0, 0,0,0,0, @@ -196,12 +278,19 @@ H5FL_DEFINE_STATIC(H5S_hyper_sel_t); /* 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 the H5S_hyper_span_info_t struct */ -H5FL_DEFINE_STATIC(H5S_hyper_span_info_t); +/* Declare a free list to manage the H5S_hyper_span_info_t + hsize_t array struct */ +H5FL_BARR_DEFINE_STATIC(H5S_hyper_span_info_t, hbounds_t, H5S_MAX_RANK * 2); /* Declare extern free list to manage the H5S_sel_iter_t struct */ H5FL_EXTERN(H5S_sel_iter_t); +#ifndef H5_HAVE_THREADSAFE +static uint64_t H5S_hyper_op_gen_g = 1; /* Current operation generation */ + /* (Use '1' to avoid clashing with '0' value in newly allocated structs) */ +#endif /* H5_HAVE_THREADSAFE */ + + +/* Uncomment this, to provide the debugging routines for printing selection info */ /* #define H5S_HYPER_DEBUG */ #ifdef H5S_HYPER_DEBUG static herr_t @@ -210,9 +299,9 @@ H5S__hyper_print_spans_helper(FILE *f, const H5S_hyper_span_t *span, unsigned de FUNC_ENTER_STATIC_NOERR while(span) { - HDfprintf(f,"%s: depth=%u, span=%p, (%Hu, %Hu), nelem=%Hu, pstride=%Hu\n", FUNC, depth, span, span->low, span->high, span->nelem, span->pstride); - if(span->down && span->down->head) { - HDfprintf(f,"%s: spans=%p, count=%u, scratch=%p, head=%p\n", FUNC, span->down, span->down->count, span->down->scratch, span->down->head); + HDfprintf(f,"%s: %*sdepth=%u, span=%p, (%Hu, %Hu), next=%p\n", FUNC, depth * 2, "", depth, span, span->low, span->high, span->next); + if(span->down) { + HDfprintf(f,"%s: %*sspans=%p, count=%u, bounds[0]={%Hu, %Hu}, head=%p\n", FUNC, (depth + 1) * 2, "", span->down, span->down->count, span->down->low_bounds[0], span->down->high_bounds[0], span->down->head); H5S__hyper_print_spans_helper(f, span->down->head, depth + 1); } /* end if */ span = span->next; @@ -227,7 +316,7 @@ H5S__hyper_print_spans(FILE *f, const H5S_hyper_span_info_t *span_lst) FUNC_ENTER_STATIC_NOERR if(span_lst != NULL) { - HDfprintf(f, "%s: spans=%p, count=%u, scratch=%p, head=%p\n", FUNC, span_lst, span_lst->count, span_lst->scratch, span_lst->head); + HDfprintf(f, "%s: spans=%p, count=%u, bounds[0]={%Hu, %Hu}, head=%p\n", FUNC, span_lst, span_lst->count, span_lst->low_bounds[0], span_lst->high_bounds[0], span_lst->head); H5S__hyper_print_spans_helper(f, span_lst->head, 0); } /* end if */ @@ -276,13 +365,241 @@ H5S__hyper_print_diminfo(FILE *f, const H5S_t *space) { FUNC_ENTER_STATIC_NOERR - H5S__hyper_print_diminfo_helper(f, "opt_diminfo", space->extent.rank, space->select.sel_info.hslab->opt_diminfo); - H5S__hyper_print_diminfo_helper(f, "app_diminfo", space->extent.rank, space->select.sel_info.hslab->app_diminfo); + H5S__hyper_print_diminfo_helper(f, "diminfo.opt", space->extent.rank, space->select.sel_info.hslab->diminfo.opt); + H5S__hyper_print_diminfo_helper(f, "diminfo.app", space->extent.rank, space->select.sel_info.hslab->diminfo.app); FUNC_LEAVE_NOAPI(SUCCEED) } + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_print_spans_dfs + PURPOSE + Output the span elements for one span list in depth-first order + USAGE + herr_t H5S__hyper_print_spans_dfs(f, span_lst, depth) + FILE *f; IN: the file to output + const H5S_hyper_span_info_t *span_lst; IN: the span list to output + unsigned depth; IN: the level of this span list + RETURNS + non-negative on success, negative on failure + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__hyper_print_spans_dfs(FILE *f, const H5S_hyper_span_info_t *span_lst, + unsigned depth, unsigned dims) +{ + H5S_hyper_span_t *actual_tail = NULL; + H5S_hyper_span_t *cur_elem; + unsigned num_elems = 0; + unsigned u, elem_idx; + + FUNC_ENTER_STATIC_NOERR + + /* get the actual tail from head */ + cur_elem = span_lst->head; + HDassert(cur_elem); /* at least 1 element */ + while(cur_elem) { + actual_tail = cur_elem; + cur_elem = cur_elem->next; + num_elems++; + } /* end while */ + + for(u = 0; u < depth; u++) + HDfprintf(f, "\t"); + HDfprintf(f, "DIM[%u]: ref_count=%u, #elems=%u, head=%p, tail=%p, actual_tail=%p, matched=%t\n", depth, + span_lst->count, num_elems, span_lst->head, + span_lst->tail, actual_tail, (span_lst->tail == actual_tail)); + + for(u = 0; u < depth; u++) + HDfprintf(f, "\t"); + HDfprintf(f, "low_bounds=["); + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", span_lst->low_bounds[u]); + HDfprintf(f, "%llu]\n", span_lst->low_bounds[dims - 1]); + + for(u = 0; u < depth; u++) + HDfprintf(f, "\t"); + HDfprintf(f, "high_bounds=["); + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", span_lst->high_bounds[u]); + HDfprintf(f, "%llu]\n", span_lst->high_bounds[dims - 1]); + + cur_elem = span_lst->head; + elem_idx = 0; + while(cur_elem) { + for(u = 0; u < depth; u++) + HDfprintf(f, "\t"); + HDfprintf(f, "ELEM[%u]: ptr=%p, low=%Hu, high=%Hu, down=%p\n", + elem_idx++, cur_elem, cur_elem->low, cur_elem->high, cur_elem->down); + if(cur_elem->down) + H5S__hyper_print_spans_dfs(f, cur_elem->down, depth + 1, dims); + cur_elem = cur_elem->next; + } /* end while */ + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5S__hyper_print_spans_dfs() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_print_space_dfs + PURPOSE + Output the span elements for one hyperslab selection space in depth-first order + USAGE + herr_t H5S__hyper_print_space_dfs(f, space) + FILE *f; IN: the file to output + const H5S_t *space; IN: the selection space to output + RETURNS + non-negative on success, negative on failure + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__hyper_print_space_dfs(FILE *f, const H5S_t *space) +{ + const H5S_hyper_sel_t *hslab = space->select.sel_info.hslab; + const unsigned dims = space->extent.rank; + unsigned u; + + FUNC_ENTER_STATIC_NOERR + + HDassert(hslab); + + HDfprintf(f, "=======================\n"); + HDfprintf(f, "SPACE: span_lst=%p, #dims=%u, offset_changed=%d\n", hslab->span_lst, dims, space->select.offset_changed); + + HDfprintf(f, " offset=["); + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%lld,", space->select.offset[u]); + HDfprintf(f, "%lld]\n", space->select.offset[dims - 1]); + + HDfprintf(f, " low_bounds=["); + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", space->select.sel_info.hslab->diminfo.low_bounds[u]); + HDfprintf(f, "%llu]\n", space->select.sel_info.hslab->diminfo.low_bounds[dims - 1]); + } /* end if */ + else { + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", space->select.sel_info.hslab->span_lst->low_bounds[u]); + HDfprintf(f, "%llu]\n", space->select.sel_info.hslab->span_lst->low_bounds[dims - 1]); + } /* end else */ + + HDfprintf(f, " high_bounds=["); + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", space->select.sel_info.hslab->diminfo.high_bounds[u]); + HDfprintf(f, "%llu]\n", space->select.sel_info.hslab->diminfo.high_bounds[dims - 1]); + } /* end if */ + else { + for(u = 0; u < dims - 1; u++) + HDfprintf(f, "%llu,", space->select.sel_info.hslab->span_lst->high_bounds[u]); + HDfprintf(f, "%llu]\n", space->select.sel_info.hslab->span_lst->high_bounds[dims - 1]); + } /* end else */ + + /* Print out diminfo, if it's valid */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) + H5S__hyper_print_diminfo(f, space); + + /* Start print out the highest-order of dimension */ + if(hslab->span_lst) + H5S__hyper_print_spans_dfs(f, hslab->span_lst, 0, dims); + HDfprintf(f, "=======================\n\n"); + + FUNC_LEAVE_NOAPI(SUCCEED) +} /* end H5S__hyper_print_space_dfs() */ #endif /* H5S_HYPER_DEBUG */ +#ifdef H5_HAVE_THREADSAFE + +/*------------------------------------------------------------------------- + * Function: H5S__hyper_op_gen + * + * Purpose: Support function for H5S_hyper_get_my_op_gen() to initialize and + * acquire per-thread hyperslab operation generation. + * + * Return: Success: Non-NULL pointer to hyperslab operation generation for thread + * Failure: NULL + * + * Programmer: Quincey Koziol + * January 19, 2019 + * + *------------------------------------------------------------------------- + */ +static uint64_t * +H5S__hyper_op_gen(void) +{ + uint64_t *op_gen = NULL; + + FUNC_ENTER_STATIC_NOERR + + op_gen = (uint64_t *)H5TS_get_thread_local_value(H5TS_hyper_op_gen_key_g); + + if(!op_gen) { + /* No associated value with current thread - create one */ +#ifdef H5_HAVE_WIN_THREADS + /* Win32 has to use LocalAlloc to match the LocalFree in DllMain */ + op_gen = (uint64_t *)LocalAlloc(LPTR, sizeof(uint64_t)); +#else + /* Use HDmalloc here since this has to match the HDfree in the + * destructor and we want to avoid the codestack there. + */ + op_gen = (uint64_t *)HDmalloc(sizeof(uint64_t)); +#endif /* H5_HAVE_WIN_THREADS */ + HDassert(op_gen); + + /* Reset the thread-specific info */ + /* (Use '1' to avoid clashing with '0' value in newly allocated structs) */ + *op_gen = 1; + + /* (It's not necessary to release this in this API, it is + * released by the "key destructor" set up in the H5TS + * routines. See calls to pthread_key_create() in H5TS.c -QAK) + */ + H5TS_set_thread_local_value(H5TS_hyper_op_gen_key_g, (void *)op_gen); + } /* end if */ + + /* Set return value */ + FUNC_LEAVE_NOAPI(op_gen) +} /* end H5S__hyper_op_gen() */ +#endif /* H5_HAVE_THREADSAFE */ + + +/*------------------------------------------------------------------------- + * Function: H5S__hyper_get_op_gen + * + * Purpose: Acquire a unique operation generation value + * + * Return: Operation generation value (can't fail) + * + * Programmer: Quincey Koziol + * Saturday, January 19, 2019 + * + * Notes: Assumes that a 64-bit value will not wrap around during + * the lifespan of the process. + * + *------------------------------------------------------------------------- + */ +uint64_t +H5S__hyper_get_op_gen(void) +{ + uint64_t *op_gen = H5S_hyper_get_my_op_gen(); /* Get the pointer to the hyperslab operation generation, for this thread */ + + FUNC_ENTER_PACKAGE_NOERR + + /* Check args */ + HDassert(op_gen); + + FUNC_LEAVE_NOAPI((*op_gen)++); +} /* end H5S__hyper_op_gen() */ + /*------------------------------------------------------------------------- * Function: H5S__hyper_iter_init @@ -294,7 +611,7 @@ H5S__hyper_print_diminfo(FILE *f, const H5S_t *space) * Programmer: Quincey Koziol * Saturday, February 24, 2001 * - * Notes: If the 'elmt_size' parameter is set to zero, the regular + * Notes: If the 'iter->elmt_size' field is set to zero, the regular * hyperslab selection iterator will not be 'flattened'. This * is used by the H5S_select_shape_same() code to avoid changing * the rank and appearance of the selection. @@ -302,37 +619,47 @@ H5S__hyper_print_diminfo(FILE *f, const H5S_t *space) *------------------------------------------------------------------------- */ static herr_t -H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) +H5S__hyper_iter_init(const H5S_t *space, H5S_sel_iter_t *iter) { - unsigned rank; /* Dataspace's dimension rank */ - unsigned u; /* Index variable */ + hsize_t *slab_size; /* Pointer to the dataspace dimensions to use for calc. slab */ + hsize_t acc; /* Accumulator for computing cumulative sizes */ + unsigned slab_dim; /* Rank of the fastest changing dimension for calc. slab */ + unsigned rank; /* Dataspace's dimension rank */ + unsigned u; /* Index variable */ + int i; /* Index variable */ + herr_t ret_value = SUCCEED; /* return value */ - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_STATIC /* Check args */ HDassert(space && H5S_SEL_HYPERSLABS == H5S_GET_SELECT_TYPE(space)); HDassert(iter); HDassert(space->select.sel_info.hslab->unlim_dim < 0); - /* Initialize the number of points to iterate over */ - iter->elmt_left = space->select.num_elem; + /* Initialize the hyperslab iterator's rank */ iter->u.hyp.iter_rank = 0; /* Get the rank of the dataspace */ - rank = space->extent.rank; + rank = iter->rank; + + /* Attempt to rebuild diminfo if it is invalid and has not been confirmed + * to be impossible. + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild((H5S_t *)space); /* Casting away const OK -NAF */ /* Check for the special case of just one H5Sselect_hyperslab call made */ - if(space->select.sel_info.hslab->diminfo_valid) { + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { /* Initialize the information needed for regular hyperslab I/O */ const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ const hsize_t *mem_size; /* Temporary pointer to dataspace extent's dimension sizes */ unsigned cont_dim = 0; /* # of contiguous dimensions */ /* Set the temporary pointer to the dimension information */ - tdiminfo = space->select.sel_info.hslab->opt_diminfo; + tdiminfo = space->select.sel_info.hslab->diminfo.opt; /* Set the temporary pointer to the dataspace extent's dimension sizes */ - mem_size = space->extent.size; + mem_size = iter->dims; /* * For a regular hyperslab to be contiguous up to some dimension, it @@ -359,11 +686,9 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) /* Check if the regular selection can be "flattened" */ if(cont_dim > 0) { - hsize_t acc; /* Accumulator for "flattened" dimension's sizes */ - hbool_t last_dim_flattened = TRUE; /* Flag to indicate that the last dimension was flattened */ + hbool_t last_dim_flattened = TRUE; /* Flag to indicate that the last dimension was flattened */ unsigned flat_rank = rank-cont_dim; /* Number of dimensions after flattening */ unsigned curr_dim; /* Current dimension */ - int i; /* Index variable */ /* Set the iterator's rank to the contiguous dimensions */ iter->u.hyp.iter_rank = flat_rank; @@ -392,7 +717,7 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) iter->u.hyp.diminfo[curr_dim].count = tdiminfo[i].count; iter->u.hyp.diminfo[curr_dim].block = tdiminfo[i].block * acc; iter->u.hyp.size[curr_dim] = mem_size[i] * acc; - iter->u.hyp.sel_off[curr_dim] = space->select.offset[i] * (hssize_t)acc; + iter->u.hyp.sel_off[curr_dim] = iter->sel_off[i] * (hssize_t)acc; /* Reset the "last dim flattened" flag to avoid flattened any further dimensions */ last_dim_flattened = FALSE; @@ -407,7 +732,7 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) iter->u.hyp.diminfo[curr_dim].count = tdiminfo[i].count; iter->u.hyp.diminfo[curr_dim].block = tdiminfo[i].block; iter->u.hyp.size[curr_dim] = mem_size[i]; - iter->u.hyp.sel_off[curr_dim] = space->select.offset[i]; + iter->u.hyp.sel_off[curr_dim] = iter->sel_off[i]; } /* end else */ /* Decrement "current" flattened dimension */ @@ -418,20 +743,23 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) /* Initialize "flattened" iterator offset to initial location and dataspace extent and selection information to correct values */ for(u = 0; u < flat_rank; u++) iter->u.hyp.off[u] = iter->u.hyp.diminfo[u].start; + + /* Set up information for computing slab sizes */ + slab_dim = iter->u.hyp.iter_rank - 1; + slab_size = iter->u.hyp.size; } /* end if */ else { - /* Initialize position to initial location */ - /* Also make local copy of the regular selection information */ - for(u = 0; u < rank; u++) { - /* Regular selection information */ - iter->u.hyp.diminfo[u].start = tdiminfo[u].start; - iter->u.hyp.diminfo[u].stride = tdiminfo[u].stride; - iter->u.hyp.diminfo[u].count = tdiminfo[u].count; - iter->u.hyp.diminfo[u].block = tdiminfo[u].block; + /* Make local copy of the regular selection information */ + HDcompile_assert(sizeof(iter->u.hyp.diminfo) == sizeof(space->select.sel_info.hslab->diminfo.opt)); + HDmemcpy(iter->u.hyp.diminfo, tdiminfo, sizeof(iter->u.hyp.diminfo)); - /* Position information */ + /* Initialize position to initial location */ + for(u = 0; u < rank; u++) iter->u.hyp.off[u] = tdiminfo[u].start; - } /* end if */ + + /* Set up information for computing slab sizes */ + slab_dim = iter->rank - 1; + slab_size = iter->dims; } /* end else */ /* Flag the diminfo information as valid in the iterator */ @@ -443,12 +771,10 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) else { /* Initialize the information needed for non-regular hyperslab I/O */ H5S_hyper_span_info_t *spans; /* Pointer to hyperslab span info node */ + /* Share the source dataspace's span tree by incrementing the reference count on it */ HDassert(space->select.sel_info.hslab->span_lst); - /* Make a copy of the span tree to iterate over */ - iter->u.hyp.spans = H5S__hyper_copy_span(space->select.sel_info.hslab->span_lst); - - /* Set the nelem & pstride values according to the element size */ - H5S__hyper_span_precompute(iter->u.hyp.spans, iter->elmt_size); + iter->u.hyp.spans = space->select.sel_info.hslab->span_lst; + iter->u.hyp.spans->count++; /* Initialize the starting span_info's and spans */ spans = iter->u.hyp.spans; @@ -467,14 +793,33 @@ H5S__hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) spans = spans->head->down; } /* end for */ + /* Set up information for computing slab sizes */ + slab_dim = iter->rank - 1; + slab_size = iter->dims; + /* Flag the diminfo information as not valid in the iterator */ iter->u.hyp.diminfo_valid = FALSE; } /* end else */ + /* Compute the cumulative size of dataspace dimensions */ + for(i = (int)slab_dim, acc = iter->elmt_size; i >= 0; i--) { + iter->u.hyp.slab[i] = acc; + acc *= slab_size[i]; + } /* end for */ + + /* Initialize more information for irregular hyperslab selections */ + if(!iter->u.hyp.diminfo_valid) { + /* Set the offset of the first element iterated on, in each dimension */ + for(u = 0; u < rank; u++) + /* Compute the sequential element offset */ + iter->u.hyp.loc_off[u] = ((hsize_t)((hssize_t)iter->u.hyp.off[u] + iter->sel_off[u])) * iter->u.hyp.slab[u]; + } /* end if */ + /* Initialize type of selection iterator */ iter->type = H5S_sel_iter_hyper; - FUNC_LEAVE_NOAPI(SUCCEED) +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_iter_init() */ @@ -602,13 +947,11 @@ H5S__hyper_iter_block(const H5S_sel_iter_t *iter, hsize_t *start, hsize_t *end) } /* end for */ } /* end if */ else { - /* Copy the start of the block */ - for(u = 0; u < iter->rank; u++) + /* Copy the start & end of the block */ + for(u = 0; u < iter->rank; u++) { start[u] = iter->u.hyp.span[u]->low; - - /* Copy the end of the block */ - for(u = 0; u < iter->rank; u++) end[u] = iter->u.hyp.span[u]->high; + } /* end for */ } /* end else */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -1079,12 +1422,11 @@ H5S__hyper_iter_next_block(H5S_sel_iter_t *iter) /*-------------------------------------------------------------------------- NAME - H5S__hyper_get_seq_list_gen + H5S__hyper_iter_get_seq_list_gen PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S_select_hyper_get_file_list_gen(space,iter,maxseq,maxelem,nseq,nelem,off,len) - H5S_t *space; IN: Dataspace containing selection to use. + herr_t H5S__hyper_iter_get_seq_list_gen(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. size_t maxseq; IN: Maximum number of sequences to generate @@ -1108,21 +1450,21 @@ H5S__hyper_iter_next_block(H5S_sel_iter_t *iter) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, - size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__hyper_iter_get_seq_list_gen(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, + size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { H5S_hyper_span_t *curr_span; /* Current hyperslab span node */ H5S_hyper_span_t **ispan; /* Iterator's hyperslab span nodes */ - hsize_t slab[H5S_MAX_RANK]; /* Cumulative size of each dimension in bytes */ - hsize_t acc; /* Accumulator for computing cumulative sizes */ - hsize_t loc_off; /* Element offset in the dataspace */ + hsize_t *slab; /* Cumulative size of each dimension in bytes */ + hsize_t loc_off; /* Byte offset in the dataspace */ hsize_t last_span_end = 0; /* The offset of the end of the last span */ - hsize_t *abs_arr; /* Absolute hyperslab span position */ - const hssize_t *off_arr; /* Offset within the dataspace extent */ + hsize_t *abs_arr; /* Absolute hyperslab span position, in elements */ + hsize_t *loc_arr; /* Byte offset of hyperslab span position within buffer */ + const hssize_t *sel_off; /* Offset within the dataspace extent */ + size_t span_elmts = 0; /* Number of elements to actually use for this span */ size_t span_size = 0; /* Number of bytes in current span to actually process */ - size_t io_left; /* Number of elements left to process */ - size_t io_bytes_left; /* Number of bytes left to process */ + size_t io_left; /* Initial number of elements to process */ + size_t io_elmts_left; /* Number of elements left to process */ size_t io_used; /* Number of elements processed */ size_t curr_seq = 0; /* Number of sequence/offsets stored in the arrays */ size_t elem_size; /* Size of each element iterating over */ @@ -1130,12 +1472,10 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ int curr_dim; /* Current dimension being operated on */ unsigned u; /* Index variable */ - int i; /* Index variable */ FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -1145,45 +1485,39 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, HDassert(len); /* Set the rank of the fastest changing dimension */ - ndims = space->extent.rank; + ndims = iter->rank; fast_dim = (ndims - 1); /* Get the pointers to the current span info and span nodes */ curr_span = iter->u.hyp.span[fast_dim]; abs_arr = iter->u.hyp.off; - off_arr = space->select.offset; + loc_arr = iter->u.hyp.loc_off; + slab = iter->u.hyp.slab; + sel_off = iter->sel_off; ispan = iter->u.hyp.span; elem_size = iter->elmt_size; /* Set the amount of elements to perform I/O on, etc. */ H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t); - io_left = MIN(maxelem, (size_t)iter->elmt_left); - io_bytes_left = io_left * elem_size; - - /* Compute the cumulative size of dataspace dimensions */ - for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { - slab[i] = acc; - acc *= space->extent.size[i]; - } /* end for */ + io_elmts_left = io_left = MIN(maxelem, (size_t)iter->elmt_left); /* Set the offset of the first element iterated on */ for(u = 0, loc_off = 0; u < ndims; u++) - /* Compute the sequential element offset */ - loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; - - /* Range check against number of elements left in selection */ - HDassert(io_bytes_left <= (iter->elmt_left * elem_size)); + loc_off += loc_arr[u]; /* Take care of any partial spans leftover from previous I/Os */ if(abs_arr[fast_dim] != curr_span->low) { /* Finish the span in the fastest changing dimension */ - /* Compute the number of bytes to attempt in this span */ - H5_CHECKED_ASSIGN(span_size, size_t, ((curr_span->high - abs_arr[fast_dim])+1)*elem_size, hsize_t); + /* Compute the number of elements to attempt in this span */ + H5_CHECKED_ASSIGN(span_elmts, size_t, ((curr_span->high - abs_arr[fast_dim]) + 1), hsize_t); - /* Check number of bytes against upper bounds allowed */ - if(span_size > io_bytes_left) - span_size = io_bytes_left; + /* Check number of elements against upper bounds allowed */ + if(span_elmts > io_elmts_left) + span_elmts = io_elmts_left; + + /* Set the span_size, in bytes */ + span_size = span_elmts * elem_size; /* Add the partial span to the list of sequences */ off[curr_seq] = loc_off; @@ -1196,10 +1530,10 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, last_span_end = loc_off + span_size; /* Decrement I/O left to perform */ - io_bytes_left -= span_size; + io_elmts_left -= span_elmts; /* Check if we are done */ - if(io_bytes_left > 0) { + if(io_elmts_left > 0) { /* Move to next span in fastest changing dimension */ curr_span = curr_span->next; @@ -1209,15 +1543,21 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Move iterator for fastest changing dimension */ abs_arr[fast_dim] = curr_span->low; + loc_arr[fast_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[fast_dim])) * slab[fast_dim]; + ispan[fast_dim] = curr_span; } /* end if */ } /* end if */ else { /* Advance the hyperslab iterator */ - abs_arr[fast_dim] += span_size / elem_size; + abs_arr[fast_dim] += span_elmts; /* Check if we are still within the span */ if(abs_arr[fast_dim] <= curr_span->high) { - iter->u.hyp.span[fast_dim] = curr_span; + /* Sanity check */ + HDassert(ispan[fast_dim] == curr_span); + + /* Update byte offset */ + loc_arr[fast_dim] += span_size; } /* end if */ /* If we walked off that span, advance to the next span */ else { @@ -1228,7 +1568,12 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, if(NULL != curr_span) { /* Reset absolute position */ abs_arr[fast_dim] = curr_span->low; - iter->u.hyp.span[fast_dim] = curr_span; + + /* Update location offset */ + loc_arr[fast_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[fast_dim])) * slab[fast_dim]; + + /* Reset the span in the current dimension */ + ispan[fast_dim] = curr_span; } /* end if */ } /* end else */ } /* end else */ @@ -1243,13 +1588,16 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Work back up through the dimensions */ while(curr_dim >= 0) { /* Reset the current span */ - curr_span = iter->u.hyp.span[curr_dim]; + curr_span = ispan[curr_dim]; /* Increment absolute position */ abs_arr[curr_dim]++; /* Check if we are still within the span */ if(abs_arr[curr_dim] <= curr_span->high) { + /* Update location offset */ + loc_arr[curr_dim] += slab[curr_dim]; + break; } /* end if */ /* If we walked off that span, advance to the next span */ @@ -1265,6 +1613,9 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Reset absolute position */ abs_arr[curr_dim] = curr_span->low; + /* Update byte location */ + loc_arr[curr_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[curr_dim])) * slab[curr_dim]; + break; } /* end if */ else @@ -1285,49 +1636,58 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, curr_dim++; /* Set the new span_info & span for this dimension */ - iter->u.hyp.span[curr_dim] = curr_span->down->head; + ispan[curr_dim] = curr_span->down->head; /* Advance span down the tree */ curr_span = curr_span->down->head; /* Reset the absolute offset for the dim */ abs_arr[curr_dim] = curr_span->low; + + /* Update the location offset */ + loc_arr[curr_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[curr_dim])) * slab[curr_dim]; } /* end while */ /* Verify that the curr_span points to the fastest dim */ - HDassert(curr_span == iter->u.hyp.span[fast_dim]); + HDassert(curr_span == ispan[fast_dim]); /* Reset the buffer offset */ for(u = 0, loc_off = 0; u < ndims; u++) - loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; + loc_off += loc_arr[u]; } /* end else */ else /* We had better be done with I/O or bad things are going to happen... */ - HDassert(io_bytes_left == 0); + HDassert(io_elmts_left == 0); } /* end if */ } /* end if */ /* Perform the I/O on the elements, based on the position of the iterator */ - while(io_bytes_left > 0 && curr_seq < maxseq) { + while(io_elmts_left > 0 && curr_seq < maxseq) { + H5S_hyper_span_t *prev_span; /* Previous hyperslab span node */ + /* Sanity check */ HDassert(curr_span); - /* Adjust location offset of destination to compensate for initial increment below */ - loc_off -= curr_span->pstride; + /* Set to current span, so the first adjustment to loc_off is 0 */ + prev_span = curr_span; /* Loop over all the spans in the fastest changing dimension */ while(curr_span != NULL) { - /* Move location offset of destination */ - loc_off += curr_span->pstride; + hsize_t nelmts; /* # of elements covered by current span */ + + /* Move location offset of current span */ + loc_off += (curr_span->low - prev_span->low) * elem_size; /* Compute the number of elements to attempt in this span */ - H5_CHECKED_ASSIGN(span_size, size_t, curr_span->nelem, hsize_t); + nelmts = (curr_span->high - curr_span->low) + 1; + H5_CHECKED_ASSIGN(span_elmts, size_t, nelmts, hsize_t); /* Check number of elements against upper bounds allowed */ - if(span_size >= io_bytes_left) { - /* Trim the number of bytes to output */ - span_size = io_bytes_left; - io_bytes_left = 0; + if(span_elmts >= io_elmts_left) { + /* Trim the number of elements to output */ + span_elmts = io_elmts_left; + span_size = span_elmts * elem_size; + io_elmts_left = 0; /* COMMON */ /* Store the I/O information for the span */ @@ -1342,9 +1702,6 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Increment the number of sequences in arrays */ curr_seq++; } /* end else */ - - /* Set the location of the last span's end */ - last_span_end = loc_off + span_size; /* end COMMON */ /* Break out now, we are finished with I/O */ @@ -1352,7 +1709,8 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, } /* end if */ else { /* Decrement I/O left to perform */ - io_bytes_left -= span_size; + span_size = span_elmts * elem_size; + io_elmts_left -= span_elmts; /* COMMON */ /* Store the I/O information for the span */ @@ -1367,9 +1725,6 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Increment the number of sequences in arrays */ curr_seq++; } /* end else */ - - /* Set the location of the last span's end */ - last_span_end = loc_off + span_size; /* end COMMON */ /* If the sequence & offset arrays are full, do what? */ @@ -1378,18 +1733,30 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, break; } /* end else */ + /* Set the location of the last span's end */ + last_span_end = loc_off + span_size; + /* Move to next span in fastest changing dimension */ + prev_span = curr_span; curr_span = curr_span->next; } /* end while */ /* Check if we are done */ - if(io_bytes_left == 0 || curr_seq >= maxseq) { + if(io_elmts_left == 0 || curr_seq >= maxseq) { + /* Sanity checks */ HDassert(curr_span); - abs_arr[fast_dim] = curr_span->low + (span_size / elem_size); + + /* Update absolute position */ + abs_arr[fast_dim] = curr_span->low + span_elmts; /* Check if we are still within the span */ if(abs_arr[fast_dim] <= curr_span->high) { - iter->u.hyp.span[fast_dim]=curr_span; + /* Reset the span for the fast dimension */ + ispan[fast_dim] = curr_span; + + /* Update location offset */ + loc_arr[fast_dim] = ((hsize_t)((hssize_t)curr_span->low + (hssize_t)span_elmts + sel_off[fast_dim])) * slab[fast_dim]; + break; } /* end if */ /* If we walked off that span, advance to the next span */ @@ -1401,7 +1768,9 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, if(curr_span != NULL) { /* Reset absolute position */ abs_arr[fast_dim] = curr_span->low; - iter->u.hyp.span[fast_dim] = curr_span; + loc_arr[fast_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[fast_dim])) * slab[fast_dim]; + ispan[fast_dim] = curr_span; + break; } /* end if */ } /* end else */ @@ -1415,13 +1784,16 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Work back up through the dimensions */ while(curr_dim >= 0) { /* Reset the current span */ - curr_span=iter->u.hyp.span[curr_dim]; + curr_span = ispan[curr_dim]; /* Increment absolute position */ abs_arr[curr_dim]++; /* Check if we are still within the span */ - if(abs_arr[curr_dim]<=curr_span->high) { + if(abs_arr[curr_dim] <= curr_span->high) { + /* Update location offset */ + loc_arr[curr_dim] += slab[curr_dim]; + break; } /* end if */ /* If we walked off that span, advance to the next span */ @@ -1437,6 +1809,9 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Reset absolute position */ abs_arr[curr_dim] = curr_span->low; + /* Update location offset */ + loc_arr[curr_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[curr_dim])) * slab[curr_dim]; + break; } /* end if */ else @@ -1448,7 +1823,7 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, /* Check if we are finished with the spans in the tree */ if(curr_dim < 0) { /* We had better be done with I/O or bad things are going to happen... */ - HDassert(io_bytes_left == 0); + HDassert(io_elmts_left == 0); break; } /* end if */ else { @@ -1462,26 +1837,29 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, curr_dim++; /* Set the new span for the next dimension down */ - iter->u.hyp.span[curr_dim] = curr_span->down->head; + ispan[curr_dim] = curr_span->down->head; /* Advance span down the tree */ curr_span = curr_span->down->head; /* Reset the absolute offset for the dim */ abs_arr[curr_dim] = curr_span->low; + + /* Update location offset */ + loc_arr[curr_dim] = ((hsize_t)((hssize_t)curr_span->low + sel_off[curr_dim])) * slab[curr_dim]; } /* end while */ /* Verify that the curr_span points to the fastest dim */ - HDassert(curr_span == iter->u.hyp.span[fast_dim]); + HDassert(curr_span == ispan[fast_dim]); } /* end else */ /* Reset the buffer offset */ for(u = 0, loc_off = 0; u < ndims; u++) - loc_off += ((hsize_t)((hssize_t)abs_arr[u] + off_arr[u])) * slab[u]; + loc_off += loc_arr[u]; } /* end while */ /* Decrement number of elements left in iterator */ - io_used = (io_left - (io_bytes_left / elem_size)); + io_used = io_left - io_elmts_left; iter->elmt_left -= io_used; /* Set the number of sequences generated */ @@ -1491,17 +1869,16 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, *nelem = io_used; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__hyper_get_seq_list_gen() */ +} /* end H5S__hyper_iter_get_seq_list_gen() */ /*-------------------------------------------------------------------------- NAME - H5S__hyper_get_seq_list_opt + H5S__hyper_iter_get_seq_list_opt PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S_select_hyper_get_file_list_opt(space,iter,maxseq,maxelem,nseq,nelem,off,len) - H5S_t *space; IN: Dataspace containing selection to use. + herr_t H5S__hyper_iter_get_seq_list_opt(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. size_t maxseq; IN: Maximum number of sequences to generate @@ -1525,12 +1902,11 @@ H5S__hyper_get_seq_list_gen(const H5S_t *space, H5S_sel_iter_t *iter, REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, - size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__hyper_iter_get_seq_list_opt(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, + size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { hsize_t *mem_size; /* Size of the source buffer */ - hsize_t slab[H5S_MAX_RANK]; /* Hyperslab size */ + hsize_t *slab; /* Hyperslab size */ const hssize_t *sel_off; /* Selection offset in dataspace */ hsize_t offset[H5S_MAX_RANK]; /* Coordinate offset in dataspace */ hsize_t tmp_count[H5S_MAX_RANK]; /* Temporary block count */ @@ -1551,7 +1927,6 @@ H5S__hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ unsigned ndims; /* Number of dimensions of dataset */ int temp_dim; /* Temporary rank holder */ - hsize_t acc; /* Accumulator */ hsize_t loc; /* Coordinate offset */ size_t curr_seq = 0; /* Current sequence being operated on */ size_t actual_elem; /* The actual number of elements to count */ @@ -1560,12 +1935,10 @@ H5S__hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, size_t start_io_left; /* The initial number of elements left in I/O operation */ size_t elem_size; /* Size of each element iterating over */ unsigned u; /* Local index variable */ - int i; /* Local index variable */ FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -1578,35 +1951,31 @@ H5S__hyper_get_seq_list_opt(const H5S_t *space, H5S_sel_iter_t *iter, tdiminfo = iter->u.hyp.diminfo; /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < space->extent.rank) { + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < iter->rank) { /* Set the aliases for a few important dimension ranks */ ndims = iter->u.hyp.iter_rank; - fast_dim = ndims - 1; /* Set the local copy of the selection offset */ sel_off = iter->u.hyp.sel_off; - /* Set up the pointer to the size of the memory space */ + /* Set up the pointer to the size of the memory dataspace */ mem_size = iter->u.hyp.size; } /* end if */ else { /* Set the aliases for a few important dimension ranks */ - ndims = space->extent.rank; - fast_dim = ndims - 1; + ndims = iter->rank; /* Set the local copy of the selection offset */ - sel_off = space->select.offset; + sel_off = iter->sel_off; - /* Set up the pointer to the size of the memory space */ - mem_size = space->extent.size; + /* Set up the pointer to the size of the memory dataspace */ + mem_size = iter->dims; } /* end else */ - /* initialize row sizes for each dimension */ + /* Set up some local variables */ + fast_dim = ndims - 1; elem_size = iter->elmt_size; - for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { - slab[i] = acc; - acc *= mem_size[i]; - } /* end for */ + slab = iter->u.hyp.slab; /* Calculate the number of elements to sequence through */ H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t); @@ -1937,17 +2306,16 @@ loc += fast_dim_buf_off; *nelem += start_io_left - io_left; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__hyper_get_seq_list_opt() */ +} /* end H5S__hyper_iter_get_seq_list_opt() */ /*-------------------------------------------------------------------------- NAME - H5S__hyper_get_seq_list_single + H5S__hyper_iter_get_seq_list_single PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S__hyper_get_seq_list_single(space, flags, iter, maxseq, maxelem, nseq, nelem, off, len) - H5S_t *space; IN: Dataspace containing selection to use. + herr_t H5S__hyper_iter_get_seq_list_single(flags, iter, maxseq, maxelem, nseq, nelem, off, len) unsigned flags; IN: Flags for extra information about operation H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. @@ -1972,18 +2340,16 @@ loc += fast_dim_buf_off; REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, - size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__hyper_iter_get_seq_list_single(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, + size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ const hssize_t *sel_off; /* Selection offset in dataspace */ hsize_t *mem_size; /* Size of the source buffer */ hsize_t base_offset[H5S_MAX_RANK]; /* Base coordinate offset in dataspace */ hsize_t offset[H5S_MAX_RANK]; /* Coordinate offset in dataspace */ - hsize_t slab[H5S_MAX_RANK]; /* Hyperslab size */ + hsize_t *slab; /* Hyperslab size */ hsize_t fast_dim_block; /* Local copies of fastest changing dimension info */ - hsize_t acc; /* Accumulator */ hsize_t loc; /* Coordinate offset */ size_t tot_blk_count; /* Total number of blocks left to output */ size_t elem_size; /* Size of each element iterating over */ @@ -1993,12 +2359,10 @@ H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ unsigned skip_dim; /* Rank of the dimension to skip along */ unsigned u; /* Local index variable */ - int i; /* Local index variable */ FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -2011,34 +2375,31 @@ H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, tdiminfo = iter->u.hyp.diminfo; /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < space->extent.rank) { + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < iter->rank) { /* Set the aliases for a few important dimension ranks */ ndims = iter->u.hyp.iter_rank; /* Set the local copy of the selection offset */ sel_off = iter->u.hyp.sel_off; - /* Set up the pointer to the size of the memory space */ + /* Set up the pointer to the size of the memory dataspace */ mem_size = iter->u.hyp.size; } /* end if */ else { /* Set the aliases for a few important dimension ranks */ - ndims = space->extent.rank; + ndims = iter->rank; /* Set the local copy of the selection offset */ - sel_off = space->select.offset; + sel_off = iter->sel_off; - /* Set up the pointer to the size of the memory space */ - mem_size = space->extent.size; + /* Set up the pointer to the size of the memory dataspace */ + mem_size = iter->dims; } /* end else */ - fast_dim = ndims - 1; - /* initialize row sizes for each dimension */ + /* Set up some local variables */ + fast_dim = ndims - 1; elem_size = iter->elmt_size; - for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { - slab[i] = acc; - acc *= mem_size[i]; - } /* end for */ + slab = iter->u.hyp.slab; /* Copy the base location of the block */ /* (Add in the selection offset) */ @@ -2091,6 +2452,7 @@ H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, else { hsize_t skip_slab; /* Temporary copy of slab[fast_dim - 1] */ size_t blk_count; /* Total number of blocks left to output */ + int i; /* Local index variable */ /* Find first dimension w/block >1 */ skip_dim = fast_dim; @@ -2222,16 +2584,16 @@ H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, HDassert(*nelem > 0); FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__hyper_get_seq_list_single() */ +} /* end H5S__hyper_iter_get_seq_list_single() */ /*-------------------------------------------------------------------------- NAME - H5S__hyper_get_seq_list + H5S__hyper_iter_get_seq_list PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S__hyper_get_seq_list(space,flags,iter,maxseq,maxelem,nseq,nelem,off,len) + herr_t H5S__hyper_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_t *space; IN: Dataspace containing selection to use. unsigned flags; IN: Flags for extra information about operation H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last @@ -2257,16 +2619,14 @@ H5S__hyper_get_seq_list_single(const H5S_t *space, H5S_sel_iter_t *iter, REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_get_seq_list(const H5S_t *space, unsigned H5_ATTR_UNUSED flags, H5S_sel_iter_t *iter, - size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__hyper_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxelem, size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { herr_t ret_value = FAIL; /* return value */ FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(iter->elmt_left > 0); HDassert(maxseq > 0); @@ -2275,13 +2635,11 @@ H5S__hyper_get_seq_list(const H5S_t *space, unsigned H5_ATTR_UNUSED flags, H5S_s HDassert(nelem); HDassert(off); HDassert(len); - HDassert(space->select.sel_info.hslab->unlim_dim < 0); /* Check for the special case of just one H5Sselect_hyperslab call made */ - if(space->select.sel_info.hslab->diminfo_valid) { + if(iter->u.hyp.diminfo_valid) { const H5S_hyper_dim_t *tdiminfo; /* Temporary pointer to diminfo information */ const hssize_t *sel_off; /* Selection offset in dataspace */ - hsize_t *mem_size; /* Size of the source buffer */ unsigned ndims; /* Number of dimensions of dataset */ unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ hbool_t single_block; /* Whether the selection is a single block */ @@ -2291,39 +2649,30 @@ H5S__hyper_get_seq_list(const H5S_t *space, unsigned H5_ATTR_UNUSED flags, H5S_s tdiminfo = iter->u.hyp.diminfo; /* Check if this is a "flattened" regular hyperslab selection */ - if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < space->extent.rank) { + if(iter->u.hyp.iter_rank != 0 && iter->u.hyp.iter_rank < iter->rank) { /* Set the aliases for a few important dimension ranks */ ndims = iter->u.hyp.iter_rank; /* Set the local copy of the selection offset */ sel_off = iter->u.hyp.sel_off; - - /* Set up the pointer to the size of the memory space */ - mem_size = iter->u.hyp.size; } /* end if */ else { /* Set the aliases for a few important dimension ranks */ - ndims = space->extent.rank; + ndims = iter->rank; /* Set the local copy of the selection offset */ - sel_off = space->select.offset; - - /* Set up the pointer to the size of the memory space */ - mem_size = space->extent.size; + sel_off = iter->sel_off; } /* end else */ fast_dim = ndims - 1; /* Check if we stopped in the middle of a sequence of elements */ if((iter->u.hyp.off[fast_dim] - tdiminfo[fast_dim].start) % tdiminfo[fast_dim].stride != 0 || ((iter->u.hyp.off[fast_dim] != tdiminfo[fast_dim].start) && tdiminfo[fast_dim].count == 1)) { - hsize_t slab[H5S_MAX_RANK]; /* Hyperslab size */ + hsize_t *slab; /* Hyperslab size */ hsize_t loc; /* Coordinate offset */ - hsize_t acc; /* Accumulator */ size_t leftover; /* The number of elements left over from the last sequence */ size_t actual_elem; /* The actual number of elements to count */ size_t elem_size; /* Size of each element iterating over */ - int i; /* Local index variable */ - /* Calculate the number of elements left in the sequence */ if(tdiminfo[fast_dim].count == 1) { @@ -2336,12 +2685,9 @@ H5S__hyper_get_seq_list(const H5S_t *space, unsigned H5_ATTR_UNUSED flags, H5S_s /* Make certain that we don't write too many */ actual_elem = MIN3(leftover, (size_t)iter->elmt_left, maxelem); - /* Initialize row sizes for each dimension */ + /* Set up some local variables */ elem_size = iter->elmt_size; - for(i = (int)fast_dim, acc = elem_size; i >= 0; i--) { - slab[i] = acc; - acc *= mem_size[i]; - } /* end for */ + slab = iter->u.hyp.slab; /* Compute the initial buffer offset */ for(u = 0, loc = 0; u < ndims; u++) @@ -2390,17 +2736,17 @@ H5S__hyper_get_seq_list(const H5S_t *space, unsigned H5_ATTR_UNUSED flags, H5S_s /* Check for single block selection */ if(single_block) /* Use single-block optimized call to generate sequence list */ - ret_value = H5S__hyper_get_seq_list_single(space, iter, maxseq, maxelem, nseq, nelem, off, len); + ret_value = H5S__hyper_iter_get_seq_list_single(iter, maxseq, maxelem, nseq, nelem, off, len); else /* Use optimized call to generate sequence list */ - ret_value = H5S__hyper_get_seq_list_opt(space, iter, maxseq, maxelem, nseq, nelem, off, len); + ret_value = H5S__hyper_iter_get_seq_list_opt(iter, maxseq, maxelem, nseq, nelem, off, len); } /* end if */ else /* Call the general sequence generator routine */ - ret_value = H5S__hyper_get_seq_list_gen(space, iter, maxseq, maxelem, nseq, nelem, off, len); + ret_value = H5S__hyper_iter_get_seq_list_gen(iter, maxseq, maxelem, nseq, nelem, off, len); FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__hyper_get_seq_list() */ +} /* end H5S__hyper_iter_get_seq_list() */ /*-------------------------------------------------------------------------- @@ -2472,8 +2818,6 @@ H5S__hyper_new_span(hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, /* Copy the span's basic information */ ret_value->low = low; ret_value->high = high; - ret_value->nelem = (high - low) + 1; - ret_value->pstride = 0; ret_value->down = down; ret_value->next = next; @@ -2488,143 +2832,45 @@ done: /*-------------------------------------------------------------------------- NAME - H5S__hyper_span_precompute_helper + H5S__hyper_new_span_info PURPOSE - Helper routine to precompute the nelem and pstrides in bytes. + Make a new hyperslab span info node USAGE - void H5S__hyper_span_precompute_helper(span_info, elmt_size) - H5S_hyper_span_info_t *span_info; IN/OUT: Span tree to work on - size_t elmt_size; IN: element size to work with + H5S_hyper_span_info_t *H5S__hyper_new_span_info(rank) + unsigned rank; IN: Rank of span info, in selection RETURNS - None + Pointer to new span node info on success, NULL on failure DESCRIPTION - Change the nelem and pstride values in the span tree from elements to - bytes using the elmt_size parameter. + Allocate and initialize a new hyperslab span info node of a given rank, + setting up the low & high bound array pointers. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS + Note that this uses the C99 "flexible array member" feature. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static void -H5S__hyper_span_precompute_helper(H5S_hyper_span_info_t *spans, size_t elmt_size) +static H5S_hyper_span_info_t * +H5S__hyper_new_span_info(unsigned rank) { - FUNC_ENTER_STATIC_NOERR + H5S_hyper_span_info_t *ret_value = NULL; /* Return value */ - /* Sanity checks */ - HDassert(spans); - HDassert(spans->scratch == (H5S_hyper_span_info_t *)~((size_t)NULL) || - spans->scratch == NULL); + FUNC_ENTER_STATIC - /* Check if we've already set this down span tree */ - if(spans->scratch != (H5S_hyper_span_info_t *)~((size_t)NULL)) { - H5S_hyper_span_t *span; /* Hyperslab span */ + /* Sanity check */ + HDassert(rank > 0); + HDassert(rank <= H5S_MAX_RANK); - /* Set the tree's scratch pointer */ - spans->scratch = (H5S_hyper_span_info_t *)~((size_t)NULL); + /* Allocate a new span info node */ + if(NULL == (ret_value = (H5S_hyper_span_info_t *)H5FL_ARR_CALLOC(hbounds_t, rank * 2))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span info") - /* Set the scratch pointers in all the nodes */ - span = spans->head; + /* Set low & high bound pointers into the 'bounds' array */ + ret_value->low_bounds = ret_value->bounds; + ret_value->high_bounds = &ret_value->bounds[rank]; - /* Loop over all the spans for this down span tree */ - while(span != NULL) { - /* If there are down spans, precompute their values also */ - if(span->down != NULL) - H5S__hyper_span_precompute_helper(span->down, elmt_size); - - /* Change the nelem & pstride values into bytes */ - span->nelem *= elmt_size; - span->pstride *= elmt_size; - - /* Advance to next span */ - span = span->next; - } /* end while */ - } /* end if */ - - FUNC_LEAVE_NOAPI_VOID -} /* end H5S__hyper_span_precompute_helper() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S__hyper_span_precompute - PURPOSE - Precompute the nelem and pstrides in bytes. - USAGE - herr_t H5S__hyper_span_precompute(span_info, elmt_size) - H5S_hyper_span_info_t *span_info; IN/OUT: Span tree to work on - size_t elmt_size; IN: element size to work with - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Change the nelem and pstride values in the span tree from elements to - bytes using the elmt_size parameter. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5S__hyper_span_precompute(H5S_hyper_span_info_t *spans, size_t elmt_size) -{ - FUNC_ENTER_STATIC_NOERR - - HDassert(spans); - - /* Call the helper routine to actually do the work */ - H5S__hyper_span_precompute_helper(spans, elmt_size); - - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(spans); - - FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__hyper_span_precompute() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S__hyper_span_scratch - PURPOSE - Reset the scratch pointers on hyperslab span trees - USAGE - void H5S__hyper_span_scratch(span_info) - H5S_hyper_span_info_t *span_info; IN: Span tree to reset - RETURNS - - DESCRIPTION - Reset the scratch pointers on a hyperslab span tree to NULL. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static void -H5S__hyper_span_scratch(H5S_hyper_span_info_t *spans) -{ - FUNC_ENTER_STATIC_NOERR - - HDassert(spans); - - /* Check if we've already set this down span tree */ - if(spans->scratch != NULL) { - H5S_hyper_span_t *span; /* Hyperslab span */ - - /* Reset the tree's scratch pointer */ - spans->scratch = NULL; - - /* Set the scratch pointers in all the nodes */ - span = spans->head; - while(span != NULL) { - /* If there are down spans, set their scratch value also */ - if(span->down != NULL) - H5S__hyper_span_scratch(span->down); - - /* Advance to next span */ - span = span->next; - } /* end while */ - } /* end if */ - - FUNC_LEAVE_NOAPI_VOID -} /* end H5S__hyper_span_scratch() */ +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_new_span_info() */ /*-------------------------------------------------------------------------- @@ -2633,8 +2879,10 @@ H5S__hyper_span_scratch(H5S_hyper_span_info_t *spans) PURPOSE Helper routine to copy a hyperslab span tree USAGE - H5S_hyper_span_info_t * H5S__hyper_copy_span_helper(spans) - H5S_hyper_span_info_t *spans; IN: Span tree to copy + H5S_hyper_span_info_t * H5S__hyper_copy_span_helper(spans, rank) + H5S_hyper_span_info_t *spans; IN: Span tree to copy + unsigned rank; IN: Rank of span tree + uint64_t op_gen; IN: Operation generation RETURNS Pointer to the copied span tree on success, NULL on failure DESCRIPTION @@ -2645,7 +2893,8 @@ H5S__hyper_span_scratch(H5S_hyper_span_info_t *spans) REVISION LOG --------------------------------------------------------------------------*/ static H5S_hyper_span_info_t * -H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans) +H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans, unsigned rank, + uint64_t op_gen) { H5S_hyper_span_t *span; /* Hyperslab span */ H5S_hyper_span_t *new_span; /* Temporary hyperslab span */ @@ -2657,26 +2906,30 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans) /* Sanity checks */ HDassert(spans); - HDassert(spans->scratch != (H5S_hyper_span_info_t *)~((size_t)NULL)); /* Check if the span tree was already copied */ - if(spans->scratch != NULL) { + if(spans->op_gen == op_gen) { /* Just return the value of the already copied span tree */ - ret_value = spans->scratch; + ret_value = spans->u.copied; /* Increment the reference count of the span tree */ ret_value->count++; } /* end if */ else { /* Allocate a new span_info node */ - if(NULL == (ret_value = H5FL_CALLOC(H5S_hyper_span_info_t))) + if(NULL == (ret_value = H5S__hyper_new_span_info(rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span info") - /* Copy the span_info information */ + /* Set the non-zero span_info information */ + HDmemcpy(ret_value->low_bounds, spans->low_bounds, rank * sizeof(hsize_t)); + HDmemcpy(ret_value->high_bounds, spans->high_bounds, rank * sizeof(hsize_t)); ret_value->count = 1; - /* Set the scratch pointer in the node being copied to the newly allocated node */ - spans->scratch = ret_value; + /* Set the operation generation for the span info, to avoid future copies */ + spans->op_gen = op_gen; + + /* Set the 'copied' pointer in the node being copied to the newly allocated node */ + spans->u.copied = ret_value; /* Copy over the nodes in the span list */ span = spans->head; @@ -2692,12 +2945,9 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans) else prev_span->next = new_span; - /* Copy the pstride */ - new_span->pstride = span->pstride; - /* Recurse to copy the 'down' spans, if there are any */ if(span->down != NULL) { - if(NULL == (new_down = H5S__hyper_copy_span_helper(span->down))) + if(NULL == (new_down = H5S__hyper_copy_span_helper(span->down, rank - 1, op_gen))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab spans") new_span->down = new_down; } /* end if */ @@ -2708,6 +2958,9 @@ H5S__hyper_copy_span_helper(H5S_hyper_span_info_t *spans) /* Advance to next span */ span = span->next; } /* end while */ + + /* Retain a pointer to the last span */ + ret_value->tail = prev_span; } /* end else */ done: @@ -2721,10 +2974,11 @@ done: PURPOSE Copy a hyperslab span tree USAGE - H5S_hyper_span_info_t * H5S__hyper_copy_span(span_info) - H5S_hyper_span_info_t *span_info; IN: Span tree to copy + H5S_hyper_span_info_t * H5S__hyper_copy_span(span_info, rank) + H5S_hyper_span_info_t *span_info; IN: Span tree to copy + unsigned rank; IN: Rank of span tree RETURNS - Non-negative on success, negative on failure + Pointer to the copied span tree on success, NULL on failure DESCRIPTION Copy a hyperslab span tree, using reference counting as appropriate. (Which means that just the nodes in the top span tree are duplicated and @@ -2735,8 +2989,9 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static H5S_hyper_span_info_t * -H5S__hyper_copy_span(H5S_hyper_span_info_t *spans) +H5S__hyper_copy_span(H5S_hyper_span_info_t *spans, unsigned rank) { + uint64_t op_gen; /* Operation generation value */ H5S_hyper_span_info_t *ret_value = NULL; /* Return value */ FUNC_ENTER_STATIC @@ -2744,12 +2999,12 @@ H5S__hyper_copy_span(H5S_hyper_span_info_t *spans) /* Sanity check */ HDassert(spans); - /* Copy the hyperslab span tree */ - if(NULL == (ret_value = H5S__hyper_copy_span_helper(spans))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab span tree") + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(spans); + /* Copy the hyperslab span tree */ + if(NULL == (ret_value = H5S__hyper_copy_span_helper(spans, rank, op_gen))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "can't copy hyperslab span tree") done: FUNC_LEAVE_NOAPI(ret_value) @@ -2779,72 +3034,75 @@ static H5_ATTR_PURE hbool_t H5S__hyper_cmp_spans(const H5S_hyper_span_info_t *span_info1, const H5S_hyper_span_info_t *span_info2) { - hbool_t ret_value = FALSE; /* Return value */ + hbool_t ret_value = TRUE; /* Return value */ FUNC_ENTER_STATIC_NOERR /* Check for redundant comparison (or both spans being NULL) */ - if(span_info1 == span_info2) - ret_value = TRUE; - else { + if(span_info1 != span_info2) { /* Check for one span being NULL */ if(span_info1 == NULL || span_info2 == NULL) - ret_value = FALSE; + HGOTO_DONE(FALSE) else { - const H5S_hyper_span_t *span1; - const H5S_hyper_span_t *span2; + /* Compare low & high bounds for this span list */ + /* (Could compare lower dimensions also, but not certain if + * that's worth it. - QAK, 2019/01/23) + */ + if(span_info1->low_bounds[0] != span_info2->low_bounds[0]) + HGOTO_DONE(FALSE) + else if(span_info1->high_bounds[0] != span_info2->high_bounds[0]) + HGOTO_DONE(FALSE) + else { + const H5S_hyper_span_t *span1; + const H5S_hyper_span_t *span2; - /* Get the pointers to the actual lists of spans */ - span1 = span_info1->head; - span2 = span_info2->head; + /* Get the pointers to the actual lists of spans */ + span1 = span_info1->head; + span2 = span_info2->head; - /* Sanity checking */ - HDassert(span1); - HDassert(span2); + /* Sanity checking */ + HDassert(span1); + HDassert(span2); - /* infinite loop which must be broken out of */ - while(1) { - /* Check for both spans being NULL */ - if(span1 == NULL && span2 == NULL) { - ret_value = TRUE; - break; - } /* end if */ - else { - /* Check for one span being NULL */ - if(span1 == NULL || span2 == NULL) { - ret_value = FALSE; - break; - } /* end if */ + /* infinite loop which must be broken out of */ + while(1) { + /* Check for both spans being NULL */ + if(span1 == NULL && span2 == NULL) + HGOTO_DONE(TRUE) else { - /* Check if the actual low & high span information is the same */ - if(span1->low != span2->low || span1->high != span2->high) { - ret_value = FALSE; - break; - } /* end if */ + /* Check for one span being NULL */ + if(span1 == NULL || span2 == NULL) + HGOTO_DONE(FALSE) else { - if(span1->down != NULL || span2 != NULL) { - if(!H5S__hyper_cmp_spans(span1->down, span2->down)) { - ret_value = FALSE; - break; + /* Check if the actual low & high span information is the same */ + if(span1->low != span2->low || span1->high != span2->high) + HGOTO_DONE(FALSE) + else { + if(span1->down != NULL || span2->down != NULL) { + if(!H5S__hyper_cmp_spans(span1->down, span2->down)) + HGOTO_DONE(FALSE) + else { + /* Keep going... */ + } /* end else */ } /* end if */ else { /* Keep going... */ } /* end else */ - } /* end if */ - else { - /* Keep going... */ } /* end else */ } /* end else */ } /* end else */ - } /* end else */ - /* Advance to the next nodes in the span list */ - span1 = span1->next; - span2 = span2->next; - } /* end while */ + /* Advance to the next nodes in the span list */ + span1 = span1->next; + span2 = span2->next; + } /* end while */ + } /* end else */ } /* end else */ - } /* end else */ + } /* end if */ + /* Fall through, with default return value of 'TRUE' if spans were already visited */ + +done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_cmp_spans() */ @@ -2855,10 +3113,10 @@ H5S__hyper_cmp_spans(const H5S_hyper_span_info_t *span_info1, PURPOSE Free a hyperslab span info node USAGE - herr_t H5S__hyper_free_span_info(span_info) + void H5S__hyper_free_span_info(span_info) H5S_hyper_span_info_t *span_info; IN: Span info node to free RETURNS - Non-negative on success, negative on failure + None DESCRIPTION Free a hyperslab span info node, along with all the span nodes and the 'down spans' from the nodes, if reducing their reference count to zero @@ -2868,14 +3126,12 @@ H5S__hyper_cmp_spans(const H5S_hyper_span_info_t *span_info1, EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static herr_t +static void H5S__hyper_free_span_info(H5S_hyper_span_info_t *span_info) { - H5S_hyper_span_t *span, *next_span; - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_STATIC + FUNC_ENTER_STATIC_NOERR + /* Sanity check */ HDassert(span_info); /* Decrement the span tree's reference count */ @@ -2883,22 +3139,28 @@ H5S__hyper_free_span_info(H5S_hyper_span_info_t *span_info) /* Free the span tree if the reference count drops to zero */ if(span_info->count == 0) { + H5S_hyper_span_t *span; /* Pointer to spans to iterate over */ /* Work through the list of spans pointed to by this 'info' node */ span = span_info->head; while(span != NULL) { + H5S_hyper_span_t *next_span; /* Pointer to next span to iterate over */ + + /* Keep a pointer to the next span */ next_span = span->next; - if(H5S__hyper_free_span(span) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab span") + + /* Free the current span */ + H5S__hyper_free_span(span); + + /* Advance to next span */ span = next_span; } /* end while */ /* Free this span info */ - span_info = H5FL_FREE(H5S_hyper_span_info_t, span_info); + span_info = (H5S_hyper_span_info_t *)H5FL_ARR_FREE(hbounds_t, span_info); } /* end if */ -done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_VOID } /* end H5S__hyper_free_span_info() */ @@ -2908,10 +3170,10 @@ done: PURPOSE Free a hyperslab span node USAGE - herr_t H5S__hyper_free_span(span) + void H5S__hyper_free_span(span) H5S_hyper_span_t *span; IN: Span node to free RETURNS - Non-negative on success, negative on failure + None DESCRIPTION Free a hyperslab span node, along with the 'down spans' from the node, if reducing their reference count to zero indicates it is appropriate to @@ -2921,25 +3183,22 @@ done: EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static herr_t +static void H5S__hyper_free_span(H5S_hyper_span_t *span) { - herr_t ret_value = SUCCEED; - - FUNC_ENTER_STATIC + FUNC_ENTER_STATIC_NOERR + /* Sanity check */ HDassert(span); /* Decrement the reference count of the 'down spans', freeing them if appropriate */ if(span->down != NULL) - if(H5S__hyper_free_span_info(span->down) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab span tree") + H5S__hyper_free_span_info(span->down); /* Free this span */ span = H5FL_FREE(H5S_hyper_span_t, span); -done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_VOID } /* end H5S__hyper_free_span() */ @@ -2954,7 +3213,7 @@ done: H5S_t *src; IN: Pointer to the source dataspace hbool_t; IN: Whether to share the selection between the dataspaces RETURNS - Non-negative on success/Negative on failure + Non-negative on success, negative on failure DESCRIPTION Copies all the hyperslab selection information from the source dataspace to the destination dataspace. @@ -2991,15 +3250,8 @@ H5S__hyper_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection) /* Copy the hyperslab information */ dst_hslab->diminfo_valid = src_hslab->diminfo_valid; - if(src_hslab->diminfo_valid) { - size_t u; /* Local index variable */ - - for(u=0; uextent.rank; u++) { - dst_hslab->opt_diminfo[u]=src_hslab->opt_diminfo[u]; - dst_hslab->app_diminfo[u]=src_hslab->app_diminfo[u]; - } /* end for */ - } /* end if */ - dst->select.sel_info.hslab->span_lst=src->select.sel_info.hslab->span_lst; + if(src_hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) + HDmemcpy(&dst_hslab->diminfo, &src_hslab->diminfo, sizeof(H5S_hyper_diminfo_t)); /* Check if there is hyperslab span information to copy */ /* (Regular hyperslab information is copied with the selection structure) */ @@ -3011,7 +3263,7 @@ H5S__hyper_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection) } /* 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); + dst->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(src->select.sel_info.hslab->span_lst, src->extent.rank); } /* end if */ else dst->select.sel_info.hslab->span_lst = NULL; @@ -3024,66 +3276,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_copy() */ - -/*-------------------------------------------------------------------------- - NAME - H5S__hyper_is_valid_helper - PURPOSE - Check whether the selection fits within the extent, with the current - offset defined. - USAGE - hbool_t H5S__hyper_is_valid_helper(spans, offset, rank); - const H5S_hyper_span_info_t *spans; IN: Pointer to current hyperslab span tree - const hssize_t *offset; IN: Pointer to offset array - const hsize_t *size; IN: Pointer to size array - hsize_t rank; IN: Current rank looking at - RETURNS - TRUE if the selection fits within the extent, FALSE if it does not - DESCRIPTION - Determines if the current selection at the current offset fits within the - extent for the dataspace. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static hbool_t -H5S__hyper_is_valid_helper(const H5S_hyper_span_info_t *spans, const hssize_t *offset, - const hsize_t *size) -{ - H5S_hyper_span_t *curr; /* Hyperslab information nodes */ - hbool_t ret_value = TRUE; /* Return value */ - - FUNC_ENTER_STATIC_NOERR - - HDassert(spans); - HDassert(offset); - HDassert(size); - - /* Check each point to determine whether selection + offset is within extent */ - curr = spans->head; - while(curr != NULL) { - /* Check if an offset has been defined */ - /* Bounds check the selected point + offset against the extent */ - if((((hssize_t)curr->low + *offset) >= (hssize_t)*size) - || (((hssize_t)curr->low + *offset) < 0) - || (((hssize_t)curr->high + *offset) >= (hssize_t)*size) - || (((hssize_t)curr->high + *offset) < 0)) - HGOTO_DONE(FALSE) - - /* Recurse if this node has down spans */ - if(curr->down != NULL) - if(!H5S__hyper_is_valid_helper(curr->down, offset + 1, size + 1)) - HGOTO_DONE(FALSE) - - /* Advance to next node */ - curr = curr->next; - } /* end while */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__hyper_is_valid_helper() */ - /*-------------------------------------------------------------------------- NAME @@ -3108,6 +3300,8 @@ done: static htri_t H5S__hyper_is_valid(const H5S_t *space) { + const hsize_t *low_bounds, *high_bounds; /* Pointers to the correct pair of low & high bounds */ + unsigned u; /* Counter */ htri_t ret_value = TRUE; /* return value */ FUNC_ENTER_STATIC_NOERR @@ -3118,34 +3312,24 @@ H5S__hyper_is_valid(const H5S_t *space) if(space->select.sel_info.hslab->unlim_dim >= 0) HGOTO_DONE(FALSE) - /* Check for a "regular" hyperslab selection */ - 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 */ - unsigned u; /* Counter */ - - /* Check each dimension */ - for(u = 0; u < space->extent.rank; u++) { - /* if block or count is zero, then can skip the test since */ - /* no data point is chosen */ - if(diminfo[u].count && diminfo[u].block) { - /* Bounds check the start point in this dimension */ - if(((hssize_t)diminfo[u].start + space->select.offset[u]) < 0 || - ((hssize_t)diminfo[u].start + space->select.offset[u]) >= (hssize_t)space->extent.size[u]) - HGOTO_DONE(FALSE) - - /* Compute the largest location in this dimension */ - end = (hssize_t)(diminfo[u].start + diminfo[u].stride * (diminfo[u].count - 1) + (diminfo[u].block - 1)) + space->select.offset[u]; - - /* Bounds check the end point in this dimension */ - if(end < 0 || end >= (hssize_t)space->extent.size[u]) - HGOTO_DONE(FALSE) - } /* end if */ - } /* end for */ + /* Check which set of low & high bounds we should be using */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + low_bounds = space->select.sel_info.hslab->diminfo.low_bounds; + high_bounds = space->select.sel_info.hslab->diminfo.high_bounds; } /* end if */ - else - /* Call the recursive routine to validate the span tree */ - ret_value = H5S__hyper_is_valid_helper(space->select.sel_info.hslab->span_lst, space->select.offset, space->extent.size); + else { + low_bounds = space->select.sel_info.hslab->span_lst->low_bounds; + high_bounds = space->select.sel_info.hslab->span_lst->high_bounds; + } /* end else */ + + /* Check each dimension */ + for(u = 0; u < space->extent.rank; u++) { + /* Bounds check the selected point + offset against the extent */ + if(((hssize_t)low_bounds[u] + space->select.offset[u]) < 0) + HGOTO_DONE(FALSE) + if((high_bounds[u] + (hsize_t)space->select.offset[u]) >= space->extent.size[u]) + HGOTO_DONE(FALSE) + } /* end for */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -3154,12 +3338,13 @@ done: /*-------------------------------------------------------------------------- NAME - H5S__hyper_span_nblocks + H5S__hyper_span_nblocks_helper PURPOSE - Count the number of blocks in a span tree + Helper routine to count the number of blocks in a span tree USAGE - hsize_t H5S__hyper_span_nblocks(spans) - const H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to count elements of + hsize_t H5S__hyper_span_nblocks_helper(spans) + H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to count blocks of + uint64_t op_gen; IN: Operation generation RETURNS Number of blocks in span tree on success; negative on failure DESCRIPTION @@ -3170,7 +3355,72 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static hsize_t -H5S__hyper_span_nblocks(const H5S_hyper_span_info_t *spans) +H5S__hyper_span_nblocks_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) +{ + hsize_t ret_value = 0; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity check */ + HDassert(spans); + + /* Check if the span tree was already counted */ + if(spans->op_gen == op_gen) + /* Just return the # of blocks in the already counted span tree */ + ret_value = spans->u.nblocks; + else { /* Count the number of elements in the span tree */ + H5S_hyper_span_t *span; /* Hyperslab span */ + + span = spans->head; + if(span->down) { + while(span) { + /* If there are down spans, add the total down span blocks */ + ret_value += H5S__hyper_span_nblocks_helper(span->down, op_gen); + + /* Advance to next span */ + span = span->next; + } /* end while */ + } /* end if */ + else { + while(span) { + /* If there are no down spans, just count the block in this span */ + ret_value++; + + /* Advance to next span */ + span = span->next; + } /* end while */ + } /* end else */ + + /* Set the operation generation for this span tree, to avoid re-computing */ + spans->op_gen = op_gen; + + /* Hold a copy of the # of blocks */ + spans->u.nblocks = ret_value; + } /* end else */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_span_nblocks_helper() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_span_nblocks + PURPOSE + Count the number of blocks in a span tree + USAGE + hsize_t H5S__hyper_span_nblocks(spans) + H5S_hyper_span_info_t *spans; IN: Hyperslab span tree to count blocks of + RETURNS + Number of blocks in span tree on success; negative on failure + DESCRIPTION + Counts the number of blocks described by the spans in a span tree. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static hsize_t +H5S__hyper_span_nblocks(H5S_hyper_span_info_t *spans) { hsize_t ret_value = 0; /* Return value */ @@ -3178,21 +3428,13 @@ H5S__hyper_span_nblocks(const H5S_hyper_span_info_t *spans) /* Count the number of elements in the span tree */ if(spans != NULL) { - H5S_hyper_span_t *span; /* Hyperslab span */ + uint64_t op_gen; /* Operation generation value */ - span = spans->head; - while(span != NULL) { - /* If there are down spans, add the total down span blocks */ - if(span->down != NULL) - ret_value += H5S__hyper_span_nblocks(span->down); - /* If there are no down spans, just count the block in this span */ - else - ret_value++; + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); - /* Advance to next span */ - span = span->next; - } /* end while */ - } /* end else */ + ret_value = H5S__hyper_span_nblocks_helper(spans, op_gen); + } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_span_nblocks() */ @@ -3226,12 +3468,13 @@ H5S__get_select_hyper_nblocks(const H5S_t *space) HDassert(space->select.sel_info.hslab->unlim_dim < 0); /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { unsigned u; /* Local index variable */ /* Check each dimension */ for(ret_value = 1, u = 0; u < space->extent.rank; u++) - ret_value *= space->select.sel_info.hslab->app_diminfo[u].count; + ret_value *= space->select.sel_info.hslab->diminfo.app[u].count; } /* end if */ else ret_value = H5S__hyper_span_nblocks(space->select.sel_info.hslab->span_lst); @@ -3333,10 +3576,13 @@ H5S__hyper_serial_size(const H5S_t *space) ret_value = 24; /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { + /* (It would be useful to rebuild the regular hyperslab selection, if we + * encoded it efficiently, which we aren't currently. *sigh* -QAK) + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { /* Check each dimension */ for(block_count = 1, u = 0; u < space->extent.rank; u++) - block_count *= space->select.sel_info.hslab->opt_diminfo[u].count; + block_count *= space->select.sel_info.hslab->diminfo.opt[u].count; } /* end if */ else /* Spin through hyperslab spans, adding 8 * rank bytes for each block */ @@ -3494,22 +3740,25 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) /* If there is an unlimited dimension, only encode opt_unlim_diminfo */ if(flags & H5S_SELECT_FLAG_UNLIM) { - unsigned i; + unsigned u; HDassert(H5S_UNLIMITED == HSIZE_UNDEF); /* Iterate over dimensions */ - for(i = 0; i < space->extent.rank; i++) { + for(u = 0; u < space->extent.rank; u++) { /* Encode start/stride/block/count */ - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].start); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].stride); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].count); - UINT64ENCODE(pp, space->select.sel_info.hslab->opt_diminfo[i].block); + UINT64ENCODE(pp, space->select.sel_info.hslab->diminfo.opt[u].start); + UINT64ENCODE(pp, space->select.sel_info.hslab->diminfo.opt[u].stride); + UINT64ENCODE(pp, space->select.sel_info.hslab->diminfo.opt[u].count); + UINT64ENCODE(pp, space->select.sel_info.hslab->diminfo.opt[u].block); } /* end for */ } /* end if */ /* Check for a "regular" hyperslab selection */ - else if(space->select.sel_info.hslab->diminfo_valid) { - const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ + /* (It would be useful to rebuild the regular hyperslab selection, if we + * encoded it efficiently, which we aren't currently. *sigh* -QAK) + */ + else if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ hsize_t offset[H5S_MAX_RANK]; /* Offset of element in dataspace */ hsize_t tmp_count[H5S_MAX_RANK]; /* Temporary hyperslab counts */ unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ @@ -3520,7 +3769,7 @@ H5S__hyper_serialize(const H5S_t *space, uint8_t **p) /* Set some convenience values */ ndims = space->extent.rank; fast_dim = ndims - 1; - diminfo = space->select.sel_info.hslab->opt_diminfo; + diminfo = space->select.sel_info.hslab->diminfo.opt; /* Check each dimension */ for(block_count = 1, u = 0; u < ndims; u++) @@ -3780,7 +4029,6 @@ H5S__hyper_span_blocklist(const H5S_hyper_span_info_t *spans, hsize_t start[], hsize_t **buf) { const H5S_hyper_span_t *curr; /* Pointer to current hyperslab span */ - hsize_t u; /* Index variable */ herr_t ret_value = SUCCEED; /* return value */ FUNC_ENTER_STATIC @@ -3818,19 +4066,19 @@ H5S__hyper_span_blocklist(const H5S_hyper_span_info_t *spans, hsize_t start[], /* Encode all the previous dimensions starting & ending points */ /* Copy previous starting points */ - for(u = 0; u < rank; u++, (*buf)++) - HDmemcpy(*buf, &start[u], sizeof(hsize_t)); + HDmemcpy(*buf, start, rank * sizeof(hsize_t)); + (*buf) += rank; /* Copy starting point for this span */ - HDmemcpy(*buf, &curr->low, sizeof(hsize_t)); + **buf = curr->low; (*buf)++; /* Copy previous ending points */ - for(u = 0; u < rank; u++, (*buf)++) - HDmemcpy(*buf, &end[u], sizeof(hsize_t)); + HDmemcpy(*buf, end, rank * sizeof(hsize_t)); + (*buf) += rank; - /* Copy starting point for this span */ - HDmemcpy(*buf, &curr->high, sizeof(hsize_t)); + /* Copy ending point for this span */ + **buf = curr->high; (*buf)++; /* Decrement the number of blocks processed */ @@ -3878,7 +4126,8 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblock, hsize_t numblocks, hsize_t *buf) +H5S__get_select_hyper_blocklist(H5S_t *space, hsize_t startblock, + hsize_t numblocks, hsize_t *buf) { herr_t ret_value = SUCCEED; /* Return value */ @@ -3888,11 +4137,18 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo HDassert(buf); HDassert(space->select.sel_info.hslab->unlim_dim < 0); + /* Attempt to rebuild diminfo if it is invalid and has not been confirmed + * to be impossible. + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild(space); + /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { const H5S_hyper_dim_t *diminfo; /* Alias for dataspace's diminfo information */ hsize_t tmp_count[H5S_MAX_RANK]; /* Temporary hyperslab counts */ hsize_t offset[H5S_MAX_RANK]; /* Offset of element in dataspace */ + hsize_t end[H5S_MAX_RANK]; /* End of elements in dataspace */ unsigned fast_dim; /* Rank of the fastest changing dimension for the dataspace */ unsigned ndims; /* Rank of the dataspace */ hbool_t done; /* Whether we are done with the iteration */ @@ -3903,31 +4159,25 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo fast_dim = ndims - 1; /* Check which set of dimension information to use */ - if(internal) + if(space->select.sel_info.hslab->unlim_dim >= 0) /* - * Use the "optimized dimension information" to pass back information - * on the blocks set, not the "application information". + * There is an unlimited dimension so we must use diminfo.opt as + * it has been "clipped" to the current extent. */ - diminfo = space->select.sel_info.hslab->opt_diminfo; + diminfo = space->select.sel_info.hslab->diminfo.opt; else - if(space->select.sel_info.hslab->unlim_dim >= 0) - /* - * There is an unlimited dimension so we must use opt_diminfo as - * it has been "clipped" to the current extent. - */ - diminfo = space->select.sel_info.hslab->opt_diminfo; - else - /* - * Use the "application dimension information" to pass back to - * the user the blocks they set, not the optimized, internal - * information. - */ - diminfo = space->select.sel_info.hslab->app_diminfo; + /* + * Use the "application dimension information" to pass back to + * the user the blocks they set, not the optimized, internal + * information. + */ + diminfo = space->select.sel_info.hslab->diminfo.app; /* Build the tables of count sizes as well as the initial offset */ for(u = 0; u < ndims; u++) { tmp_count[u] = diminfo[u].count; offset[u] = diminfo[u].start; + end[u] = diminfo[u].start + (diminfo[u].block - 1); } /* end for */ /* We're not done with the iteration */ @@ -3935,31 +4185,45 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo /* Go iterate over the hyperslabs */ while(!done && numblocks > 0) { - hsize_t temp_off; /* Offset in a given dimension */ + /* Skip over initial blocks */ + if(startblock > 0) { + /* Skip all blocks in row */ + if(startblock >= tmp_count[fast_dim]) { + startblock -= tmp_count[fast_dim]; + tmp_count[fast_dim] = 0; + } /* end if */ + else { + /* Move the offset to the next sequence to start */ + offset[fast_dim] += diminfo[fast_dim].stride * startblock; + end[fast_dim] += diminfo[fast_dim].stride * startblock; + + /* Decrement the block count */ + tmp_count[fast_dim] -= startblock; + + /* Done with starting blocks */ + startblock = 0; + } /* end else */ + } /* end if */ /* Iterate over the blocks in the fastest dimension */ while(tmp_count[fast_dim] > 0 && numblocks > 0) { + /* Sanity check */ + HDassert(startblock == 0); - /* Check if we should copy this block information */ - if(startblock == 0) { - /* Copy the starting location */ - HDmemcpy(buf, offset, sizeof(hsize_t) * ndims); - buf += ndims; + /* Copy the starting location */ + HDmemcpy(buf, offset, sizeof(hsize_t) * ndims); + buf += ndims; - /* Compute the ending location */ - HDmemcpy(buf, offset, sizeof(hsize_t) * ndims); - for(u = 0; u < ndims; u++) - buf[u] += (diminfo[u].block - 1); - buf += ndims; + /* Compute the ending location */ + HDmemcpy(buf, end, sizeof(hsize_t) * ndims); + buf += ndims; - /* Decrement the number of blocks to retrieve */ - numblocks--; - } /* end if */ - else - startblock--; + /* Decrement the number of blocks to retrieve */ + numblocks--; /* Move the offset to the next sequence to start */ offset[fast_dim] += diminfo[fast_dim].stride; + end[fast_dim] += diminfo[fast_dim].stride; /* Decrement the block count */ tmp_count[fast_dim]--; @@ -3982,23 +4246,24 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo if(tmp_count[temp_dim] > 0) break; + /* Reset the block count in this dimension */ + tmp_count[temp_dim] = diminfo[temp_dim].count; + /* Check for getting out of iterator */ if(temp_dim == 0) done = TRUE; - /* Reset the block count in this dimension */ - tmp_count[temp_dim] = diminfo[temp_dim].count; - /* Wrapped a dimension, go up to next dimension */ temp_dim--; } /* end while */ } /* end if */ - /* Re-compute offset array */ - for(u = 0; u < ndims; u++) { - temp_off = diminfo[u].start + diminfo[u].stride * (diminfo[u].count - tmp_count[u]); - offset[u] = temp_off; - } /* end for */ + /* Re-compute offset & end arrays */ + if(!done) + for(u = 0; u < ndims; u++) { + offset[u] = diminfo[u].start + diminfo[u].stride * (diminfo[u].count - tmp_count[u]); + end[u] = offset[u] + (diminfo[u].block - 1); + } /* end for */ } /* end while */ } /* end if */ else { @@ -4024,7 +4289,7 @@ H5S__get_select_hyper_blocklist(H5S_t *space, hbool_t internal, hsize_t startblo hsize_t numblocks; IN: Number of hyperslab blocks to get hsize_t buf[]; OUT: List of hyperslab blocks selected RETURNS - Non-negative on success, negative on failure + Non-negative on success/Negative on failure DESCRIPTION Puts a list of the hyperslab blocks into the user's buffer. The blocks start with the 'startblock'th block in the list of blocks and put @@ -4064,7 +4329,7 @@ H5Sget_select_hyper_blocklist(hid_t spaceid, hsize_t startblock, /* Go get the correct number of blocks */ if(numblocks > 0) - ret_value = H5S__get_select_hyper_blocklist(space, 0, startblock, numblocks, buf); + ret_value = H5S__get_select_hyper_blocklist(space, startblock, numblocks, buf); else ret_value = SUCCEED; /* Successfully got 0 blocks... */ @@ -4072,76 +4337,6 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Sget_select_hyper_blocklist() */ - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_bounds_helper - PURPOSE - Gets the bounding box containing the selection. - USAGE - htri_t H5S_hyper_bounds_helper(spans, offset, rank); - const H5S_hyper_span_info_t *spans; IN: Pointer to current hyperslab span tree - const hssize_t *offset; IN: Pointer to offset array - hsize_t rank; IN: Current rank looking at - hsize_t *start; OUT: Start array bounds - hsize_t *end; OUT: End array bounds - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Retrieves the bounding box containing the current selection and places - it into the user's buffers. The start and end buffers must be large - enough to hold the dataspace rank number of coordinates. The bounding box - exactly contains the selection, ie. if a 2-D element selection is currently - defined with the following points: (4,5), (6,8) (10,7), the bounding box - with be (4, 5), (10, 8). - The bounding box calculations _does_ include the current offset of the - selection within the dataspace extent. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5S_hyper_bounds_helper(const H5S_hyper_span_info_t *spans, const hssize_t *offset, hsize_t rank, hsize_t *start, hsize_t *end) -{ - H5S_hyper_span_t *curr; /* Hyperslab information nodes */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT - - HDassert(spans); - HDassert(offset); - HDassert(rank < H5S_MAX_RANK); - HDassert(start); - HDassert(end); - - /* Check each point to determine whether selection+offset is within extent */ - curr=spans->head; - while(curr!=NULL) { - /* Check for offset moving selection negative */ - if(((hssize_t)curr->low + offset[rank]) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") - - /* Check if the current span extends the bounding box */ - if((curr->low + (hsize_t)offset[rank]) < start[rank]) - start[rank] = curr->low + (hsize_t)offset[rank]; - if((curr->high + (hsize_t)offset[rank]) > end[rank]) - end[rank] = curr->high + (hsize_t)offset[rank]; - - /* Recurse if this node has down spans */ - if(curr->down != NULL) { - if(H5S_hyper_bounds_helper(curr->down, offset, (rank + 1), start, end) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "failure in lower dimension") - } /* end if */ - - /* Advance to next node */ - curr = curr->next; - } /* end while */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S_hyper_bounds_helper() */ - /*-------------------------------------------------------------------------- NAME @@ -4172,8 +4367,8 @@ done: static herr_t H5S__hyper_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) { - unsigned rank; /* Dataspace rank */ - unsigned i; /* index variable */ + const hsize_t *low_bounds, *high_bounds; /* Pointers to the correct pair of low & high bounds */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -4183,37 +4378,32 @@ H5S__hyper_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) HDassert(start); HDassert(end); - /* Set the start and end arrays up */ - rank = space->extent.rank; - for(i = 0; i < rank; i++) { - start[i] = HSIZET_MAX; - end[i] = 0; - } /* end for */ - - /* Check for a "regular" hyperslab selection */ - 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; i < rank; i++) { - /* Check for offset moving selection negative */ - if((space->select.offset[i] + (hssize_t)diminfo[i].start) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") - - /* Compute the smallest location in this dimension */ - start[i] = diminfo[i].start + (hsize_t)space->select.offset[i]; - - /* Compute the largest location in this dimension */ - if((int)i == space->select.sel_info.hslab->unlim_dim) - end[i] = H5S_UNLIMITED; - else - end[i] = diminfo[i].start + diminfo[i].stride * (diminfo[i].count - 1) + (diminfo[i].block - 1) + (hsize_t)space->select.offset[i]; - } /* end for */ + /* Check which set of low & high bounds we should be using */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + low_bounds = space->select.sel_info.hslab->diminfo.low_bounds; + high_bounds = space->select.sel_info.hslab->diminfo.high_bounds; } /* end if */ else { - /* Call the recursive routine to get the bounds for the span tree */ - ret_value = H5S_hyper_bounds_helper(space->select.sel_info.hslab->span_lst, space->select.offset, (hsize_t)0, start, end); - } /* end if */ + low_bounds = space->select.sel_info.hslab->span_lst->low_bounds; + high_bounds = space->select.sel_info.hslab->span_lst->high_bounds; + } /* end else */ + + /* Loop over dimensions */ + for(u = 0; u < space->extent.rank; u++) { + /* Sanity check */ + HDassert(low_bounds[u] <= high_bounds[u]); + + /* Check for offset moving selection negative */ + if(((hssize_t)low_bounds[u] + space->select.offset[u]) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") + + /* Set the low & high bounds in this dimension */ + start[u] = (hsize_t)((hssize_t)low_bounds[u] + space->select.offset[u]); + if((int)u == space->select.sel_info.hslab->unlim_dim) + end[u] = H5S_UNLIMITED; + else + end[u] = (hsize_t)((hssize_t)high_bounds[u] + space->select.offset[u]); + } /* end for */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -4264,8 +4454,9 @@ H5S__hyper_offset(const H5S_t *space, hsize_t *offset) dim_size = space->extent.size; /* Check for a "regular" hyperslab selection */ - 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 */ + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + const H5S_hyper_dim_t *diminfo = space->select.sel_info.hslab->diminfo.opt; /* Local alias for diminfo */ /* Loop through starting coordinates, calculating the linear offset */ accum = 1; @@ -4428,8 +4619,9 @@ H5S__hyper_is_contiguous(const H5S_t *space) HDassert(space); /* Check for a "regular" hyperslab selection */ - 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 */ + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + const H5S_hyper_dim_t *diminfo=space->select.sel_info.hslab->diminfo.opt; /* local alias for diminfo */ /* * For a regular hyperslab to be contiguous, it must have only one @@ -4610,7 +4802,10 @@ H5S__hyper_is_single(const H5S_t *space) HDassert(space); /* Check for a "single" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { + /* (No need to rebuild the dimension info yet, since the span-tree + * algorithm is fast -QAK) + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { unsigned u; /* index variable */ /* @@ -4620,7 +4815,7 @@ H5S__hyper_is_single(const H5S_t *space) /* Check for a single block */ for(u = 0; u < space->extent.rank; u++) - if(space->select.sel_info.hslab->opt_diminfo[u].count > 1) + if(space->select.sel_info.hslab->diminfo.opt[u].count > 1) HGOTO_DONE(FALSE) } /* end if */ else { @@ -4668,7 +4863,6 @@ done: This is primarily used for reading the entire selection in one swoop. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS - Doesn't check for "regular" hyperslab selections composed of spans EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ @@ -4682,8 +4876,14 @@ H5S__hyper_is_regular(const H5S_t *space) /* Check args */ HDassert(space); + /* Attempt to rebuild diminfo if it is invalid and has not been confirmed + * to be impossible. + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild((H5S_t *)space); /* Casting away const OK -NAF */ + /* Only simple check for regular hyperslabs for now... */ - if(space->select.sel_info.hslab->diminfo_valid) + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) ret_value = TRUE; else ret_value = FALSE; @@ -4691,6 +4891,360 @@ H5S__hyper_is_regular(const H5S_t *space) FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_is_regular() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_spans_shape_same_helper + PURPOSE + Helper routine to check if two hyperslab span trees are the same shape + USAGE + hbool_t H5S__hyper_spans_shape_same_helper(span1, span2, offset, rest_zeros) + H5S_hyper_span_info_t *span_info1; IN: First span tree to compare + H5S_hyper_span_info_t *span_info2; IN: Second span tree to compare + hssize_t offset[]; IN: Offset between the span trees + hbool_t rest_zeros[]; IN: Array of flags which indicate + the rest of the offset[] array + is zero values. + RETURNS + TRUE (1) or FALSE (0) on success, can't fail + DESCRIPTION + Compare two hyperslab span trees to determine if they refer to a selection + with the same shape, with a possible (constant) offset between their + elements. Very similar to H5S__hyper_cmp_spans, except the selected + elements can be offset by a vector. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static H5_ATTR_PURE hbool_t +H5S__hyper_spans_shape_same_helper(const H5S_hyper_span_info_t *span_info1, + const H5S_hyper_span_info_t *span_info2, hssize_t offset[], + hbool_t rest_zeros[]) +{ + hbool_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_PACKAGE_NOERR + + /* Sanity checks */ + HDassert(span_info1); + HDassert(span_info2); + HDassert(offset); + HDassert(rest_zeros); + + /* Compare low & high bounds for this span list */ + /* (Could compare lower dimensions also, but not certain if + * that's worth it. - QAK, 2019/01/23) + */ + if((hsize_t)((hssize_t)span_info1->low_bounds[0] + offset[0]) != span_info2->low_bounds[0]) + HGOTO_DONE(FALSE) + else if((hsize_t)((hssize_t)span_info1->high_bounds[0] + offset[0]) != span_info2->high_bounds[0]) + HGOTO_DONE(FALSE) + else { + const H5S_hyper_span_t *span1; + const H5S_hyper_span_t *span2; + + /* Get the pointers to the actual lists of spans */ + span1 = span_info1->head; + span2 = span_info2->head; + + /* Sanity checking */ + HDassert(span1); + HDassert(span2); + + /* infinite loop which must be broken out of */ + while(1) { + /* Check for both spans being NULL */ + if(span1 == NULL && span2 == NULL) + HGOTO_DONE(TRUE) + else { + /* Check for one span being NULL */ + if(span1 == NULL || span2 == NULL) + HGOTO_DONE(FALSE) + else { + /* Check if the actual low & high span information is the same */ + if((hsize_t)((hssize_t)span1->low + offset[0]) != span2->low || (hsize_t)((hssize_t)span1->high + offset[0]) != span2->high) + HGOTO_DONE(FALSE) + else { + if(span1->down != NULL || span2->down != NULL) { + /* If the rest of the span trees have a zero offset, use the faster comparison routine */ + if(rest_zeros[0]) { + if(!H5S__hyper_cmp_spans(span1->down, span2->down)) + HGOTO_DONE(FALSE) + else { + /* Keep going... */ + } /* end else */ + } /* end if */ + else { + if(!H5S__hyper_spans_shape_same_helper(span1->down, span2->down, &offset[1], &rest_zeros[1])) + HGOTO_DONE(FALSE) + else { + /* Keep going... */ + } /* end else */ + } /* end else */ + } /* end if */ + else { + /* Keep going... */ + } /* end else */ + } /* end else */ + } /* end else */ + } /* end else */ + + /* Advance to the next nodes in the span list */ + span1 = span1->next; + span2 = span2->next; + } /* end while */ + } /* end else */ + + /* Fall through, with default return value of 'TRUE' if spans were already visited */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_spans_shape_same_helper() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_spans_shape_same + PURPOSE + Check if two hyperslab span trees are the same shape + USAGE + hbool_t H5S__hyper_spans_shape_same(span1, span2) + H5S_hyper_span_info_t *span_info1; IN: First span tree to compare + H5S_hyper_span_info_t *span_info2; IN: Second span tree to compare + RETURNS + TRUE (1) or FALSE (0) on success, can't fail + DESCRIPTION + Compare two hyperslab span trees to determine if they refer to a selection + with the same shape. Very similar to H5S__hyper_cmp_spans, except the + selected elements can be offset by a vector. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static H5_ATTR_PURE hbool_t +H5S__hyper_spans_shape_same(const H5S_hyper_span_info_t *span_info1, + const H5S_hyper_span_info_t *span_info2, unsigned ndims) +{ + const H5S_hyper_span_t *span1; /* Pointer to spans in first span tree */ + const H5S_hyper_span_t *span2; /* Pointer to spans in second span tree */ + hssize_t offset[H5S_MAX_RANK]; /* Offset vector for selections */ + hbool_t rest_zeros[H5S_MAX_RANK]; /* Vector of flags to indicate when remaining offset is all zero */ + hbool_t zero_offset; /* Whether the two selections have a non-zero offset */ + unsigned u; /* Local index variable */ + hbool_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity check */ + HDassert(span_info1); + HDassert(span_info2); + HDassert(ndims > 0); + + /* Initialize arrays */ + HDmemset(offset, 0, sizeof(offset)); + HDmemset(rest_zeros, 0, sizeof(rest_zeros)); + + /* Check for an offset between the two selections */ + span1 = span_info1->head; + span2 = span_info2->head; + zero_offset = TRUE; + for(u = 0; u < ndims; u++) { + /* Check for offset in this dimension */ + if(span1->low != span2->low) { + offset[u] = (hssize_t)span2->low - (hssize_t)span1->low; + + /* Indicate that the offset vector is not all zeros */ + if(zero_offset) + zero_offset = FALSE; + } /* end if */ + + /* Sanity check */ + /* (Both span trees must have the same depth) */ + HDassert((span1->down && span2->down) || (NULL == span1->down && NULL == span2->down)); + + /* Advance to next dimension */ + if(span1->down) { + span1 = span1->down->head; + span2 = span2->down->head; + } /* end if */ + } /* end for */ + + /* Check if there's a "tail" of all zeros in a non-zero offset vector */ + if(!zero_offset) { + int i; /* Local index variable */ + + /* Find first non-zero offset, from the fastest dimension up */ + for(i = (int)(ndims - 1); i >= 0; i--) + if(offset[i]) { + rest_zeros[i] = TRUE; + break; + } /* end if */ + + /* Sanity check */ + /* (Must eventually have found a non-zero offset) */ + HDassert(i >= 0); + } /* end if */ + + /* If the offset vector is all zero, we can use the faster span tree + * comparison routine. Otherwise, use a generalized version of that + * routine. + */ + if(zero_offset) + ret_value = H5S__hyper_cmp_spans(span_info1, span_info2); + else + ret_value = H5S__hyper_spans_shape_same_helper(span_info1, span_info2, offset, rest_zeros); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_spans_shape_same() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_shape_same + PURPOSE + Check if a two hyperslab selections are the same shape + USAGE + htri_t H5S__hyper_shape_same(space1, space2) + const H5S_t *space1; IN: First dataspace to check + const H5S_t *space2; IN: Second dataspace to check + RETURNS + TRUE / FALSE / FAIL + DESCRIPTION + Checks to see if the current selection in each dataspace are the same + shape. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + Handles when both are regular in an efficient way, otherwise converts + both to span tree form (if necessary) and compares efficiently them in + that form. + + Rank of space1 must always be >= to rank of space2. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static htri_t +H5S__hyper_shape_same(const H5S_t *space1, const H5S_t *space2) +{ + unsigned space1_rank; /* Number of dimensions of first dataspace */ + unsigned space2_rank; /* Number of dimensions of second dataspace */ + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check args */ + HDassert(space1); + HDassert(space2); + + /* Get dataspace ranks */ + space1_rank = space1->extent.rank; + space2_rank = space2->extent.rank; + + /* Sanity check */ + HDassert(space1_rank >= space2_rank); + HDassert(space2_rank > 0); + + /* Rebuild diminfo if it is invalid and has not been confirmed to be + * impossible */ + if(space1->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild((H5S_t *)space1); /* Casting away const OK -QAK */ + if(space2->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild((H5S_t *)space2); /* Casting away const OK -QAK */ + + /* If both are regular hyperslabs, compare their diminfo values */ + if(space1->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES + && space2->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + int space1_dim; /* Current dimension in first dataspace */ + int space2_dim; /* Current dimension in second dataspace */ + + /* Initialize dimensions */ + space1_dim = (int)space1_rank - 1; + space2_dim = (int)space2_rank - 1; + + /* Check that the shapes are the same in the common dimensions, and that + * block == 1 in all dimensions that appear only in space1. + */ + while(space2_dim >= 0) { + if(space1->select.sel_info.hslab->diminfo.opt[space1_dim].stride != + space2->select.sel_info.hslab->diminfo.opt[space2_dim].stride) + HGOTO_DONE(FALSE) + + if(space1->select.sel_info.hslab->diminfo.opt[space1_dim].count != + space2->select.sel_info.hslab->diminfo.opt[space2_dim].count) + HGOTO_DONE(FALSE) + + if(space1->select.sel_info.hslab->diminfo.opt[space1_dim].block != + space2->select.sel_info.hslab->diminfo.opt[space2_dim].block) + HGOTO_DONE(FALSE) + + space1_dim--; + space2_dim--; + } /* end while */ + + while(space1_dim >= 0) { + if(space1->select.sel_info.hslab->diminfo.opt[space1_dim].block != 1) + HGOTO_DONE(FALSE) + + space1_dim--; + } /* end while */ + } /* end if */ + /* If both aren't regular, use fast irregular comparison */ + else { + H5S_hyper_span_info_t *spans1; /* Hyperslab spans for first dataspace */ + + /* Make certain that both selections have span trees */ + if(NULL == space1->select.sel_info.hslab->span_lst) + if(H5S__hyper_generate_spans((H5S_t *)space1) < 0) /* Casting away const OK -QAK */ + HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "can't construct span tree for hyperslab selection") + if(NULL == space2->select.sel_info.hslab->span_lst) + if(H5S__hyper_generate_spans((H5S_t *)space2) < 0) /* Casting away const OK -QAK */ + HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "can't construct span tree for hyperslab selection") + + /* If rank of space A is different (guaranteed greater) than + * rank of space B, walk down the span tree, verifying + * that the block size is 1 on the way down. + */ + if(space1_rank > space2_rank) { + unsigned diff_rank = space1_rank - space2_rank; /* Difference in ranks */ + + /* Walk down the dimensions */ + spans1 = space1->select.sel_info.hslab->span_lst; + while(diff_rank > 0) { + H5S_hyper_span_t *span; /* Span for this dimension */ + + /* Get pointer to first span in tree */ + span = spans1->head; + + /* Check for more spans in this dimension */ + if(span->next) + HGOTO_DONE(FALSE) + + /* Check for span size > 1 element */ + if(span->low != span->high) + HGOTO_DONE(FALSE) + + /* Walk down to the next dimension */ + spans1 = span->down; + diff_rank--; + } /* end while */ + + /* Sanity check */ + HDassert(spans1); + } /* end if */ + else + spans1 = space1->select.sel_info.hslab->span_lst; + + /* Compare the span trees */ + ret_value = H5S__hyper_spans_shape_same(spans1, space2->select.sel_info.hslab->span_lst, space2_rank); + } /* end else */ + + /* Fall through with 'TRUE' value, if not set earlier */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_shape_same() */ + /*-------------------------------------------------------------------------- NAME @@ -4708,18 +5262,11 @@ H5S__hyper_is_regular(const H5S_t *space) COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG - * Robb Matzke, 1998-08-25 - * The fields which are freed are set to NULL to prevent them from being - * freed again later. This fixes some allocation problems where - * changing the hyperslab selection of one dataspace causes a core dump - * when closing some other dataspace. --------------------------------------------------------------------------*/ static herr_t H5S__hyper_release(H5S_t *space) { - herr_t ret_value = SUCCEED; - - FUNC_ENTER_STATIC + FUNC_ENTER_STATIC_NOERR /* Check args */ HDassert(space && H5S_SEL_HYPERSLABS == H5S_GET_SELECT_TYPE(space)); @@ -4730,57 +5277,14 @@ H5S__hyper_release(H5S_t *space) /* Release irregular hyperslab information */ if(space->select.sel_info.hslab) { if(space->select.sel_info.hslab->span_lst != NULL) - if(H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") + H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst); /* Release space for the hyperslab selection information */ space->select.sel_info.hslab = H5FL_FREE(H5S_hyper_sel_t, space->select.sel_info.hslab); } /* end if */ -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__hyper_release() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S__hyper_recover_span - PURPOSE - Recover a generated span, if appropriate - USAGE - herr_t H5S__hyper_recover_span(recover, curr_span, next_span) - unsigned *recover; IN/OUT: Pointer recover flag - H5S_hyper_span_t **curr_span; IN/OUT: Pointer to current span in list - H5S_hyper_span_t *next_span; IN: Pointer to next span - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Check if the current span needs to be recovered and free it if so. - Set the current span to the next span in any case. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static herr_t -H5S__hyper_recover_span(hbool_t *recover, H5S_hyper_span_t **curr_span, H5S_hyper_span_t *next_span) -{ - FUNC_ENTER_STATIC_NOERR - - HDassert(recover); - HDassert(curr_span); - - /* Check if the span should be recovered */ - if(*recover) { - H5S__hyper_free_span(*curr_span); - *recover = FALSE; - } /* end if */ - - /* Set the current span to next span */ - *curr_span = next_span; - FUNC_LEAVE_NOAPI(SUCCEED) -} /* H5S__hyper_recover_span() */ +} /* end H5S__hyper_release() */ /*-------------------------------------------------------------------------- @@ -4793,7 +5297,7 @@ H5S__hyper_recover_span(hbool_t *recover, H5S_hyper_span_t **curr_span, H5S_hype unsigned rank; IN: Number of dimensions of coordinate hsize_t *coords; IN: Location of element RETURNS - Non-negative on success, negative on failure + Non-NULL pointer to new span tree on success, NULL on failure DESCRIPTION Create a span tree for a single element GLOBAL VARIABLES @@ -4815,14 +5319,20 @@ H5S__hyper_coord_to_span(unsigned rank, const hsize_t *coords) /* Search for location to insert new element in tree */ if(rank > 1) { - /* Allocate a span info node */ - if(NULL == (down = H5FL_CALLOC(H5S_hyper_span_info_t))) + /* Allocate a span info node for coordinates below this one */ + if(NULL == (down = H5S__hyper_new_span_info(rank - 1))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") + /* Set the low & high bounds for this span info node */ + HDmemcpy(down->low_bounds, &coords[1], (rank - 1) * sizeof(hsize_t)); + HDmemcpy(down->high_bounds, &coords[1], (rank - 1) * sizeof(hsize_t)); /* Build span tree for coordinates below this one */ if(NULL == (down->head = H5S__hyper_coord_to_span(rank - 1, &coords[1]))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") + + /* Update the tail pointer of the down dimension, and it's a single span element */ + down->tail = down->head; } /* end if */ /* Build span for this coordinate */ @@ -4844,12 +5354,13 @@ done: NAME H5S__hyper_add_span_element_helper PURPOSE - Add a single element to a span tree + Helper routine to add a single element to a span tree USAGE - herr_t H5S_hyper_add_span_element_helper(prev_span, span_tree, rank, coords) + herr_t H5S__hyper_add_span_element_helper(span_tree, rank, coords, first_dim_modified) H5S_hyper_span_info_t *span_tree; IN/OUT: Pointer to span tree to append to unsigned rank; IN: Number of dimensions of coordinates - hsize_t *coords; IN: Location of element to add to span tree + hsize_t *coords; IN: Location of element to add to span tree + int *first_dim_modified; IN: Index of the first dimension modified RETURNS Non-negative on success, negative on failure DESCRIPTION @@ -4862,13 +5373,9 @@ done: --------------------------------------------------------------------------*/ static herr_t H5S__hyper_add_span_element_helper(H5S_hyper_span_info_t *span_tree, - unsigned rank, const hsize_t *coords) + unsigned rank, const hsize_t *coords, int *first_dim_modified) { - H5S_hyper_span_info_t *tspan_info; /* Temporary pointer to span info */ - H5S_hyper_span_info_t *prev_span_info; /* Pointer to span info for level above current position */ - H5S_hyper_span_t *tmp_span; /* Temporary pointer to a span */ - H5S_hyper_span_t *tmp2_span; /* Another temporary pointer to a span */ - H5S_hyper_span_t *new_span; /* New span created for element */ + H5S_hyper_span_t *tail_span; /* Pointer to the tail span of one dimension */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -4877,166 +5384,196 @@ H5S__hyper_add_span_element_helper(H5S_hyper_span_info_t *span_tree, HDassert(span_tree); HDassert(rank > 0); HDassert(coords); + HDassert(first_dim_modified); /* Get pointer to last span in span tree */ - tspan_info=span_tree; - if(span_tree->scratch) - tmp_span=(H5S_hyper_span_t *)span_tree->scratch; - else { - tmp_span=span_tree->head; - HDassert(tmp_span); - span_tree->scratch=(H5S_hyper_span_info_t *)tmp_span; - } /* end else */ + tail_span = span_tree->tail; - /* Find last span tree which includes a portion of the coordinate */ - prev_span_info=NULL; - while(coords[0]>=tmp_span->low && coords[0]<=tmp_span->high) { - /* Move rank & coordinate offset down a dimension */ - rank--; - coords++; + /* Determine if tail span includes a portion of the coordinate */ + /* (Should never happen with the lowest level in the span tree) */ + if(coords[0] >= tail_span->low && coords[0] <= tail_span->high) { + H5S_hyper_span_t *prev_down_tail_span; /* Pointer to previous down spans' tail pointer */ + hsize_t prev_down_tail_span_high; /* Value of previous down spans' tail's high value */ - /* Remember the span tree we are descending into */ - prev_span_info=tspan_info; - tspan_info=tmp_span->down; + /* Retain into about down spans' tail */ + prev_down_tail_span = tail_span->down->tail; + prev_down_tail_span_high = tail_span->down->tail->high; - /* Get the last span in this span's 'down' tree */ - if(tspan_info->scratch) - tmp_span=(H5S_hyper_span_t *)tspan_info->scratch; - else { - tmp_span=tspan_info->head; - HDassert(tmp_span); - tspan_info->scratch=(H5S_hyper_span_info_t *)tmp_span; - } /* end else */ - } /* end while */ + /* Drop down a dimension */ + HDassert(rank > 1); + if(H5S__hyper_add_span_element_helper(tail_span->down, rank - 1, &coords[1], first_dim_modified) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTINSERT, FAIL, "can't insert coordinate into span tree") - /* Check if we made it all the way to the bottom span in the tree */ - if(rank>1) { - /* Before we create another span at this level in the tree, check if - * the last span's "down tree" was equal to any other spans in this - * list of spans in the span tree. - * - * If so, release last span information and make last span merge into - * previous span (if possible), or at least share their "down tree" - * information. - */ - tmp2_span=tspan_info->head; - while(tmp2_span!=tmp_span) { - if(H5S__hyper_cmp_spans(tmp2_span->down,tmp_span->down)==TRUE) { - /* Check for merging into previous span */ - if(tmp2_span->high+1==tmp_span->low) { - /* Release last span created */ - H5S__hyper_free_span(tmp_span); + /* Check & update high bounds for lower dimensions */ + if(*first_dim_modified >= 0) { + unsigned first_dim; /* First dimension modified, relative to this span tree */ + hbool_t first_dim_set = FALSE; /* Whether first dimension modified is set */ + unsigned u; /* Local index variable */ - /* Increase size of previous span */ - tmp2_span->high++; - tmp2_span->nelem++; + /* Adjust first dimension modified to be relative to this span tree */ + first_dim = (unsigned)(*first_dim_modified + 1); - /* Reset the 'tmp_span' for the rest of this block's algorithm */ - tmp_span=tmp2_span; + /* Reset modified dimension, in case no bounds in this span tree change */ + *first_dim_modified = -1; + + /* Iterate through coordinates */ + for(u = first_dim; u < rank; u++) { + /* Check if coordinate is outside the bounds for this span tree */ + if(coords[u] > span_tree->high_bounds[u]) { + /* Update high bounds for this tree */ + span_tree->high_bounds[u] = coords[u]; + + /* Need to signal to higher dimensions if high bounds changed */ + if(!first_dim_set) { + *first_dim_modified = (int)u; + first_dim_set = TRUE; + } /* end if */ + } /* end if */ + } /* end for */ + } /* end if */ + + /* Check if previous tail span in down spans is different than current + * tail span, or if its high value changed, in which case we should + * check if the updated node can share down spans with other nodes. + */ + if(tail_span->down->tail != prev_down_tail_span || + prev_down_tail_span_high != tail_span->down->tail->high) { + H5S_hyper_span_t *stop_span; /* Pointer to span to stop at */ + H5S_hyper_span_t *tmp_span; /* Temporary pointer to a span */ + uint64_t op_gen; /* Operation generation value */ + + /* Determine which span to stop at */ + if(tail_span->down->tail != prev_down_tail_span) { + /* Sanity check */ + HDassert(prev_down_tail_span->next == tail_span->down->tail); + + /* Set the span to stop at */ + stop_span = prev_down_tail_span; + } /* end if */ + else { + /* Sanity check */ + HDassert(prev_down_tail_span_high != tail_span->down->tail->high); + + /* Set the span to stop at */ + stop_span = tail_span->down->tail; + } /* end else */ + + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); + + /* Check if the 'stop' span in the "down tree" is equal to any other + * spans in the list of spans in the span tree. + * + * If so, release last span information and make last span merge into + * previous span (if possible), or at least share their "down tree" + * information. + */ + tmp_span = tail_span->down->head; + while(tmp_span != stop_span) { + hbool_t attempt_merge_spans = FALSE; /* Whether to merge spans */ + + /* Different tests for when to run the 'merge' algorithm, + * depending whether there's "down trees" or not. + */ + if(NULL == tmp_span->down) { + /* Spin through spans until we find the one before the 'stop' span */ + if(tmp_span->next == stop_span) + attempt_merge_spans = TRUE; } /* end if */ - /* Span is disjoint, but has the same "down tree" selection */ else { - /* Release "down tree" information */ - H5S__hyper_free_span_info(tmp_span->down); + /* Check if we've compared the 'stop' span's "down tree" to + * this span's "down tree" already. + */ + if(tmp_span->down->op_gen != op_gen) { + if(H5S__hyper_cmp_spans(tmp_span->down, stop_span->down)) + attempt_merge_spans = TRUE; - /* Point at earlier span's "down tree" */ - tmp_span->down=tmp2_span->down; - - /* Increment reference count on shared "down tree" */ - tmp_span->down->count++; + /* Remember that we visited this span's "down tree" already */ + /* (Because it wasn't the same as the 'stop' span's down tree + * and we don't need to compare it again) + */ + tmp_span->down->op_gen = op_gen; + } /* end if */ } /* end else */ - /* Found span to merge into, break out now */ - break; - } /* end if */ + /* Check for merging into previous span */ + if(attempt_merge_spans) { + if(tmp_span->high + 1 == stop_span->low) { + /* Increase size of previous span */ + tmp_span->high++; - /* Advance to next span to check */ - tmp2_span=tmp2_span->next; - } /* end while */ + /* Update pointers appropriately */ + if(stop_span == prev_down_tail_span) { + /* Sanity check */ + HDassert(stop_span->next == tail_span->down->tail); - /* Make span tree for current coordinates */ - if(NULL == (new_span = H5S__hyper_coord_to_span(rank, coords))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") - - /* Add new span tree as span */ - HDassert(tmp_span); - tmp_span->next=new_span; - - /* Make scratch pointer point to last span in list */ - HDassert(tspan_info); - tspan_info->scratch=(H5S_hyper_span_info_t *)new_span; - - /* Set the proper 'pstride' for new span */ - new_span->pstride=new_span->low-tmp_span->low; - } /* end if */ - else { - /* Does new node adjoin existing node? */ - if(tmp_span->high+1==coords[0]) { - tmp_span->high++; - tmp_span->nelem++; - - /* Check if this span tree should now be merged with a level higher in the tree */ - if(prev_span_info!=NULL) { - /* Before we create another span at this level in the tree, check if - * the last span's "down tree" was equal to any other spans in this - * list of spans in the span tree. - * - * If so, release last span information and make last span merge into - * previous span (if possible), or at least share their "down tree" - * information. - */ - tmp2_span=prev_span_info->head; - tmp_span=(H5S_hyper_span_t *)prev_span_info->scratch; - while(tmp2_span!=tmp_span) { - if(H5S__hyper_cmp_spans(tmp2_span->down,tmp_span->down)==TRUE) { - /* Check for merging into previous span */ - if(tmp2_span->high+1==tmp_span->low) { - /* Release last span created */ - H5S__hyper_free_span(tmp_span); - - /* Increase size of previous span */ - tmp2_span->high++; - tmp2_span->nelem++; - - /* Update pointers */ - tmp2_span->next=NULL; - prev_span_info->scratch=(H5S_hyper_span_info_t *)tmp2_span; + tmp_span->next = stop_span->next; } /* end if */ - /* Span is disjoint, but has the same "down tree" selection */ else { - /* Release "down tree" information */ - H5S__hyper_free_span_info(tmp_span->down); + /* Sanity check */ + HDassert(tmp_span->next == tail_span->down->tail); - /* Point at earlier span's "down tree" */ - tmp_span->down=tmp2_span->down; - - /* Increment reference count on shared "down tree" */ - tmp_span->down->count++; + tmp_span->next = NULL; + tail_span->down->tail = tmp_span; } /* end else */ - /* Found span to merge into, break out now */ - break; + /* Release last span created */ + H5S__hyper_free_span(stop_span); } /* end if */ + /* Span is disjoint, but has the same "down tree" selection */ + /* (If it has a "down tree") */ + else if(stop_span->down) { + /* Release "down tree" information */ + H5S__hyper_free_span_info(stop_span->down); - /* Advance to next span to check */ - tmp2_span=tmp2_span->next; - } /* end while */ - } /* end if */ + /* Point at earlier span's "down tree" */ + stop_span->down = tmp_span->down; + + /* Increment reference count on shared "down tree" */ + stop_span->down->count++; + } /* end else */ + + /* Found span to merge into, break out now */ + break; + } /* end if */ + + /* Advance to next span to check */ + tmp_span = tmp_span->next; + } /* end while */ } /* end if */ + } /* end if */ + else { + unsigned u; /* Local index variable */ + + /* Check if we made it all the way to the bottom span list in the tree + * and the new coordinate adjoins the current tail span. + */ + if(rank == 1 && (tail_span->high + 1) == coords[0]) + /* Append element to current tail span */ + tail_span->high++; else { - if(NULL == (new_span = H5S__hyper_new_span(coords[0], coords[0], NULL, NULL))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") + H5S_hyper_span_t *new_span; /* New span created for element */ - /* Add new span tree as span */ - HDassert(tmp_span); - tmp_span->next=new_span; + /* Make span tree for current coordinate(s) */ + if(NULL == (new_span = H5S__hyper_coord_to_span(rank, coords))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab spans for coordinate") - /* Make scratch pointer point to last span in list */ - tspan_info->scratch=(H5S_hyper_span_info_t *)new_span; - - /* Set the proper 'pstride' for new span */ - new_span->pstride = new_span->low - tmp_span->low; + /* Add new span to span tree list */ + tail_span->next = new_span; + span_tree->tail = new_span; } /* end else */ + + /* Update high bound for current span tree */ + HDassert(coords[0] > span_tree->high_bounds[0]); + span_tree->high_bounds[0] = coords[0]; + + /* Update high bounds for dimensions below this one */ + for(u = 1; u < rank; u++) + if(coords[u] > span_tree->high_bounds[u]) + span_tree->high_bounds[u] = coords[u]; + + /* Need to signal to higher dimensions that high bounds changed */ + *first_dim_modified = 0; } /* end else */ done: @@ -5061,6 +5598,24 @@ done: GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS Assumes that the element is not already in the dataspace's selection + + NOTE: There's also an assumption about the context of this function call - + This function is only called is only being called from H5D_chunk_mem_cb + in src/H5Dchunk.c, when the library is iterating over a memory + selection, so the coordinates passed to H5S_hyper_add_span_element will + always be in increasing order (according to a row-major (i.e. C, not + FORTRAN) scan) over the dataset. Therefore, for every input of + coordinates, only the last span element (i.e., the tail pointer) in + one dimension is checked against the input. + + NOTE: This algorithm is definitely "correct" and tries to conserve memory + as much as possible, but it's doing a _lot_ of work that might be + better spent running a similar algorithm to "condense" the span tree + (possibly even back into a regular selection) just before the selection + is used for I/O on the chunk. I'm not going to spend the time on this + currently, but it does sound like a good direction to explore. + QAK, 2019/01/24 + EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ @@ -5080,9 +5635,13 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords) /* Check if this is the first element in the selection */ if(NULL == space->select.sel_info.hslab) { /* Allocate a span info node */ - if(NULL == (head = H5FL_CALLOC(H5S_hyper_span_info_t))) + if(NULL == (head = H5S__hyper_new_span_info(rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span info") + /* Set the low & high bounds for this span info node */ + HDmemcpy(head->low_bounds, coords, rank * sizeof(hsize_t)); + HDmemcpy(head->high_bounds, coords, rank * sizeof(hsize_t)); + /* Set the reference count */ head->count = 1; @@ -5090,6 +5649,9 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords) if(NULL == (head->head = H5S__hyper_coord_to_span(rank, coords))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab spans for coordinate") + /* Update the tail pointer of this newly created span in dimension "rank" */ + head->tail = head->head; + /* Allocate selection info */ if(NULL == (space->select.sel_info.hslab = H5FL_MALLOC(H5S_hyper_sel_t))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab selection") @@ -5101,7 +5663,7 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords) space->select.type = H5S_sel_hyper; /* Reset "regular" hyperslab flag */ - space->select.sel_info.hslab->diminfo_valid = FALSE; + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; /* Set unlim_dim */ space->select.sel_info.hslab->unlim_dim = -1; @@ -5110,7 +5672,10 @@ H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords) space->select.num_elem = 1; } /* end if */ else { - if(H5S__hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst, rank, coords) < 0) + int first_dim_modified = -1; /* Index of first dimension modified */ + + /* Add the element to the current set of spans */ + if(H5S__hyper_add_span_element_helper(space->select.sel_info.hslab->span_lst, rank, coords, &first_dim_modified) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert coordinate into span tree") /* Increment # of elements in selection */ @@ -5125,109 +5690,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_add_span_element() */ - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_reset_scratch - PURPOSE - Reset the scratch information for span tree - USAGE - herr_t H5S_hyper_reset_scratch(space) - H5S_t *space; IN/OUT: Pointer to dataspace to reset scratch pointers - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Resets the "scratch" pointers used for various tasks in computing hyperslab - spans. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5S_hyper_reset_scratch(H5S_t *space) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - HDassert(space); - - /* Check if there are spans in the span tree */ - if(space->select.sel_info.hslab->span_lst != NULL) - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(space->select.sel_info.hslab->span_lst); - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S_hyper_reset_scratch() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_convert - PURPOSE - Convert a compatible selection to span tree form - USAGE - herr_t H5S_hyper_convert(space) - H5S_t *space; IN/OUT: Pointer to dataspace to convert - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Converts a compatible selection (currently only "all" selections) to the - span-tree form of a hyperslab selection. (Point and "none" selection aren't - currently supported and hyperslab selection always have the span-tree form - available). - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5S_hyper_convert(H5S_t *space) -{ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(FAIL) - - HDassert(space); - - /* Check the type of selection */ - switch(H5S_GET_SELECT_TYPE(space)) { - case H5S_SEL_ALL: /* All elements selected in dataspace */ - /* Convert current "all" selection to "real" hyperslab selection */ - { - const hsize_t *tmp_start; /* Temporary start information */ - const hsize_t *tmp_stride; /* Temporary stride information */ - const hsize_t *tmp_count; /* Temporary count information */ - const hsize_t *tmp_block; /* Temporary block information */ - - /* Set up temporary information for the dimensions */ - tmp_start = H5S_hyper_zeros_g; - tmp_stride = tmp_count = H5S_hyper_ones_g; - tmp_block = space->extent.size; - - /* Convert to hyperslab selection */ - if(H5S_select_hyperslab(space,H5S_SELECT_SET,tmp_start,tmp_stride,tmp_count,tmp_block)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't convert selection") - } /* end case */ - break; - - case H5S_SEL_HYPERSLABS: /* Hyperslab selection */ - break; - - case H5S_SEL_NONE: /* No elements selected in dataspace */ - case H5S_SEL_POINTS: /* Point selection */ - case H5S_SEL_ERROR: /* Selection error */ - case H5S_SEL_N: /* Selection count */ - default: - HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "can't convert to span tree selection") - } /* end switch */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S_hyper_convert() */ - /*-------------------------------------------------------------------------- NAME @@ -5237,8 +5699,10 @@ done: USAGE hbool_t H5S__hyper_intersect_block_helper(spans, start, end) H5S_hyper_span_info_t *spans; IN: First span tree to operate with + unsigned rank; IN: Number of dimensions for span tree hsize_t *start; IN: Starting coordinate for block hsize_t *end; IN: Ending coordinate for block + uint64_t op_gen; IN: Operation generation RETURN Non-negative (TRUE/FALSE) on success, can't fail DESCRIPTION @@ -5249,10 +5713,9 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static hbool_t -H5S__hyper_intersect_block_helper(const H5S_hyper_span_info_t *spans, - const hsize_t *start, const hsize_t *end) +H5S__hyper_intersect_block_helper(H5S_hyper_span_info_t *spans, + unsigned rank, const hsize_t *start, const hsize_t *end, uint64_t op_gen) { - H5S_hyper_span_t *curr; /* Pointer to current span in 1st span tree */ hbool_t ret_value = FALSE; /* Return value */ FUNC_ENTER_STATIC_NOERR @@ -5262,37 +5725,52 @@ H5S__hyper_intersect_block_helper(const H5S_hyper_span_info_t *spans, HDassert(start); HDassert(end); - /* Get the span list for spans in this tree */ - curr = spans->head; + /* Check if we've already visited this span tree */ + if(spans->op_gen != op_gen) { + H5S_hyper_span_t *curr; /* Pointer to current span in 1st span tree */ + unsigned u; /* Local index variable */ - /* Iterate over the spans in the tree */ - while(curr != NULL) { - /* Check for span entirely before block */ - if(curr->high < *start) - /* Advance to next span in this dimension */ - curr = curr->next; - /* If this span is past the end of the block, then we're done in this dimension */ - else if(curr->low > *end) - HGOTO_DONE(FALSE) - /* block & span overlap */ - else { - if(curr->down == NULL) - HGOTO_DONE(TRUE) - else { - hbool_t status; /* Status from recursive call */ + /* Verify that there is a possibility of an overlap by checking the block + * against the low & high bounds for the span tree. + */ + for(u = 0; u < rank; u++) + if(start[u] > spans->high_bounds[u] || end[u] < spans->low_bounds[u]) + HGOTO_DONE(FALSE) - /* Recursively check spans in next dimension down */ - status = H5S__hyper_intersect_block_helper(curr->down, start + 1, end + 1); + /* Get the span list for spans in this tree */ + curr = spans->head; - /* If there is a span intersection in the down dimensions, the span trees overlap */ - if(status == TRUE) - HGOTO_DONE(TRUE); - - /* No intersection in down dimensions, advance to next span */ + /* Iterate over the spans in the tree */ + while(curr != NULL) { + /* Check for span entirely before block */ + if(curr->high < *start) + /* Advance to next span in this dimension */ curr = curr->next; + /* If this span is past the end of the block, then we're done in this dimension */ + else if(curr->low > *end) + HGOTO_DONE(FALSE) + /* block & span overlap */ + else { + /* If this is the bottom dimension, then the span tree overlaps the block */ + if(curr->down == NULL) + HGOTO_DONE(TRUE) + /* Recursively check spans in next dimension down */ + else { + /* If there is an intersection in the "down" dimensions, + * the span trees overlap. + */ + if(H5S__hyper_intersect_block_helper(curr->down, rank - 1, start + 1, end + 1, op_gen)) + HGOTO_DONE(TRUE) + + /* No intersection in down dimensions, advance to next span */ + curr = curr->next; + } /* end else */ } /* end else */ - } /* end else */ - } /* end while */ + } /* end while */ + + /* Set the tree's operation generation */ + spans->op_gen = op_gen; + } /* end if */ /* Fall through with 'FALSE' return value */ @@ -5317,33 +5795,130 @@ done: Quickly detect intersections between span tree and block GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS + Does not use selection offset. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ htri_t H5S_hyper_intersect_block(H5S_t *space, const hsize_t *start, const hsize_t *end) { + const hsize_t *low_bounds, *high_bounds; /* Pointers to the correct pair of low & high bounds */ + unsigned u; /* Local index variable */ htri_t ret_value = FAIL; /* Return value */ FUNC_ENTER_NOAPI(FAIL) /* Sanity check */ HDassert(space); + HDassert(H5S_SEL_HYPERSLABS == H5S_GET_SELECT_TYPE(space)); HDassert(start); HDassert(end); - /* Check for 'all' selection, instead of a hyperslab selection */ - /* (Technically, this shouldn't be in the "hyperslab" routines...) */ - if(H5S_GET_SELECT_TYPE(space) == H5S_SEL_ALL) - HGOTO_DONE(TRUE); + /* Attempt to rebuild diminfo if it is invalid and has not been confirmed + * to be impossible. + */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild(space); - /* Check that the space selection has a span tree */ - if(NULL == space->select.sel_info.hslab->span_lst) - if(H5S__hyper_generate_spans(space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") + /* Check which set of low & high bounds we should be using */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + low_bounds = space->select.sel_info.hslab->diminfo.low_bounds; + high_bounds = space->select.sel_info.hslab->diminfo.high_bounds; + } /* end if */ + else { + low_bounds = space->select.sel_info.hslab->span_lst->low_bounds; + high_bounds = space->select.sel_info.hslab->span_lst->high_bounds; + } /* end else */ - /* Perform the span-by-span intersection check */ - ret_value = H5S__hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst, start, end); + /* Loop over selection bounds and block, checking for overlap */ + for(u = 0; u < space->extent.rank; u++) + /* If selection bounds & block don't overlap, can leave now */ + if(!H5S_RANGE_OVERLAP(low_bounds[u], high_bounds[u], start[u], end[u])) + HGOTO_DONE(FALSE) + + /* Check for regular hyperslab intersection */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + hbool_t single_block; /* Whether the regular selection is a single block */ + + /* Check for a single block */ + /* For a regular hyperslab to be single, it must have only one block + * (i.e. count == 1 in all dimensions). + */ + single_block = TRUE; + for(u = 0; u < space->extent.rank; u++) + if(space->select.sel_info.hslab->diminfo.opt[u].count > 1) + single_block = FALSE; + + /* Single blocks have already been "compared" above, in the low / high + * bound checking, so just return TRUE if we've reached here - they + * would have been rejected earlier, if they didn't intersect. + */ + if(single_block) + HGOTO_DONE(TRUE) + else { + /* Loop over the dimensions, checking for an intersection */ + for(u = 0; u < space->extent.rank; u++) { + /* If the block's start is <= the hyperslab start, they intersect */ + /* (So, if the start is > the hyperslab start, check more conditions) */ + if(start[u] > space->select.sel_info.hslab->diminfo.opt[u].start) { + hsize_t adj_start; /* Start coord, adjusted for hyperslab selection parameters */ + hsize_t nstride; /* Number of strides into the selection */ + + /* Adjust start coord for selection's 'start' offset */ + adj_start = start[u] - space->select.sel_info.hslab->diminfo.opt[u].start; + + /* Compute # of strides into the selection */ + if(space->select.sel_info.hslab->diminfo.opt[u].count > 1) + nstride = adj_start / space->select.sel_info.hslab->diminfo.opt[u].stride; + else + nstride = 0; + + /* Sanity check */ + HDassert(nstride <= space->select.sel_info.hslab->diminfo.opt[u].count); + + /* "Rebase" the adjusted start coord into the same range + * range of values as the selections's first block. + */ + adj_start -= nstride * space->select.sel_info.hslab->diminfo.opt[u].stride; + + /* If the adjusted start doesn't fall within the first hyperslab + * span, check for the block overlapping with the next one. + */ + if(adj_start >= space->select.sel_info.hslab->diminfo.opt[u].block) { + hsize_t adj_end; /* End coord, adjusted for hyperslab selection parameters */ + + /* Adjust end coord for selection's 'start' offset */ + adj_end = end[u] - space->select.sel_info.hslab->diminfo.opt[u].start; + + /* "Rebase" the adjusted end coord into the same range + * range of values as the selections's first block. + */ + adj_end -= nstride * space->select.sel_info.hslab->diminfo.opt[u].stride; + + /* If block doesn't extend over beginning of next span, + * it doesn't intersect. + */ + if(adj_end < space->select.sel_info.hslab->diminfo.opt[u].stride) + HGOTO_DONE(FALSE) + } /* end if */ + } /* end if */ + } /* end for */ + + /* If we've looped through all dimensions and none of them didn't + * overlap, then all of them do, so we report TRUE. + */ + HGOTO_DONE(TRUE) + } /* end else */ + } /* end if */ + else { + uint64_t op_gen; /* Operation generation value */ + + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); + + /* Perform the span-by-span intersection check */ + ret_value = H5S__hyper_intersect_block_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, start, end, op_gen); + } /* end else */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -5358,7 +5933,9 @@ done: USAGE void H5S__hyper_adjust_u_helper(spans, offset) H5S_hyper_span_info_t *spans; IN: Span tree to operate with + unsigned rank; IN: Number of dimensions for span tree const hsize_t *offset; IN: Offset to subtract + uint64_t op_gen; IN: Operation generation RETURNS None DESCRIPTION @@ -5369,23 +5946,26 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static void -H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, - const hsize_t *offset) +H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, unsigned rank, + const hsize_t *offset, uint64_t op_gen) { FUNC_ENTER_STATIC_NOERR /* Sanity checks */ HDassert(spans); - HDassert(spans->scratch == (H5S_hyper_span_info_t *)~((size_t)NULL) || - spans->scratch == NULL); HDassert(offset); - /* Check if we've already set this down span tree */ - if(spans->scratch != (H5S_hyper_span_info_t *)~((size_t)NULL)) { + /* Check if we've already set this span tree */ + if(spans->op_gen != op_gen) { H5S_hyper_span_t *span; /* Pointer to current span in span tree */ + unsigned u; /* Local index variable */ - /* Set the tree's scratch pointer */ - spans->scratch = (H5S_hyper_span_info_t *)~((size_t)NULL); + /* Adjust the span tree's low & high bounds */ + for(u = 0; u < rank; u++) { + HDassert(spans->low_bounds[u] >= offset[u]); + spans->low_bounds[u] -= offset[u]; + spans->high_bounds[u] -= offset[u]; + } /* end for */ /* Iterate over the spans in tree */ span = spans->head; @@ -5397,11 +5977,14 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, /* Recursively adjust spans in next dimension down */ if(span->down != NULL) - H5S__hyper_adjust_u_helper(span->down, offset + 1); + H5S__hyper_adjust_u_helper(span->down, rank - 1, offset + 1, op_gen); /* Advance to next span in this dimension */ span = span->next; } /* end while */ + + /* Set the tree's operation generation */ + spans->op_gen = op_gen; } /* end if */ FUNC_LEAVE_NOAPI_VOID @@ -5436,21 +6019,29 @@ H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset) HDassert(offset); /* Subtract the offset from the "regular" coordinates, if they exist */ - if(space->select.sel_info.hslab->diminfo_valid) { + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { unsigned u; /* Local index variable */ for(u = 0; u < space->extent.rank; u++) { - HDassert(space->select.sel_info.hslab->opt_diminfo[u].start >= offset[u]); - space->select.sel_info.hslab->opt_diminfo[u].start -= offset[u]; + HDassert(space->select.sel_info.hslab->diminfo.opt[u].start >= offset[u]); + space->select.sel_info.hslab->diminfo.opt[u].start -= offset[u]; + + /* Adjust the low & high bounds */ + HDassert(space->select.sel_info.hslab->diminfo.low_bounds[u] >= offset[u]); + space->select.sel_info.hslab->diminfo.low_bounds[u] -= offset[u]; + space->select.sel_info.hslab->diminfo.high_bounds[u] -= offset[u]; } /* end for */ } /* end if */ /* Subtract the offset from the span tree coordinates, if they exist */ if(space->select.sel_info.hslab->span_lst) { - H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, offset); + uint64_t op_gen; /* Operation generation value */ - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(space->select.sel_info.hslab->span_lst); + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); + + H5S__hyper_adjust_u_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, op_gen); } /* end if */ FUNC_LEAVE_NOAPI(SUCCEED) @@ -5482,12 +6073,20 @@ H5S__hyper_project_scalar(const H5S_t *space, hsize_t *offset) HDassert(offset); /* Check for a "regular" hyperslab selection */ - if(space->select.sel_info.hslab->diminfo_valid) { - const H5S_hyper_dim_t *diminfo = space->select.sel_info.hslab->opt_diminfo; /* Alias for dataspace's diminfo information */ + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + const H5S_hyper_dim_t *diminfo = space->select.sel_info.hslab->diminfo.opt; /* Alias for dataspace's diminfo information */ unsigned u; /* Counter */ /* Build the table of the initial offset */ for(u = 0; u < space->extent.rank; u++) { + /* Sanity check diminfo */ + HDassert(1 == diminfo[u].count); + HDassert(1 == diminfo[u].block); + + /* Sanity check bounds, while we're here */ + HDassert(diminfo[u].start == space->select.sel_info.hslab->diminfo.low_bounds[u]); + /* Keep the offset for later */ block[u] = diminfo[u].start; } /* end for */ @@ -5499,17 +6098,22 @@ H5S__hyper_project_scalar(const H5S_t *space, hsize_t *offset) /* Advance down selected spans */ curr = space->select.sel_info.hslab->span_lst->head; curr_dim = 0; - while(curr) { - /* Sanity check for more than one span */ + while(1) { + /* Sanity checks */ HDassert(NULL == curr->next); HDassert(curr->low == curr->high); + HDassert(curr_dim < space->extent.rank); /* Save the location of the selection in current dimension */ block[curr_dim] = curr->low; /* Advance down to next dimension */ - curr = curr->down->head; - curr_dim++; + if(curr->down) { + curr = curr->down->head; + curr_dim++; + } /* end if */ + else + break; } /* end while */ } /* end else */ @@ -5586,6 +6190,7 @@ H5S__hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space) H5S_hyper_span_t *prev_span = NULL; /* Pointer to previous list of spans */ unsigned delta_rank; /* Difference in dataspace ranks */ unsigned curr_dim; /* Current dimension being operated on */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -5604,10 +6209,9 @@ H5S__hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space) H5S_hyper_span_t *new_span; /* Temporary hyperslab span */ /* Allocate a new span_info node */ - if(NULL == (new_span_info = H5FL_CALLOC(H5S_hyper_span_info_t))) { + if(NULL == (new_span_info = H5S__hyper_new_span_info(new_space->extent.rank))) { if(prev_span) - if(H5S__hyper_free_span(prev_span) < 0) - HERROR(H5E_DATASPACE, H5E_CANTFREE, "can't free hyperslab span"); + H5S__hyper_free_span(prev_span); HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span info") } /* end if */ @@ -5619,13 +6223,24 @@ H5S__hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space) if(NULL == (new_span = H5S__hyper_new_span((hsize_t)0, (hsize_t)0, NULL, NULL))) { HDassert(new_span_info); if(!prev_span) - (void)H5FL_FREE(H5S_hyper_span_info_t, new_span_info); + (void)H5FL_ARR_FREE(hbounds_t, new_span_info); HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") } /* end if */ /* Set the span_info information */ new_span_info->count = 1; new_span_info->head = new_span; + new_span_info->tail = new_span; + + /* Set the bounding box */ + for(u = 0; u < delta_rank; u++) { + new_span_info->low_bounds[u] = 0; + new_span_info->high_bounds[u] = 0; + } /* end for */ + for(; u < new_space->extent.rank; u++) { + new_span_info->low_bounds[u] = base_space->select.sel_info.hslab->span_lst->low_bounds[u - delta_rank]; + new_span_info->high_bounds[u] = base_space->select.sel_info.hslab->span_lst->high_bounds[u - delta_rank]; + } /* end for */ /* Attach to new space, if top span info */ if(NULL == new_space->select.sel_info.hslab->span_lst) @@ -5647,10 +6262,9 @@ H5S__hyper_project_simple_higher(const H5S_t *base_space, H5S_t *new_space) done: if(ret_value < 0 && new_space->select.sel_info.hslab->span_lst) { if(new_space->select.sel_info.hslab->span_lst->head) - if(H5S__hyper_free_span(new_space->select.sel_info.hslab->span_lst->head) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't free hyperslab span") + H5S__hyper_free_span(new_space->select.sel_info.hslab->span_lst->head); - new_space->select.sel_info.hslab->span_lst = H5FL_FREE(H5S_hyper_span_info_t, new_space->select.sel_info.hslab->span_lst); + new_space->select.sel_info.hslab->span_lst = (H5S_hyper_span_info_t *)H5FL_ARR_FREE(hbounds_t, new_space->select.sel_info.hslab->span_lst); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) @@ -5695,15 +6309,16 @@ H5S__hyper_project_simple(const H5S_t *base_space, H5S_t *new_space, new_space->select.sel_info.hslab->unlim_dim = -1; /* Check for a "regular" hyperslab selection */ - if(base_space->select.sel_info.hslab->diminfo_valid) { + /* (No need to rebuild the dimension info yet -QAK) */ + if(base_space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { unsigned base_space_dim; /* Current dimension in the base dataspace */ unsigned new_space_dim; /* Current dimension in the new dataspace */ + unsigned u; /* Local index variable */ /* Check if the new space's rank is < or > base space's rank */ if(new_space->extent.rank < base_space->extent.rank) { - const H5S_hyper_dim_t *opt_diminfo = base_space->select.sel_info.hslab->opt_diminfo; /* Alias for dataspace's diminfo information */ + const H5S_hyper_dim_t *opt_diminfo = base_space->select.sel_info.hslab->diminfo.opt; /* Alias for dataspace's diminfo information */ hsize_t block[H5S_MAX_RANK]; /* Block selected in base dataspace */ - unsigned u; /* Local index variable */ /* Compute the offset for the down-projection */ HDmemset(block, 0, sizeof(block)); @@ -5723,15 +6338,15 @@ H5S__hyper_project_simple(const H5S_t *base_space, H5S_t *new_space, /* Set the diminfo information for the higher dimensions */ for(new_space_dim = 0; new_space_dim < (new_space->extent.rank - base_space->extent.rank); new_space_dim++) { - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].start = 0; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].stride = 1; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].count = 1; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].block = 1; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].start = 0; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].stride = 1; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].count = 1; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].block = 1; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].start = 0; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].stride = 1; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].count = 1; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].block = 1; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].start = 0; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].stride = 1; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].count = 1; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].block = 1; } /* end for */ /* Start at beginning of base space's dimension info */ @@ -5740,31 +6355,37 @@ H5S__hyper_project_simple(const H5S_t *base_space, H5S_t *new_space, /* Copy the diminfo */ while(base_space_dim < base_space->extent.rank) { - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].start = - base_space->select.sel_info.hslab->app_diminfo[base_space_dim].start; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].stride = - base_space->select.sel_info.hslab->app_diminfo[base_space_dim].stride; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].count = - base_space->select.sel_info.hslab->app_diminfo[base_space_dim].count; - new_space->select.sel_info.hslab->app_diminfo[new_space_dim].block = - base_space->select.sel_info.hslab->app_diminfo[base_space_dim].block; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].start = + base_space->select.sel_info.hslab->diminfo.app[base_space_dim].start; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].stride = + base_space->select.sel_info.hslab->diminfo.app[base_space_dim].stride; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].count = + base_space->select.sel_info.hslab->diminfo.app[base_space_dim].count; + new_space->select.sel_info.hslab->diminfo.app[new_space_dim].block = + base_space->select.sel_info.hslab->diminfo.app[base_space_dim].block; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].start = - base_space->select.sel_info.hslab->opt_diminfo[base_space_dim].start; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].stride = - base_space->select.sel_info.hslab->opt_diminfo[base_space_dim].stride; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].count = - base_space->select.sel_info.hslab->opt_diminfo[base_space_dim].count; - new_space->select.sel_info.hslab->opt_diminfo[new_space_dim].block = - base_space->select.sel_info.hslab->opt_diminfo[base_space_dim].block; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].start = + base_space->select.sel_info.hslab->diminfo.opt[base_space_dim].start; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].stride = + base_space->select.sel_info.hslab->diminfo.opt[base_space_dim].stride; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].count = + base_space->select.sel_info.hslab->diminfo.opt[base_space_dim].count; + new_space->select.sel_info.hslab->diminfo.opt[new_space_dim].block = + base_space->select.sel_info.hslab->diminfo.opt[base_space_dim].block; /* Advance to next dimensions */ base_space_dim++; new_space_dim++; } /* end for */ + /* Update the bounding box */ + for(u = 0; u < new_space->extent.rank; u++) { + new_space->select.sel_info.hslab->diminfo.low_bounds[u] = new_space->select.sel_info.hslab->diminfo.opt[u].start; + new_space->select.sel_info.hslab->diminfo.high_bounds[u] = new_space->select.sel_info.hslab->diminfo.low_bounds[u] + new_space->select.sel_info.hslab->diminfo.opt[u].stride * (new_space->select.sel_info.hslab->diminfo.opt[u].count - 1) + (new_space->select.sel_info.hslab->diminfo.opt[u].block - 1); + } /* end for */ + /* Indicate that the dimension information is valid */ - new_space->select.sel_info.hslab->diminfo_valid = TRUE; + new_space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_YES; /* Indicate that there's no slab information */ new_space->select.sel_info.hslab->span_lst = NULL; @@ -5809,8 +6430,8 @@ H5S__hyper_project_simple(const H5S_t *base_space, H5S_t *new_space, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't project hyperslab selection into less dimensions") } /* end else */ - /* Indicate that the dimension information is not valid */ - new_space->select.sel_info.hslab->diminfo_valid = FALSE; + /* Copy the status of the dimension information */ + new_space->select.sel_info.hslab->diminfo_valid = base_space->select.sel_info.hslab->diminfo_valid; } /* end else */ /* Number of elements selected will be the same */ @@ -5832,7 +6453,9 @@ done: USAGE void H5S__hyper_adjust_s_helper(spans, offset) H5S_hyper_span_info_t *spans; IN: Span tree to operate with + unsigned rank; IN: Number of dimensions for span tree const hssize_t *offset; IN: Offset to subtract + uint64_t op_gen; IN: Operation generation RETURNS None DESCRIPTION @@ -5843,23 +6466,26 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static void -H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, - const hssize_t *offset) +H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, unsigned rank, + const hssize_t *offset, uint64_t op_gen) { FUNC_ENTER_STATIC_NOERR /* Sanity checks */ HDassert(spans); - HDassert(spans->scratch == (H5S_hyper_span_info_t *)~((size_t)NULL) || - spans->scratch == NULL); HDassert(offset); - /* Check if we've already set this down span tree */ - if(spans->scratch != (H5S_hyper_span_info_t *)~((size_t)NULL)) { + /* Check if we've already set this span tree */ + if(spans->op_gen != op_gen) { H5S_hyper_span_t *span; /* Pointer to current span in span tree */ + unsigned u; /* Local index variable */ - /* Set the tree's scratch pointer */ - spans->scratch = (H5S_hyper_span_info_t *)~((size_t)NULL); + /* Adjust the span tree's low & high bounds */ + for(u = 0; u < rank; u++) { + HDassert((hssize_t)spans->low_bounds[u] >= offset[u]); + spans->low_bounds[u] = (hsize_t)((hssize_t)spans->low_bounds[u] - offset[u]); + spans->high_bounds[u] = (hsize_t)((hssize_t)spans->high_bounds[u] - offset[u]); + } /* end for */ /* Iterate over the spans in tree */ span = spans->head; @@ -5871,11 +6497,14 @@ H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, /* Recursively adjust spans in next dimension down */ if(span->down != NULL) - H5S__hyper_adjust_s_helper(span->down, offset + 1); + H5S__hyper_adjust_s_helper(span->down, rank - 1, offset + 1, op_gen); /* Advance to next span in this dimension */ span = span->next; } /* end while */ + + /* Set the tree's operation generation */ + spans->op_gen = op_gen; } /* end if */ FUNC_LEAVE_NOAPI_VOID @@ -5903,6 +6532,8 @@ H5S__hyper_adjust_s_helper(H5S_hyper_span_info_t *spans, herr_t H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset) { + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -5911,22 +6542,38 @@ H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset) HDassert(space); HDassert(offset); - /* Subtract the offset from the "regular" coordinates, if they exist */ - if(space->select.sel_info.hslab->diminfo_valid) { - unsigned u; /* Local index variable */ + /* Check for an all-zero offset vector */ + for(u = 0; u < space->extent.rank; u++) + if(0 != offset[u]) { + non_zero_offset = TRUE; + break; + } /* end if */ - for(u = 0; u < space->extent.rank; u++) { - HDassert((hssize_t)space->select.sel_info.hslab->opt_diminfo[u].start >= offset[u]); - space->select.sel_info.hslab->opt_diminfo[u].start = (hsize_t)((hssize_t)space->select.sel_info.hslab->opt_diminfo[u].start - offset[u]); - } /* end for */ - } /* end if */ + /* Only perform operation if the offset is non-zero */ + if(non_zero_offset) { + /* Subtract the offset from the "regular" coordinates, if they exist */ + /* (No need to rebuild the dimension info yet -QAK) */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + for(u = 0; u < space->extent.rank; u++) { + HDassert((hssize_t)space->select.sel_info.hslab->diminfo.opt[u].start >= offset[u]); + space->select.sel_info.hslab->diminfo.opt[u].start = (hsize_t)((hssize_t)space->select.sel_info.hslab->diminfo.opt[u].start - offset[u]); - /* Subtract the offset from the span tree coordinates, if they exist */ - if(space->select.sel_info.hslab->span_lst) { - H5S__hyper_adjust_s_helper(space->select.sel_info.hslab->span_lst, offset); + /* Adjust the low & high bounds */ + HDassert((hssize_t)space->select.sel_info.hslab->diminfo.low_bounds[u] >= offset[u]); + space->select.sel_info.hslab->diminfo.low_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.hslab->diminfo.low_bounds[u] - offset[u]); + space->select.sel_info.hslab->diminfo.high_bounds[u] = (hsize_t)((hssize_t)space->select.sel_info.hslab->diminfo.high_bounds[u] - offset[u]); + } /* end for */ + } /* end if */ - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(space->select.sel_info.hslab->span_lst); + /* Subtract the offset from the span tree coordinates, if they exist */ + if(space->select.sel_info.hslab->span_lst) { + uint64_t op_gen; /* Operation generation value */ + + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); + + H5S__hyper_adjust_s_helper(space->select.sel_info.hslab->span_lst, space->extent.rank, offset, op_gen); + } /* end if */ } /* end if */ done: @@ -6042,12 +6689,11 @@ done: PURPOSE Create a new span and append to span list USAGE - herr_t H5S__hyper_append_span(prev_span, span_tree, low, high, down, next) - H5S_hyper_span_t **prev_span; IN/OUT: Pointer to previous span in list + herr_t H5S__hyper_append_span(span_tree, ndims, low, high, down) H5S_hyper_span_info_t **span_tree; IN/OUT: Pointer to span tree to append to - hsize_t low, high; IN: Low and high bounds for new span node + unsigned ndims; IN: Number of dimension for span + hsize_t low, high; IN: Low and high bounds for new span node H5S_hyper_span_info_t *down; IN: Down span tree for new node - H5S_hyper_span_t *next; IN: Next span for new node RETURNS Non-negative on success, negative on failure DESCRIPTION @@ -6059,81 +6705,117 @@ done: REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_append_span(H5S_hyper_span_t **prev_span, - H5S_hyper_span_info_t **span_tree, hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, H5S_hyper_span_t *next) +H5S__hyper_append_span(H5S_hyper_span_info_t **span_tree, unsigned ndims, + hsize_t low, hsize_t high, H5S_hyper_span_info_t *down) { H5S_hyper_span_t *new_span = NULL; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC - HDassert(prev_span); + /* Sanity check */ HDassert(span_tree); /* Check for adding first node to merged spans */ - if(*prev_span == NULL) { + if(*span_tree == NULL) { /* Allocate new span node to append to list */ - if(NULL == (new_span = H5S__hyper_new_span(low, high, down, next))) + if(NULL == (new_span = H5S__hyper_new_span(low, high, down, NULL))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") - /* Make first node in span list */ - - /* Check that we haven't already allocated a span tree */ - HDassert(*span_tree == NULL); + /* Make new span the first node in span list */ /* Allocate a new span_info node */ - if(NULL == (*span_tree = H5FL_CALLOC(H5S_hyper_span_info_t))) + if(NULL == (*span_tree = H5S__hyper_new_span_info(ndims))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") /* Set the span tree's basic information */ (*span_tree)->count = 1; (*span_tree)->head = new_span; + (*span_tree)->tail = new_span; - /* Update previous merged span */ - *prev_span = new_span; + /* Set low & high bounds for new span tree */ + (*span_tree)->low_bounds[0] = low; + (*span_tree)->high_bounds[0] = high; + if(down) { + /* Sanity check */ + HDassert(ndims > 1); + + HDmemcpy(&((*span_tree)->low_bounds[1]), down->low_bounds, sizeof(hsize_t) * (ndims - 1)); + HDmemcpy(&((*span_tree)->high_bounds[1]), down->high_bounds, sizeof(hsize_t) * (ndims - 1)); + } /* end if */ } /* end if */ /* Merge or append to existing merged spans list */ else { + htri_t down_cmp = (-1); /* Comparison value for down spans */ + /* Check if span can just extend the previous merged span */ - if((((*prev_span)->high + 1) == low) && - H5S__hyper_cmp_spans(down, (*prev_span)->down)==TRUE) { + if((((*span_tree)->tail->high + 1) == low) && + (down_cmp = H5S__hyper_cmp_spans(down, (*span_tree)->tail->down))) { /* Extend previous merged span to include new high bound */ - (*prev_span)->high = high; - (*prev_span)->nelem += (high - low) + 1; + (*span_tree)->tail->high = high; + + /* Extend span tree's high bound in this dimension */ + /* (No need to update lower dimensions, since this span shares them with previous span) */ + (*span_tree)->high_bounds[0] = high; } /* end if */ else { - /* Allocate new span node to append to list */ - if(NULL == (new_span = H5S__hyper_new_span(low, high, down, next))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") + H5S_hyper_span_info_t *new_down; /* Down pointer for new span node */ + + /* Sanity check */ + /* (If down_cmp was set to TRUE above, we won't be in this branch) */ + HDassert(down_cmp != TRUE); /* Check if there is actually a down span */ - if(new_span->down) { + if(down) { /* Check if the down spans for the new span node are the same as the previous span node */ - if(H5S__hyper_cmp_spans(new_span->down, (*prev_span)->down)) { - /* Release the down span for the new node */ - H5S__hyper_free_span_info(new_span->down); + /* (Uses the 'down span comparison' from earlier, if already computed) */ + if(down_cmp < 0 && (down_cmp = H5S__hyper_cmp_spans(down, (*span_tree)->tail->down))) + /* Share the previous span's down span tree */ + new_down = (*span_tree)->tail->down; + else + new_down = down; + } /* end if */ + else + new_down = NULL; - /* Point the new node's down span at the previous node's down span */ - new_span->down = (*prev_span)->down; + /* Allocate new span node to append to list */ + if(NULL == (new_span = H5S__hyper_new_span(low, high, new_down, NULL))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") - /* Increment the reference count to the shared down span */ - new_span->down->count++; + /* Update the high bounds for current dimension */ + (*span_tree)->high_bounds[0] = high; + + /* Update low & high bounds in lower dimensions, if there are any */ + if(down) { + /* Sanity checks */ + HDassert(ndims > 1); + HDassert(down_cmp >= 0); + + /* Check if we are sharing down spans with a previous node */ + /* (Only need to check for bounds changing if down spans aren't shared) */ + if(down_cmp == FALSE) { + unsigned u; /* Local index variable */ + + /* Loop over lower dimensions, checking & updating low & high bounds */ + for(u = 0; u < (ndims - 1); u++) { + if(down->low_bounds[u] < (*span_tree)->low_bounds[u + 1]) + (*span_tree)->low_bounds[u + 1] = down->low_bounds[u]; + if(down->high_bounds[u] > (*span_tree)->high_bounds[u + 1]) + (*span_tree)->high_bounds[u + 1] = down->high_bounds[u]; + } /* end for */ } /* end if */ } /* end if */ - /* Indicate elements from previous span */ - new_span->pstride = low - (*prev_span)->low; - /* Append to end of merged spans list */ - (*prev_span)->next = new_span; - *prev_span = new_span; + (*span_tree)->tail->next = new_span; + (*span_tree)->tail = new_span; } /* end else */ } /* end else */ done: if(ret_value < 0) - if(new_span && H5S__hyper_free_span(new_span) < 0) - HDONE_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "failed to release new hyperslab span") + if(new_span) + H5S__hyper_free_span(new_span); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_append_span() */ @@ -6145,9 +6827,18 @@ done: PURPOSE Clip a new span tree against the current spans in the hyperslab selection USAGE - herr_t H5S__hyper_clip_spans(span_a, span_b, a_not_b, a_and_b, b_not_a) + herr_t H5S__hyper_clip_spans(span_a, span_b, selector, curr_dim, dim_size, + span_a_b_bounds[4], all_clips_bound, + a_not_b, a_and_b, b_not_a) H5S_hyper_span_t *a_spans; IN: Span tree 'a' to clip with. H5S_hyper_span_t *b_spans; IN: Span tree 'b' to clip with. + unsigned selector; IN: The parameter deciding which output is needed + (only considering the last three bits ABC: + If A is set, then a_not_b is needed; + If B is set, then a_and_b is needed; + If C is set, then b_not_a is needed; + ) + unsigned ndims; IN: Number of dimensions of this span tree H5S_hyper_span_t **a_not_b; OUT: Span tree of 'a' hyperslab spans which doesn't overlap with 'b' hyperslab spans. @@ -6172,20 +6863,14 @@ done: --------------------------------------------------------------------------*/ static herr_t H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_spans, + unsigned selector, unsigned ndims, H5S_hyper_span_info_t **a_not_b, H5S_hyper_span_info_t **a_and_b, H5S_hyper_span_info_t **b_not_a) { - H5S_hyper_span_t *span_a; /* Pointer to a node in span tree 'a' */ - H5S_hyper_span_t *span_b; /* Pointer to a node in span tree 'b' */ - H5S_hyper_span_t *tmp_span; /* Temporary pointer to new span */ - H5S_hyper_span_t *last_a_not_b; /* Pointer to previous node in span tree 'a_not_b' */ - H5S_hyper_span_t *last_a_and_b; /* Pointer to previous node in span tree 'a_and_b' */ - H5S_hyper_span_t *last_b_not_a; /* Pointer to previous node in span tree 'b_not_a' */ - H5S_hyper_span_info_t *down_a_not_b; /* Temporary pointer to a_not_b span tree of down spans for overlapping nodes */ - H5S_hyper_span_info_t *down_a_and_b; /* Temporary pointer to a_and_b span tree of down spans for overlapping nodes */ - H5S_hyper_span_info_t *down_b_not_a; /* Temporary pointer to b_and_a span tree of down spans for overlapping nodes */ - hbool_t recover_a, recover_b; /* Flags to indicate when to recover temporary spans */ - herr_t ret_value = SUCCEED; /* Return value */ + hbool_t need_a_not_b; /* Whether to generate a_not_b list */ + hbool_t need_a_and_b; /* Whether to generate a_and_b list */ + hbool_t need_b_not_a; /* Whether to generate b_not_a list */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -6196,6 +6881,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s HDassert(a_and_b); HDassert(b_not_a); + /* Set which list(s) to be generated, based on selector */ + need_a_not_b = ((selector & H5S_HYPER_COMPUTE_A_NOT_B) != 0); + need_a_and_b = ((selector & H5S_HYPER_COMPUTE_A_AND_B) != 0); + need_b_not_a = ((selector & H5S_HYPER_COMPUTE_B_NOT_A) != 0); + /* Check if both span trees are not defined */ if(a_spans == NULL && b_spans == NULL) { *a_not_b = NULL; @@ -6206,38 +6896,56 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s else if(a_spans == NULL) { *a_not_b = NULL; *a_and_b = NULL; - if(NULL == (*b_not_a = H5S__hyper_copy_span(b_spans))) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") + if(need_b_not_a) { + if(NULL == (*b_not_a = H5S__hyper_copy_span(b_spans, ndims))) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") + } /* end if */ + else + *b_not_a = NULL; } /* end if */ /* If span 'b' is not defined, but 'a' is, copy 'a' and set the other return span trees to empty */ else if(b_spans == NULL) { - if(NULL == (*a_not_b = H5S__hyper_copy_span(a_spans)) ) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") *a_and_b = NULL; *b_not_a = NULL; + if(need_a_not_b) { + if(NULL == (*a_not_b = H5S__hyper_copy_span(a_spans, ndims))) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") + } /* end if */ + else + *a_not_b = NULL; } /* end if */ /* If span 'a' and 'b' are both defined, calculate the proper span trees */ else { /* Check if both span trees completely overlap */ if(H5S__hyper_cmp_spans(a_spans, b_spans)) { *a_not_b = NULL; - if(NULL == (*a_and_b = H5S__hyper_copy_span(a_spans))) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") *b_not_a = NULL; + if(need_a_and_b) { + if(NULL == (*a_and_b = H5S__hyper_copy_span(a_spans, ndims))) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, FAIL, "can't copy hyperslab span tree") + } /* end if */ + else + *a_and_b = NULL; } /* end if */ else { + H5S_hyper_span_t *span_a; /* Pointer to a node in span tree 'a' */ + H5S_hyper_span_t *span_b; /* Pointer to a node in span tree 'b' */ + hbool_t recover_a, recover_b; /* Flags to indicate when to recover temporary spans */ + /* Get the pointers to the new and old span lists */ span_a = a_spans->head; span_b = b_spans->head; - /* Reset the pointers to the previous spans */ - last_a_not_b = last_a_and_b = last_b_not_a = NULL; - /* No spans to recover yet */ recover_a = recover_b = FALSE; /* Work through the list of spans in the new list */ while(span_a != NULL && span_b != NULL) { + H5S_hyper_span_info_t *down_a_not_b; /* Temporary pointer to a_not_b span tree of down spans for overlapping nodes */ + H5S_hyper_span_info_t *down_a_and_b; /* Temporary pointer to a_and_b span tree of down spans for overlapping nodes */ + H5S_hyper_span_info_t *down_b_not_a; /* Temporary pointer to b_and_a span tree of down spans for overlapping nodes */ + H5S_hyper_span_t *tmp_span; /* Temporary pointer to new span */ + /* Check if span 'a' is completely before span 'b' */ /* AAAAAAA */ /* <-----------------------------------> */ @@ -6246,11 +6954,12 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Copy span 'a' and add to a_not_b list */ /* Merge/add span 'a' with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b, a_not_b, span_a->low, span_a->high, span_a->down, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_not_b) + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Advance span 'a', leave span 'b' */ - H5S__hyper_recover_span(&recover_a, &span_a, span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); } /* end if */ /* Check if span 'a' overlaps only the lower bound */ /* of span 'b' , up to the upper bound of span 'b' */ @@ -6261,8 +6970,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Split span 'a' into two parts at the low bound of span 'b' */ /* Merge/add lower part of span 'a' with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b, a_not_b, span_a->low, span_b->low - 1, span_a->down, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_not_b) + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_b->low - 1, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Check for overlaps between upper part of span 'a' and lower part of span 'b' */ @@ -6272,8 +6982,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* If there are no down spans, just add the overlapping area to the a_and_b list */ if(span_a->down == NULL) { /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b, a_and_b, span_b->low, span_a->high, NULL, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_and_b) + if(H5S__hyper_append_span(a_and_b, ndims, span_b->low, span_a->high, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ /* If there are down spans, check for the overlap in them and add to each appropriate list */ else { @@ -6283,14 +6994,20 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s down_b_not_a = NULL; /* Check for overlaps in the 'down spans' of span 'a' & 'b' */ - if(H5S__hyper_clip_spans(span_a->down,span_b->down,&down_a_not_b,&down_a_and_b,&down_b_not_a)<0) + /** Note: since the bound box of remaining dimensions + * has been updated in the following clip function (via + * all_clips_bounds), there's no need updating the bound box + * after each append call in the following codes */ + if(H5S__hyper_clip_spans(span_a->down, span_b->down, selector, ndims - 1, &down_a_not_b, &down_a_and_b, &down_b_not_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") /* Check for additions to the a_not_b list */ if(down_a_not_b) { + HDassert(need_a_not_b == TRUE); + /* Merge/add overlapped part with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_b->low,span_a->high,down_a_not_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_not_b, ndims, span_b->low, span_a->high, down_a_not_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_not_b); @@ -6298,9 +7015,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check for additions to the a_and_b list */ if(down_a_and_b) { + HDassert(need_a_and_b == TRUE); + /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_b->low,span_a->high,down_a_and_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_and_b, ndims, span_b->low, span_a->high, down_a_and_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_and_b); @@ -6308,9 +7027,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check for additions to the b_not_a list */ if(down_b_not_a) { + HDassert(need_b_not_a == TRUE); + /* Merge/add overlapped part with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_a->high,down_b_not_a,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_a->high, down_b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_b_not_a); @@ -6326,17 +7047,17 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s HGOTO_ERROR(H5E_DATASPACE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") /* Advance span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); /* Make upper part of span 'b' into new span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, tmp_span); recover_b = TRUE; } /* end if */ /* No upper part of span 'b' to split */ else { /* Advance both 'a' and 'b' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end if */ /* Check if span 'a' overlaps the lower & upper bound */ @@ -6348,8 +7069,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Split off lower part of span 'a' at lower span of span 'b' */ /* Merge/add lower part of span 'a' with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_a->low,span_b->low-1,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_not_b) + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_b->low - 1, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Check for overlaps between middle part of span 'a' and span 'b' */ @@ -6359,8 +7081,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* If there are no down spans, just add the overlapping area to the a_and_b list */ if(span_a->down == NULL) { /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_b->low,span_b->high,NULL,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_and_b) + if(H5S__hyper_append_span(a_and_b, ndims, span_b->low, span_b->high, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ /* If there are down spans, check for the overlap in them and add to each appropriate list */ else { @@ -6370,14 +7093,16 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s down_b_not_a = NULL; /* Check for overlaps in the 'down spans' of span 'a' & 'b' */ - if(H5S__hyper_clip_spans(span_a->down,span_b->down,&down_a_not_b,&down_a_and_b,&down_b_not_a)<0) + if(H5S__hyper_clip_spans(span_a->down, span_b->down, selector, ndims - 1, &down_a_not_b, &down_a_and_b, &down_b_not_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") /* Check for additions to the a_not_b list */ if(down_a_not_b) { + HDassert(need_a_not_b == TRUE); + /* Merge/add overlapped part with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_b->low,span_b->high,down_a_not_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_not_b, ndims, span_b->low, span_b->high, down_a_not_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_not_b); @@ -6385,9 +7110,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check for additions to the a_and_b list */ if(down_a_and_b) { + HDassert(need_a_and_b == TRUE); + /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_b->low,span_b->high,down_a_and_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_and_b, ndims, span_b->low, span_b->high, down_a_and_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_and_b); @@ -6395,9 +7122,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check for additions to the b_not_a list */ if(down_b_not_a) { + HDassert(need_b_not_a == TRUE); + /* Merge/add overlapped part with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_b->high,down_b_not_a,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_b->high, down_b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_b_not_a); @@ -6411,11 +7140,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s HGOTO_ERROR(H5E_DATASPACE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") /* Make upper part of span 'a' the new span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, tmp_span); recover_a = TRUE; /* Advance span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end if */ /* Check if span 'a' is entirely within span 'b' */ /* AAAAA */ @@ -6427,8 +7156,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check if there is actually a lower part of span 'b' to split off */ if(span_a->low > span_b->low) { /* Merge/add lower part of span 'b' with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_a->low-1,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_b_not_a) + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_a->low - 1, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ else { /* Keep going, nothing to split off */ @@ -6442,8 +7172,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* If there are no down spans, just add the overlapping area to the a_and_b list */ if(span_a->down == NULL) { /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_a->low,span_a->high,NULL,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_and_b) + if(H5S__hyper_append_span(a_and_b, ndims, span_a->low, span_a->high, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ /* If there are down spans, check for the overlap in them and add to each appropriate list */ else { @@ -6453,34 +7184,40 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s down_b_not_a = NULL; /* Check for overlaps in the 'down spans' of span 'a' & 'b' */ - if(H5S__hyper_clip_spans(span_a->down,span_b->down,&down_a_not_b,&down_a_and_b,&down_b_not_a)<0) + if(H5S__hyper_clip_spans(span_a->down, span_b->down, selector, ndims - 1, &down_a_not_b, &down_a_and_b, &down_b_not_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") /* Check for additions to the a_not_b list */ if(down_a_not_b) { + HDassert(need_a_not_b == TRUE); + /* Merge/add overlapped part with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_a->low,span_a->high,down_a_not_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_a->high, down_a_not_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_not_b); } /* end if */ /* Check for additions to the a_and_b list */ - if(down_a_and_b!=NULL) { + if(down_a_and_b) { + HDassert(need_a_and_b == TRUE); + /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_a->low,span_a->high,down_a_and_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_and_b, ndims, span_a->low, span_a->high, down_a_and_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_and_b); } /* end if */ /* Check for additions to the b_not_a list */ - if(down_b_not_a!=NULL) { + if(down_b_not_a) { + HDassert(need_b_not_a == TRUE); + /* Merge/add overlapped part with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_a->low,span_a->high,down_b_not_a,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(b_not_a, ndims, span_a->low, span_a->high, down_b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_b_not_a); @@ -6496,16 +7233,16 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") /* And advance span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); /* Make upper part of span 'b' the new span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,tmp_span); - recover_b=1; + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, tmp_span); + recover_b = TRUE; } /* end if */ else { /* Advance both span 'a' & span 'b' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end if */ /* Check if span 'a' overlaps only the upper bound */ @@ -6519,8 +7256,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Split off lower part of span 'b' at lower span of span 'a' */ /* Merge/add lower part of span 'b' with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_a->low-1,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_b_not_a) + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_a->low - 1, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ else { /* Keep going, nothing to split off */ @@ -6534,8 +7272,9 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* If there are no down spans, just add the overlapping area to the a_and_b list */ if(span_a->down == NULL) { /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_a->low,span_b->high,NULL,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_a_and_b) + if(H5S__hyper_append_span(a_and_b, ndims, span_a->low, span_b->high, NULL) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") } /* end if */ /* If there are down spans, check for the overlap in them and add to each appropriate list */ else { @@ -6545,24 +7284,28 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s down_b_not_a = NULL; /* Check for overlaps in the 'down spans' of span 'a' & 'b' */ - if(H5S__hyper_clip_spans(span_a->down,span_b->down,&down_a_not_b,&down_a_and_b,&down_b_not_a)<0) + if(H5S__hyper_clip_spans(span_a->down, span_b->down, selector, ndims - 1, &down_a_not_b, &down_a_and_b, &down_b_not_a) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") /* Check for additions to the a_not_b list */ if(down_a_not_b) { + HDassert(need_a_not_b == TRUE); + /* Merge/add overlapped part with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_a->low,span_b->high,down_a_not_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_b->high, down_a_not_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_not_b); } /* end if */ /* Check for additions to the a_and_b list */ - if(down_a_and_b!=NULL) { + if(down_a_and_b) { + HDassert(need_a_and_b == TRUE); + /* Merge/add overlapped part with/to a_and_b list */ - if(H5S__hyper_append_span(&last_a_and_b,a_and_b,span_a->low,span_b->high,down_a_and_b,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(a_and_b, ndims, span_a->low, span_b->high, down_a_and_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_a_and_b); @@ -6570,9 +7313,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Check for additions to the b_not_a list */ if(down_b_not_a) { + HDassert(need_b_not_a == TRUE); + /* Merge/add overlapped part with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_a->low,span_b->high,down_b_not_a,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(b_not_a, ndims, span_a->low, span_b->high, down_b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Release the down span tree generated */ H5S__hyper_free_span_info(down_b_not_a); @@ -6586,11 +7331,11 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") /* Make upper part of span 'a' into new span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,tmp_span); - recover_a=1; + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, tmp_span); + recover_a = TRUE; /* Advance span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end if */ /* span 'a' must be entirely above span 'b' */ /* AAAAA */ @@ -6600,40 +7345,70 @@ H5S__hyper_clip_spans(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_s /* Copy span 'b' and add to b_not_a list */ /* Merge/add span 'b' with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_b->high,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") + if(need_b_not_a) + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_b->high, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Advance span 'b', leave span 'a' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end while */ /* Clean up 'a' spans which haven't been covered yet */ if(span_a != NULL && span_b == NULL) { - while(span_a != NULL) { - /* Copy span 'a' and add to a_not_b list */ + /* Check if need to merge/add 'a' spans with/to a_not_b list */ + if(need_a_not_b) { + /* (This loop, and the similar one below for 'b' spans, + * could be replaced with an optimized routine that quickly + * appended the remaining spans to the 'not' list, but + * until it looks like it's taking a lot of time for an + * important use case, it's been left generic, and similar + * to other code above. -QAK, 2019/02/01) + */ + while(span_a != NULL) { + /* Copy span 'a' and add to a_not_b list */ + if(H5S__hyper_append_span(a_not_b, ndims, span_a->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - /* Merge/add span 'a' with/to a_not_b list */ - if(H5S__hyper_append_span(&last_a_not_b,a_not_b,span_a->low,span_a->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - - /* Advance to the next 'a' span */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); - } /* end while */ + /* Advance to the next 'a' span */ + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); + } /* end while */ + } /* end if */ + else { + /* Free the span, if it's generated */ + if(recover_a) + H5S__hyper_free_span(span_a); + } /* end else */ } /* end if */ /* Clean up 'b' spans which haven't been covered yet */ else if(span_a == NULL && span_b != NULL) { - while(span_b != NULL) { - /* Copy span 'b' and add to b_not_a list */ + /* Check if need to merge/add 'b' spans with/to b_not_a list */ + if(need_b_not_a) { + /* (This loop, and the similar one above for 'a' spans, + * could be replaced with an optimized routine that quickly + * appended the remaining spans to the 'not' list, but + * until it looks like it's taking a lot of time for an + * important use case, it's been left generic, and similar + * to other code above. -QAK, 2019/02/01) + */ + while(span_b != NULL) { + /* Copy span 'b' and add to b_not_a list */ + if(H5S__hyper_append_span(b_not_a, ndims, span_b->low, span_b->high, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - /* Merge/add span 'b' with/to b_not_a list */ - if(H5S__hyper_append_span(&last_b_not_a,b_not_a,span_b->low,span_b->high,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") - - /* Advance to the next 'b' span */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); - } /* end while */ + /* Advance to the next 'b' span */ + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); + } /* end while */ + } /* end if */ + else { + /* Free the span, if it's generated */ + if(recover_b) + H5S__hyper_free_span(span_b); + } /* end else */ } /* end if */ + else + /* Sanity check */ + HDassert(span_a == NULL && span_b == NULL); } /* end else */ } /* end else */ @@ -6653,6 +7428,7 @@ done: together H5S_hyper_span_info_t *b_spans; IN: Second hyperslab spans to merge together + unsigned ndims; IN: Number of dimensions of this span tree RETURNS Pointer to span tree containing the merged spans on success, NULL on failure DESCRIPTION @@ -6660,11 +7436,13 @@ done: the merged set. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS + Handles merging span trees that overlap. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ static H5S_hyper_span_info_t * -H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_spans) +H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_info_t *b_spans, + unsigned ndims) { H5S_hyper_span_info_t *merged_spans = NULL; /* Pointer to the merged span tree */ H5S_hyper_span_info_t *ret_value = NULL; /* Return value */ @@ -6680,23 +7458,19 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf merged_spans = NULL; else { /* Copy one of the span trees to return */ - if(NULL == (merged_spans = H5S__hyper_copy_span(a_spans))) + if(NULL == (merged_spans = H5S__hyper_copy_span(a_spans, ndims))) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTCOPY, NULL, "can't copy hyperslab span tree") } /* end else */ } /* end if */ else { H5S_hyper_span_t *span_a; /* Pointer to current span 'a' working on */ H5S_hyper_span_t *span_b; /* Pointer to current span 'b' working on */ - H5S_hyper_span_t *prev_span_merge; /* Pointer to previous merged span */ hbool_t recover_a, recover_b; /* Flags to indicate when to recover temporary spans */ /* Get the pointers to the 'a' and 'b' span lists */ span_a = a_spans->head; span_b = b_spans->head; - /* Set the pointer to the previous spans */ - prev_span_merge = NULL; - /* No spans to recover yet */ recover_a = recover_b = FALSE; @@ -6711,11 +7485,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* BBBBBBBBBB */ if(span_a->high < span_b->low) { /* Merge/add span 'a' with/to the merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_a->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Advance span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); } /* end if */ /* Check if span 'a' overlaps only the lower bound */ /* of span 'b', up to the upper bound of span 'b' */ @@ -6726,20 +7500,20 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* Check if span 'a' and span 'b' down spans are equal */ if(H5S__hyper_cmp_spans(span_a->down, span_b->down)) { /* Merge/add copy of span 'a' with/to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_a->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* Merge/add lower part of span 'a' with/to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_b->low-1,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_b->low - 1, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Get merged span tree for overlapped section */ - tmp_spans = H5S__hyper_merge_spans_helper(span_a->down,span_b->down); + tmp_spans = H5S__hyper_merge_spans_helper(span_a->down, span_b->down, ndims - 1); /* Merge/add overlapped section to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_a->high,tmp_spans,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_a->high, tmp_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Release merged span tree for overlapped section */ H5S__hyper_free_span_info(tmp_spans); @@ -6750,20 +7524,20 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* Copy upper part of span 'b' as new span 'b' */ /* Allocate new span node to append to list */ - if((tmp_span = H5S__hyper_new_span(span_a->high+1,span_b->high,span_b->down,span_b->next))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "can't allocate hyperslab span") + if(NULL == (tmp_span = H5S__hyper_new_span(span_a->high + 1, span_b->high, span_b->down, span_b->next))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Advance span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); /* Set new span 'b' to tmp_span */ - H5S__hyper_recover_span(&recover_b,&span_b,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, tmp_span); recover_b = TRUE; } /* end if */ else { /* Advance both span 'a' & 'b' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end if */ /* Check if span 'a' overlaps the lower & upper bound */ @@ -6775,20 +7549,20 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* Check if span 'a' and span 'b' down spans are equal */ if(H5S__hyper_cmp_spans(span_a->down, span_b->down)) { /* Merge/add copy of lower & middle parts of span 'a' to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_b->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_b->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* Merge/add lower part of span 'a' to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_b->low-1,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_b->low - 1, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Get merged span tree for overlapped section */ - tmp_spans = H5S__hyper_merge_spans_helper(span_a->down,span_b->down); + tmp_spans = H5S__hyper_merge_spans_helper(span_a->down, span_b->down, ndims - 1); /* Merge/add overlapped section to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_b->high,tmp_spans,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_b->high, tmp_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Release merged span tree for overlapped section */ H5S__hyper_free_span_info(tmp_spans); @@ -6801,11 +7575,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Set new span 'a' to tmp_span */ - H5S__hyper_recover_span(&recover_a,&span_a,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, tmp_span); recover_a = TRUE; /* Advance span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end if */ /* Check if span 'a' is entirely within span 'b' */ /* AAAAA */ @@ -6815,26 +7589,26 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* Check if span 'a' and span 'b' down spans are equal */ if(H5S__hyper_cmp_spans(span_a->down, span_b->down)) { /* Merge/add copy of lower & middle parts of span 'b' to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_a->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* Check if there is a lower part of span 'b' */ if(span_a->low > span_b->low) { /* Merge/add lower part of span 'b' to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_a->low-1,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_a->low - 1, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* No lower part of span 'b' , keep going... */ } /* end else */ /* Get merged span tree for overlapped section */ - tmp_spans = H5S__hyper_merge_spans_helper(span_a->down,span_b->down); + tmp_spans = H5S__hyper_merge_spans_helper(span_a->down, span_b->down, ndims - 1); /* Merge/add overlapped section to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_a->high,tmp_spans,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_a->high, tmp_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Release merged span tree for overlapped section */ H5S__hyper_free_span_info(tmp_spans); @@ -6849,16 +7623,16 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Advance span 'a' */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); /* Set new span 'b' to tmp_span */ - H5S__hyper_recover_span(&recover_b,&span_b,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, tmp_span); recover_b = TRUE; } /* end if */ else { /* Advance both spans */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end if */ /* Check if span 'a' overlaps only the upper bound */ @@ -6870,26 +7644,26 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* Check if span 'a' and span 'b' down spans are equal */ if(H5S__hyper_cmp_spans(span_a->down, span_b->down)) { /* Merge/add copy of span 'b' to merged spans if so */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_b->high,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_b->high, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* Check if there is a lower part of span 'b' */ if(span_a->low > span_b->low) { /* Merge/add lower part of span 'b' to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_a->low-1,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_a->low - 1, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") } /* end if */ else { /* No lower part of span 'b' , keep going... */ } /* end else */ /* Get merged span tree for overlapped section */ - tmp_spans = H5S__hyper_merge_spans_helper(span_a->down,span_b->down); + tmp_spans = H5S__hyper_merge_spans_helper(span_a->down, span_b->down, ndims - 1); /* Merge/add overlapped section to merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_b->high,tmp_spans,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_b->high, tmp_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Release merged span tree for overlapped section */ H5S__hyper_free_span_info(tmp_spans); @@ -6902,11 +7676,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Set new span 'a' to tmp_span */ - H5S__hyper_recover_span(&recover_a,&span_a,tmp_span); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, tmp_span); recover_a = TRUE; /* Advance span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end if */ /* Span 'a' must be entirely above span 'b' */ /* AAAAA */ @@ -6914,11 +7688,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf /* BBBBBBBBBB */ else { /* Merge/add span 'b' with the merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_b->high,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_b->high, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Advance span 'b' */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end else */ } /* end while */ @@ -6926,11 +7700,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf if(span_a != NULL && span_b == NULL) { while(span_a != NULL) { /* Merge/add all 'a' spans into the merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_a->low,span_a->high,span_a->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_a->low, span_a->high, span_a->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Advance to next 'a' span, until all processed */ - H5S__hyper_recover_span(&recover_a,&span_a,span_a->next); + H5S_HYPER_ADVANCE_SPAN(recover_a, span_a, span_a->next); } /* end while */ } /* end if */ @@ -6938,11 +7712,11 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf if(span_a == NULL && span_b != NULL) { while(span_b != NULL) { /* Merge/add all 'b' spans into the merged spans */ - if(H5S__hyper_append_span(&prev_span_merge,&merged_spans,span_b->low,span_b->high,span_b->down,NULL)==FAIL) - HGOTO_ERROR(H5E_RESOURCE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") + if(H5S__hyper_append_span(&merged_spans, ndims, span_b->low, span_b->high, span_b->down) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, NULL, "can't allocate hyperslab span") /* Advance to next 'b' span, until all processed */ - H5S__hyper_recover_span(&recover_b,&span_b,span_b->next); + H5S_HYPER_ADVANCE_SPAN(recover_b, span_b, span_b->next); } /* end while */ } /* end if */ } /* end else */ @@ -6952,8 +7726,8 @@ H5S__hyper_merge_spans_helper(H5S_hyper_span_info_t *a_spans, H5S_hyper_span_inf done: if(ret_value == NULL) - if(merged_spans && H5S__hyper_free_span_info(merged_spans) < 0) - HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, NULL, "failed to release merged hyperslab spans") + if(merged_spans) + H5S__hyper_free_span_info(merged_spans); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_merge_spans_helper() */ @@ -6970,44 +7744,37 @@ done: selection. H5S_hyper_span_t *new_spans; IN: Span tree of new spans to add to hyperslab selection - hbool_t can_own; IN: Flag to indicate that it is OK to point - directly to the new spans, instead of - copying them. RETURNS non-negative on success, negative on failure DESCRIPTION - Add a set of hyperslab spans to an existing hyperslab selection. The - new spans are required to be non-overlapping with the existing spans in - the dataspace's current hyperslab selection. + Add a set of hyperslab spans to an existing hyperslab selection. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans, hbool_t can_own) +H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans) { - FUNC_ENTER_STATIC_NOERR + herr_t ret_value = SUCCEED; /* Return value */ - /* Check args */ + FUNC_ENTER_STATIC + + /* Sanity checks */ HDassert(space); HDassert(new_spans); /* If this is the first span tree in the hyperslab selection, just use it */ if(space->select.sel_info.hslab->span_lst == NULL) { - if(can_own) - space->select.sel_info.hslab->span_lst = new_spans; - else - space->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(new_spans); + space->select.sel_info.hslab->span_lst = new_spans; + space->select.sel_info.hslab->span_lst->count++; } /* end if */ else { H5S_hyper_span_info_t *merged_spans; /* Get the merged spans */ - merged_spans = H5S__hyper_merge_spans_helper(space->select.sel_info.hslab->span_lst, new_spans); - - /* Sanity checking since we started with some spans, we should still have some after the merge */ - HDassert(merged_spans); + if(NULL == (merged_spans = H5S__hyper_merge_spans_helper(space->select.sel_info.hslab->span_lst, new_spans, space->extent.rank))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTMERGE, FAIL, "can't merge hyperslab spans") /* Free the previous spans */ H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst); @@ -7016,9 +7783,81 @@ H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans, hbool_t c space->select.sel_info.hslab->span_lst = merged_spans; } /* end else */ - FUNC_LEAVE_NOAPI(SUCCEED) +done: + FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_merge_spans() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_spans_nelem_helper + PURPOSE + Count the number of elements in a span tree + USAGE + hsize_t H5S__hyper_spans_nelem_helper(spans, op_gen) + const H5S_hyper_span_info_t *spans; IN: Hyperslan span tree to count elements of + uint64_t op_gen; IN: Operation generation + RETURNS + Number of elements in span tree on success; negative on failure + DESCRIPTION + Counts the number of elements described by the spans in a span tree. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static hsize_t +H5S__hyper_spans_nelem_helper(H5S_hyper_span_info_t *spans, uint64_t op_gen) +{ + hsize_t ret_value = 0; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity check */ + HDassert(spans); + + /* Check if the span tree was already counted */ + if(spans->op_gen == op_gen) + /* Just return the # of elements in the already counted span tree */ + ret_value = spans->u.nelmts; + else { /* Count the number of elements in the span tree */ + const H5S_hyper_span_t *span; /* Hyperslab span */ + + span = spans->head; + if(NULL == span->down) { + while(span != NULL) { + /* Compute # of elements covered */ + ret_value += (span->high - span->low) + 1; + + /* Advance to next span */ + span = span->next; + } /* end while */ + } /* end if */ + else { + while(span != NULL) { + hsize_t nelmts; /* # of elements covered by current span */ + + /* Compute # of elements covered */ + nelmts = (span->high - span->low) + 1; + + /* Multiply the size of this span by the total down span elements */ + ret_value += nelmts * H5S__hyper_spans_nelem_helper(span->down, op_gen); + + /* Advance to next span */ + span = span->next; + } /* end while */ + } /* end else */ + + /* Set the operation generation for this span tree, to avoid re-computing */ + spans->op_gen = op_gen; + + /* Hold a copy of the # of elements */ + spans->u.nelmts = ret_value; + } /* end else */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_spans_nelem_helper() */ + /*-------------------------------------------------------------------------- NAME @@ -7038,33 +7877,74 @@ H5S__hyper_merge_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans, hbool_t c REVISION LOG --------------------------------------------------------------------------*/ static hsize_t -H5S__hyper_spans_nelem(const H5S_hyper_span_info_t *spans) +H5S__hyper_spans_nelem(H5S_hyper_span_info_t *spans) { - hsize_t ret_value = 0; /* Return value */ + uint64_t op_gen; /* Operation generation value */ + hsize_t ret_value = 0; /* Return value */ FUNC_ENTER_STATIC_NOERR + /* Sanity check */ + HDassert(spans); + + /* Acquire an operation generation value for this operation */ + op_gen = H5S__hyper_get_op_gen(); + /* Count the number of elements in the span tree */ - if(spans != NULL) { - const H5S_hyper_span_t *span; /* Hyperslab span */ - - span = spans->head; - while(span != NULL) { - /* If there are down spans, multiply the size of this span by the total down span elements */ - if(span->down != NULL) - ret_value += span->nelem * H5S__hyper_spans_nelem(span->down); - /* If there are no down spans, just count the elements in this span */ - else - ret_value += span->nelem; - - /* Advance to next span */ - span = span->next; - } /* end while */ - } /* end else */ + ret_value = H5S__hyper_spans_nelem_helper(spans, op_gen); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_spans_nelem() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_add_disjoint_spans + PURPOSE + Add new hyperslab spans to existing hyperslab selection in the case the + new hyperslab spans don't overlap with the existing hyperslab selection + USAGE + herr_t H5S__hyper_add_disjoint_spans(space, new_spans) + H5S_t *space; IN: Dataspace to add new spans to hyperslab + selection. + H5S_hyper_span_t *new_spans; IN: Span tree of new spans to add to + hyperslab selection + RETURNS + Non-negative on success, negative on failure + DESCRIPTION + Add a set of hyperslab spans to an existing hyperslab selection. The + new spans are required not to overlap with the existing spans in the + dataspace's current hyperslab selection in terms of bound box. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__hyper_add_disjoint_spans(H5S_t *space, H5S_hyper_span_info_t *new_spans) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check args */ + HDassert(space); + HDassert(new_spans); + + /* Update the number of elements in the selection */ + space->select.num_elem += H5S__hyper_spans_nelem(new_spans); + + /* Add the new spans to the existing selection in the dataspace */ + if(H5S__hyper_merge_spans(space, new_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't merge hyperslabs") + + /* Free the memory space for new spans */ + H5S__hyper_free_span_info(new_spans); + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_add_disjoint_spans */ + /*-------------------------------------------------------------------------- NAME @@ -7098,9 +7978,7 @@ H5S__hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride H5S_hyper_span_info_t *down = NULL; /* Pointer to spans in next dimension down */ H5S_hyper_span_t *last_span; /* Current position in hyperslab span list */ H5S_hyper_span_t *head = NULL; /* Head of new hyperslab span list */ - hsize_t stride_iter; /* Iterator over the stride values */ int i; /* Counters */ - unsigned u; /* Counters */ H5S_hyper_span_info_t *ret_value = NULL; /* Return value */ FUNC_ENTER_STATIC @@ -7114,6 +7992,9 @@ H5S__hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride /* Start creating spans in fastest changing dimension */ for(i = (int)(rank - 1); i >= 0; i--) { + hsize_t curr_low, curr_high; /* Current low & high values */ + hsize_t dim_stride; /* Current dim's stride */ + unsigned u; /* Local index variable */ /* Sanity check */ if(0 == count[i]) @@ -7124,8 +8005,10 @@ H5S__hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride last_span = NULL; /* Generate all the span segments for this dimension */ - for(u = 0, stride_iter = 0; u < count[i]; u++, stride_iter += stride[i]) - { + curr_low = start[i]; + curr_high = start[i] + (block[i] - 1); + dim_stride = stride[i]; + for(u = 0; u < count[i]; u++, curr_low += dim_stride, curr_high += dim_stride) { H5S_hyper_span_t *span; /* New hyperslab span */ /* Allocate a span node */ @@ -7133,12 +8016,14 @@ H5S__hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Set the span's basic information */ - span->low = start[i] + stride_iter; - span->high = span->low + (block[i] - 1); - span->nelem = block[i]; - span->pstride = stride[i]; + span->low = curr_low; + span->high = curr_high; span->next = NULL; + /* Set the information for the next dimension down's spans */ + /* (Will be NULL for fastest changing dimension) */ + span->down = down; + /* Append to the list of spans in this dimension */ if(head == NULL) head = span; @@ -7147,23 +8032,32 @@ H5S__hyper_make_spans(unsigned rank, const hsize_t *start, const hsize_t *stride /* Move current pointer */ last_span = span; - - /* Set the information for the next dimension down's spans, if appropriate */ - if(down != NULL) { - span->down = down; - down->count++; /* Increment reference count for shared span */ - } /* end if */ - else - span->down = NULL; } /* end for */ + /* Increment ref. count of shared span */ + if(down != NULL) + down->count = (unsigned)count[i]; + /* Allocate a span info node */ - if(NULL == (down = H5FL_CALLOC(H5S_hyper_span_info_t))) + if(NULL == (down = H5S__hyper_new_span_info(rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate hyperslab span") /* Keep the pointer to the next dimension down's completed list */ down->head = head; + /* Keep the tail pointer to the next dimension down's completed list */ + down->tail = last_span; + + /* Set the low & high bounds for this dimension */ + down->low_bounds[0] = down->head->low; + down->high_bounds[0] = down->tail->high; + + /* Copy bounds from lower dimensions */ + /* (head & tail pointers share lower dimensions, so using either is OK) */ + if(head->down) { + HDmemcpy(&down->low_bounds[1], &head->down->low_bounds[0], sizeof(hsize_t) * ((rank - 1) - (unsigned)i)); + HDmemcpy(&down->high_bounds[1], &head->down->high_bounds[0], sizeof(hsize_t) * ((rank - 1) - (unsigned)i)); + } /* end if */ } /* end for */ /* Indicate that there is a pointer to this tree */ @@ -7184,7 +8078,7 @@ done: do { if(down) { head = down->head; - down = H5FL_FREE(H5S_hyper_span_info_t, down); + down = (H5S_hyper_span_info_t *)H5FL_ARR_FREE(hbounds_t, down); } /* end if */ down = head->down; @@ -7200,6 +8094,224 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_make_spans() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__hyper_update_diminfo + PURPOSE + Attempt to update optimized hyperslab information quickly. (It can be + recovered with regular selection). If this algorithm cannot determine + the optimized dimension info quickly, this function will simply mark it + as invalid and unknown if it can be built (H5S_DIMINFO_VALID_NO), so + H5S__hyper_rebuild can be run later to determine for sure. + USAGE + herr_t H5S__hyper_update_diminfo(space, op, new_hyper_diminfo) + H5S_t *space; IN: Dataspace to check + H5S_seloper_t op; IN: The operation being performed on the + selection + const H5S_hyper_dim_t new_hyper_diminfo; IN: The new selection that + is being combined with + the current + RETURNS + >=0 on success, <0 on failure + DESCRIPTION + Examine the span tree for a hyperslab selection and rebuild + the start/stride/count/block information for the selection, if possible. + + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__hyper_update_diminfo(H5S_t *space, H5S_seloper_t op, + const H5S_hyper_dim_t *new_hyper_diminfo) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Check args */ + HDassert(space); + HDassert(new_hyper_diminfo); + + /* Check for conditions that prevent us from using the fast algorithm here */ + /* (and instead require H5S__hyper_rebuild) */ + if(!((op == H5S_SELECT_OR) || (op == H5S_SELECT_XOR)) + || space->select.sel_info.hslab->diminfo_valid != H5S_DIMINFO_VALID_YES + || !space->select.sel_info.hslab->span_lst->head) + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + else { + H5S_hyper_dim_t tmp_diminfo[H5S_MAX_RANK]; /* Temporary dimension info */ + hbool_t found_nonidentical_dim = FALSE; + unsigned curr_dim; + + /* Copy current diminfo.opt values */ + HDmemcpy(tmp_diminfo, space->select.sel_info.hslab->diminfo.opt, sizeof(tmp_diminfo)); + + /* Loop over dimensions */ + for(curr_dim = 0; curr_dim < space->extent.rank; curr_dim++) { + /* Check for this being identical */ + if((tmp_diminfo[curr_dim].start != new_hyper_diminfo[curr_dim].start) + || (tmp_diminfo[curr_dim].stride != new_hyper_diminfo[curr_dim].stride) + || (tmp_diminfo[curr_dim].count != new_hyper_diminfo[curr_dim].count) + || (tmp_diminfo[curr_dim].block != new_hyper_diminfo[curr_dim].block)) { + hsize_t high_start, high_count, high_block; /* The start, count & block values for the higher block */ + + /* Dimension is not identical */ + /* Check if we already found a nonidentical dim - only one is + * allowed */ + if(found_nonidentical_dim) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Check that strides are the same, or count is 1 for one of the + * slabs */ + if((tmp_diminfo[curr_dim].stride != new_hyper_diminfo[curr_dim].stride) + && (tmp_diminfo[curr_dim].count > 1) + && (new_hyper_diminfo[curr_dim].count > 1)) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Patch tmp_diminfo.stride if its count is 1 */ + if((tmp_diminfo[curr_dim].count == 1) + && (new_hyper_diminfo[curr_dim].count > 1)) + tmp_diminfo[curr_dim].stride = new_hyper_diminfo[curr_dim].stride; + + /* Determine lowest start, and set tmp_diminfo.start, count and + * block to use the lowest, and high_start, high_count and + * high_block to use the highest + */ + if(tmp_diminfo[curr_dim].start < new_hyper_diminfo[curr_dim].start) { + high_start = new_hyper_diminfo[curr_dim].start; + high_count = new_hyper_diminfo[curr_dim].count; + high_block = new_hyper_diminfo[curr_dim].block; + } /* end if */ + else { + high_start = tmp_diminfo[curr_dim].start; + tmp_diminfo[curr_dim].start = new_hyper_diminfo[curr_dim].start; + high_count = tmp_diminfo[curr_dim].count; + tmp_diminfo[curr_dim].count = new_hyper_diminfo[curr_dim].count; + high_block = tmp_diminfo[curr_dim].block; + tmp_diminfo[curr_dim].block = new_hyper_diminfo[curr_dim].block; + } /* end else */ + + /* If count is 1 for both slabs, take different actions */ + if((tmp_diminfo[curr_dim].count == 1) && (high_count == 1)) { + /* Check for overlap */ + if((tmp_diminfo[curr_dim].start + tmp_diminfo[curr_dim].block) + > high_start) { + /* Check operation type */ + if(op == H5S_SELECT_OR) + /* Merge blocks */ + tmp_diminfo[curr_dim].block = ((high_start + high_block) + >= (tmp_diminfo[curr_dim].start + tmp_diminfo[curr_dim].block)) + ? (high_start + high_block - tmp_diminfo[curr_dim].start) + : tmp_diminfo[curr_dim].block; + else { + /* Block values must be the same */ + if(tmp_diminfo[curr_dim].block != high_block) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* XOR - overlap creates 2 blocks */ + tmp_diminfo[curr_dim].stride = high_block; + tmp_diminfo[curr_dim].count = 2; + tmp_diminfo[curr_dim].block = high_start - tmp_diminfo[curr_dim].start; + } /* end else */ + } /* end if */ + else if((tmp_diminfo[curr_dim].start + tmp_diminfo[curr_dim].block) + == high_start) + /* Blocks border, merge them */ + tmp_diminfo[curr_dim].block += high_block; + else { + /* Distinct blocks */ + /* Block values must be the same */ + if(tmp_diminfo[curr_dim].block != high_block) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Create strided selection */ + tmp_diminfo[curr_dim].stride = high_start - tmp_diminfo[curr_dim].start; + tmp_diminfo[curr_dim].count = 2; + } /* end else */ + } /* end if */ + else { + /* Check if block values are the same */ + if(tmp_diminfo[curr_dim].block != new_hyper_diminfo[curr_dim].block) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Check phase of strides */ + if((tmp_diminfo[curr_dim].start % tmp_diminfo[curr_dim].stride) + != (new_hyper_diminfo[curr_dim].start % tmp_diminfo[curr_dim].stride)) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Check operation type */ + if(op == H5S_SELECT_OR) { + /* Make sure the slabs border or overlap */ + if(high_start > (tmp_diminfo[curr_dim].start + + (tmp_diminfo[curr_dim].count + * tmp_diminfo[curr_dim].stride))) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + } /* end if */ + else + /* XOR: Make sure the slabs border */ + if(high_start != (tmp_diminfo[curr_dim].start + + (tmp_diminfo[curr_dim].count + * tmp_diminfo[curr_dim].stride))) { + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + break; + } /* end if */ + + /* Set count for combined selection */ + tmp_diminfo[curr_dim].count = ((high_start + - tmp_diminfo[curr_dim].start) + / tmp_diminfo[curr_dim].stride) + high_count; + } /* end else */ + + /* Indicate that we found a nonidentical dim */ + found_nonidentical_dim = TRUE; + } /* end if */ + } /* end for */ + + /* Check if we succeeded, if so, set the new diminfo values */ + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) + for(curr_dim = 0; curr_dim < space->extent.rank; curr_dim++) { + hsize_t tmp_high_bound; + + /* Set the new diminfo values */ + space->select.sel_info.hslab->diminfo.app[curr_dim].start = space->select.sel_info.hslab->diminfo.opt[curr_dim].start = tmp_diminfo[curr_dim].start; + HDassert(tmp_diminfo[curr_dim].stride > 0); + space->select.sel_info.hslab->diminfo.app[curr_dim].stride = space->select.sel_info.hslab->diminfo.opt[curr_dim].stride = tmp_diminfo[curr_dim].stride; + HDassert(tmp_diminfo[curr_dim].count > 0); + space->select.sel_info.hslab->diminfo.app[curr_dim].count = space->select.sel_info.hslab->diminfo.opt[curr_dim].count = tmp_diminfo[curr_dim].count; + HDassert(tmp_diminfo[curr_dim].block > 0); + space->select.sel_info.hslab->diminfo.app[curr_dim].block = space->select.sel_info.hslab->diminfo.opt[curr_dim].block = tmp_diminfo[curr_dim].block; + + /* Check for updating the low & high bounds */ + if(tmp_diminfo[curr_dim].start < space->select.sel_info.hslab->diminfo.low_bounds[curr_dim]) + space->select.sel_info.hslab->diminfo.low_bounds[curr_dim] = tmp_diminfo[curr_dim].start; + tmp_high_bound = tmp_diminfo[curr_dim].start + + (tmp_diminfo[curr_dim].block - 1) + + (tmp_diminfo[curr_dim].stride * (tmp_diminfo[curr_dim].count - 1)); + if(tmp_high_bound > space->select.sel_info.hslab->diminfo.low_bounds[curr_dim]) + space->select.sel_info.hslab->diminfo.high_bounds[curr_dim] = tmp_high_bound; + } /* end for */ + } /* end else */ + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__hyper_update_diminfo() */ + /*-------------------------------------------------------------------------- NAME @@ -7212,6 +8324,7 @@ done: const H5S_hyper_span_t *span; IN: Portion of span tree to check H5S_hyper_dim_t span_slab[]; OUT: Rebuilt section of hyperslab description unsigned rank; IN: Current dimension to work on + uint64_t op_gen; IN: Operation generation RETURNS TRUE/FALSE for hyperslab selection rebuilt DESCRIPTION @@ -7226,108 +8339,85 @@ done: KY, 2005/9/22 --------------------------------------------------------------------------*/ static hbool_t -H5S__hyper_rebuild_helper(const H5S_hyper_span_t *span, H5S_hyper_dim_t span_slab_info[], - unsigned rank) +H5S__hyper_rebuild_helper(const H5S_hyper_span_info_t *spans, H5S_hyper_dim_t span_slab_info[]) { + const H5S_hyper_span_t *span; /* Hyperslab span */ + const H5S_hyper_span_t *prev_span; /* Previous span in list */ + hsize_t start; /* Starting element for this dimension */ + hsize_t stride; /* Stride for this dimension */ + hsize_t block; /* Block size for this dimension */ + hsize_t prev_low; /* Low bound for previous span */ + size_t spancount; /* Number of spans encountered in this dimension */ hbool_t ret_value = TRUE; /* Return value */ FUNC_ENTER_STATIC_NOERR - if(span) { - const H5S_hyper_span_t *prev_span = NULL; /* Previous span in list */ - H5S_hyper_dim_t canon_down_span_slab_info[H5S_MAX_RANK]; - hsize_t curr_stride; - hsize_t curr_block; - hsize_t curr_start; - hsize_t curr_low; - size_t outcount; /* Number of spans encountered in this dimension */ + /* Sanity check */ + HDassert(spans); - /* Initialization */ - curr_stride = 1; - curr_low = 0; - outcount = 0; + /* Initialization */ + span = spans->head; + stride = 1; + prev_low = 0; + spancount = 0; - /* Get "canonical" down span information */ - if(span->down) { - HDassert(span->down->head); + /* Get "canonical" down span information */ + if(span->down) + /* Go to the next down span and check whether the selection can be rebuilt */ + if(!H5S__hyper_rebuild_helper(span->down, &span_slab_info[1])) + HGOTO_DONE(FALSE) - /* Go to the next down span and check whether the selection can be rebuilt */ - if(!H5S__hyper_rebuild_helper(span->down->head, span_slab_info, rank - 1)) + /* Assign the initial starting point & block size for this dimension */ + start = span->low; + block = (span->high - span->low) + 1; + + /* Loop the spans */ + prev_span = NULL; + while(span) { + if(spancount > 0) { + hsize_t curr_stride; /* Current stride from previous span */ + hsize_t curr_block; /* Block size of current span */ + + /* Sanity check */ + HDassert(prev_span); + + /* Check that down spans match current slab info */ + /* (Can skip check if previous span's down pointer is same as current one) */ + if(span->down && prev_span->down != span->down) + if(!H5S__hyper_cmp_spans(span->down, prev_span->down)) + HGOTO_DONE(FALSE) + + /* Obtain values for stride and block */ + curr_stride = span->low - prev_low; + curr_block = (span->high - span->low) + 1; + + /* Compare stride and block for this span. To compare stride, + * three spans are needed. Account for the first two spans. + */ + if(curr_block != block) HGOTO_DONE(FALSE) - - HDmemcpy(canon_down_span_slab_info, span_slab_info, sizeof(H5S_hyper_dim_t) * rank); + if(spancount > 1) { + if(stride != curr_stride) + HGOTO_DONE(FALSE) + } /* end if */ + else + stride = curr_stride; } /* end if */ - /* Assign the initial starting point & block size */ - curr_start = span->low; - curr_block = (span->high - span->low) + 1; + /* Keep current starting point */ + prev_low = span->low; - /* Loop the spans */ - while(span) { - if(outcount > 0) { - hsize_t next_stride; /* Stride from previous span */ - hsize_t next_block; /* Block size of current span */ + /* Advance to next span */ + prev_span = span; + span = span->next; + spancount++; + } /* end while */ - /* Check that down spans match current slab info */ - /* (Can skip check if previous span's down pointer is same as current one) */ - if(span->down && (NULL == prev_span || prev_span->down != span->down)) { - H5S_hyper_dim_t *curr_down_span_slab_info; - unsigned u; /* Local index variable */ - - HDassert(span->down->head); - - /* Go to the next down span and check whether the selection can be rebuilt.*/ - if(!H5S__hyper_rebuild_helper(span->down->head, span_slab_info, rank - 1)) - HGOTO_DONE(FALSE) - - /* Compare the slab information of the adjacent spans in the down span tree. - We have to compare all the sub-tree slab information with the canon_down_span_slab_info.*/ - for(u = 0; u < rank - 1; u++) { - curr_down_span_slab_info = &span_slab_info[u]; - - if(curr_down_span_slab_info->count > 0 && canon_down_span_slab_info[u].count > 0) { - if(curr_down_span_slab_info->start != canon_down_span_slab_info[u].start - || curr_down_span_slab_info->stride != canon_down_span_slab_info[u].stride - || curr_down_span_slab_info->block != canon_down_span_slab_info[u].block - || curr_down_span_slab_info->count != canon_down_span_slab_info[u].count) - HGOTO_DONE(FALSE) - } /* end if */ - else if(!((curr_down_span_slab_info->count == 0) && (canon_down_span_slab_info[u].count == 0))) - HGOTO_DONE(FALSE) - } /* end for */ - } /* end if */ - - /* Obtain values for stride and block */ - next_stride = span->low - curr_low; - next_block = (span->high - span->low) + 1; - - /* Compare stride and block in this span, to compare stride, - * three spans are needed. Account for the first two spans. - */ - if(next_block != curr_block) - HGOTO_DONE(FALSE) - if(outcount > 1 && curr_stride != next_stride) - HGOTO_DONE(FALSE) - - /* Keep the isolated stride to be 1 */ - curr_stride = next_stride; - } /* end if */ - - /* Keep current starting point */ - curr_low = span->low; - - /* Advance to next span */ - prev_span = span; - span = span->next; - outcount++; - } /* end while */ - - /* Save the span information. */ - span_slab_info[rank - 1].start = curr_start; - span_slab_info[rank - 1].count = outcount; - span_slab_info[rank - 1].block = curr_block; - span_slab_info[rank - 1].stride = curr_stride; - } /* end if */ + /* Save the span information. */ + span_slab_info[0].start = start; + span_slab_info[0].count = spancount; + span_slab_info[0].block = block; + span_slab_info[0].stride = stride; done: FUNC_LEAVE_NOAPI(ret_value) @@ -7341,65 +8431,46 @@ done: Rebuild optimized hyperslab information if possible. (It can be recovered with regular selection) USAGE - hbool_t H5S__hyper_rebuild(space) - const H5S_t *space; IN: Dataspace to check + void H5S__hyper_rebuild(space) + H5S_t *space; IN: Dataspace to check RETURNS - TRUE/FALSE for hyperslab selection rebuilt + None DESCRIPTION - Examine the span tree for a hyperslab selection and rebuild - the start/stride/count/block information for the selection, if possible. + Examine the span tree for a hyperslab selection and rebuild a regular + start/stride/count/block hyperslab selection, if possible. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS To be able to recover the optimized information, the span tree must conform to span tree able to be generated from a single H5S_SELECT_SET operation. EXAMPLES REVISION LOG - This routine is the optimization of the old version. The previous version - can only detect a singluar selection. This version is general enough to - detect any regular selection. - KY, 2005/9/22 --------------------------------------------------------------------------*/ -static hbool_t +void H5S__hyper_rebuild(H5S_t *space) { - H5S_hyper_dim_t top_span_slab_info[H5S_MAX_RANK]; - unsigned rank, curr_dim; - hbool_t ret_value = TRUE; /* Return value */ + H5S_hyper_dim_t rebuilt_slab_info[H5S_MAX_RANK]; - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Check args */ HDassert(space); HDassert(space->select.sel_info.hslab->span_lst); - /* Check the rank of space */ - rank = space->extent.rank; - - /* Check whether the slab can be rebuilt. Only regular selection can be rebuilt. If yes, fill in correct values.*/ - if(!H5S__hyper_rebuild_helper(space->select.sel_info.hslab->span_lst->head, top_span_slab_info, rank)) { - HGOTO_DONE(FALSE) - } /* end if */ + /* Check whether the slab can be rebuilt */ + /* (Only regular selection can be rebuilt. If yes, fill in correct values) */ + if(FALSE == H5S__hyper_rebuild_helper(space->select.sel_info.hslab->span_lst, rebuilt_slab_info)) + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_IMPOSSIBLE; else { - H5S_hyper_dim_t *diminfo; - H5S_hyper_dim_t *app_diminfo; + /* Set the dimension info & bounds for the dataspace, from the rebuilt info */ + HDmemcpy(space->select.sel_info.hslab->diminfo.app, rebuilt_slab_info, sizeof(rebuilt_slab_info)); + HDmemcpy(space->select.sel_info.hslab->diminfo.opt, rebuilt_slab_info, sizeof(rebuilt_slab_info)); + HDmemcpy(space->select.sel_info.hslab->diminfo.low_bounds, space->select.sel_info.hslab->span_lst->low_bounds, sizeof(hsize_t) * space->extent.rank); + HDmemcpy(space->select.sel_info.hslab->diminfo.high_bounds, space->select.sel_info.hslab->span_lst->high_bounds, sizeof(hsize_t) * space->extent.rank); - diminfo = space->select.sel_info.hslab->opt_diminfo; - app_diminfo = space->select.sel_info.hslab->app_diminfo; - - for(curr_dim = 0; curr_dim < rank; curr_dim++) { - - app_diminfo[(rank - curr_dim) - 1].start = diminfo[(rank - curr_dim) - 1].start = top_span_slab_info[curr_dim].start; - app_diminfo[(rank - curr_dim) - 1].stride = diminfo[(rank - curr_dim) - 1].stride = top_span_slab_info[curr_dim].stride; - app_diminfo[(rank - curr_dim) - 1].count = diminfo[(rank - curr_dim) - 1].count = top_span_slab_info[curr_dim].count; - app_diminfo[(rank - curr_dim) - 1].block = diminfo[(rank - curr_dim) - 1].block = top_span_slab_info[curr_dim].block; - - } /* end for */ - - space->select.sel_info.hslab->diminfo_valid = TRUE; + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_YES; } /* end else */ -done: - FUNC_LEAVE_NOAPI(ret_value) + FUNC_LEAVE_NOAPI_VOID } /* end H5S__hyper_rebuild() */ @@ -7442,15 +8513,15 @@ H5S__hyper_generate_spans(H5S_t *space) /* These should be able to be converted to assertions once everything * that calls this function checks for unlimited selections first * (especially the new hyperslab API) -NAF */ - if(space->select.sel_info.hslab->opt_diminfo[u].count == H5S_UNLIMITED) + if(space->select.sel_info.hslab->diminfo.opt[u].count == H5S_UNLIMITED) HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "can't generate spans with unlimited count") - if(space->select.sel_info.hslab->opt_diminfo[u].block == H5S_UNLIMITED) + if(space->select.sel_info.hslab->diminfo.opt[u].block == H5S_UNLIMITED) HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "can't generate spans with unlimited block") - tmp_start[u]=space->select.sel_info.hslab->opt_diminfo[u].start; - tmp_stride[u]=space->select.sel_info.hslab->opt_diminfo[u].stride; - tmp_count[u]=space->select.sel_info.hslab->opt_diminfo[u].count; - tmp_block[u]=space->select.sel_info.hslab->opt_diminfo[u].block; + tmp_start[u] = space->select.sel_info.hslab->diminfo.opt[u].start; + tmp_stride[u] = space->select.sel_info.hslab->diminfo.opt[u].stride; + tmp_count[u] = space->select.sel_info.hslab->diminfo.opt[u].count; + tmp_block[u] = space->select.sel_info.hslab->diminfo.opt[u].block; } /* end for */ /* Build the hyperslab information also */ @@ -7461,6 +8532,386 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_generate_spans() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__check_spans_overlap + PURPOSE + Check if two selections' bounds overlap. + USAGE + hbool_t H5S__check_spans_overlap(spans1, spans2) + const H5S_hyper_span_info_t *spans1; IN: Second span list + const H5S_hyper_span_info_t *spans2; IN: Second span list + RETURNS + TRUE for overlap, FALSE for no overlap + PROGRAMMER + Quincey Koziol - January 24, 2019 + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static H5_ATTR_PURE hbool_t +H5S__check_spans_overlap(const H5S_hyper_span_info_t *spans1, + const H5S_hyper_span_info_t *spans2) +{ + hbool_t ret_value = FALSE; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity checks */ + HDassert(spans1); + HDassert(spans2); + + /* Use low & high bounds to try to avoid spinning through the span lists */ + if(H5S_RANGE_OVERLAP(spans1->low_bounds[0], spans1->high_bounds[0], + spans2->low_bounds[0], spans2->high_bounds[0])) { + H5S_hyper_span_t *span1, *span2; /* Hyperslab spans */ + + /* Walk over spans, comparing them for overlap */ + span1 = spans1->head; + span2 = spans2->head; + while(span1 && span2) { + /* Check current two spans for overlap */ + if(H5S_RANGE_OVERLAP(span1->low, span1->high, span2->low, span2->high)) { + /* Check for spans in lowest dimension already */ + if(span1->down) { + /* Sanity check */ + HDassert(span2->down); + + /* Check lower dimensions for overlap */ + if(H5S__check_spans_overlap(span1->down, span2->down)) + HGOTO_DONE(TRUE); + } /* end if */ + else + HGOTO_DONE(TRUE); + } /* end if */ + + /* Advance one of the spans */ + if(span1->high <= span2->high) { + /* Advance span1, unless it would be off the list and span2 has more nodes */ + if(NULL == span1->next && NULL != span2->next) + span2 = span2->next; + else + span1 = span1->next; + } /* end if */ + else { + /* Advance span2, unless it would be off the list and span1 has more nodes */ + if(NULL == span2->next && NULL != span1->next) + span1 = span1->next; + else + span2 = span2->next; + } /* end else */ + } /* end while */ + + /* Make certain we've exhausted our comparisons */ + HDassert((NULL == span1 && (NULL != span2 && NULL == span2->next)) || + ((NULL != span1 && NULL == span1->next) && NULL == span2)); + } /* end of */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__check_spans_overlap() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__fill_in_new_space + PURPOSE + Combine two span lists, one from an existing dataspace and the + other from input arguments, into a new selection depending on the + selection operator. The new selection is put into a resulting dataspace + which could be allocated inside the function. + USAGE + herr_t H5S__fill_in_new_space(space1, op, space2_span_lst, can_own_span2, + span2_owned, result) + H5S_t *space1; IN: Dataspace containing the first span list + H5S_seloper_t op; IN: Selection operation + H5S_hyper_span_info_t *space2_span_lst; IN: Second span list + hbool_t can_own_span2; IN: Indicates whether the 2nd span list could be + owned by the result. If not, the 2nd span list + has to be copied. + hbool_t *span2_owned; OUT: Indicates if the 2nd span list is actually owned + H5S_t **result; OUT: The dataspace containing the the new selection. It + could be same with the 1st dataspace. + RETURNS + Non-negative on success, negative on failure + PROGRAMMER + Chao Mei July 8, 2011 + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__fill_in_new_space(H5S_t *space1, H5S_seloper_t op, + H5S_hyper_span_info_t *space2_span_lst, hbool_t can_own_span2, + hbool_t *span2_owned, hbool_t *updated_spans, H5S_t **result) +{ + H5S_hyper_span_info_t *a_not_b = NULL; /* Span tree for hyperslab spans in old span tree and not in new span tree */ + H5S_hyper_span_info_t *a_and_b = NULL; /* Span tree for hyperslab spans in both old and new span trees */ + H5S_hyper_span_info_t *b_not_a = NULL; /* Span tree for hyperslab spans in new span tree and not in old span tree */ + hbool_t overlapped = FALSE; /* Whether selections overlap */ + hbool_t is_result_new = FALSE; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + HDassert(space1); + HDassert(space2_span_lst); + HDassert(op >= H5S_SELECT_OR && op <= H5S_SELECT_NOTA); + /* The result is either a to-be-created space or an empty one */ + HDassert(*result == NULL || *result == space1); + HDassert(space1->select.sel_info.hslab->span_lst); + HDassert(span2_owned); + + /* Reset flags to return */ + *span2_owned = FALSE; + *updated_spans = FALSE; + + /* The result shares the same info from space1 */ + if(*result == NULL) { + if(NULL == ((*result) = H5S_copy(space1, TRUE, TRUE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy dataspace") + space1->select.sel_info.hslab->span_lst->count--; + (*result)->select.sel_info.hslab->span_lst = NULL; + is_result_new = TRUE; + } /* end if */ + + /* Check both spaces to see if they overlap */ + overlapped = H5S__check_spans_overlap(space1->select.sel_info.hslab->span_lst, space2_span_lst); + + if(!overlapped) { + switch(op) { + case H5S_SELECT_OR: + case H5S_SELECT_XOR: + /* Add the new disjoint spans to the space */ + /* Copy of space1's spans to *result, and another copy of space2's spans */ + if(is_result_new) + (*result)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(space1->select.sel_info.hslab->span_lst, space1->extent.rank); + if(!can_own_span2) { + b_not_a = H5S__hyper_copy_span(space2_span_lst, space1->extent.rank); + if(H5S__hyper_add_disjoint_spans(*result, b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't append hyperslabs") + + /* The new_spans are now owned by 'space', so they should not be released */ + b_not_a = NULL; + } /* end if */ + else { + if(H5S__hyper_add_disjoint_spans(*result, space2_span_lst) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't append hyperslabs") + *span2_owned = TRUE; + } /* end else */ + + /* Indicate that the spans changed */ + *updated_spans = TRUE; + break; + + case H5S_SELECT_AND: + /* Convert *result to "none" selection */ + if(H5S_select_none(*result) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + HGOTO_DONE(SUCCEED); + + case H5S_SELECT_NOTB: + /* Copy space1's spans to *result */ + if(is_result_new) + (*result)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(space1->select.sel_info.hslab->span_lst, space1->extent.rank); + + /* Indicate that the spans changed */ + *updated_spans = TRUE; + break; + + case H5S_SELECT_NOTA: + if(!is_result_new) { + HDassert(space1 == *result); + + /* Free the current selection */ + H5S__hyper_free_span_info(space1->select.sel_info.hslab->span_lst); + space1->select.sel_info.hslab->span_lst = NULL; + } /* end if */ + + /* Copy space2's spans to *result */ + if(!can_own_span2) + (*result)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(space2_span_lst, space1->extent.rank); + else { + (*result)->select.sel_info.hslab->span_lst = space2_span_lst; + *span2_owned = TRUE; + } /* end else */ + + /* Reset the number of items in selection */ + (*result)->select.num_elem = H5S__hyper_spans_nelem(space2_span_lst); + + /* Indicate that the spans changed */ + *updated_spans = TRUE; + break; + + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: + default: + HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") + } /* end switch */ + } /* end if */ + else { + unsigned selector = 0; /* Select which clipping spans to generate */ + + /* Generate mask for clip operation depending on the op */ + switch(op) { + case H5S_SELECT_OR: /* a + b_not_a */ + selector = H5S_HYPER_COMPUTE_B_NOT_A; + break; + + case H5S_SELECT_XOR: /* a_not_b + b_not_a */ + selector = H5S_HYPER_COMPUTE_A_NOT_B | H5S_HYPER_COMPUTE_B_NOT_A; + break; + + case H5S_SELECT_AND: /* a_and_b */ + selector = H5S_HYPER_COMPUTE_A_AND_B; + break; + + case H5S_SELECT_NOTB: /* a_not_b */ + selector = H5S_HYPER_COMPUTE_A_NOT_B; + break; + + case H5S_SELECT_NOTA: /* b_not_a */ + selector = H5S_HYPER_COMPUTE_B_NOT_A; + break; + + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: + default: + HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") + } /* end switch */ + + /* Generate lists of spans which overlap and don't overlap */ + if(H5S__hyper_clip_spans(space1->select.sel_info.hslab->span_lst, + space2_span_lst, selector, space1->extent.rank, + &a_not_b, &a_and_b, &b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") + switch(op) { + case H5S_SELECT_OR: + if(is_result_new) + (*result)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(space1->select.sel_info.hslab->span_lst, space1->extent.rank); + break; + + case H5S_SELECT_AND: + case H5S_SELECT_XOR: + case H5S_SELECT_NOTB: + case H5S_SELECT_NOTA: + if(!is_result_new) { + HDassert(space1 == *result); + + /* Free the current selection */ + H5S__hyper_free_span_info(space1->select.sel_info.hslab->span_lst); + space1->select.sel_info.hslab->span_lst = NULL; + } /* end if */ + + /* Reset the number of items in selection */ + /* (Will be set below) */ + (*result)->select.num_elem = 0; + break; + + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: + default: + HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") + } /* end switch */ + + /* Check if there are any non-overlapped selections */ + if(a_not_b) { + /* Other than OR, the span_lst is set to NULL. And in OR, + * a_not_b is not needed + */ + HDassert(NULL == (*result)->select.sel_info.hslab->span_lst); + + /* The results dataspace takes ownership of the spans */ + /* (Since it must be NULL) */ + (*result)->select.sel_info.hslab->span_lst = a_not_b; + + /* Update the number of elements in current selection */ + (*result)->select.num_elem = H5S__hyper_spans_nelem(a_not_b); + + /* Indicate that the spans were updated */ + *updated_spans = TRUE; + + /* Indicate that the a_not_b spans are owned */ + a_not_b = NULL; + } /* end if */ + + if(a_and_b) { + /** + * 1. Other than OR, the span_lst is set to NULL. And in OR, + * a_and_b is not needed + * 2. a_not_b will never be computed together with a_and_b + * because merging these two equals to a. + */ + HDassert(NULL == (*result)->select.sel_info.hslab->span_lst); + + /* The results dataspace takes ownership of the spans */ + /* (Since it must be NULL) */ + (*result)->select.sel_info.hslab->span_lst = a_and_b; + + /* Update the number of elements in current selection */ + (*result)->select.num_elem = H5S__hyper_spans_nelem(a_and_b); + + /* Indicate that the spans were updated */ + *updated_spans = TRUE; + + /* Indicate that the a_and_b spans are owned */ + a_and_b = NULL; + } /* end if */ + + if(b_not_a) { + /* Merge the b_not_a spans into the result dataspace */ + if(H5S__hyper_merge_spans(*result, b_not_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") + + /* Update the number of elements in current selection */ + (*result)->select.num_elem += H5S__hyper_spans_nelem(b_not_a); + + /* Indicate that the spans were updated */ + *updated_spans = TRUE; + } /* end if */ + } /* end else for the case the new span overlaps with the old (i.e. space) */ + + /* Check if the spans weren't updated, and reset selection if so */ + if(!*updated_spans) { + /* If updated_spans remains FALSE as in this branch, it means the + * result has been cleared in XOR / AND / NOTB / NOTA cases, and the + * result is a copy of the dataspace in the OR case. + * + * If two dataspaces have generated any of the three clipped + * span trees (i.e. a_not_b, a_and_b, and b_not_a), the + * updated_spans must be TRUE. + */ + if(H5S_SELECT_OR != op) { + /* Convert *result to "none" selection */ + if(H5S_select_none(*result) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + } /* end else */ + } /* end if */ + +done: + /* Free resources */ + if(a_not_b) + H5S__hyper_free_span_info(a_not_b); + if(a_and_b) + H5S__hyper_free_span_info(a_and_b); + if(b_not_a) + H5S__hyper_free_span_info(b_not_a); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__fill_in_new_space() */ + /*------------------------------------------------------------------------- * Function: H5S__generate_hyperlab @@ -7478,10 +8929,7 @@ static herr_t H5S__generate_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], const hsize_t stride[], const hsize_t count[], const hsize_t block[]) { - H5S_hyper_span_info_t *new_spans=NULL; /* Span tree for new hyperslab */ - H5S_hyper_span_info_t *a_not_b = NULL; /* Span tree for hyperslab spans in old span tree and not in new span tree */ - H5S_hyper_span_info_t *a_and_b = NULL; /* Span tree for hyperslab spans in both old and new span trees */ - H5S_hyper_span_info_t *b_not_a = NULL; /* Span tree for hyperslab spans in new span tree and not in old span tree */ + H5S_hyper_span_info_t *new_spans = NULL; /* Span tree for new hyperslab */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -7499,10 +8947,13 @@ H5S__generate_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't create hyperslab information") /* Generate list of blocks to add/remove based on selection operation */ - if(op==H5S_SELECT_SET) { - /* Add new spans to current selection */ - if(H5S__hyper_merge_spans(space,new_spans,TRUE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") + if(op == H5S_SELECT_SET) { + /* Free current selection */ + if(NULL != space->select.sel_info.hslab->span_lst) + H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst); + + /* Set the hyperslab selection to the new span tree */ + space->select.sel_info.hslab->span_lst = new_spans; /* Set the number of elements in current selection */ space->select.num_elem = H5S__hyper_spans_nelem(new_spans); @@ -7511,194 +8962,375 @@ H5S__generate_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], new_spans = NULL; } /* end if */ else { - hbool_t updated_spans = FALSE; /* Whether the spans in the selection were modified */ + hbool_t new_spans_owned = FALSE; + hbool_t updated_spans = FALSE; - /* Generate lists of spans which overlap and don't overlap */ - if(H5S__hyper_clip_spans(space->select.sel_info.hslab->span_lst,new_spans,&a_not_b,&a_and_b,&b_not_a)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") + /* Generate new spans for space */ + if(H5S__fill_in_new_space(space, op, new_spans, TRUE, &new_spans_owned, &updated_spans, &space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't generate the specified hyperslab") - switch(op) { - case H5S_SELECT_OR: - /* Add any new spans from b_not_a to current selection */ - if(b_not_a!=NULL) { - if(H5S__hyper_merge_spans(space,b_not_a,FALSE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem += H5S__hyper_spans_nelem(b_not_a); - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - break; - - case H5S_SELECT_AND: - /* Free the current selection */ - if(H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst)<0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") - space->select.sel_info.hslab->span_lst=NULL; - - /* Reset the number of items in selection */ - space->select.num_elem=0; - - /* Check if there are any overlapped selections */ - if(a_and_b!=NULL) { - if(H5S__hyper_merge_spans(space,a_and_b,TRUE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem = H5S__hyper_spans_nelem(a_and_b); - - /* Indicate that the a_and_b spans are owned */ - a_and_b=NULL; - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - break; - - case H5S_SELECT_XOR: - /* Free the current selection */ - if(H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst)<0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") - space->select.sel_info.hslab->span_lst=NULL; - - /* Reset the number of items in selection */ - space->select.num_elem=0; - - /* Check if there are any non-overlapped selections */ - if(a_not_b!=NULL) { - if(H5S__hyper_merge_spans(space,a_not_b,FALSE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem = H5S__hyper_spans_nelem(a_not_b); - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - if(b_not_a!=NULL) { - if(H5S__hyper_merge_spans(space,b_not_a,FALSE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem += H5S__hyper_spans_nelem(b_not_a); - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - break; - - case H5S_SELECT_NOTB: - /* Free the current selection */ - if(H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst)<0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") - space->select.sel_info.hslab->span_lst=NULL; - - /* Reset the number of items in selection */ - space->select.num_elem=0; - - /* Check if there are any non-overlapped selections */ - if(a_not_b!=NULL) { - if(H5S__hyper_merge_spans(space,a_not_b,TRUE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem = H5S__hyper_spans_nelem(a_not_b); - - /* Indicate that the a_not_b are owned */ - a_not_b=NULL; - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - break; - - case H5S_SELECT_NOTA: - /* Free the current selection */ - if(H5S__hyper_free_span_info(space->select.sel_info.hslab->span_lst)<0) - HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release hyperslab spans") - space->select.sel_info.hslab->span_lst=NULL; - - /* Reset the number of items in selection */ - space->select.num_elem=0; - - /* Check if there are any non-overlapped selections */ - if(b_not_a!=NULL) { - if(H5S__hyper_merge_spans(space,b_not_a,TRUE)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert hyperslabs") - - /* Update the number of elements in current selection */ - space->select.num_elem = H5S__hyper_spans_nelem(b_not_a); - - /* Indicate that the b_not_a are owned */ - b_not_a=NULL; - - /* Indicate that the spans were updated */ - updated_spans = TRUE; - } /* end if */ - break; - - case H5S_SELECT_NOOP: - case H5S_SELECT_SET: - case H5S_SELECT_APPEND: - case H5S_SELECT_PREPEND: - case H5S_SELECT_INVALID: - default: - HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") - } /* end switch */ - - /* Check if the resulting hyperslab span tree is empty */ - if(space->select.sel_info.hslab->span_lst==NULL) { - H5S_hyper_span_info_t *spans; /* Empty hyperslab span tree */ + /* Check if the spans were updated by H5S__fill_in_new_space */ + if(updated_spans) { + H5S_hyper_dim_t new_hyper_diminfo[H5S_MAX_RANK]; + unsigned u; /* Local index variable */ /* Sanity check */ - HDassert(space->select.num_elem == 0); + HDassert(space->select.sel_info.hslab->span_lst->head); - /* Allocate a span info node */ - if((spans = H5FL_MALLOC(H5S_hyper_span_info_t))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab span") + /* Build diminfo struct */ + for(u = 0; u extent.rank; u++) { + new_hyper_diminfo[u].start = start[u]; + new_hyper_diminfo[u].stride = stride[u]; + new_hyper_diminfo[u].count = count[u]; + new_hyper_diminfo[u].block = block[u]; + } /* end for */ - /* Set the reference count */ - spans->count=1; + /* Update space's dim info */ + if(H5S__hyper_update_diminfo(space, op, new_hyper_diminfo) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOUNT, FAIL, "can't update hyperslab info") + } /* end if */ - /* Reset the scratch pad space */ - spans->scratch=0; + /* Indicate that the new_spans are owned, there's no need to free */ + if(new_spans_owned) + new_spans = NULL; + } /* end else */ - /* Set to empty tree */ - spans->head=NULL; +done: + if(new_spans) + H5S__hyper_free_span_info(new_spans); - /* Set pointer to empty span tree */ - space->select.sel_info.hslab->span_lst=spans; + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__generate_hyperslab() */ + + +/*------------------------------------------------------------------------- + * Function: H5S__set_regular_hyperslab + * + * Purpose: Set a regular hyperslab + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, October 2, 2014 + * + *------------------------------------------------------------------------- + */ +herr_t +H5S__set_regular_hyperslab(H5S_t *space, const hsize_t start[], + const hsize_t *app_stride, const hsize_t app_count[], const hsize_t *app_block, + const hsize_t *opt_stride, const hsize_t opt_count[], const hsize_t *opt_block) +{ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check args */ + HDassert(space); + HDassert(start); + HDassert(app_stride); + HDassert(app_count); + HDassert(app_block); + HDassert(opt_stride); + HDassert(opt_count); + HDassert(opt_block); + + /* If we are setting a new selection, remove current selection first */ + if(H5S_SELECT_RELEASE(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection") + + /* Allocate space for the hyperslab selection information */ + if(NULL == (space->select.sel_info.hslab = H5FL_MALLOC(H5S_hyper_sel_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab info") + + /* Set the diminfo */ + space->select.num_elem = 1; + space->select.sel_info.hslab->unlim_dim = -1; + for(u = 0; u < space->extent.rank; u++) { + /* Set application and optimized hyperslab info */ + space->select.sel_info.hslab->diminfo.app[u].start = start[u]; + space->select.sel_info.hslab->diminfo.app[u].stride = app_stride[u]; + space->select.sel_info.hslab->diminfo.app[u].count = app_count[u]; + space->select.sel_info.hslab->diminfo.app[u].block = app_block[u]; + + space->select.sel_info.hslab->diminfo.opt[u].start = start[u]; + space->select.sel_info.hslab->diminfo.opt[u].stride = opt_stride[u]; + space->select.sel_info.hslab->diminfo.opt[u].count = opt_count[u]; + space->select.sel_info.hslab->diminfo.opt[u].block = opt_block[u]; + + /* Update # of elements selected */ + space->select.num_elem *= (opt_count[u] * opt_block[u]); + + /* Set low bound of bounding box for the hyperslab selection */ + space->select.sel_info.hslab->diminfo.low_bounds[u] = start[u]; + + /* Check for unlimited dimension & set high bound */ + if((app_count[u] == H5S_UNLIMITED) || (app_block[u] == H5S_UNLIMITED)) { + space->select.sel_info.hslab->unlim_dim = (int)u; + space->select.sel_info.hslab->diminfo.high_bounds[u] = H5S_UNLIMITED; + } /* end if */ + else + space->select.sel_info.hslab->diminfo.high_bounds[u] = start[u] + opt_stride[u] * (opt_count[u] - 1) + (opt_block[u] - 1); + } /* end for */ + + /* Handle unlimited selections */ + if(space->select.sel_info.hslab->unlim_dim >= 0) { + /* Calculate num_elem_non_unlim */ + space->select.sel_info.hslab->num_elem_non_unlim = (hsize_t)1; + for(u = 0; u < space->extent.rank; u++) + if((int)u != space->select.sel_info.hslab->unlim_dim) + space->select.sel_info.hslab->num_elem_non_unlim *= (opt_count[u] * opt_block[u]); + + /* Update num_elem */ + space->select.num_elem = H5S_UNLIMITED; + } /* end if */ + + /* Indicate that the dimension information is valid */ + space->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_YES; + + /* Indicate that there's no slab information */ + space->select.sel_info.hslab->span_lst = NULL; + + /* Set selection type */ + space->select.type = H5S_sel_hyper; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__set_regular_hyperslab() */ + + +/*------------------------------------------------------------------------- + * Function: H5S__hyper_regular_and_single_block + * + * Purpose: Optimized routine to perform "AND" operation of a single + * block against a regular hyperslab selection. + * + * Note: This algorithm is invoked when constructing the chunk map + * and a regular hyperslab is selected in the file's dataspace. + * + * Return: Non-negative on success / Negative on failure + * + * Programmer: Quincey Koziol + * Saturday, February 9, 2019 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5S__hyper_regular_and_single_block(H5S_t *space, const hsize_t start[], + const hsize_t block[]) +{ + hsize_t select_end, block_end; /* End of block & selection */ + hbool_t single_block; /* Whether the selection is a single block */ + hbool_t overlap; /* Whether block & selection overlap */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Check args */ + HDassert(space); + HDassert(start); + HDassert(block); + + /* Check for single block selection in dataspace */ + single_block = TRUE; + for(u = 0; u < space->extent.rank; u++) + if(1 != space->select.sel_info.hslab->diminfo.opt[u].count) { + single_block = FALSE; + break; + } /* end if */ + + /* Perform different optimizations, based on type of regular selection */ + if(single_block) { + hsize_t new_start[H5S_MAX_RANK]; /* New starting coordinate */ + hsize_t new_block[H5S_MAX_RANK]; /* New block size */ + + /* Check for overlap and compute new start offset & block sizes */ + overlap = TRUE; + for(u = 0; u < space->extent.rank; u++) { + /* Compute the end of the selection & block in this dimension */ + select_end = space->select.sel_info.hslab->diminfo.high_bounds[u]; + block_end = (start[u] + block[u]) - 1; + + /* Check for overlap */ + if(!H5S_RANGE_OVERLAP(space->select.sel_info.hslab->diminfo.opt[u].start, select_end, start[u], block_end)) { + overlap = FALSE; + break; + } /* end if */ + + /* Set new start & block size in this dimension */ + new_start[u] = MAX(space->select.sel_info.hslab->diminfo.opt[u].start, start[u]); + new_block[u] = (MIN(select_end, block_end) - new_start[u]) + 1; + } /* end for */ + + /* Check for overlap of selection & block */ + if(overlap) { + /* Set selection to regular hyperslab */ + if(H5S__set_regular_hyperslab(space, new_start, H5S_hyper_ones_g, H5S_hyper_ones_g, new_block, + H5S_hyper_ones_g, H5S_hyper_ones_g, new_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't set regular hyperslab selection") + } /* end if */ + else + /* Selection & block don't overlap, set to "none" selection */ + if(H5S_select_none(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + } /* end if */ + else { + hsize_t new_start[H5S_MAX_RANK]; /* New start for hyperslab selection */ + hsize_t new_count[H5S_MAX_RANK]; /* New count for hyperslab selection */ + hsize_t stride[H5S_MAX_RANK]; /* Stride for hyperslab selection */ + hsize_t new_block[H5S_MAX_RANK]; /* New block for hyperslab selection */ + hbool_t partial_first_span; /* Whether first span in intersection is partial */ + hbool_t partial_last_span; /* Whether last span in intersection is partial */ + + /* Iterate over selection, checking for overlap and computing first / last + * span that intersects with the block. + */ + overlap = TRUE; + partial_first_span = FALSE; + partial_last_span = FALSE; + for(u = 0; u < space->extent.rank; u++) { + hsize_t first_span_start, first_span_end; /* Start / end of first span */ + hsize_t last_span_start, last_span_end; /* Start / end of last span */ + hsize_t nstride; /* Number of strides into the selection */ + + /* Compute the end of the selection & block in this dimension */ + select_end = space->select.sel_info.hslab->diminfo.high_bounds[u]; + block_end = (start[u] + block[u]) - 1; + + /* Check for overlap */ + if(!H5S_RANGE_OVERLAP(space->select.sel_info.hslab->diminfo.opt[u].start, select_end, start[u], block_end)) { + overlap = FALSE; + break; + } /* end if */ + + /* Find first span that is before or overlaps with start of block */ + if(space->select.sel_info.hslab->diminfo.opt[u].start >= start[u]) { + /* Calculate start & end of first span */ + first_span_start = space->select.sel_info.hslab->diminfo.opt[u].start; + first_span_end = (first_span_start + + space->select.sel_info.hslab->diminfo.opt[u].block) - 1; + + /* Check if first span overlaps _end_ of block */ + if(block_end >= first_span_start && block_end <= first_span_end) + partial_first_span = TRUE; + } /* end if */ + else { + hsize_t adj_start; /* Start coord, adjusted for hyperslab selection parameters */ + + /* Adjust start coord for selection's 'start' offset */ + adj_start = start[u] - space->select.sel_info.hslab->diminfo.opt[u].start; + + /* Compute # of strides into the selection */ + if(space->select.sel_info.hslab->diminfo.opt[u].count > 1) + nstride = adj_start / space->select.sel_info.hslab->diminfo.opt[u].stride; + else + nstride = 0; + + /* Calculate start & end of first span */ + first_span_start = space->select.sel_info.hslab->diminfo.opt[u].start + + (nstride * space->select.sel_info.hslab->diminfo.opt[u].stride); + first_span_end = (first_span_start + + space->select.sel_info.hslab->diminfo.opt[u].block) - 1; + + /* Check if first span overlaps start of block */ + if(first_span_start < start[u] && first_span_end >= start[u]) + partial_first_span = TRUE; + + /* Advance first span to start higher than block's start, + * if it's not partial. + */ + if(first_span_end < start[u]) { + first_span_start += space->select.sel_info.hslab->diminfo.opt[u].stride; + first_span_end += space->select.sel_info.hslab->diminfo.opt[u].stride; + } /* end if */ + } /* end else */ + + /* Find last span that is before or overlaps with end of block */ + if(select_end < block_end) { + /* Calculate start & end of last span */ + last_span_start = (select_end - + space->select.sel_info.hslab->diminfo.opt[u].block) + 1; + last_span_end = select_end; + + /* Check if last span overlaps _start_ of block */ + if(start[u] >= last_span_start && start[u] <= last_span_end) + partial_last_span = TRUE; + } /* end if */ + else { + hsize_t adj_end; /* End coord, adjusted for hyperslab selection parameters */ + + /* Adjust end coord for selection's 'start' offset */ + adj_end = block_end - space->select.sel_info.hslab->diminfo.opt[u].start; + + /* Compute # of strides into the selection */ + if(space->select.sel_info.hslab->diminfo.opt[u].count > 1) + nstride = adj_end / space->select.sel_info.hslab->diminfo.opt[u].stride; + else + nstride = 0; + + /* Calculate start & end of last span */ + last_span_start = space->select.sel_info.hslab->diminfo.opt[u].start + + (nstride * space->select.sel_info.hslab->diminfo.opt[u].stride); + last_span_end = (last_span_start + + space->select.sel_info.hslab->diminfo.opt[u].block) - 1; + + /* Check if last span overlaps end of block */ + if(block_end >= last_span_start && block_end <= last_span_end) + partial_last_span = TRUE; + } /* end else */ + + /* Check if no spans are inside block */ + /* (Can happen when block falls in "gap" between spans) */ + if(last_span_end < start[u]) { + overlap = FALSE; + break; + } /* end if */ + + /* Sanity check */ + HDassert(first_span_start <= last_span_start); + + /* Compute new start / count / block values */ + new_start[u] = first_span_start; + if(last_span_start != first_span_start) + new_count[u] = ((last_span_start - first_span_start) / + space->select.sel_info.hslab->diminfo.opt[u].stride) + 1; + else + new_count[u] = 1; + new_block[u] = space->select.sel_info.hslab->diminfo.opt[u].block; + + /* Keep same stride */ + stride[u] = space->select.sel_info.hslab->diminfo.opt[u].stride; + } /* end for */ + + /* Check for overlap of selection & block */ + if(overlap) { + /* Set selection to regular hyperslab */ + if(H5S__set_regular_hyperslab(space, new_start, stride, new_count, new_block, + stride, new_count, new_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't set regular hyperslab selection") + + /* If there's a partial first or last span, have to 'AND' against selection */ + if(partial_first_span || partial_last_span) { + /* Generate span tree for regular selection */ + if(H5S__hyper_generate_spans(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") + + /* 'AND' against block */ + if(H5S__generate_hyperslab(space, H5S_SELECT_AND, start, H5S_hyper_ones_g, H5S_hyper_ones_g, block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't generate hyperslabs") + } /* end if */ } /* end if */ else { - /* Check if we updated the spans */ - if(updated_spans) { - /* Attempt to rebuild "optimized" start/stride/count/block information. - * from resulting hyperslab span tree - */ - H5S__hyper_rebuild(space); - } /* end if */ + /* Selection & block don't overlap, set to "none" selection */ + if(H5S_select_none(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") } /* end else */ } /* end else */ done: - /* Free resources */ - if(a_not_b) - if(H5S__hyper_free_span_info(a_not_b) < 0) - HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans") - if(a_and_b) - if(H5S__hyper_free_span_info(a_and_b) < 0) - HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans") - if(b_not_a) - if(H5S__hyper_free_span_info(b_not_a) < 0) - HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans") - if(new_spans) - if(H5S__hyper_free_span_info(new_spans) < 0) - HDONE_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "failed to release temporary hyperslab spans") - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__generate_hyperslab() */ +} /* end H5S__hyper_regular_and_single_block() */ /*------------------------------------------------------------------------- @@ -7937,56 +9569,13 @@ H5S_select_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], } /* end switch */ if(op == H5S_SELECT_SET) { - /* If we are setting a new selection, remove current selection first */ - if(H5S_SELECT_RELEASE(space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection") - - /* Allocate space for the hyperslab selection information */ - if(NULL == (space->select.sel_info.hslab = H5FL_MALLOC(H5S_hyper_sel_t))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate hyperslab info") - - /* Save the diminfo */ - space->select.num_elem = 1; - for(u = 0; u < space->extent.rank; u++) { - 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]; - - space->select.sel_info.hslab->opt_diminfo[u].start = start[u]; - space->select.sel_info.hslab->opt_diminfo[u].stride = opt_stride[u]; - space->select.sel_info.hslab->opt_diminfo[u].count = opt_count[u]; - space->select.sel_info.hslab->opt_diminfo[u].block = opt_block[u]; - - space->select.num_elem *= (opt_count[u] * opt_block[u]); - } /* end for */ - - /* Save unlim_dim */ - space->select.sel_info.hslab->unlim_dim = unlim_dim; - - /* Indicate that the dimension information is valid */ - space->select.sel_info.hslab->diminfo_valid = TRUE; - - /* Indicate that there's no slab information */ - space->select.sel_info.hslab->span_lst = NULL; - - /* Handle unlimited selections */ - if(unlim_dim >= 0) { - /* Calculate num_elem_non_unlim */ - space->select.sel_info.hslab->num_elem_non_unlim = (hsize_t)1; - for(u = 0; u < space->extent.rank; u++) - if((int)u != unlim_dim) - space->select.sel_info.hslab->num_elem_non_unlim *= (opt_count[u] * opt_block[u]); - - /* Set num_elem */ - if(space->select.num_elem != (hsize_t)0) - space->select.num_elem = H5S_UNLIMITED; - } /* end if */ - - /* Set selection type */ - space->select.type = H5S_sel_hyper; + /* Set selection to regular hyperslab */ + if(H5S__set_regular_hyperslab(space, start, stride, count, block, opt_stride, opt_count, opt_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't set regular hyperslab selection") } /* end if */ else if(op >= H5S_SELECT_OR && op <= H5S_SELECT_NOTA) { + hbool_t single_block; /* Whether the selection is a single block */ + /* Sanity check */ HDassert(H5S_GET_SELECT_TYPE(space) == H5S_SEL_HYPERSLABS); @@ -8023,21 +9612,35 @@ H5S_select_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], } /* end if */ } /* end if */ - /* Check if there's no hyperslab span information currently */ - if(NULL == space->select.sel_info.hslab->span_lst) - if(H5S__hyper_generate_spans(space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") + /* Check for a single block selected */ + single_block = TRUE; + for(u = 0; u < space->extent.rank; u++) + if(1 != opt_count[u]) { + single_block = FALSE; + break; + } /* end if */ - /* Indicate that the regular dimensions are no longer valid */ - space->select.sel_info.hslab->diminfo_valid = FALSE; + /* Check for single block "AND" operation on a regular hyperslab, which + * is used for constructing chunk maps and can be optimized for. + */ + if(H5S_SELECT_AND == op && single_block && + space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + if(H5S__hyper_regular_and_single_block(space, start, opt_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTOPERATE, FAIL, "can't 'AND' single block against regular hyperslab") + } /* end if */ + else { + /* Check if there's no hyperslab span information currently */ + if(NULL == space->select.sel_info.hslab->span_lst) + if(H5S__hyper_generate_spans(space) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") - /* Set selection type */ - /* (Could be overridden by resetting selection to 'none', below) */ - space->select.type = H5S_sel_hyper; + /* Set selection type */ + space->select.type = H5S_sel_hyper; - /* Add in the new hyperslab information */ - if(H5S__generate_hyperslab(space, op, start, opt_stride, opt_count, opt_block) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't generate hyperslabs") + /* Add in the new hyperslab information */ + if(H5S__generate_hyperslab(space, op, start, opt_stride, opt_count, opt_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't generate hyperslabs") + } /* end else */ } /* end if */ else HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") @@ -8110,6 +9713,325 @@ done: FUNC_LEAVE_API(ret_value) } /* end H5Sselect_hyperslab() */ + +/*-------------------------------------------------------------------------- + NAME + H5S_combine_hyperslab + PURPOSE + Specify a hyperslab to combine with the current hyperslab selection, and + store the result in the new hyperslab selection. + USAGE + herr_t H5S_combine_hyperslab(new_space, old_space, op, start, stride, count, block) + H5S_t *old_space; IN: The old space the selection is performed on + H5S_seloper_t op; IN: Operation to perform on current selection + const hsize_t start[]; IN: Offset of start of hyperslab + const hsize_t *stride; IN: Hyperslab stride + const hsize_t count[]; IN: Number of blocks included in hyperslab + const hsize_t *block; IN: Size of block in hyperslab + H5S_t **new_space; OUT: The new dataspace to store the selection result + RETURNS + Non-negative on success/Negative on failure + DESCRIPTION + Combines a hyperslab selection with the current selection for a dataspace. + If STRIDE or BLOCK is NULL, they are assumed to be set to all '1'. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + In some cases, copying the whole span tree from old_space to new_space + can be avoided. Deal with such cases directly, otherwise this function + is equivalent to: + 1. Copy the whole span tree from old_space into new_space + 2. Call H5S_select_hyperslab with the new_space. + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5S_combine_hyperslab(H5S_t *old_space, H5S_seloper_t op, const hsize_t start[], + const hsize_t *stride, const hsize_t count[], const hsize_t *block, + H5S_t **new_space) +{ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI(FAIL) + + /* Check args */ + HDassert(old_space); + HDassert(start); + HDassert(count); + HDassert(op >= H5S_SELECT_SET && op <= H5S_SELECT_NOTA); + HDassert(new_space); + HDassert(*new_space == NULL); + + /* Point to the correct stride values */ + if(stride == NULL) + stride = H5S_hyper_ones_g; + + /* Point to the correct block values */ + if(block == NULL) + block = H5S_hyper_ones_g; + + /* Check new selection. */ + for(u = 0; u < old_space->extent.rank; u++) { + /* Check for overlapping hyperslab blocks in new selection. */ + if(count[u] > 1 && stride[u] < block[u]) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hyperslab blocks overlap") + + /* Detect zero-sized hyperslabs in new selection */ + if(count[u] == 0 || block[u] == 0) { + switch(op) { + case H5S_SELECT_AND: /* Binary "and" operation for hyperslabs */ + case H5S_SELECT_NOTA: /* Binary "B not A" operation for hyperslabs */ + /* Convert to "none" selection */ + /* Copy the first dataspace without sharing the list of spans */ + if(NULL == ((*new_space) = H5S_copy(old_space, TRUE, TRUE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy dataspace") + if(H5S_select_none((*new_space)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + HGOTO_DONE(SUCCEED); + + case H5S_SELECT_OR: /* Binary "or" operation for hyperslabs */ + case H5S_SELECT_XOR: /* Binary "xor" operation for hyperslabs */ + case H5S_SELECT_NOTB: /* Binary "A not B" operation for hyperslabs */ + /* Copy the first dataspace with sharing the list of spans */ + if(NULL == ((*new_space) = H5S_copy(old_space, FALSE, TRUE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy dataspace") + HGOTO_DONE(SUCCEED); /* Selection stays same */ + + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: + default: + HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") + } /* end switch */ + } /* end if */ + } /* end for */ + + if(H5S_GET_SELECT_TYPE(old_space) == H5S_SEL_HYPERSLABS) { + hsize_t *old_low_bounds; /* Pointer to old space's low & high bounds */ + hsize_t *old_high_bounds; + hsize_t new_low_bounds[H5S_MAX_RANK]; /* New space's low & high bounds */ + hsize_t new_high_bounds[H5S_MAX_RANK]; + hbool_t overlapped = FALSE; + + /* Set up old space's low & high bounds */ + if(old_space->select.sel_info.hslab->span_lst) { + old_low_bounds = old_space->select.sel_info.hslab->span_lst->low_bounds; + old_high_bounds = old_space->select.sel_info.hslab->span_lst->high_bounds; + } /* end if */ + else { + old_low_bounds = old_space->select.sel_info.hslab->diminfo.low_bounds; + old_high_bounds = old_space->select.sel_info.hslab->diminfo.high_bounds; + } /* end else */ + + /* Generate bounding box for hyperslab parameters */ + for(u = 0; u < old_space->extent.rank; u++) { + new_low_bounds[u] = start[u]; + new_high_bounds[u] = start[u] + stride[u] * (count[u] - 1) + (block[u] - 1); + } /* end for */ + + /* Check bound box of both spaces to see if they overlap */ + if(H5S_RANGE_OVERLAP(old_low_bounds[0], old_high_bounds[0], + new_low_bounds[0], new_high_bounds[0])) + overlapped = TRUE; + + /* Non-overlapping situations can be handled in special ways */ + if(!overlapped) { + H5S_hyper_span_info_t *new_spans = NULL; + H5S_hyper_dim_t new_hyper_diminfo[H5S_MAX_RANK]; + + if(NULL == ((*new_space) = H5S_copy(old_space, TRUE, TRUE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy dataspace") + if(NULL != (*new_space)->select.sel_info.hslab->span_lst) { + old_space->select.sel_info.hslab->span_lst->count--; + (*new_space)->select.sel_info.hslab->span_lst = NULL; + } /* end if */ + + /* Generate hyperslab info for new space */ + switch(op) { + case H5S_SELECT_OR: + case H5S_SELECT_XOR: + /* Add the new space to the space */ + if(NULL == (new_spans = H5S__hyper_make_spans(old_space->extent.rank, start, stride, count, block))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't create hyperslab information") + if(NULL != old_space->select.sel_info.hslab->span_lst) + (*new_space)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(old_space->select.sel_info.hslab->span_lst, old_space->extent.rank); + if(H5S__hyper_add_disjoint_spans(*new_space, new_spans) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't append hyperslabs") + + /* Build diminfo struct */ + for(u = 0; u < (*new_space)->extent.rank; u++) { + new_hyper_diminfo[u].start = start[u]; + new_hyper_diminfo[u].stride = stride[u]; + new_hyper_diminfo[u].count = count[u]; + new_hyper_diminfo[u].block = block[u]; + } /* end for */ + + /* Update space's dim info */ + if(H5S__hyper_update_diminfo(*new_space, op, new_hyper_diminfo) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOUNT, FAIL, "can't update hyperslab info") + break; + + case H5S_SELECT_AND: + if(H5S_select_none((*new_space)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + break; + + case H5S_SELECT_NOTB: + if(NULL != old_space->select.sel_info.hslab->span_lst) { + if(NULL == ((*new_space)->select.sel_info.hslab->span_lst = H5S__hyper_copy_span(old_space->select.sel_info.hslab->span_lst, old_space->extent.rank))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy dataspace") + } /* end if */ + else { + if(H5S_select_none((*new_space)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") + } /* end else */ + break; + + case H5S_SELECT_NOTA: + if(H5S__set_regular_hyperslab(*new_space, start, stride, count, block, stride, count, block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSET, FAIL, "can't set regular selection") + break; + + case H5S_SELECT_NOOP: + case H5S_SELECT_SET: + case H5S_SELECT_APPEND: + case H5S_SELECT_PREPEND: + case H5S_SELECT_INVALID: + default: + HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "invalid selection operation") + } /* end switch */ + + HGOTO_DONE(SUCCEED); + } /* end if(!overlapped) */ + } /* end if the selection of old space is H5S_SEL_HYPERSLABS */ + + /* Copy the first dataspace with sharing the list of spans */ + if(NULL == ((*new_space) = H5S_copy(old_space, TRUE, TRUE))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to copy dataspace") + + /* Note: a little overhead in calling the function as some conditions are checked again */ + if(H5S_select_hyperslab(*new_space, op, start, stride, count, block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to set hyperslab selection") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S_combine_hyperslab() */ + + +/*------------------------------------------------------------------------- + * Function: H5S__fill_in_select + * + * Purpose: Combines two hyperslabs with an operation, putting the + * result into a third hyperslab selection + * + * Return: Non-negative on success/negative on failure + * + * Programmer: Chao Mei + * Tuesday, July 5, 2011 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5S__fill_in_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2, H5S_t **result) +{ + hbool_t span2_owned; + hbool_t updated_spans; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(space1); + HDassert(space2); + HDassert(op >= H5S_SELECT_OR && op <= H5S_SELECT_NOTA); + HDassert(space1->extent.rank == space2->extent.rank); + /* The result is either a to-be-created space or an empty one */ + HDassert(NULL == *result || *result == space1); + HDassert(space1->select.sel_info.hslab->span_lst); + HDassert(space2->select.sel_info.hslab->span_lst); + + /* Note: the offset of space2 is not considered here for bounding box */ + if(H5S__fill_in_new_space(space1, op, space2->select.sel_info.hslab->span_lst, FALSE, &span2_owned, &updated_spans, result) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't create the specified selection") + + /* Update diminfo if space2's diminfo was valid, otherwise just mark it as + * invalid if the spans were updated */ + HDassert(result); + if(updated_spans) { + if(space2->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + if(H5S__hyper_update_diminfo(*result, op, space2->select.sel_info.hslab->diminfo.opt) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOUNT, FAIL, "can't update hyperslab info") + } /* end if */ + else + (*result)->select.sel_info.hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; + } /* end if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__fill_in_select() */ + + +/*------------------------------------------------------------------------- + * Function: H5S__modify_select + * + * Purpose: Internal version of H5Smodify_select(). + * + * Return: New dataspace on success/NULL on failure + * + * Programmer: Quincey Koziol + * Tuesday, October 30, 2001 + * + *------------------------------------------------------------------------- + */ +herr_t +H5S__modify_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2) +{ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + /* Check args */ + HDassert(space1); + HDassert(space2); + HDassert(op >= H5S_SELECT_OR && op <= H5S_SELECT_NOTA); + + /* Check that the space selections both have span trees */ + if(NULL == space1->select.sel_info.hslab->span_lst) + if(H5S__hyper_generate_spans(space1) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") + + /* Set unlim_dim */ + space1->select.sel_info.hslab->unlim_dim = -1; + + if(NULL == space2->select.sel_info.hslab->span_lst) { + hsize_t tmp_start[H5S_MAX_RANK]; + hsize_t tmp_stride[H5S_MAX_RANK]; + hsize_t tmp_count[H5S_MAX_RANK]; + hsize_t tmp_block[H5S_MAX_RANK]; + unsigned u; + + for(u = 0; u < space2->extent.rank; u++) { + tmp_start[u] = space2->select.sel_info.hslab->diminfo.opt[u].start; + tmp_stride[u] = space2->select.sel_info.hslab->diminfo.opt[u].stride; + tmp_count[u] = space2->select.sel_info.hslab->diminfo.opt[u].count; + tmp_block[u] = space2->select.sel_info.hslab->diminfo.opt[u].block; + } /* end for */ + + /* Call H5S_select_hyperslab directly */ + if(H5S_select_hyperslab(space1, op, tmp_start, tmp_stride, tmp_count, tmp_block) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to set hyperslab selection") + } /* end if */ + else + /* Combine spans from space1 & spans from space2, with the result in space1 */ + if(H5S__fill_in_select(space1, op, space2, &space1) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't perform operation on two selections") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__modify_select() */ + /*-------------------------------------------------------------------------- NAME @@ -8148,15 +10070,15 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t ss_nelem; /* Number of elements for src_space */ size_t ss_i = (size_t)0; /* Index into offset/length arrays for src_space */ hbool_t advance_ss = FALSE; /* Whether to advance ss_i on the next iteration */ - H5S_sel_iter_t *ss_iter = NULL; /* Selection iterator for src_space */ + H5S_sel_iter_t *ss_iter = NULL; /* Selection iterator for src_space */ hbool_t ss_iter_init = FALSE; /* Whether ss_iter is initialized */ hsize_t ss_sel_off = (hsize_t)0; /* Offset within src_space selection */ hsize_t ds_off[H5S_PROJECT_INTERSECT_NSEQS]; /* Offset array for dst_space */ size_t ds_len[H5S_PROJECT_INTERSECT_NSEQS]; /* Length array for dst_space */ size_t ds_nseq; /* Number of sequences for dst_space */ size_t ds_nelem; /* Number of elements for dst_space */ - size_t ds_i = (size_t)0; /* Index into offset/length arrays for dst_space */ - H5S_sel_iter_t *ds_iter = NULL; /* Selection iterator for dst_space */ + size_t ds_i = (size_t)0; /* Index into offset/length arrays for dst_space */ + H5S_sel_iter_t *ds_iter = NULL; /* Selection iterator for dst_space */ hbool_t ds_iter_init = FALSE; /* Whether ds_iter is initialized */ hsize_t ds_sel_off = (hsize_t)0; /* Offset within dst_space selection */ hsize_t sis_off[H5S_PROJECT_INTERSECT_NSEQS]; /* Offset array for src_intersect_space */ @@ -8165,7 +10087,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t sis_nelem; /* Number of elements for src_intersect_space */ size_t sis_i = (size_t)0; /* Index into offset/length arrays for src_intersect_space */ hbool_t advance_sis = FALSE; /* Whether to advance sis_i on the next iteration */ - H5S_sel_iter_t *sis_iter = NULL; /* Selection iterator for src_intersect_space */ + H5S_sel_iter_t *sis_iter = NULL; /* Selection iterator for src_intersect_space */ hbool_t sis_iter_init = FALSE; /* Whether sis_iter is initialized */ hsize_t int_sel_off; /* Offset within intersected selections (ss/sis and ds/ps) */ size_t int_len; /* Length of segment in intersected selections */ @@ -8174,14 +10096,11 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, size_t proj_len_rem; /* Remaining length in proj_space for segment */ hsize_t proj_down_dims[H5S_MAX_RANK]; /* "Down" dimensions in proj_space */ H5S_hyper_span_info_t *curr_span_tree[H5S_MAX_RANK]; /* Current span tree being built (in each dimension) */ - H5S_hyper_span_t *prev_span[H5S_MAX_RANK]; /* Previous span in tree (in each dimension) */ hsize_t curr_span_up_dim[H5S_MAX_RANK]; /* "Up" dimensions for current span */ unsigned proj_rank; /* Rank of proj_space */ hsize_t low; /* Low value of span */ - hsize_t high; /* High value of span */ - size_t span_len; /* Length of span */ size_t nelem; /* Number of elements returned for get_seq_list op */ - unsigned i; /* Local index variable */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_PACKAGE @@ -8203,7 +10122,6 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, /* Initialize prev_space, curr_span_tree, and curr_span_up_dim */ HDmemset(curr_span_tree, 0, sizeof(curr_span_tree)); - HDmemset(prev_span, 0, sizeof(prev_span)); HDmemset(curr_span_up_dim, 0, sizeof(curr_span_up_dim)); /* Save rank of projected space */ @@ -8244,12 +10162,12 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate source selection iterator") /* Initialize source space iterator */ - if(H5S_select_iter_init(ss_iter, src_space, (size_t)1) < 0) + if(H5S_select_iter_init(ss_iter, src_space, (size_t)1, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ss_iter_init = TRUE; /* Get sequence list for source space */ - if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") ss_nelem -= nelem; HDassert(ss_nseq > 0); @@ -8259,12 +10177,12 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate destination selection iterator") /* Initialize destination space iterator */ - if(H5S_select_iter_init(ds_iter, dst_space, (size_t)1) < 0) + if(H5S_select_iter_init(ds_iter, dst_space, (size_t)1, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ds_iter_init = TRUE; /* Get sequence list for destination space */ - if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") ds_nelem -= nelem; HDassert(ds_nseq > 0); @@ -8274,12 +10192,12 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate source intersect space iterator") /* Initialize source intersect space iterator */ - if(H5S_select_iter_init(sis_iter, src_intersect_space, (size_t)1) < 0) + if(H5S_select_iter_init(sis_iter, src_intersect_space, (size_t)1, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") sis_iter_init = TRUE; /* Get sequence list for source intersect space */ - if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") sis_nelem -= nelem; HDassert(sis_nseq > 0); @@ -8294,7 +10212,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, if(++ss_i == ss_nseq) { if(ss_nelem > 0) { /* Try to grab more sequences from src_space */ - if(H5S_SELECT_GET_SEQ_LIST(src_space, 0u, ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(ss_iter, H5S_PROJECT_INTERSECT_NSEQS, ss_nelem, &ss_nseq, &nelem, ss_off, ss_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(ss_len[0] > 0); @@ -8325,7 +10243,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, if(sis_nelem > 0) { /* Try to grab more sequences from src_intersect_space */ - if(H5S_SELECT_GET_SEQ_LIST(src_intersect_space, 0u, sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(sis_iter, H5S_PROJECT_INTERSECT_NSEQS, sis_nelem, &sis_nseq, &nelem, sis_off, sis_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(sis_len[0] > 0); @@ -8377,7 +10295,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, HDassert(ds_nelem > 0); /* Try to grab more sequences from dst_space */ - if(H5S_SELECT_GET_SEQ_LIST(dst_space, 0u, ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(ds_iter, H5S_PROJECT_INTERSECT_NSEQS, ds_nelem, &ds_nseq, &nelem, ds_off, ds_len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") HDassert(ds_len[0] > 0); @@ -8399,34 +10317,33 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, /* Add to span tree */ while(proj_len_rem > (size_t)0) { - /* Check for more than one full row (in every dim) and - * append multiple spans at once? -NAF */ + hsize_t high; /* High value of span */ + size_t span_len; /* Length of span */ + /* Append spans in higher dimensions if we're going ouside * the plane of the span currently being built (i.e. it's * finished being built) */ - for(i = proj_rank - 1; ((i > 0) - && ((proj_off / proj_down_dims[i - 1]) - != curr_span_up_dim[i - 1])); i--) { - if(curr_span_tree[i]) { - HDassert(prev_span[i]); - + /* Check for more than one full row (in every dim) and + * append multiple spans at once? -NAF */ + for(u = proj_rank - 1; ((u > 0) + && ((proj_off / proj_down_dims[u - 1]) + != curr_span_up_dim[u - 1])); u--) { + if(curr_span_tree[u]) { /* Append complete lower dimension span tree to * current dimension */ - low = curr_span_up_dim[i - 1] % proj_space->extent.size[i - 1]; - if(H5S__hyper_append_span(&prev_span[i - 1], &curr_span_tree[i - 1], low, low, curr_span_tree[i], NULL) < 0) + low = curr_span_up_dim[u - 1] % proj_space->extent.size[u - 1]; + if(H5S__hyper_append_span(&curr_span_tree[u - 1], (proj_rank - u) + 1, low, low, curr_span_tree[u]) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Reset lower dimension's span tree and previous * span since we just committed it and will start * over with a new one */ - if(H5S__hyper_free_span_info(curr_span_tree[i]) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't free span info") - curr_span_tree[i] = NULL; - prev_span[i] = NULL; + H5S__hyper_free_span_info(curr_span_tree[u]); + curr_span_tree[u] = NULL; } /* end if */ /* Update curr_span_up_dim */ - curr_span_up_dim[i - 1] = proj_off / proj_down_dims[i - 1]; + curr_span_up_dim[u - 1] = proj_off / proj_down_dims[u - 1]; } /* end for */ /* Compute bounds for new span in lowest dimension */ @@ -8438,7 +10355,7 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, high = (low + (hsize_t)span_len) - (hsize_t)1; /* Append span in lowest dimension */ - if(H5S__hyper_append_span(&prev_span[proj_rank - 1], &curr_span_tree[proj_rank - 1], low, high, NULL, NULL) < 0) + if(H5S__hyper_append_span(&curr_span_tree[proj_rank - 1], 1, low, high, NULL) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Update remaining offset and length */ @@ -8455,19 +10372,16 @@ H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, loop_end: /* Add remaining spans to span tree */ - for(i = proj_rank - 1; i > 0; i--) - if(curr_span_tree[i]) { - HDassert(prev_span[i]); - + for(u = proj_rank - 1; u > 0; u--) + if(curr_span_tree[u]) { /* Append remaining span tree to higher dimension */ - low = curr_span_up_dim[i - 1] % proj_space->extent.size[i - 1]; - if(H5S__hyper_append_span(&prev_span[i - 1], &curr_span_tree[i - 1], low, low, curr_span_tree[i], NULL) < 0) + low = curr_span_up_dim[u - 1] % proj_space->extent.size[u - 1]; + if(H5S__hyper_append_span(&curr_span_tree[u - 1], (proj_rank - u) + 1, low, low, curr_span_tree[u]) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTAPPEND, FAIL, "can't allocate hyperslab span") /* Reset span tree */ - if(H5S__hyper_free_span_info(curr_span_tree[i]) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't free span info") - curr_span_tree[i] = NULL; + H5S__hyper_free_span_info(curr_span_tree[u]); + curr_span_tree[u] = NULL; } /* end if */ /* Add span tree to proj_space */ @@ -8514,129 +10428,14 @@ done: HDONE_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection") /* Free span trees */ - for(i = 0; i < proj_rank; i++) - if(curr_span_tree[i]) { - if(H5S__hyper_free_span_info(curr_span_tree[i]) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTFREE, FAIL, "can't free span info") - curr_span_tree[i] = NULL; - } /* end if */ + for(u = 0; u < proj_rank; u++) + if(curr_span_tree[u]) + H5S__hyper_free_span_info(curr_span_tree[u]); } /* end if */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__hyper_project_intersection() */ - -/*-------------------------------------------------------------------------- - NAME - H5S__hyper_subtract - PURPOSE - Subtract one hyperslab selection from another - USAGE - herr_t H5S__hyper_subtract(space,subtract_space) - H5S_t *space; IN/OUT: Selection to be operated on - H5S_t *subtract_space; IN: Selection that will be subtracted from space - RETURNS - Non-negative on success/Negative on failure. - DESCRIPTION - Removes any and all portions of space that are also present in - subtract_space. In essence, performs an A_NOT_B operation with the - two selections. - - Note this function basically duplicates a subset of the functionality - of H5S_select_select(). It should probably be removed when that - function is enabled. - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -herr_t -H5S__hyper_subtract(H5S_t *space, H5S_t *subtract_space) -{ - H5S_hyper_span_info_t *a_not_b = NULL; /* Span tree for hyperslab spans in old span tree and not in new span tree */ - H5S_hyper_span_info_t *a_and_b = NULL; /* Span tree for hyperslab spans in both old and new span trees */ - H5S_hyper_span_info_t *b_not_a = NULL; /* Span tree for hyperslab spans in new span tree and not in old span tree */ - herr_t ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT - - /* Check args */ - HDassert(space); - HDassert(subtract_space); - - /* Check that the space selections both have span trees */ - if(space->select.sel_info.hslab->span_lst == NULL) - if(H5S__hyper_generate_spans(space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") - if(subtract_space->select.sel_info.hslab->span_lst == NULL) - if(H5S__hyper_generate_spans(subtract_space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") - - /* Generate lists of spans which overlap and don't overlap */ - if(H5S__hyper_clip_spans(space->select.sel_info.hslab->span_lst, subtract_space->select.sel_info.hslab->span_lst, &a_not_b, &a_and_b, &b_not_a)<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't clip hyperslab information") - - /* Reset the other dataspace selection information */ - if(H5S_SELECT_RELEASE(space) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release selection") - - /* Allocate space for the hyperslab selection information */ - if((space->select.sel_info.hslab = H5FL_CALLOC(H5S_hyper_sel_t)) == NULL) - HGOTO_ERROR(H5E_DATASPACE, H5E_NOSPACE, FAIL, "can't allocate hyperslab info") - - /* Set unlim_dim */ - space->select.sel_info.hslab->unlim_dim = -1; - - /* Check for anything returned in a_not_b */ - if(a_not_b) { - /* Update spans in space */ - space->select.sel_info.hslab->span_lst = a_not_b; - a_not_b = NULL; - - /* Update number of elements */ - space->select.num_elem = H5S__hyper_spans_nelem(space->select.sel_info.hslab->span_lst); - - /* Attempt to rebuild "optimized" start/stride/count/block information. - * from resulting hyperslab span tree */ - H5S__hyper_rebuild(space); - } /* end if */ - else { - H5S_hyper_span_info_t *spans; /* Empty hyperslab span tree */ - - /* Set number of elements */ - space->select.num_elem = 0; - - /* Allocate a span info node */ - if(NULL == (spans = H5FL_MALLOC(H5S_hyper_span_info_t))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate hyperslab span") - - /* Set the reference count */ - spans->count = 1; - - /* Reset the scratch pad space */ - spans->scratch = 0; - - /* Set to empty tree */ - spans->head = NULL; - - /* Set pointer to empty span tree */ - space->select.sel_info.hslab->span_lst = spans; - } /* end if */ - -done: - /* Free span trees */ - if(a_and_b) - H5S__hyper_free_span_info(a_and_b); - if(b_not_a) - H5S__hyper_free_span_info(b_not_a); - if(a_not_b) { - HDassert(ret_value < 0); - H5S__hyper_free_span_info(b_not_a); - } /* end if */ - - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__hyper_subtract() */ - /*-------------------------------------------------------------------------- NAME @@ -8706,7 +10505,7 @@ H5S__hyper_get_clip_diminfo(hsize_t start, hsize_t stride, hsize_t *count, RETURNS Non-negative on success/Negative on failure. DESCRIPTION - This function changes the unlimited selection into a limited selection + This function changes the unlimited selection into a fixed-dimension selection with the extent of the formerly unlimited dimension specified by clip_size. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS @@ -8720,7 +10519,7 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) H5S_hyper_sel_t *hslab; /* Convenience pointer to hyperslab info */ hsize_t orig_count; /* Original count in unlimited dimension */ int orig_unlim_dim; /* Original unliminted dimension */ - H5S_hyper_dim_t *diminfo; /* Convenience pointer to opt_diminfo in unlimited dimension */ + H5S_hyper_dim_t *diminfo; /* Convenience pointer to diminfo.opt in unlimited dimension */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -8735,7 +10534,8 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) /* Save original unlimited dimension */ orig_unlim_dim = hslab->unlim_dim; - diminfo = &hslab->opt_diminfo[orig_unlim_dim]; + /* Set up convenience pointer */ + diminfo = &hslab->diminfo.opt[orig_unlim_dim]; /* Save original count in unlimited dimension */ orig_count = diminfo->count; @@ -8757,8 +10557,8 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) /* Calculate number of elements */ space->select.num_elem = diminfo->block * hslab->num_elem_non_unlim; - /* Mark that opt_diminfo is valid */ - hslab->diminfo_valid = TRUE; + /* Mark that diminfo.opt is valid */ + hslab->diminfo_valid = H5S_DIMINFO_VALID_YES; } /* end if */ else { /* Calculate number of elements */ @@ -8771,7 +10571,7 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) > (clip_size - diminfo->start)) { hsize_t start[H5S_MAX_RANK]; hsize_t block[H5S_MAX_RANK]; - unsigned i; + unsigned u; /* Last block is partial, need to construct compound selection */ /* Fill start with zeros */ @@ -8779,11 +10579,11 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) /* Set block to clip_size in unlimited dimension, H5S_MAX_SIZE in * others so only unlimited dimension is clipped */ - for(i = 0; i < space->extent.rank; i++) - if((int)i == orig_unlim_dim) - block[i] = clip_size; + for(u = 0; u < space->extent.rank; u++) + if((int)u == orig_unlim_dim) + block[u] = clip_size; else - block[i] = H5S_MAX_SIZE; + block[u] = H5S_MAX_SIZE; /* Generate span tree in selection */ if(!hslab->span_lst) @@ -8791,17 +10591,24 @@ H5S_hyper_clip_unlim(H5S_t *space, hsize_t clip_size) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to generate span tree") /* Indicate that the regular dimensions are no longer valid */ - hslab->diminfo_valid = FALSE; + hslab->diminfo_valid = H5S_DIMINFO_VALID_NO; /* "And" selection with calculated block to perform clip operation */ if(H5S__generate_hyperslab(space, H5S_SELECT_AND, start, H5S_hyper_ones_g, H5S_hyper_ones_g, block) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't generate hyperslabs") } /* end if */ else - /* Last block is complete, simply mark that opt_diminfo is valid */ - hslab->diminfo_valid = TRUE; + /* Last block is complete, simply mark that diminfo.opt is valid */ + hslab->diminfo_valid = H5S_DIMINFO_VALID_YES; } /* end else */ + /* Update the upper bound, if the diminfo is valid */ + if(H5S_DIMINFO_VALID_YES == hslab->diminfo_valid) + hslab->diminfo.high_bounds[orig_unlim_dim] = + hslab->diminfo.opt[orig_unlim_dim].start + + hslab->diminfo.opt[orig_unlim_dim].stride * (hslab->diminfo.opt[orig_unlim_dim].count - 1) + + (hslab->diminfo.opt[orig_unlim_dim].block - 1); + done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_clip_unlim() */ @@ -8850,7 +10657,7 @@ H5S__hyper_get_clip_extent_real(const H5S_t *clip_space, hsize_t num_slices, HDassert(clip_space->select.sel_info.hslab); HDassert(clip_space->select.sel_info.hslab->unlim_dim >= 0); - diminfo = &clip_space->select.sel_info.hslab->opt_diminfo[clip_space->select.sel_info.hslab->unlim_dim]; + diminfo = &clip_space->select.sel_info.hslab->diminfo.opt[clip_space->select.sel_info.hslab->unlim_dim]; if(num_slices == 0) ret_value = incl_trail ? diminfo->start : 0; @@ -9004,7 +10811,7 @@ H5S_hyper_get_clip_extent_match(const H5S_t *clip_space, HDassert(clip_space->select.sel_info.hslab->num_elem_non_unlim == match_space->select.sel_info.hslab->num_elem_non_unlim); - match_diminfo = &match_space->select.sel_info.hslab->opt_diminfo[match_space->select.sel_info.hslab->unlim_dim]; + match_diminfo = &match_space->select.sel_info.hslab->diminfo.opt[match_space->select.sel_info.hslab->unlim_dim]; /* Get initial count and block */ count = match_diminfo->count; @@ -9068,13 +10875,13 @@ H5S_t * H5S_hyper_get_unlim_block(const H5S_t *space, hsize_t block_index) { H5S_hyper_sel_t *hslab; /* Convenience pointer to hyperslab info */ - H5S_t *space_out = NULL; - hsize_t start[H5S_MAX_RANK]; + H5S_t *space_out = NULL; /* Dataspace to return */ + hsize_t start[H5S_MAX_RANK];/* Hyperslab selection info for unlim. selection */ hsize_t stride[H5S_MAX_RANK]; hsize_t count[H5S_MAX_RANK]; hsize_t block[H5S_MAX_RANK]; - unsigned i; - H5S_t *ret_value = NULL; + unsigned u; /* Local index variable */ + H5S_t *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(NULL) @@ -9083,23 +10890,23 @@ H5S_hyper_get_unlim_block(const H5S_t *space, hsize_t block_index) hslab = space->select.sel_info.hslab; HDassert(hslab); HDassert(hslab->unlim_dim >= 0); - HDassert(hslab->opt_diminfo[hslab->unlim_dim].count == H5S_UNLIMITED); + HDassert(hslab->diminfo.opt[hslab->unlim_dim].count == H5S_UNLIMITED); /* Set start to select block_indexth block in unlimited dimension and set * count to 1 in that dimension to only select that block. Copy all other * diminfo parameters. */ - for(i = 0; i < space->extent.rank; i++) { - if((int)i == hslab->unlim_dim){ - start[i] = hslab->opt_diminfo[i].start + (block_index - * hslab->opt_diminfo[i].stride); - count[i] = (hsize_t)1; + for(u = 0; u < space->extent.rank; u++) { + if((int)u == hslab->unlim_dim){ + start[u] = hslab->diminfo.opt[u].start + (block_index + * hslab->diminfo.opt[u].stride); + count[u] = (hsize_t)1; } /* end if */ else { - start[i] = hslab->opt_diminfo[i].start; - count[i] = hslab->opt_diminfo[i].count; + start[u] = hslab->diminfo.opt[u].start; + count[u] = hslab->diminfo.opt[u].count; } /* end else */ - stride[i] = hslab->opt_diminfo[i].stride; - block[i] = hslab->opt_diminfo[i].block; + stride[u] = hslab->diminfo.opt[u].stride; + block[u] = hslab->diminfo.opt[u].block; } /* end for */ /* Create output space, copy extent */ @@ -9154,7 +10961,7 @@ H5S_hyper_get_first_inc_block(const H5S_t *space, hsize_t clip_size, hbool_t *partial) { H5S_hyper_sel_t *hslab; /* Convenience pointer to hyperslab info */ - H5S_hyper_dim_t *diminfo; /* Convenience pointer to opt_diminfo in unlimited dimension */ + H5S_hyper_dim_t *diminfo; /* Convenience pointer to diminfo.opt in unlimited dimension */ hsize_t ret_value = 0; FUNC_ENTER_NOAPI(0) @@ -9164,9 +10971,9 @@ H5S_hyper_get_first_inc_block(const H5S_t *space, hsize_t clip_size, hslab = space->select.sel_info.hslab; HDassert(hslab); HDassert(hslab->unlim_dim >= 0); - HDassert(hslab->opt_diminfo[hslab->unlim_dim].count == H5S_UNLIMITED); + HDassert(hslab->diminfo.opt[hslab->unlim_dim].count == H5S_UNLIMITED); - diminfo = &hslab->opt_diminfo[hslab->unlim_dim]; + diminfo = &hslab->diminfo.opt[hslab->unlim_dim]; /* Check for selection outside of clip_size */ if(diminfo->start >= clip_size) { @@ -9283,16 +11090,16 @@ H5Sget_regular_hyperslab(hid_t spaceid, hsize_t start[], hsize_t stride[], /* Retrieve hyperslab parameters */ if(start) for(u = 0; u < space->extent.rank; u++) - start[u] = space->select.sel_info.hslab->app_diminfo[u].start; + start[u] = space->select.sel_info.hslab->diminfo.app[u].start; if(stride) for(u = 0; u < space->extent.rank; u++) - stride[u] = space->select.sel_info.hslab->app_diminfo[u].stride; + stride[u] = space->select.sel_info.hslab->diminfo.app[u].stride; if(count) for(u = 0; u < space->extent.rank; u++) - count[u] = space->select.sel_info.hslab->app_diminfo[u].count; + count[u] = space->select.sel_info.hslab->diminfo.app[u].count; if(block) for(u = 0; u < space->extent.rank; u++) - block[u] = space->select.sel_info.hslab->app_diminfo[u].block; + block[u] = space->select.sel_info.hslab->diminfo.app[u].block; done: FUNC_LEAVE_API(ret_value) diff --git a/src/H5Smpio.c b/src/H5Smpio.c index 01ec3e18cc..aeec566ea8 100644 --- a/src/H5Smpio.c +++ b/src/H5Smpio.c @@ -31,6 +31,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ +#include "H5FLprivate.h" /* Free Lists */ #include "H5MMprivate.h" /* Memory management */ #include "H5Spkg.h" /* Dataspaces */ #include "H5VMprivate.h" /* Vector and array functions */ @@ -51,6 +52,18 @@ /* Local Typedefs */ /******************/ +/* Node in linked list of MPI data types created during traversal of irregular hyperslab selection */ +typedef struct H5S_mpio_mpitype_node_t { + MPI_Datatype type; /* MPI Datatype */ + struct H5S_mpio_mpitype_node_t *next; /* Pointer to next node in list */ +} H5S_mpio_mpitype_node_t; + +/* List to track MPI data types generated during traversal of irregular hyperslab selection */ +typedef struct H5S_mpio_mpitype_list_t { + H5S_mpio_mpitype_node_t *head; /* Pointer to head of list */ + H5S_mpio_mpitype_node_t *tail; /* Pointer to tail of list */ +} H5S_mpio_mpitype_list_t; + /********************/ /* Local Prototypes */ @@ -71,9 +84,12 @@ static herr_t H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count, hbool_t *is_derived_type); static herr_t H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count, hbool_t *is_derived_type); -static herr_t H5S__obtain_datatype(const hsize_t down[], H5S_hyper_span_t* span, - const MPI_Datatype *elmt_type, MPI_Datatype *span_type, size_t elmt_size); -static herr_t H5S__mpio_create_large_type(hsize_t, MPI_Aint, MPI_Datatype , MPI_Datatype *); +static herr_t H5S__release_datatype(H5S_mpio_mpitype_list_t *type_list); +static herr_t H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, + size_t elmt_size, const MPI_Datatype *elmt_type, MPI_Datatype *span_type, + H5S_mpio_mpitype_list_t *type_list, uint64_t op_gen); +static herr_t H5S__mpio_create_large_type(hsize_t num_elements, MPI_Aint stride_bytes, + MPI_Datatype old_type, MPI_Datatype *new_type); /*****************************/ @@ -91,6 +107,8 @@ static herr_t H5S__mpio_create_large_type(hsize_t, MPI_Aint, MPI_Datatype , MPI_ /*******************/ static hsize_t bigio_count = H5S_MAX_MPI_COUNT; +/* Declare a free list to manage the H5S_mpio_mpitype_node_t struct */ +H5FL_DEFINE_STATIC(H5S_mpio_mpitype_node_t); @@ -542,7 +560,7 @@ H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") /* Initialize selection iterator */ - if(H5S_select_iter_init(&sel_iter, space, elmt_size) < 0) + if(H5S_select_iter_init(&sel_iter, space, elmt_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") sel_iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -559,7 +577,7 @@ H5S__mpio_permute_type(const H5S_t *space, size_t elmt_size, hsize_t **permute, size_t curr_seq; /* Current sequence being worked on */ /* Get the sequences of bytes */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, &sel_iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(&sel_iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -679,7 +697,7 @@ H5S__mpio_reg_hyper_type(const H5S_t *space, size_t elmt_size, HDassert(sizeof(MPI_Aint) >= sizeof(elmt_size)); /* Initialize selection iterator */ - if(H5S_select_iter_init(&sel_iter, space, elmt_size) < 0) + if(H5S_select_iter_init(&sel_iter, space, elmt_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") sel_iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -979,10 +997,12 @@ static herr_t H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, MPI_Datatype *new_type, int *count, hbool_t *is_derived_type) { + H5S_mpio_mpitype_list_t type_list; /* List to track MPI data types created */ MPI_Datatype elmt_type; /* MPI datatype for an element */ hbool_t elmt_type_is_derived = FALSE; /* Whether the element type has been created */ MPI_Datatype span_type; /* MPI datatype for overall span tree */ hsize_t down[H5S_MAX_RANK]; /* 'down' sizes for each dimension */ + uint64_t op_gen; /* Operation generation value */ int mpi_code; /* MPI return code */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1008,12 +1028,21 @@ H5S__mpio_span_hyper_type(const H5S_t *space, size_t elmt_size, if(H5VM_array_down(space->extent.rank, space->extent.size, down) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGETSIZE, FAIL, "couldn't compute 'down' dimension sizes") - /* Obtain derived data type */ - if(H5S__obtain_datatype(down, space->select.sel_info.hslab->span_lst->head, &elmt_type, &span_type, elmt_size) < 0) + /* Acquire an operation generation value for creating MPI datatypes */ + op_gen = H5S__hyper_get_op_gen(); + + /* Obtain derived MPI data type */ + type_list.head = type_list.tail = NULL; + if(H5S__obtain_datatype(space->select.sel_info.hslab->span_lst, down, elmt_size, &elmt_type, &span_type, &type_list, op_gen) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't obtain MPI derived data type") - if(MPI_SUCCESS != (mpi_code = MPI_Type_commit(&span_type))) + if(MPI_SUCCESS != (mpi_code = MPI_Type_dup(span_type, new_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_commit failed", mpi_code) - *new_type = span_type; + if(MPI_SUCCESS != (mpi_code = MPI_Type_commit(new_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_commit failed", mpi_code) + + /* Release MPI data types generated during span tree traversal */ + if(H5S__release_datatype(&type_list) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "couldn't release MPI derived data type") /* fill in the remaining return values */ *count = 1; @@ -1028,6 +1057,53 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__mpio_span_hyper_type() */ + +/*------------------------------------------------------------------------- + * Function: H5S__release_datatype + * + * Purpose: Release the MPI derived datatypes for span-tree hyperslab selection + * + * Return: Non-negative on success, negative on failure. + * + * Programmer: Quincey Koziol, February 2, 2019 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5S__release_datatype(H5S_mpio_mpitype_list_t *type_list) +{ + H5S_mpio_mpitype_node_t *curr; /* Pointer to head of list */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity check */ + HDassert(type_list); + + /* Iterate over the list, freeing the MPI data types */ + curr = type_list->head; + while(curr) { + H5S_mpio_mpitype_node_t *next; /* Pointer to next node in list */ + int mpi_code; /* MPI return status code */ + + /* Release the MPI data type for this span tree */ + if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&curr->type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) + + /* Get pointer to next node in list */ + next = curr->next; + + /* Free the current node */ + curr = H5FL_FREE(H5S_mpio_mpitype_node_t, curr); + + /* Advance to next node */ + curr = next; + } /* end while */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__release_datatype() */ + /*------------------------------------------------------------------------- * Function: H5S__obtain_datatype @@ -1043,206 +1119,219 @@ done: *------------------------------------------------------------------------- */ static herr_t -H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *span, - const MPI_Datatype *elmt_type, MPI_Datatype *span_type, size_t elmt_size) +H5S__obtain_datatype(H5S_hyper_span_info_t *spans, const hsize_t *down, + size_t elmt_size, const MPI_Datatype *elmt_type, MPI_Datatype *span_type, + H5S_mpio_mpitype_list_t *type_list, uint64_t op_gen) { + H5S_hyper_span_t *span; /* Hyperslab span to iterate with */ size_t alloc_count = 0; /* Number of span tree nodes allocated at this level */ size_t outercount; /* Number of span tree nodes at this level */ MPI_Datatype *inner_type = NULL; hbool_t inner_types_freed = FALSE; /* Whether the inner_type MPI datatypes have been freed */ - hbool_t span_type_valid = FALSE; /* Whether the span_type MPI datatypes is valid */ - hbool_t large_block = FALSE; /* Wether the block length is larger than 32 bit integer */ int *blocklen = NULL; MPI_Aint *disp = NULL; - H5S_hyper_span_t *tspan = NULL; /* Temporary pointer to span tree node */ + size_t u; /* Local index variable */ int mpi_code; /* MPI return status code */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC /* Sanity check */ - HDassert(span); + HDassert(spans); + HDassert(type_list); - /* Allocate the initial displacement & block length buffers */ - alloc_count = H5S_MPIO_INITIAL_ALLOC_COUNT; - if(NULL == (disp = (MPI_Aint *)H5MM_malloc(alloc_count * sizeof(MPI_Aint)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") - if(NULL == (blocklen = (int *)H5MM_malloc(alloc_count * sizeof(int)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") + /* Check if we've visited this span tree before */ + if(spans->op_gen != op_gen) { + H5S_mpio_mpitype_node_t *type_node; /* Pointer to new node in MPI data type list */ - /* if this is the fastest changing dimension, it is the base case for derived datatype. */ - if(NULL == span->down) { - tspan = span; - outercount = 0; - while(tspan) { - /* Check if we need to increase the size of the buffers */ - if(outercount >= alloc_count) { - MPI_Aint *tmp_disp; /* Temporary pointer to new displacement buffer */ - int *tmp_blocklen; /* Temporary pointer to new block length buffer */ + /* Allocate the initial displacement & block length buffers */ + alloc_count = H5S_MPIO_INITIAL_ALLOC_COUNT; + if(NULL == (disp = (MPI_Aint *)H5MM_malloc(alloc_count * sizeof(MPI_Aint)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") + if(NULL == (blocklen = (int *)H5MM_malloc(alloc_count * sizeof(int)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") - /* Double the allocation count */ - alloc_count *= 2; + /* If this is the fastest changing dimension, it is the base case for derived datatype. */ + span = spans->head; + if(NULL == span->down) { + hbool_t large_block = FALSE; /* Wether the block length is larger than 32 bit integer */ - /* Re-allocate the buffers */ - if(NULL == (tmp_disp = (MPI_Aint *)H5MM_realloc(disp, alloc_count * sizeof(MPI_Aint)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") - disp = tmp_disp; - if(NULL == (tmp_blocklen = (int *)H5MM_realloc(blocklen, alloc_count * sizeof(int)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") - blocklen = tmp_blocklen; + outercount = 0; + while(span) { + hsize_t nelmts; /* # of elements covered by current span */ + + /* Check if we need to increase the size of the buffers */ + if(outercount >= alloc_count) { + MPI_Aint *tmp_disp; /* Temporary pointer to new displacement buffer */ + int *tmp_blocklen; /* Temporary pointer to new block length buffer */ + + /* Double the allocation count */ + alloc_count *= 2; + + /* Re-allocate the buffers */ + if(NULL == (tmp_disp = (MPI_Aint *)H5MM_realloc(disp, alloc_count * sizeof(MPI_Aint)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") + disp = tmp_disp; + if(NULL == (tmp_blocklen = (int *)H5MM_realloc(blocklen, alloc_count * sizeof(int)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") + blocklen = tmp_blocklen; + } /* end if */ + + /* Compute the number of elements to attempt in this span */ + nelmts = (span->high - span->low) + 1; + + /* Store displacement & block length */ + disp[outercount] = (MPI_Aint)elmt_size * span->low; + H5_CHECK_OVERFLOW(nelmts, hsize_t, int) + blocklen[outercount] = (int)nelmts; + + if(bigio_count < blocklen[outercount]) + large_block = TRUE; /* at least one block type is large, so set this flag to true */ + + span = span->next; + outercount++; + } /* end while */ + + /* Everything fits into integers, so cast them and use hindexed */ + if(bigio_count >= outercount && large_block == FALSE) { + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)outercount, blocklen, disp, *elmt_type, &spans->u.down_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hindexed failed", mpi_code) } /* end if */ + else { /* LARGE_DATATYPE:: Something doesn't fit into a 32 bit integer */ + for(u = 0 ; u < outercount; u++) { + MPI_Datatype temp_type = MPI_DATATYPE_NULL; - /* Store displacement & block length */ - disp[outercount] = (MPI_Aint)elmt_size * tspan->low; - H5_CHECK_OVERFLOW(tspan->nelem, hsize_t, int) - blocklen[outercount] = (int)tspan->nelem; - tspan = tspan->next; + /* create the block type from elmt_type while checking the 32 bit int limit */ + if(blocklen[u] > bigio_count) { + if(H5S__mpio_create_large_type(blocklen[u], 0, *elmt_type, &temp_type) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't create a large element datatype in span_hyper selection") + } /* end if */ + else + if(MPI_SUCCESS != (mpi_code = MPI_Type_contiguous((int)blocklen[u], *elmt_type, &temp_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_contiguous failed", mpi_code) - if(bigio_count < blocklen[outercount]) - large_block = TRUE; /* at least one block type is large, so set this flag to true */ + /* Combine the current datatype that is created with this current block type */ + if(0 == u) /* first iteration, there is no combined datatype yet */ + spans->u.down_type = temp_type; + else { + int bl[2] = {1, 1}; + MPI_Aint ds[2] = {disp[u - 1], disp[u]}; + MPI_Datatype dt[2] = {spans->u.down_type, temp_type}; - outercount++; - } /* end while */ + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct(2, /* count */ + bl, /* blocklength */ + ds, /* stride in bytes*/ + dt, /* old type */ + &spans->u.down_type))) /* new type */ + HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) - /* Everything fits into integers, so cast them and use hindexed */ - if(bigio_count >= outercount && large_block == FALSE) { - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)outercount, blocklen, disp, *elmt_type, span_type))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hindexed failed", mpi_code) - span_type_valid = TRUE; - } - else { /* LARGE_DATATYPE:: Something doesn't fit into a 32 bit integer */ - size_t i; - - for (i=0 ; i bigio_count) { - if (H5S__mpio_create_large_type (blocklen[i], 0, *elmt_type, &temp_type) < 0) { - HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, - "couldn't create a large element datatype in span_hyper selection") - } - } - else { - if(MPI_SUCCESS != (mpi_code = MPI_Type_contiguous((int)blocklen[i], - *elmt_type, - &temp_type))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_contiguous failed", mpi_code) - } - - /* combine the current datatype that is created with this current block type */ - if (0 == i) { /* first iteration, there is no combined datatype yet */ - *span_type = temp_type; - } - else { - int bl[2] = {1,1}; - MPI_Aint ds[2] = {disp[i-1],disp[i]}; - MPI_Datatype dt[2] = {*span_type, temp_type}; - - if (MPI_SUCCESS != (mpi_code = MPI_Type_create_struct (2, /* count */ - bl, /* blocklength */ - ds, /* stride in bytes*/ - dt, /* old type */ - &outer_type))){ /* new type */ - HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) - } - *span_type = outer_type; - } - - if (outer_type != MPI_DATATYPE_NULL) - MPI_Type_free(&outer_type); - /* temp_type shouldn't be freed here... - * Note that we have simply copied it above (not MPI_Type_dup) - * into the 'span_type' argument of the caller. - * The caller needs to deal with it there! - */ - } - } /* end (LARGE_DATATYPE::) */ - - } /* end if */ - else { - size_t u; /* Local index variable */ - - if(NULL == (inner_type = (MPI_Datatype *)H5MM_malloc(alloc_count * sizeof(MPI_Datatype)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of inner MPI datatypes") - - tspan = span; - outercount = 0; - while(tspan) { - MPI_Datatype down_type; /* Temporary MPI datatype for a span tree node's children */ + /* Release previous temporary datatype */ + if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&temp_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) + } /* end else */ + } /* end for */ + } /* end else (LARGE_DATATYPE::) */ + } /* end if */ + else { MPI_Aint stride; /* Distance between inner MPI datatypes */ - /* Check if we need to increase the size of the buffers */ - if(outercount >= alloc_count) { - MPI_Aint *tmp_disp; /* Temporary pointer to new displacement buffer */ - int *tmp_blocklen; /* Temporary pointer to new block length buffer */ - MPI_Datatype *tmp_inner_type; /* Temporary pointer to inner MPI datatype buffer */ + if(NULL == (inner_type = (MPI_Datatype *)H5MM_malloc(alloc_count * sizeof(MPI_Datatype)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of inner MPI datatypes") - /* Double the allocation count */ - alloc_count *= 2; - - /* Re-allocate the buffers */ - if(NULL == (tmp_disp = (MPI_Aint *)H5MM_realloc(disp, alloc_count * sizeof(MPI_Aint)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") - disp = tmp_disp; - if(NULL == (tmp_blocklen = (int *)H5MM_realloc(blocklen, alloc_count * sizeof(int)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") - blocklen = tmp_blocklen; - if(NULL == (tmp_inner_type = (MPI_Datatype *)H5MM_realloc(inner_type, alloc_count * sizeof(MPI_Datatype)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of inner MPI datatypes") - inner_type = tmp_inner_type; - } /* end if */ - - /* Displacement should be in byte and should have dimension information */ - /* First using MPI Type vector to build derived data type for this span only */ - /* Need to calculate the disp in byte for this dimension. */ /* Calculate the total bytes of the lower dimension */ - disp[outercount] = tspan->low * (*down) * elmt_size; - blocklen[outercount] = 1; - - /* Generate MPI datatype for next dimension down */ - if(H5S__obtain_datatype(down + 1, tspan->down->head, elmt_type, &down_type, elmt_size) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't obtain MPI derived data type") - - /* Build the MPI datatype for this node */ stride = (*down) * elmt_size; - H5_CHECK_OVERFLOW(tspan->nelem, hsize_t, int) - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hvector((int)tspan->nelem, 1, stride, down_type, &inner_type[outercount]))) { - MPI_Type_free(&down_type); - HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hvector failed", mpi_code) - } /* end if */ - /* Release MPI datatype for next dimension down */ - if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&down_type))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) + /* Loop over span nodes */ + outercount = 0; + while(span) { + MPI_Datatype down_type; /* Temporary MPI datatype for a span tree node's children */ + hsize_t nelmts; /* # of elements covered by current span */ - tspan = tspan->next; - outercount++; - } /* end while */ + /* Check if we need to increase the size of the buffers */ + if(outercount >= alloc_count) { + MPI_Aint *tmp_disp; /* Temporary pointer to new displacement buffer */ + int *tmp_blocklen; /* Temporary pointer to new block length buffer */ + MPI_Datatype *tmp_inner_type; /* Temporary pointer to inner MPI datatype buffer */ - /* building the whole vector datatype */ - H5_CHECK_OVERFLOW(outercount, size_t, int) - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct((int)outercount, blocklen, disp, inner_type, span_type))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) - span_type_valid = TRUE; + /* Double the allocation count */ + alloc_count *= 2; - /* Release inner node types */ - for(u = 0; u < outercount; u++) - if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&inner_type[u]))) - HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) - inner_types_freed = TRUE; + /* Re-allocate the buffers */ + if(NULL == (tmp_disp = (MPI_Aint *)H5MM_realloc(disp, alloc_count * sizeof(MPI_Aint)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of displacements") + disp = tmp_disp; + if(NULL == (tmp_blocklen = (int *)H5MM_realloc(blocklen, alloc_count * sizeof(int)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of block lengths") + blocklen = tmp_blocklen; + if(NULL == (tmp_inner_type = (MPI_Datatype *)H5MM_realloc(inner_type, alloc_count * sizeof(MPI_Datatype)))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate array of inner MPI datatypes") + inner_type = tmp_inner_type; + } /* end if */ + + /* Displacement should be in byte and should have dimension information */ + /* First using MPI Type vector to build derived data type for this span only */ + /* Need to calculate the disp in byte for this dimension. */ + disp[outercount] = span->low * stride; + blocklen[outercount] = 1; + + /* Generate MPI datatype for next dimension down */ + if(H5S__obtain_datatype(span->down, down + 1, elmt_size, elmt_type, &down_type, type_list, op_gen) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADTYPE, FAIL, "couldn't obtain MPI derived data type") + + /* Compute the number of elements to attempt in this span */ + nelmts = (span->high - span->low) + 1; + + /* Build the MPI datatype for this node */ + H5_CHECK_OVERFLOW(nelmts, hsize_t, int) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hvector((int)nelmts, 1, stride, down_type, &inner_type[outercount]))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hvector failed", mpi_code) + + span = span->next; + outercount++; + } /* end while */ + + /* Building the whole vector datatype */ + H5_CHECK_OVERFLOW(outercount, size_t, int) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_struct((int)outercount, blocklen, disp, inner_type, &spans->u.down_type))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_struct failed", mpi_code) + + /* Release inner node types */ + for(u = 0; u < outercount; u++) + if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&inner_type[u]))) + HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) + inner_types_freed = TRUE; + } /* end else */ + + /* Allocate space for the MPI data type list node */ + if(NULL == (type_node = H5FL_MALLOC(H5S_mpio_mpitype_node_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate MPI data type list node") + + /* Set up MPI type node */ + type_node->type = spans->u.down_type; + type_node->next = NULL; + + /* Add MPI type node to list */ + if(type_list->head == NULL) + type_list->head = type_list->tail = type_node; + else { + type_list->tail->next = type_node; + type_list->tail = type_node; + } /* end else */ + + /* Remember that we've visited this span tree */ + spans->op_gen = op_gen; } /* end else */ + /* Return MPI data type for span tree */ + *span_type = spans->u.down_type; + done: /* General cleanup */ if(inner_type != NULL) { - if(!inner_types_freed) { - size_t u; /* Local index variable */ - + if(!inner_types_freed) for(u = 0; u < outercount; u++) if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&inner_type[u]))) HMPI_DONE_ERROR(FAIL, "MPI_Type_free failed", mpi_code) - } /* end if */ - H5MM_free(inner_type); } /* end if */ if(blocklen != NULL) @@ -1250,13 +1339,6 @@ done: if(disp != NULL) H5MM_free(disp); - /* Error cleanup */ - if(ret_value < 0) { - if(span_type_valid) - if(MPI_SUCCESS != (mpi_code = MPI_Type_free(span_type))) - HMPI_DONE_ERROR(FAIL, "MPI_Type_free failed", mpi_code) - } /* end if */ - FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__obtain_datatype() */ diff --git a/src/H5Snone.c b/src/H5Snone.c index 86994dd459..de85bad474 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -51,9 +51,6 @@ /* Selection callbacks */ static herr_t H5S__none_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); -static herr_t H5S__none_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__none_release(H5S_t *space); static htri_t H5S__none_is_valid(const H5S_t *space); static hssize_t H5S__none_serial_size(const H5S_t *space); @@ -66,10 +63,11 @@ static int H5S__none_unlim_dim(const H5S_t *space); static htri_t H5S__none_is_contiguous(const H5S_t *space); static htri_t H5S__none_is_single(const H5S_t *space); static htri_t H5S__none_is_regular(const H5S_t *space); +static htri_t H5S__none_shape_same(const H5S_t *space1, const H5S_t *space2); static herr_t H5S__none_adjust_u(H5S_t *space, const hsize_t *offset); static herr_t H5S__none_project_scalar(const H5S_t *space, hsize_t *offset); static herr_t H5S__none_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); -static herr_t H5S__none_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); +static herr_t H5S__none_iter_init(const H5S_t *space, H5S_sel_iter_t *iter); /* Selection iteration callbacks */ static herr_t H5S__none_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); @@ -78,6 +76,8 @@ static hsize_t H5S__none_iter_nelmts(const H5S_sel_iter_t *iter); static htri_t H5S__none_iter_has_next_block(const H5S_sel_iter_t *iter); static herr_t H5S__none_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); static herr_t H5S__none_iter_next_block(H5S_sel_iter_t *sel_iter); +static herr_t H5S__none_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__none_iter_release(H5S_sel_iter_t *sel_iter); @@ -96,7 +96,6 @@ const H5S_select_class_t H5S_sel_none[1] = {{ /* Methods on selection */ H5S__none_copy, - H5S__none_get_seq_list, H5S__none_release, H5S__none_is_valid, H5S__none_serial_size, @@ -109,6 +108,7 @@ const H5S_select_class_t H5S_sel_none[1] = {{ H5S__none_is_contiguous, H5S__none_is_single, H5S__none_is_regular, + H5S__none_shape_same, H5S__none_adjust_u, H5S__none_project_scalar, H5S__none_project_simple, @@ -131,6 +131,7 @@ static const H5S_sel_iter_class_t H5S_sel_iter_none[1] = {{ H5S__none_iter_has_next_block, H5S__none_iter_next, H5S__none_iter_next_block, + H5S__none_iter_get_seq_list, H5S__none_iter_release, }}; @@ -149,7 +150,7 @@ static const H5S_sel_iter_class_t H5S_sel_iter_none[1] = {{ *------------------------------------------------------------------------- */ static herr_t -H5S__none_iter_init(H5S_sel_iter_t *iter, const H5S_t H5_ATTR_UNUSED *space) +H5S__none_iter_init(const H5S_t H5_ATTR_UNUSED *space, H5S_sel_iter_t *iter) { FUNC_ENTER_STATIC_NOERR @@ -334,13 +335,11 @@ H5S__none_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter) /*-------------------------------------------------------------------------- NAME - H5S__none_get_seq_list + H5S__none_iter_get_seq_list PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S__none_get_seq_list(space,flags,iter,maxseq,maxelem,nseq,nelem,off,len) - H5S_t *space; IN: Dataspace containing selection to use. - unsigned flags; IN: Flags for extra information about operation + herr_t H5S__none_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. size_t maxseq; IN: Maximum number of sequences to generate @@ -364,14 +363,13 @@ H5S__none_iter_next_block(H5S_sel_iter_t H5_ATTR_UNUSED *iter) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__none_get_seq_list(const H5S_t H5_ATTR_UNUSED *space, unsigned H5_ATTR_UNUSED flags, H5S_sel_iter_t H5_ATTR_UNUSED *iter, - size_t H5_ATTR_UNUSED maxseq, size_t H5_ATTR_UNUSED maxelem, size_t *nseq, size_t *nelem, - hsize_t H5_ATTR_UNUSED *off, size_t H5_ATTR_UNUSED *len) +H5S__none_iter_get_seq_list(H5S_sel_iter_t H5_ATTR_UNUSED *iter, + size_t H5_ATTR_UNUSED maxseq, size_t H5_ATTR_UNUSED maxelem, size_t *nseq, + size_t *nelem, hsize_t H5_ATTR_UNUSED *off, size_t H5_ATTR_UNUSED *len) { FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -387,7 +385,7 @@ H5S__none_get_seq_list(const H5S_t H5_ATTR_UNUSED *space, unsigned H5_ATTR_UNUSE *nelem = 0; FUNC_LEAVE_NOAPI(SUCCEED) -} /* end H5S__none_get_seq_list() */ +} /* end H5S__none_iter_get_seq_list() */ /*-------------------------------------------------------------------------- @@ -830,7 +828,40 @@ H5S__none_is_regular(const H5S_t H5_ATTR_UNUSED *space) /*-------------------------------------------------------------------------- NAME - H5S_none_adjust_u + H5S__none_shape_same + PURPOSE + Check if a two "none" selections are the same shape + USAGE + htri_t H5S__none_shape_same(space1, space2) + const H5S_t *space1; IN: First dataspace to check + const H5S_t *space2; IN: Second dataspace to check + RETURNS + TRUE / FALSE / FAIL + DESCRIPTION + Checks to see if the current selection in each dataspace are the same + shape. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static htri_t +H5S__none_shape_same(const H5S_t H5_ATTR_UNUSED *space1, + const H5S_t H5_ATTR_UNUSED *space2) +{ + FUNC_ENTER_STATIC_NOERR + + /* Check args */ + HDassert(space1); + HDassert(space2); + + FUNC_LEAVE_NOAPI(TRUE) +} /* end H5S__none_shape_same() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__none_adjust_u PURPOSE Adjust an "none" selection by subtracting an offset USAGE diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 0575f030df..9de0bec1a5 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -84,49 +84,97 @@ struct H5S_extent_t { /* Node in point selection list (typedef'd in H5Sprivate.h) */ struct H5S_pnt_node_t { - hsize_t *pnt; /* Pointer to a selected point */ - struct H5S_pnt_node_t *next; /* pointer to next point in list */ + struct H5S_pnt_node_t *next; /* Pointer to next point in list */ + hsize_t pnt[]; /* Selected point */ + /* (NOTE: This uses the C99 "flexible array member" feature) */ }; -/* Information about point selection list */ -typedef struct { +/* Information about point selection list (typedef'd in H5Sprivate.h) */ +struct H5S_pnt_list_t { + /* The following two fields defines the bounding box of the whole set of points, relative to the offset */ + hsize_t low_bounds[H5S_MAX_RANK]; /* The smallest element selected in each dimension */ + hsize_t high_bounds[H5S_MAX_RANK]; /* The largest element selected in each dimension */ + H5S_pnt_node_t *head; /* Pointer to head of point list */ -} H5S_pnt_list_t; + H5S_pnt_node_t *tail; /* Pointer to tail of point list */ +}; /* Information about hyperslab spans */ /* Information a particular hyperslab span (typedef'd in H5Sprivate.h) */ struct H5S_hyper_span_t { - hsize_t low, high; /* Low & high bounds of span */ - hsize_t nelem; /* Number of elements in span (only needed during I/O) */ - hsize_t pstride; /* Pseudo-stride from start of previous span (only used during I/O) */ - struct H5S_hyper_span_info_t *down; /* Pointer to list of spans in next dimension down */ - struct H5S_hyper_span_t *next; /* Pointer to next span in list */ + hsize_t low, high; /* Low & high bounds of elements selected for span, inclusive */ + struct H5S_hyper_span_info_t *down; /* Pointer to list of spans in next dimension down */ + struct H5S_hyper_span_t *next; /* Pointer to next span in list */ }; -/* Information about a list of hyperslab spans in one dimension */ +/* Information about a list of hyperslab spans in one dimension (typedef'd in H5Sprivate.h) */ struct H5S_hyper_span_info_t { - unsigned count; /* Ref. count of number of spans which share this span */ - struct H5S_hyper_span_info_t *scratch; /* Scratch pointer - * (used during copies, as mark - * during precomputes for I/O & - * to point to the last span in a - * list during single element adds) - */ - struct H5S_hyper_span_t *head; /* Pointer to list of spans in next dimension down */ + unsigned count; /* Ref. count of number of spans which share this span */ + + /* The following two fields define the bounding box of this set of spans + * and all lower dimensions, relative to the offset. + */ + /* (NOTE: The bounds arrays are _relative_ to the depth of the span_info + * node in the span tree, so the top node in a 5-D span tree will + * use indices 0-4 in the arrays to store it's bounds information, + * but the next level down in the span tree will use indices 0-3. + * So, each level in the span tree will have the 0th index in the + * arrays correspond to the bounds in "this" dimension, even if + * it's not the highest level in the span tree. + */ + hsize_t *low_bounds; /* The smallest element selected in each dimension */ + hsize_t *high_bounds; /* The largest element selected in each dimension */ + + /* "Operation generation" fields */ + /* (Used during copies, 'adjust', 'nelem', and 'rebuild' operations) */ + uint64_t op_gen; /* Generation of the scratch info */ + union { + struct H5S_hyper_span_info_t *copied; /* Pointer to already copied span tree */ + hsize_t nelmts; /* # of elements */ + hsize_t nblocks; /* # of blocks */ +#ifdef H5_HAVE_PARALLEL + MPI_Datatype down_type; /* MPI datatype for span tree */ +#endif /* H5_HAVE_PARALLEL */ + }u; + + struct H5S_hyper_span_t *head; /* Pointer to the first span of list of spans in the current dimension */ + struct H5S_hyper_span_t *tail; /* Pointer to the last span of list of spans in the current dimension */ + hsize_t bounds[]; /* Array for storing low & high bounds */ + /* (NOTE: This uses the C99 "flexible array member" feature) */ }; +/* Enum for diminfo_valid field in H5S_hyper_sel_t */ +typedef enum { + H5S_DIMINFO_VALID_IMPOSSIBLE, /* 0: diminfo is not valid and can never be valid with the current selection */ + H5S_DIMINFO_VALID_NO, /* 1: diminfo is not valid but may or may not be possible to constuct */ + H5S_DIMINFO_VALID_YES /* 2: diminfo is valid */ +} H5S_diminfo_valid_t; + /* Information about 'diminfo' form of hyperslab selection */ typedef struct { - 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 - * hyperslab to the application when it queries the hyperslab selection - * information. */ + /* 'opt' points to a [potentially] optimized version of the user's + * regular hyperslab information. 'app' points to the actual parameters + * that the application used for setting the hyperslab selection. + * + * The 'app' values are only used for regurgitating the original values + * used to set the hyperslab to the application when it queries the + * hyperslab selection information. + */ + H5S_hyper_dim_t app[H5S_MAX_RANK]; /* Application-set per-dim selection info */ + H5S_hyper_dim_t opt[H5S_MAX_RANK]; /* Optimized per-dim selection info */ + + /* The following two fields defines the bounding box of the diminfo selection */ + /* (relative to the offset) */ + hsize_t low_bounds[H5S_MAX_RANK]; /* The smallest element selected in each dimension */ + hsize_t high_bounds[H5S_MAX_RANK]; /* The largest element selected in each dimension */ +} H5S_hyper_diminfo_t; + +/* Information about hyperslab selection */ +typedef struct { + H5S_diminfo_valid_t diminfo_valid; /* Whether the dataset has valid diminfo */ + + H5S_hyper_diminfo_t diminfo; /* Dimension info form of hyperslab selection */ int unlim_dim; /* Dimension where selection is unlimited, or -1 if none */ hsize_t num_elem_non_unlim; /* # of elements in a "slice" excluding the unlimited dimension */ H5S_hyper_span_info_t *span_lst; /* List of hyperslab span information of all dimensions */ @@ -135,10 +183,6 @@ typedef struct { /* Selection information methods */ /* Method to copy a selection */ typedef herr_t (*H5S_sel_copy_func_t)(H5S_t *dst, const H5S_t *src, hbool_t share_selection); -/* Method to retrieve a list of offset/length sequences for selection */ -typedef herr_t (*H5S_sel_get_seq_list_func_t)(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); /* Method to release current selection */ typedef herr_t (*H5S_sel_release_func_t)(H5S_t *space); /* Method to determine if current selection is valid for dataspace */ @@ -165,6 +209,8 @@ typedef htri_t (*H5S_sel_is_contiguous_func_t)(const H5S_t *space); typedef htri_t (*H5S_sel_is_single_func_t)(const H5S_t *space); /* Method to determine if current selection is "regular" */ typedef htri_t (*H5S_sel_is_regular_func_t)(const H5S_t *space); +/* Method to determine if two dataspaces' selections are the same shape */ +typedef htri_t (*H5S_sel_shape_same_func_t)(const H5S_t *space1, const H5S_t *space2); /* Method to adjust a selection by an offset */ typedef herr_t (*H5S_sel_adjust_u_func_t)(H5S_t *space, const hsize_t *offset); /* Method to construct single element projection onto scalar dataspace */ @@ -172,7 +218,7 @@ typedef herr_t (*H5S_sel_project_scalar)(const H5S_t *space, hsize_t *offset); /* Method to construct selection projection onto/into simple dataspace */ typedef herr_t (*H5S_sel_project_simple)(const H5S_t *space, H5S_t *new_space, hsize_t *offset); /* Method to initialize iterator for current selection */ -typedef herr_t (*H5S_sel_iter_init_func_t)(H5S_sel_iter_t *sel_iter, const H5S_t *space); +typedef herr_t (*H5S_sel_iter_init_func_t)(const H5S_t *space, H5S_sel_iter_t *sel_iter); /* Selection class information */ typedef struct { @@ -180,7 +226,6 @@ typedef struct { /* Methods */ H5S_sel_copy_func_t copy; /* Method to make a copy of a selection */ - H5S_sel_get_seq_list_func_t get_seq_list; /* Method to retrieve a list of offset/length sequences for selection */ H5S_sel_release_func_t release; /* Method to release current selection */ H5S_sel_is_valid_func_t is_valid; /* Method to determine if current selection is valid for dataspace */ H5S_sel_serial_size_func_t serial_size; /* Method to determine number of bytes required to store current selection */ @@ -193,6 +238,7 @@ typedef struct { H5S_sel_is_contiguous_func_t is_contiguous; /* Method to determine if current selection is contiguous */ H5S_sel_is_single_func_t is_single; /* Method to determine if current selection is a single block */ H5S_sel_is_regular_func_t is_regular; /* Method to determine if current selection is "regular" */ + H5S_sel_shape_same_func_t shape_same; /* Method to determine if two dataspaces' selections are the same shape */ H5S_sel_adjust_u_func_t adjust_u; /* Method to adjust a selection by an offset */ H5S_sel_project_scalar project_scalar; /* Method to construct scalar dataspace projection */ H5S_sel_project_simple project_simple; /* Method to construct simple dataspace projection */ @@ -235,6 +281,10 @@ typedef htri_t (*H5S_sel_iter_has_next_block_func_t)(const H5S_sel_iter_t *iter) typedef herr_t (*H5S_sel_iter_next_func_t)(H5S_sel_iter_t *iter, size_t nelem); /* Method to move selection iterator to the next block in the selection */ typedef herr_t (*H5S_sel_iter_next_block_func_t)(H5S_sel_iter_t *iter); +/* Method to retrieve a list of offset/length sequences for selection iterator */ +typedef herr_t (*H5S_sel_iter_get_seq_list_func_t)(H5S_sel_iter_t *iter, + size_t maxseq, size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, + size_t *len); /* Method to release iterator for current selection */ typedef herr_t (*H5S_sel_iter_release_func_t)(H5S_sel_iter_t *iter); @@ -249,6 +299,7 @@ typedef struct H5S_sel_iter_class_t { H5S_sel_iter_has_next_block_func_t iter_has_next_block; /* Method to query if there is another block left in the selection */ H5S_sel_iter_next_func_t iter_next; /* Method to move selection iterator to the next element in the selection */ H5S_sel_iter_next_block_func_t iter_next_block; /* Method to move selection iterator to the next block in the selection */ + H5S_sel_iter_get_seq_list_func_t iter_get_seq_list; /* Method to retrieve a list of offset/length sequences for selection iterator */ H5S_sel_iter_release_func_t iter_release; /* Method to release iterator for current selection */ } H5S_sel_iter_class_t; @@ -281,14 +332,20 @@ H5_DLL herr_t H5S__extent_copy_real(H5S_extent_t *dst, const H5S_extent_t *src, hbool_t copy_max); /* Operations on hyperslab selections */ +H5_DLL uint64_t H5S__hyper_get_op_gen(void); +H5_DLL void H5S__hyper_rebuild(H5S_t *space); +H5_DLL herr_t H5S__modify_select(H5S_t *space1, H5S_seloper_t op, H5S_t *space2); H5_DLL herr_t H5S__hyper_project_intersection(const H5S_t *src_space, const H5S_t *dst_space, const H5S_t *src_intersect_space, H5S_t *proj_space); -H5_DLL herr_t H5S__hyper_subtract(H5S_t *space, H5S_t *subtract_space); /* Testing functions */ #ifdef H5S_TESTING H5_DLL htri_t H5S__select_shape_same_test(hid_t sid1, hid_t sid2); -H5_DLL htri_t H5S__get_rebuild_status_test(hid_t space_id); +H5_DLL herr_t H5S__get_rebuild_status_test(hid_t space_id, + H5S_diminfo_valid_t *status1, H5S_diminfo_valid_t *status2); +H5_DLL herr_t H5S__get_diminfo_status_test(hid_t space_id, + H5S_diminfo_valid_t *status); +H5_DLL htri_t H5S__internal_consistency_test(hid_t space_id); #endif /* H5S_TESTING */ #endif /*_H5Spkg_H*/ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 6411b94409..2970a99b12 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -46,16 +46,22 @@ /* Local Typedefs */ /******************/ +/* Define alias for hsize_t, for allocating H5S_pnt_node_t + point objects */ +/* (Makes it easier to understand the alloc / free calls) */ +typedef hsize_t hcoords_t; + /********************/ /* Local Prototypes */ /********************/ +static herr_t H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, + const hsize_t *coord); +static H5S_pnt_list_t *H5S__copy_pnt_list(const H5S_pnt_list_t *src, + unsigned rank); +static void H5S__free_pnt_list(H5S_pnt_list_t *pnt_lst); /* Selection callbacks */ static herr_t H5S__point_copy(H5S_t *dst, const H5S_t *src, hbool_t share_selection); -static herr_t H5S__point_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__point_release(H5S_t *space); static htri_t H5S__point_is_valid(const H5S_t *space); static hssize_t H5S__point_serial_size(const H5S_t *space); @@ -68,11 +74,12 @@ static int H5S__point_unlim_dim(const H5S_t *space); static htri_t H5S__point_is_contiguous(const H5S_t *space); static htri_t H5S__point_is_single(const H5S_t *space); static htri_t H5S__point_is_regular(const H5S_t *space); +static htri_t H5S__point_shape_same(const H5S_t *space1, const H5S_t *space2); static herr_t H5S__point_adjust_u(H5S_t *space, const hsize_t *offset); static herr_t H5S__point_project_scalar(const H5S_t *space, hsize_t *offset); static herr_t H5S__point_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset); -static herr_t H5S__point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space); +static herr_t H5S__point_iter_init(const H5S_t *space, H5S_sel_iter_t *iter); /* Selection iteration callbacks */ static herr_t H5S__point_iter_coords(const H5S_sel_iter_t *iter, hsize_t *coords); @@ -82,6 +89,8 @@ static hsize_t H5S__point_iter_nelmts(const H5S_sel_iter_t *iter); static htri_t H5S__point_iter_has_next_block(const H5S_sel_iter_t *iter); static herr_t H5S__point_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); static herr_t H5S__point_iter_next_block(H5S_sel_iter_t *sel_iter); +static herr_t H5S__point_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); static herr_t H5S__point_iter_release(H5S_sel_iter_t *sel_iter); @@ -100,7 +109,6 @@ const H5S_select_class_t H5S_sel_point[1] = {{ /* Methods on selection */ H5S__point_copy, - H5S__point_get_seq_list, H5S__point_release, H5S__point_is_valid, H5S__point_serial_size, @@ -113,6 +121,7 @@ const H5S_select_class_t H5S_sel_point[1] = {{ H5S__point_is_contiguous, H5S__point_is_single, H5S__point_is_regular, + H5S__point_shape_same, H5S__point_adjust_u, H5S__point_project_scalar, H5S__point_project_simple, @@ -135,11 +144,12 @@ static const H5S_sel_iter_class_t H5S_sel_iter_point[1] = {{ H5S__point_iter_has_next_block, H5S__point_iter_next, H5S__point_iter_next_block, + H5S__point_iter_get_seq_list, H5S__point_iter_release, }}; -/* Declare a free list to manage the H5S_pnt_node_t struct */ -H5FL_DEFINE_STATIC(H5S_pnt_node_t); +/* Declare a free list to manage the H5S_pnt_node_t + hcoords_t array struct */ +H5FL_BARR_DEFINE_STATIC(H5S_pnt_node_t, hcoords_t, H5S_MAX_RANK); /* Declare a free list to manage the H5S_pnt_list_t struct */ H5FL_DEFINE_STATIC(H5S_pnt_list_t); @@ -159,7 +169,7 @@ H5FL_DEFINE_STATIC(H5S_pnt_list_t); *------------------------------------------------------------------------- */ static herr_t -H5S__point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) +H5S__point_iter_init(const H5S_t *space, H5S_sel_iter_t *iter) { FUNC_ENTER_STATIC_NOERR @@ -167,11 +177,11 @@ H5S__point_iter_init(H5S_sel_iter_t *iter, const H5S_t *space) HDassert(space && H5S_SEL_POINTS == H5S_GET_SELECT_TYPE(space)); HDassert(iter); - /* Initialize the number of points to iterate over */ - iter->elmt_left = space->select.num_elem; + /* Share point list for internal iterations */ + iter->u.pnt.pnt_lst = space->select.sel_info.pnt_lst; /* Start at the head of the list of points */ - iter->u.pnt.curr=space->select.sel_info.pnt_lst->head; + iter->u.pnt.curr = iter->u.pnt.pnt_lst->head; /* Initialize type of selection iterator */ iter->type = H5S_sel_iter_point; @@ -371,13 +381,11 @@ H5S__point_iter_next_block(H5S_sel_iter_t *iter) /*-------------------------------------------------------------------------- NAME - H5S__point_get_seq_list + H5S__point_iter_get_seq_list PURPOSE Create a list of offsets & lengths for a selection USAGE - herr_t H5S__point_get_seq_list(space,flags,iter,maxseq,maxelem,nseq,nelem,off,len) - H5S_t *space; IN: Dataspace containing selection to use. - unsigned flags; IN: Flags for extra information about operation + herr_t H5S__point_iter_get_seq_list(iter,maxseq,maxelem,nseq,nelem,off,len) H5S_sel_iter_t *iter; IN/OUT: Selection iterator describing last position of interest in selection. size_t maxseq; IN: Maximum number of sequences to generate @@ -401,25 +409,22 @@ H5S__point_iter_next_block(H5S_sel_iter_t *iter) REVISION LOG --------------------------------------------------------------------------*/ static herr_t -H5S__point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter, - size_t maxseq, size_t maxelem, size_t *nseq, size_t *nelem, - hsize_t *off, size_t *len) +H5S__point_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelem, + size_t *nseq, size_t *nelem, hsize_t *off, size_t *len) { size_t io_left; /* The number of bytes left in the selection */ size_t start_io_left; /* The initial number of bytes left in the selection */ H5S_pnt_node_t *node; /* Point node */ - hsize_t dims[H5S_MAX_RANK]; /* Total size of memory buf */ - int ndims; /* Dimensionality of space*/ + unsigned ndims; /* Dimensionality of dataspace*/ hsize_t acc; /* Coordinate accumulator */ hsize_t loc; /* Coordinate offset */ size_t curr_seq; /* Current sequence being operated on */ int i; /* Local index variable */ herr_t ret_value = SUCCEED; /* return value */ - FUNC_ENTER_STATIC + FUNC_ENTER_STATIC_NOERR /* Check args */ - HDassert(space); HDassert(iter); HDassert(maxseq > 0); HDassert(maxelem > 0); @@ -432,9 +437,8 @@ H5S__point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter H5_CHECK_OVERFLOW(iter->elmt_left, hsize_t, size_t); start_io_left = io_left = (size_t)MIN(iter->elmt_left, maxelem); - /* Get the dataspace dimensions */ - if((ndims = H5S_get_simple_extent_dims (space, dims, NULL)) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to retrieve dataspace dimensions") + /* Get the dataspace's rank */ + ndims = iter->rank; /* Walk through the points in the selection, starting at the current */ /* location in the iterator */ @@ -442,15 +446,15 @@ H5S__point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter curr_seq = 0; while(NULL != node) { /* Compute the offset of each selected point in the buffer */ - for(i = ndims - 1, acc = iter->elmt_size, loc = 0; i >= 0; i--) { - loc += (hsize_t)((hssize_t)node->pnt[i] + space->select.offset[i]) * acc; - acc *= dims[i]; + for(i = (int)(ndims - 1), acc = iter->elmt_size, loc = 0; i >= 0; i--) { + loc += (hsize_t)((hssize_t)node->pnt[i] + iter->sel_off[i]) * acc; + acc *= iter->dims[i]; } /* end for */ /* Check if this is a later point in the selection */ if(curr_seq > 0) { /* If a sorted sequence is requested, make certain we don't go backwards in the offset */ - if((flags&H5S_GET_SEQ_LIST_SORTED) && locflags & H5S_SEL_ITER_GET_SEQ_LIST_SORTED) && loc < off[curr_seq - 1]) break; /* Check if this point extends the previous sequence */ @@ -502,9 +506,8 @@ H5S__point_get_seq_list(const H5S_t *space, unsigned flags, H5S_sel_iter_t *iter /* Set the number of elements used */ *nelem = start_io_left - io_left; -done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S__point_get_seq_list() */ +} /* end H5S__point_iter_get_seq_list() */ /*-------------------------------------------------------------------------- @@ -571,14 +574,14 @@ H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *c HDassert(op == H5S_SELECT_SET || op == H5S_SELECT_APPEND || op == H5S_SELECT_PREPEND); for(u = 0; u < num_elem; u++) { + unsigned dim; /* Counter for dimensions */ + /* Allocate space for the new node */ - if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t))) + if(NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, space->extent.rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node") /* Initialize fields in node */ new_node->next = NULL; - if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(space->extent.rank * sizeof(hsize_t)))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") /* Copy over the coordinates */ HDmemcpy(new_node->pnt, coord + (u * space->extent.rank), (space->extent.rank * sizeof(hsize_t))); @@ -589,6 +592,17 @@ H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *c else curr->next = new_node; curr = new_node; + + /* Update bound box */ + /* (Note: when op is H5S_SELECT_SET, the bound box has been reset + * inside H5S_select_elements, the only caller of this function. + * So the following bound box update procedure works correctly + * for the SET operation) + */ + for(dim = 0; dim < space->extent.rank; dim++) { + space->select.sel_info.pnt_lst->low_bounds[dim] = MIN(space->select.sel_info.pnt_lst->low_bounds[dim], curr->pnt[dim]); + space->select.sel_info.pnt_lst->high_bounds[dim] = MAX(space->select.sel_info.pnt_lst->high_bounds[dim], curr->pnt[dim]); + } /* end for */ } /* end for */ new_node = NULL; @@ -600,20 +614,22 @@ H5S__point_add(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *c /* Put new list in point selection */ space->select.sel_info.pnt_lst->head = top; + + /* Change the tail pointer if tail has not been set */ + if(NULL == space->select.sel_info.pnt_lst->tail) + space->select.sel_info.pnt_lst->tail = curr; } /* end if */ else { /* op==H5S_SELECT_APPEND */ H5S_pnt_node_t *tmp_node; /* Temporary point selection node */ tmp_node = space->select.sel_info.pnt_lst->head; if(tmp_node != NULL) { - while(tmp_node->next != NULL) - tmp_node = tmp_node->next; - - /* Append new list to point selection */ - tmp_node->next = top; + HDassert(space->select.sel_info.pnt_lst->tail); + space->select.sel_info.pnt_lst->tail->next = top; } /* end if */ else space->select.sel_info.pnt_lst->head = top; + space->select.sel_info.pnt_lst->tail = curr; } /* end else */ /* Set the number of elements in the new selection */ @@ -626,13 +642,12 @@ done: if(ret_value < 0) { /* Release possibly partially initialized new node */ if(new_node) - new_node = H5FL_FREE(H5S_pnt_node_t, new_node); + new_node = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, new_node); /* Release possible linked list of nodes */ while(top) { - curr = top->next; - H5MM_xfree(top->pnt); - top = H5FL_FREE(H5S_pnt_node_t, top); + curr = top->next; + top = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, top); top = curr; } /* end while */ } /* end if */ @@ -661,24 +676,16 @@ done: static herr_t H5S__point_release(H5S_t *space) { - H5S_pnt_node_t *curr, *next; /* Point selection nodes */ - FUNC_ENTER_STATIC_NOERR /* Check args */ HDassert(space); - /* Delete all the nodes from the list */ - curr = space->select.sel_info.pnt_lst->head; - while(curr != NULL) { - next = curr->next; - H5MM_xfree(curr->pnt); - curr = H5FL_FREE(H5S_pnt_node_t, curr); - curr = next; - } /* end while */ + /* Free the point list */ + H5S__free_pnt_list(space->select.sel_info.pnt_lst); - /* Free & reset the point list header */ - space->select.sel_info.pnt_lst = H5FL_FREE(H5S_pnt_list_t, space->select.sel_info.pnt_lst); + /* Reset the point list header */ + space->select.sel_info.pnt_lst = NULL; /* Reset the number of elements in the selection */ space->select.num_elem = 0; @@ -734,10 +741,17 @@ H5S_select_elements(H5S_t *space, H5S_seloper_t op, size_t num_elem, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't release point selection") /* Allocate space for the point selection information if necessary */ - if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS || space->select.sel_info.pnt_lst == NULL) + if(H5S_GET_SELECT_TYPE(space) != H5S_SEL_POINTS || space->select.sel_info.pnt_lst == NULL) { + hsize_t tmp = HSIZET_MAX; + if(NULL == (space->select.sel_info.pnt_lst = H5FL_CALLOC(H5S_pnt_list_t))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "can't allocate element information") + /* Set the bound box to the default value */ + H5VM_array_fill(space->select.sel_info.pnt_lst->low_bounds, &tmp, sizeof(hsize_t), space->extent.rank); + HDmemset(space->select.sel_info.pnt_lst->high_bounds, 0, sizeof(hsize_t) * space->extent.rank); + } /* end if */ + /* Add points to selection */ if(H5S__point_add(space, op, num_elem, coord) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINSERT, FAIL, "can't insert elements") @@ -749,6 +763,124 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_elements() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__copy_pnt_list + PURPOSE + Copy a point selection list + USAGE + H5S_pnt_list_t *H5S__copy_pnt_list(src) + const H5S_pnt_list_t *src; IN: Pointer to the source point list + unsigned rank; IN: # of dimensions for points + RETURNS + Non-NULL pointer to new point list on success / NULL on failure + DESCRIPTION + Copies point selection information from the source point list to newly + created point list. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static H5S_pnt_list_t * +H5S__copy_pnt_list(const H5S_pnt_list_t *src, unsigned rank) +{ + H5S_pnt_list_t *dst = NULL; /* New point list */ + H5S_pnt_node_t *curr, *new_tail; /* Point information nodes */ + H5S_pnt_list_t *ret_value = NULL; /* Return value */ + + FUNC_ENTER_STATIC + + /* Sanity checks */ + HDassert(src); + HDassert(rank > 0); + + /* Allocate room for the head of the point list */ + if(NULL == (dst = H5FL_MALLOC(H5S_pnt_list_t))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate point list node") + + curr = src->head; + new_tail = NULL; + while(curr) { + H5S_pnt_node_t *new_node; /* New point information node */ + + /* Create new point */ + if(NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, rank))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, NULL, "can't allocate point node") + new_node->next = NULL; + + /* Copy over the point's coordinates */ + HDmemcpy(new_node->pnt, curr->pnt, (rank * sizeof(hsize_t))); + + /* Keep the order the same when copying */ + if(NULL == new_tail) + new_tail = dst->head = new_node; + else { + new_tail->next = new_node; + new_tail = new_node; + } /* end else */ + + curr = curr->next; + } /* end while */ + dst->tail = new_tail; + + /* Copy the selection bounds */ + HDmemcpy(dst->high_bounds, src->high_bounds, (rank * sizeof(hsize_t))); + HDmemcpy(dst->low_bounds, src->low_bounds, (rank * sizeof(hsize_t))); + + /* Set return value */ + ret_value = dst; + +done: + if(NULL == ret_value && dst) + H5S__free_pnt_list(dst); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__copy_pnt_list() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__free_pnt_list + PURPOSE + Free a point selection list + USAGE + void H5S__free_pnt_list(pnt_lst) + H5S_pnt_list_t *pnt_lst; IN: Pointer to the point list to free + RETURNS + None + DESCRIPTION + Frees point selection information from the point list + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static void +H5S__free_pnt_list(H5S_pnt_list_t *pnt_lst) +{ + H5S_pnt_node_t *curr; /* Point information nodes */ + + FUNC_ENTER_STATIC_NOERR + + /* Sanity checks */ + HDassert(pnt_lst); + + /* Traverse the list, freeing all memory */ + curr = pnt_lst->head; + while(curr) { + H5S_pnt_node_t *tmp_node = curr; + + curr = curr->next; + tmp_node = (H5S_pnt_node_t *)H5FL_ARR_FREE(hcoords_t, tmp_node); + } /* end while */ + + H5FL_FREE(H5S_pnt_list_t, pnt_lst); + + FUNC_LEAVE_NOAPI_VOID +} /* end H5S__free_pnt_list() */ + /*-------------------------------------------------------------------------- NAME @@ -757,8 +889,8 @@ done: Copy a selection from one dataspace to another USAGE herr_t H5S__point_copy(dst, src, share_selection) - H5S_t *dst; OUT: Pointer to the destination dataspace - H5S_t *src; IN: Pointer to the source dataspace + H5S_t *dst; OUT: Pointer to the destination dataspace + H5S_t *src; IN: Pointer to the source dataspace hbool_t share_selection; IN: Whether to share the selection between the dataspaces RETURNS Non-negative on success/Negative on failure @@ -773,60 +905,19 @@ done: static herr_t H5S__point_copy(H5S_t *dst, const H5S_t *src, hbool_t H5_ATTR_UNUSED share_selection) { - H5S_pnt_node_t *curr, *new_node, *new_tail; /* Point information nodes */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC - /* Sanity checks */ + /* Sanity check */ HDassert(src); HDassert(dst); /* Allocate room for the head of the point list */ - if(NULL == (dst->select.sel_info.pnt_lst = H5FL_MALLOC(H5S_pnt_list_t))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point list node") - - curr = src->select.sel_info.pnt_lst->head; - new_tail = NULL; - while(curr) { - /* Create new point */ - if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t))) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node") - new_node->next = NULL; - if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(src->extent.rank * sizeof(hsize_t)))) { - new_node = H5FL_FREE(H5S_pnt_node_t, new_node); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") - } /* end if */ - - /* Copy over the point's coordinates */ - HDmemcpy(new_node->pnt, curr->pnt, (src->extent.rank * sizeof(hsize_t))); - - /* Keep the order the same when copying */ - if(NULL == new_tail) - new_tail = dst->select.sel_info.pnt_lst->head = new_node; - else { - new_tail->next = new_node; - new_tail = new_node; - } /* end else */ - - curr = curr->next; - } /* end while */ + if(NULL == (dst->select.sel_info.pnt_lst = H5S__copy_pnt_list(src->select.sel_info.pnt_lst, src->extent.rank))) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "can't copy point list") done: - if(ret_value < 0 && dst->select.sel_info.pnt_lst) { - /* Traverse the (incomplete?) dst list, freeing all memory */ - curr = dst->select.sel_info.pnt_lst->head; - while(curr) { - H5S_pnt_node_t *tmp_node = curr; - - curr->pnt = (hsize_t *)H5MM_xfree(curr->pnt); - curr = curr->next; - tmp_node = H5FL_FREE(H5S_pnt_node_t, tmp_node); - } /* end while */ - - dst->select.sel_info.pnt_lst = H5FL_FREE(H5S_pnt_list_t, dst->select.sel_info.pnt_lst); - } /* end if */ - FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__point_copy() */ @@ -854,7 +945,6 @@ done: static htri_t H5S__point_is_valid(const H5S_t *space) { - H5S_pnt_node_t *curr; /* Point information nodes */ unsigned u; /* Counter */ htri_t ret_value = TRUE; /* Return value */ @@ -862,20 +952,14 @@ H5S__point_is_valid(const H5S_t *space) HDassert(space); - /* Check each point to determine whether selection+offset is within extent */ - curr = space->select.sel_info.pnt_lst->head; - while(curr != NULL) { - /* Check each dimension */ - for(u = 0; u < space->extent.rank; u++) { - /* Check if an offset has been defined */ - /* Bounds check the selected point + offset against the extent */ - if(((curr->pnt[u] + (hsize_t)space->select.offset[u]) > space->extent.size[u]) - || (((hssize_t)curr->pnt[u] + space->select.offset[u]) < 0)) - HGOTO_DONE(FALSE) - } /* end for */ - - curr = curr->next; - } /* end while */ + /* Check each dimension */ + for(u = 0; u < space->extent.rank; u++) { + /* Bounds check the selected point + offset against the extent */ + if((space->select.sel_info.pnt_lst->high_bounds[u] + (hsize_t)space->select.offset[u]) > space->extent.size[u]) + HGOTO_DONE(FALSE) + if(((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]) < 0) + HGOTO_DONE(FALSE) + } /* end for */ done: FUNC_LEAVE_NOAPI(ret_value) @@ -1258,8 +1342,6 @@ done: static herr_t H5S__point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) { - H5S_pnt_node_t *node; /* Point node */ - unsigned rank; /* Dataspace rank */ unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ @@ -1270,31 +1352,20 @@ H5S__point_bounds(const H5S_t *space, hsize_t *start, hsize_t *end) HDassert(start); HDassert(end); - /* Get the dataspace extent rank */ - rank = space->extent.rank; + /* Loop over dimensions */ + for(u = 0; u < space->extent.rank; u++) { + /* Sanity check */ + HDassert(space->select.sel_info.pnt_lst->low_bounds[u] <= space->select.sel_info.pnt_lst->high_bounds[u]); - /* Set the start and end arrays up */ - for(u = 0; u < rank; u++) { - start[u] = HSIZET_MAX; - end[u] = 0; + /* Check for offset moving selection negative */ + if(((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") + + /* Set the low & high bounds in this dimension */ + start[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->low_bounds[u] + space->select.offset[u]); + end[u] = (hsize_t)((hssize_t)space->select.sel_info.pnt_lst->high_bounds[u] + space->select.offset[u]); } /* end for */ - /* Iterate through the node, checking the bounds on each element */ - node = space->select.sel_info.pnt_lst->head; - while(node != NULL) { - for(u = 0; u < rank; u++) { - /* Check for offset moving selection negative */ - if(((hssize_t)node->pnt[u] + space->select.offset[u]) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "offset moves selection out of bounds") - - if(start[u] > (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u])) - start[u] = (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u]); - if(end[u] < (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u])) - end[u] = (hsize_t)((hssize_t)node->pnt[u] + space->select.offset[u]); - } /* end for */ - node = node->next; - } /* end while */ - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__point_bounds() */ @@ -1510,6 +1581,114 @@ H5S__point_is_regular(const H5S_t *space) FUNC_LEAVE_NOAPI(ret_value) } /* end H5S__point_is_regular() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__point_shape_same + PURPOSE + Check if a two "point" selections are the same shape + USAGE + htri_t H5S__point_shape_same(space1, space2) + const H5S_t *space1; IN: First dataspace to check + const H5S_t *space2; IN: Second dataspace to check + RETURNS + TRUE / FALSE / FAIL + DESCRIPTION + Checks to see if the current selection in each dataspace are the same + shape. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static htri_t +H5S__point_shape_same(const H5S_t *space1, const H5S_t *space2) +{ + H5S_pnt_node_t *pnt1, *pnt2; /* Point information nodes */ + hssize_t offset[H5S_MAX_RANK]; /* Offset between the selections */ + unsigned space1_rank; /* Number of dimensions of first dataspace */ + unsigned space2_rank; /* Number of dimensions of second dataspace */ + int space1_dim; /* Current dimension in first dataspace */ + int space2_dim; /* Current dimension in second dataspace */ + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC_NOERR + + /* Check args */ + HDassert(space1); + HDassert(space2); + + /* Get dataspace ranks */ + space1_rank = space1->extent.rank; + space2_rank = space2->extent.rank; + + /* Sanity check */ + HDassert(space1_rank >= space2_rank); + HDassert(space2_rank > 0); + + /* Initialize dimensions */ + space1_dim = (int)space1_rank - 1; + space2_dim = (int)space2_rank - 1; + + /* Look at first point in each selection to compute the offset for common + * dimensions. + */ + pnt1 = space1->select.sel_info.pnt_lst->head; + pnt2 = space2->select.sel_info.pnt_lst->head; + while(space2_dim >= 0) { + /* Set the relative locations of the selections */ + offset[space1_dim] = (hssize_t)pnt2->pnt[space2_dim] - (hssize_t)pnt1->pnt[space1_dim]; + + space1_dim--; + space2_dim--; + } /* end while */ + + /* For dimensions that appear only in space1: */ + while(space1_dim >= 0) { + /* Set the absolute offset of the remaining dimensions */ + offset[space1_dim] = (hssize_t)pnt1->pnt[space1_dim]; + + space1_dim--; + } /* end while */ + + /* Advance to next point */ + pnt1 = pnt1->next; + pnt2 = pnt2->next; + + /* Loop over remaining points */ + while(pnt1 && pnt2) { + /* Initialize dimensions */ + space1_dim = (int)space1_rank - 1; + space2_dim = (int)space2_rank - 1; + + /* Compare locations in common dimensions, including relative offset */ + while(space2_dim >= 0) { + if((hsize_t)((hssize_t)pnt1->pnt[space1_dim] + offset[space1_dim]) != pnt2->pnt[space2_dim]) + HGOTO_DONE(FALSE) + + space1_dim--; + space2_dim--; + } /* end while */ + + /* For dimensions that appear only in space1: */ + while(space1_dim >= 0) { + /* Compare the absolute offset in the remaining dimensions */ + if((hssize_t)pnt1->pnt[space1_dim] != offset[space1_dim]) + HGOTO_DONE(FALSE) + + space1_dim--; + } /* end while */ + + + /* Advance to next point */ + pnt1 = pnt1->next; + pnt2 = pnt2->next; + } /* end while */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5S__point_shape_same() */ + /*-------------------------------------------------------------------------- NAME @@ -1534,6 +1713,7 @@ H5S__point_adjust_u(H5S_t *space, const hsize_t *offset) { H5S_pnt_node_t *node; /* Point node */ unsigned rank; /* Dataspace rank */ + unsigned u; /* Local index variable */ FUNC_ENTER_STATIC_NOERR @@ -1544,8 +1724,6 @@ H5S__point_adjust_u(H5S_t *space, const hsize_t *offset) node = space->select.sel_info.pnt_lst->head; rank = space->extent.rank; while(node) { - unsigned u; /* Local index variable */ - /* Adjust each coordinate for point node */ for(u = 0; u < rank; u++) { /* Check for offset moving selection negative */ @@ -1559,6 +1737,12 @@ H5S__point_adjust_u(H5S_t *space, const hsize_t *offset) node = node->next; } /* end while */ + /* update the bound box of the selection */ + for(u = 0; u < rank; u++) { + space->select.sel_info.pnt_lst->low_bounds[u] -= offset[u]; + space->select.sel_info.pnt_lst->high_bounds[u] -= offset[u]; + } /* end for */ + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__point_adjust_u() */ @@ -1623,6 +1807,7 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of H5S_pnt_node_t *new_node; /* Point node in new space */ H5S_pnt_node_t *prev_node; /* Previous point node in new space */ unsigned rank_diff; /* Difference in ranks between spaces */ + unsigned u; /* Local index variable */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -1657,13 +1842,9 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of prev_node = NULL; while(base_node) { /* Create new point */ - if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t))) + if(NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, new_space->extent.rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node") new_node->next = NULL; - if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(new_space->extent.rank * sizeof(hsize_t)))) { - new_node = H5FL_FREE(H5S_pnt_node_t, new_node); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") - } /* end if */ /* Copy over the point's coordinates */ HDmemcpy(new_node->pnt, &base_node->pnt[rank_diff], (new_space->extent.rank * sizeof(hsize_t))); @@ -1679,6 +1860,12 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of /* Advance to next node */ base_node = base_node->next; } /* end while */ + + /* Update the bounding box */ + for(u = 0; u < new_space->extent.rank; u++) { + new_space->select.sel_info.pnt_lst->low_bounds[u] = base_space->select.sel_info.pnt_lst->low_bounds[u + rank_diff]; + new_space->select.sel_info.pnt_lst->high_bounds[u] = base_space->select.sel_info.pnt_lst->high_bounds[u + rank_diff]; + } /* end for */ } /* end if */ else { HDassert(new_space->extent.rank > base_space->extent.rank); @@ -1694,13 +1881,9 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of prev_node = NULL; while(base_node) { /* Create new point */ - if(NULL == (new_node = H5FL_MALLOC(H5S_pnt_node_t))) + if(NULL == (new_node = (H5S_pnt_node_t *)H5FL_ARR_MALLOC(hcoords_t, new_space->extent.rank))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate point node") new_node->next = NULL; - if(NULL == (new_node->pnt = (hsize_t *)H5MM_malloc(new_space->extent.rank * sizeof(hsize_t)))) { - new_node = H5FL_FREE(H5S_pnt_node_t, new_node); - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate coordinate information") - } /* end if */ /* Copy over the point's coordinates */ HDmemset(new_node->pnt, 0, sizeof(hsize_t) * rank_diff); @@ -1717,6 +1900,16 @@ H5S__point_project_simple(const H5S_t *base_space, H5S_t *new_space, hsize_t *of /* Advance to next node */ base_node = base_node->next; } /* end while */ + + /* Update the bounding box */ + for(u = 0; u < rank_diff; u++) { + new_space->select.sel_info.pnt_lst->low_bounds[u] = 0; + new_space->select.sel_info.pnt_lst->high_bounds[u] = 0; + } /* end for */ + for(; u < new_space->extent.rank; u++) { + new_space->select.sel_info.pnt_lst->low_bounds[u] = base_space->select.sel_info.pnt_lst->low_bounds[u - rank_diff]; + new_space->select.sel_info.pnt_lst->high_bounds[u] = base_space->select.sel_info.pnt_lst->high_bounds[u - rank_diff]; + } /* end for */ } /* end else */ /* Number of elements selected will be the same */ diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index f4e0006302..6646f8423a 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -39,12 +39,10 @@ #define H5S_CONV_STORAGE_CHUNKED 0x0004 /* i.e. '2' */ #define H5S_CONV_STORAGE_MASK 0x0006 -/* Flags for "get_seq_list" methods */ -#define H5S_GET_SEQ_LIST_SORTED 0x0001 - /* Forward references of package typedefs */ typedef struct H5S_extent_t H5S_extent_t; typedef struct H5S_pnt_node_t H5S_pnt_node_t; +typedef struct H5S_pnt_list_t H5S_pnt_list_t; typedef struct H5S_hyper_span_t H5S_hyper_span_t; typedef struct H5S_hyper_span_info_t H5S_hyper_span_info_t; @@ -58,6 +56,7 @@ typedef struct H5S_hyper_dim_t { /* Point selection iteration container */ typedef struct { + H5S_pnt_list_t *pnt_lst; /* Pointer to point list */ H5S_pnt_node_t *curr; /* Pointer to next node to output */ } H5S_point_iter_t; @@ -65,6 +64,7 @@ typedef struct { typedef struct { /* Common fields for all hyperslab selections */ hsize_t off[H5S_MAX_RANK]; /* Offset in span node (used as position for regular hyperslabs) */ + hsize_t slab[H5S_MAX_RANK]; /* Cumulative size of each dimension in bytes */ unsigned iter_rank; /* Rank of iterator information */ /* (This should always be the same as the dataspace * rank, except for regular hyperslab selections in @@ -80,6 +80,7 @@ typedef struct { hbool_t flattened[H5S_MAX_RANK]; /* Whether this dimension has been flattened */ /* Irregular hyperslab selection fields */ + hsize_t loc_off[H5S_MAX_RANK]; /* Byte offset in buffer, for each dimension's current offset */ H5S_hyper_span_info_t *spans; /* Pointer to copy of the span tree */ H5S_hyper_span_t *span[H5S_MAX_RANK];/* Array of pointers to span nodes */ } H5S_hyper_iter_t; @@ -100,9 +101,11 @@ typedef struct H5S_sel_iter_t { /* Information common to all iterators */ unsigned rank; /* Rank of dataspace the selection iterator is operating on */ - hsize_t *dims; /* Dimensions of dataspace the selection is operating on */ + hsize_t dims[H5S_MAX_RANK]; /* Dimensions of dataspace the selection is operating on */ + hssize_t sel_off[H5S_MAX_RANK]; /* Selection offset in dataspace */ hsize_t elmt_left; /* Number of elements left to iterate over */ size_t elmt_size; /* Size of elements to iterate over */ + unsigned flags; /* Flags controlling iterator behavior */ /* Information specific to each type of iterator */ union { @@ -142,7 +145,6 @@ typedef struct H5S_sel_iter_op_t { #define H5S_GET_EXTENT_NPOINTS(S) ((S)->extent.nelem) #define H5S_GET_SELECT_NPOINTS(S) ((S)->select.num_elem) #define H5S_GET_SELECT_TYPE(S) ((S)->select.type->type) -#define H5S_SELECT_GET_SEQ_LIST(S,FLAGS,ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN) ((*(S)->select.type->get_seq_list)(S,FLAGS,ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN)) #define H5S_SELECT_VALID(S) ((*(S)->select.type->is_valid)(S)) #define H5S_SELECT_SERIAL_SIZE(S) ((*(S)->select.type->serial_size)(S)) #define H5S_SELECT_SERIALIZE(S,BUF) ((*(S)->select.type->serialize)(S,BUF)) @@ -160,6 +162,7 @@ typedef struct H5S_sel_iter_op_t { #define H5S_SELECT_ITER_HAS_NEXT_BLOCK(ITER) ((*(ITER)->type->iter_has_next_block)(ITER)) #define H5S_SELECT_ITER_NEXT(ITER,NELEM)((*(ITER)->type->iter_next)(ITER,NELEM)) #define H5S_SELECT_ITER_NEXT_BLOCK(ITER) ((*(ITER)->type->iter_next_block)(ITER)) +#define H5S_SELECT_ITER_GET_SEQ_LIST(ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN) ((*(ITER)->type->iter_get_seq_list)(ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN)) #define H5S_SELECT_ITER_RELEASE(ITER) ((*(ITER)->type->iter_release)(ITER)) #else /* H5S_MODULE */ #define H5S_GET_EXTENT_TYPE(S) (H5S_get_simple_extent_type(S)) @@ -167,7 +170,6 @@ typedef struct H5S_sel_iter_op_t { #define H5S_GET_EXTENT_NPOINTS(S) (H5S_get_simple_extent_npoints(S)) #define H5S_GET_SELECT_NPOINTS(S) (H5S_get_select_npoints(S)) #define H5S_GET_SELECT_TYPE(S) (H5S_get_select_type(S)) -#define H5S_SELECT_GET_SEQ_LIST(S,FLAGS,ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN) (H5S_select_get_seq_list(S,FLAGS,ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN)) #define H5S_SELECT_VALID(S) (H5S_select_valid(S)) #define H5S_SELECT_SERIAL_SIZE(S) (H5S_select_serial_size(S)) #define H5S_SELECT_SERIALIZE(S,BUF) (H5S_select_serialize(S,BUF)) @@ -185,6 +187,7 @@ typedef struct H5S_sel_iter_op_t { #define H5S_SELECT_ITER_HAS_NEXT_BLOCK(ITER) (H5S_select_iter_has_next_block(ITER)) #define H5S_SELECT_ITER_NEXT(ITER,NELEM)(H5S_select_iter_next(ITER,NELEM)) #define H5S_SELECT_ITER_NEXT_BLOCK(ITER) (H5S_select_iter_next_block(ITER)) +#define H5S_SELECT_ITER_GET_SEQ_LIST(ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN) (H5S_select_iter_get_seq_list(ITER,MAXSEQ,MAXBYTES,NSEQ,NBYTES,OFF,LEN)) #define H5S_SELECT_ITER_RELEASE(ITER) (H5S_select_iter_release(ITER)) #endif /* H5S_MODULE */ /* Handle these callbacks in a special way, since they have prologs that need to be executed */ @@ -253,9 +256,6 @@ H5_DLL herr_t H5S_select_construct_projection(const H5S_t *base_space, H5S_t **new_space_ptr, unsigned new_space_rank, const void *buf, void const **adj_buf_ptr, hsize_t element_size); H5_DLL herr_t H5S_select_release(H5S_t *ds); -H5_DLL herr_t H5S_select_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); H5_DLL hssize_t H5S_select_serial_size(const H5S_t *space); H5_DLL herr_t H5S_select_serialize(const H5S_t *space, uint8_t **p); H5_DLL htri_t H5S_select_is_contiguous(const H5S_t *space); @@ -282,10 +282,11 @@ H5_DLL herr_t H5S_select_elements(H5S_t *space, H5S_seloper_t op, /* Operations on hyperslab selections */ H5_DLL herr_t H5S_select_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], const hsize_t *stride, const hsize_t count[], const hsize_t *block); +H5_DLL herr_t H5S_combine_hyperslab(H5S_t *old_space, H5S_seloper_t op, + const hsize_t start[], const hsize_t *stride, const hsize_t count[], + const hsize_t *block, H5S_t **new_space); H5_DLL herr_t H5S_hyper_add_span_element(H5S_t *space, unsigned rank, const hsize_t *coords); -H5_DLL herr_t H5S_hyper_reset_scratch(H5S_t *space); -H5_DLL herr_t H5S_hyper_convert(H5S_t *space); H5_DLL htri_t H5S_hyper_intersect_block(H5S_t *space, const hsize_t *start, const hsize_t *end); H5_DLL herr_t H5S_hyper_adjust_s(H5S_t *space, const hssize_t *offset); H5_DLL htri_t H5S_hyper_normalize_offset(H5S_t *space, hssize_t *old_offset); @@ -302,11 +303,14 @@ H5_DLL hsize_t H5S_hyper_get_first_inc_block(const H5S_t *space, /* Operations on selection iterators */ H5_DLL herr_t H5S_select_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, - size_t elmt_size); + size_t elmt_size, unsigned flags); H5_DLL herr_t H5S_select_iter_coords(const H5S_sel_iter_t *sel_iter, hsize_t *coords); H5_DLL hsize_t H5S_select_iter_nelmts(const H5S_sel_iter_t *sel_iter); H5_DLL herr_t H5S_select_iter_next(H5S_sel_iter_t *sel_iter, size_t nelem); +H5_DLL herr_t H5S_select_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, + size_t maxbytes, size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len); H5_DLL herr_t H5S_select_iter_release(H5S_sel_iter_t *sel_iter); +H5_DLL herr_t H5S_sel_iter_close(H5S_sel_iter_t *sel_iter); #ifdef H5_HAVE_PARALLEL H5_DLL hsize_t H5S_mpio_set_bigio_count(hsize_t new_count); diff --git a/src/H5Spublic.h b/src/H5Spublic.h index 561875a8b5..a65ce71c91 100644 --- a/src/H5Spublic.h +++ b/src/H5Spublic.h @@ -28,6 +28,23 @@ /* Define user-level maximum number of dimensions */ #define H5S_MAX_RANK 32 +/* Flags for selection iterators */ +#define H5S_SEL_ITER_GET_SEQ_LIST_SORTED 0x0001 /* Retrieve elements from iterator + * in increasing offset order, for + * each call to retrieve sequences. + * Currently, this only applies to + * point selections, as hyperslab + * selections are always returned + * in increasing offset order. + * + * Note that the order is only + * increasing for each call to + * get_seq_list, the next set of + * sequences could start with an + * earlier offset than the previous + * one. + */ + /* Different types of dataspaces */ typedef enum H5S_class_t { H5S_NO_CLASS = -1, /*error */ diff --git a/src/H5Sselect.c b/src/H5Sselect.c index 24586dec91..d4ca1c75ac 100644 --- a/src/H5Sselect.c +++ b/src/H5Sselect.c @@ -32,7 +32,6 @@ #include "H5Eprivate.h" /* Error handling */ #include "H5FLprivate.h" /* Free Lists */ #include "H5Iprivate.h" /* IDs */ -#include "H5MMprivate.h" /* Memory management */ #include "H5Spkg.h" /* Dataspaces */ #include "H5VMprivate.h" /* Vector and array functions */ @@ -998,7 +997,9 @@ H5S_select_is_regular(const H5S_t *space) herr_t H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) { - herr_t ret_value = FAIL; /* Return value */ + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ + unsigned u; /* Local index variable */ + herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI_NOINIT_NOERR @@ -1006,7 +1007,16 @@ H5S_select_adjust_u(H5S_t *space, const hsize_t *offset) HDassert(space); HDassert(offset); - ret_value = (*space->select.type->adjust_u)(space, offset); + /* Check for an all-zero offset vector */ + for(u = 0; u < space->extent.rank; u++) + if(0 != offset[u]) { + non_zero_offset = TRUE; + break; + } /* end if */ + + /* Only perform operation if the offset is non-zero */ + if(non_zero_offset) + ret_value = (*space->select.type->adjust_u)(space, offset); FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_select_adjust_u() */ @@ -1098,11 +1108,12 @@ H5S_select_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset) PURPOSE Initializes iteration information for a selection. USAGE - herr_t H5S_select_iter_init(sel_iter, space, elmt_size) + herr_t H5S_select_iter_init(sel_iter, space, elmt_size, flags) H5S_sel_iter_t *sel_iter; OUT: Selection iterator to initialize. H5S_t *space; IN: Dataspace object containing selection to iterate over size_t elmt_size; IN: Size of elements in the selection + unsigned flags; IN: Flags to control iteration behavior RETURNS Non-negative on success, negative on failure. DESCRIPTION @@ -1110,7 +1121,8 @@ H5S_select_project_simple(const H5S_t *space, H5S_t *new_space, hsize_t *offset) in the dataspace's selection. --------------------------------------------------------------------------*/ herr_t -H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, size_t elmt_size) +H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, + size_t elmt_size, unsigned flags) { herr_t ret_value = FAIL; /* Return value */ @@ -1125,17 +1137,23 @@ H5S_select_iter_init(H5S_sel_iter_t *sel_iter, const H5S_t *space, size_t elmt_s /* Save the dataspace's rank */ sel_iter->rank = space->extent.rank; - /* Point to the dataspace dimensions, if there are any */ - if(sel_iter->rank > 0) - sel_iter->dims = space->extent.size; - else - sel_iter->dims = NULL; + /* If dims > 0, copy the dataspace dimensions & selection offset */ + if(sel_iter->rank > 0) { + HDmemcpy(sel_iter->dims, space->extent.size, sizeof(hsize_t) * space->extent.rank); + HDmemcpy(sel_iter->sel_off, space->select.offset, sizeof(hsize_t) * space->extent.rank); + } /* end if */ /* Save the element size */ sel_iter->elmt_size = elmt_size; + /* Initialize the number of elements to iterate over */ + sel_iter->elmt_left = space->select.num_elem; + + /* Set the flags for the iterator */ + sel_iter->flags = flags; + /* Call initialization routine for selection type */ - ret_value = (*space->select.type->iter_init)(sel_iter, space); + ret_value = (*space->select.type->iter_init)(space, sel_iter); HDassert(sel_iter->type); FUNC_LEAVE_NOAPI(ret_value) @@ -1389,7 +1407,7 @@ H5S_select_iter_next_block(H5S_sel_iter_t *iter) /*------------------------------------------------------------------------- - * Function: H5S_select_get_seq_list + * Function: H5S_select_iter_get_seq_list * * Purpose: Retrieves the next sequence of offset/length pairs for an * iterator on a dataspace @@ -1406,24 +1424,23 @@ H5S_select_iter_next_block(H5S_sel_iter_t *iter) *------------------------------------------------------------------------- */ herr_t -H5S_select_get_seq_list(const H5S_t *space, unsigned flags, - H5S_sel_iter_t *iter, size_t maxseq, size_t maxbytes, - size_t *nseq, size_t *nbytes, hsize_t *off, size_t *len) +H5S_select_iter_get_seq_list(H5S_sel_iter_t *iter, size_t maxseq, size_t maxelmts, + size_t *nseq, size_t *nelmts, hsize_t *off, size_t *len) { herr_t ret_value = FAIL; /* Return value */ FUNC_ENTER_NOAPI_NOINIT /* Sanity check */ - HDassert(space); + HDassert(iter); /* Call the selection type's get_seq_list function */ - if((ret_value = (*space->select.type->get_seq_list)(space, flags, iter, maxseq, maxbytes, nseq, nbytes, off, len)) < 0) + if((ret_value = (*iter->type->iter_get_seq_list)(iter, maxseq, maxelmts, nseq, nelmts, off, len)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get selection sequence list") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5S_select_get_seq_list() */ +} /* end H5S_select_iter_get_seq_list() */ /*-------------------------------------------------------------------------- @@ -1524,7 +1541,7 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") /* Initialize iterator */ - if(H5S_select_iter_init(iter, space, elmt_size) < 0) + if(H5S_select_iter_init(iter, space, elmt_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -1558,7 +1575,7 @@ H5S_select_iterate(void *buf, const H5T_t *type, const H5S_t *space, size_t curr_seq; /* Current sequence being worked on */ /* Get the sequences of bytes */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Loop, while sequences left to process */ @@ -1729,7 +1746,6 @@ H5S_get_select_type(const H5S_t *space) This is primarily used for reading the entire selection in one swoop. GLOBAL VARIABLES COMMENTS, BUGS, ASSUMPTIONS - Assumes that there is only a single "block" for hyperslab selections. EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ @@ -1759,6 +1775,10 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) const H5S_t *space_b; /* Dataspace with smaller rank */ unsigned space_a_rank; /* Number of dimensions of dataspace A */ unsigned space_b_rank; /* Number of dimensions of dataspace B */ + int space_a_dim; /* Current dimension in dataspace A */ + int space_b_dim; /* Current dimension in dataspace B */ + H5S_sel_type sel_a_type; /* Selection type for dataspace A */ + H5S_sel_type sel_b_type; /* Selection type for dataspace B */ /* Need to be able to handle spaces of different rank: * @@ -1776,106 +1796,77 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) */ if(space1->extent.rank >= space2->extent.rank) { space_a = space1; - space_a_rank = space_a->extent.rank; - space_b = space2; - space_b_rank = space_b->extent.rank; } /* end if */ else { space_a = space2; - space_a_rank = space_a->extent.rank; - space_b = space1; - space_b_rank = space_b->extent.rank; } /* end else */ + space_a_rank = space_a->extent.rank; + space_b_rank = space_b->extent.rank; HDassert(space_a_rank >= space_b_rank); HDassert(space_b_rank > 0); - /* Check for "easy" cases before getting into generalized block iteration code */ - if((H5S_GET_SELECT_TYPE(space_a) == H5S_SEL_ALL) && (H5S_GET_SELECT_TYPE(space_b) == H5S_SEL_ALL)) { - hsize_t dims1[H5O_LAYOUT_NDIMS]; /* End point of selection block in dataspace #1 */ - hsize_t dims2[H5O_LAYOUT_NDIMS]; /* End point of selection block in dataspace #2 */ - int space_a_dim; /* Current dimension in dataspace A */ - int space_b_dim; /* Current dimension in dataspace B */ + /* Get selection type for both dataspaces */ + sel_a_type = H5S_GET_SELECT_TYPE(space_a); + sel_b_type = H5S_GET_SELECT_TYPE(space_b); - if(H5S_get_simple_extent_dims(space_a, dims1, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get dimensionality") - if(H5S_get_simple_extent_dims(space_b, dims2, NULL) < 0) - HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get dimensionality") + /* If selections aren't "none", compare their bounds */ + if(sel_a_type != H5S_SEL_NONE && sel_b_type != H5S_SEL_NONE) { + hsize_t low_a[H5S_MAX_RANK]; /* Low bound of selection in dataspace a */ + hsize_t low_b[H5S_MAX_RANK]; /* Low bound of selection in dataspace b */ + hsize_t high_a[H5S_MAX_RANK]; /* High bound of selection in dataspace a */ + hsize_t high_b[H5S_MAX_RANK]; /* High bound of selection in dataspace b */ + /* Get low & high bounds for both dataspaces */ + if(H5S_SELECT_BOUNDS(space_a, low_a, high_a) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds for first dataspace") + if(H5S_SELECT_BOUNDS(space_b, low_b, high_b) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get selection bounds for second dataspace") + + /* Check that the range between the low & high bounds are the same */ space_a_dim = (int)space_a_rank - 1; space_b_dim = (int)space_b_rank - 1; - - /* recall that space_a_rank >= space_b_rank. - * - * In the following while loop, we test to see if space_a and space_b - * have identical size in all dimensions they have in common. - */ while(space_b_dim >= 0) { - if(dims1[space_a_dim] != dims2[space_b_dim]) + /* Sanity check */ + HDassert(low_a[space_a_dim] <= high_a[space_a_dim]); + HDassert(low_a[space_b_dim] <= high_a[space_b_dim]); + + /* Verify that the ranges are the same */ + if((high_a[space_a_dim] - low_a[space_a_dim]) + != (high_b[space_b_dim] - low_b[space_b_dim])) HGOTO_DONE(FALSE) + /* Go to next dimension */ space_a_dim--; space_b_dim--; } /* end while */ - /* Since we are selecting the entire space, we must also verify that space_a - * has size 1 in all dimensions that it does not share with space_b. - */ + /* Check that the rest of the ranges in space a are "flat" */ while(space_a_dim >= 0) { - if(dims1[space_a_dim] != 1) + /* Sanity check */ + HDassert(low_a[space_a_dim] <= high_a[space_a_dim]); + + /* This range should be flat to be the same in a lower dimension */ + if(low_a[space_a_dim] != high_a[space_a_dim]) HGOTO_DONE(FALSE) space_a_dim--; } /* end while */ } /* end if */ - else if((H5S_GET_SELECT_TYPE(space1) == H5S_SEL_NONE) || (H5S_GET_SELECT_TYPE(space2) == H5S_SEL_NONE)) { - /* (Both must be, at this point, if one is) */ - HGOTO_DONE(TRUE) - } /* end if */ - else if((H5S_GET_SELECT_TYPE(space_a) == H5S_SEL_HYPERSLABS && space_a->select.sel_info.hslab->diminfo_valid) - && (H5S_GET_SELECT_TYPE(space_b) == H5S_SEL_HYPERSLABS && space_b->select.sel_info.hslab->diminfo_valid)) { - int space_a_dim; /* Current dimension in dataspace A */ - int space_b_dim; /* Current dimension in dataspace B */ - space_a_dim = (int)space_a_rank - 1; - space_b_dim = (int)space_b_rank - 1; - - /* check that the shapes are the same in the common dimensions, and that - * block == 1 in all dimensions that appear only in space_a. - */ - while(space_b_dim >= 0) { - if(space_a->select.sel_info.hslab->opt_diminfo[space_a_dim].stride != - space_b->select.sel_info.hslab->opt_diminfo[space_b_dim].stride) - HGOTO_DONE(FALSE) - - if(space_a->select.sel_info.hslab->opt_diminfo[space_a_dim].count != - space_b->select.sel_info.hslab->opt_diminfo[space_b_dim].count) - HGOTO_DONE(FALSE) - - if(space_a->select.sel_info.hslab->opt_diminfo[space_a_dim].block != - space_b->select.sel_info.hslab->opt_diminfo[space_b_dim].block) - HGOTO_DONE(FALSE) - - space_a_dim--; - space_b_dim--; - } /* end while */ - - while(space_a_dim >= 0) { - if(space_a->select.sel_info.hslab->opt_diminfo[space_a_dim].block != 1) - HGOTO_DONE(FALSE) - - space_a_dim--; - } /* end while */ - } /* end if */ - /* Iterate through all the blocks in the selection */ + /* If the dataspaces have the same selection type, use the selection's + * shape_same operator. + */ + if(sel_a_type == sel_b_type) + ret_value = (*space_a->select.type->shape_same)(space_a, space_b); + /* Otherwise, iterate through all the blocks in the selection */ else { hsize_t start_a[H5S_MAX_RANK]; /* Start point of selection block in dataspace a */ hsize_t start_b[H5S_MAX_RANK]; /* Start point of selection block in dataspace b */ hsize_t end_a[H5S_MAX_RANK]; /* End point of selection block in dataspace a */ hsize_t end_b[H5S_MAX_RANK]; /* End point of selection block in dataspace b */ - hsize_t off_a[H5S_MAX_RANK]; /* Offset of selection a blocks */ - hsize_t off_b[H5S_MAX_RANK]; /* Offset of selection b blocks */ + hssize_t offset[H5S_MAX_RANK]; /* Offset of selection b blocks relative to selection a blocks */ hbool_t first_block = TRUE; /* Flag to indicate the first block */ /* Allocate the selection iterators */ @@ -1889,17 +1880,15 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) * that the selection iterator shouldn't be "flattened", since we * aren't actually going to be doing I/O with the iterators. */ - if(H5S_select_iter_init(iter_a, space_a, (size_t)0) < 0) + if(H5S_select_iter_init(iter_a, space_a, (size_t)0, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator a") iter_a_init = TRUE; - if(H5S_select_iter_init(iter_b, space_b, (size_t)0) < 0) + if(H5S_select_iter_init(iter_b, space_b, (size_t)0, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator b") iter_b_init = TRUE; /* Iterate over all the blocks in each selection */ while(1) { - int space_a_dim; /* Current dimension in dataspace A */ - int space_b_dim; /* Current dimension in dataspace B */ htri_t status_a, status_b; /* Status from next block checks */ /* Get the current block for each selection iterator */ @@ -1924,8 +1913,7 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) HGOTO_DONE(FALSE) /* Set the relative locations of the selections */ - off_a[space_a_dim] = start_a[space_a_dim]; - off_b[space_b_dim] = start_b[space_b_dim]; + offset[space_a_dim] = (hssize_t)start_b[space_b_dim] - (hssize_t)start_a[space_a_dim]; space_a_dim--; space_b_dim--; @@ -1935,12 +1923,9 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) * in space_a is not equal to 1, get out. */ while(space_a_dim >= 0) { - if((end_a[space_a_dim] - start_a[space_a_dim]) != 0) + if(start_a[space_a_dim] != end_a[space_a_dim]) HGOTO_DONE(FALSE) - /* Set the relative locations of the selections */ - off_a[space_a_dim] = start_a[space_a_dim]; - space_a_dim--; } /* end while */ @@ -1952,8 +1937,7 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) /* For dimensions that space_a and space_b have in common: */ while(space_b_dim >= 0) { /* Check if the blocks are in the same relative location */ - if((start_a[space_a_dim] - off_a[space_a_dim]) != - (start_b[space_b_dim] - off_b[space_b_dim])) + if((hsize_t)((hssize_t)start_a[space_a_dim] + offset[space_a_dim]) != start_b[space_b_dim]) HGOTO_DONE(FALSE) /* If the block sizes from each selection doesn't match, get out */ @@ -1968,7 +1952,7 @@ H5S_select_shape_same(const H5S_t *space1, const H5S_t *space2) /* For dimensions that appear only in space_a: */ while(space_a_dim >= 0) { /* If the block size isn't 1, get out */ - if((end_a[space_a_dim] - start_a[space_a_dim]) != 0) + if(start_a[space_a_dim] != end_a[space_a_dim]) HGOTO_DONE(FALSE) space_a_dim--; @@ -2329,7 +2313,7 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b HGOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL, "can't allocate selection iterator") /* Initialize iterator */ - if(H5S_select_iter_init(iter, space, fill_size) < 0) + if(H5S_select_iter_init(iter, space, fill_size, 0) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init = TRUE; /* Selection iteration info has been initialized */ @@ -2353,7 +2337,7 @@ H5S_select_fill(const void *fill, size_t fill_size, const H5S_t *space, void *_b size_t nelem; /* Number of elements used in sequences */ /* Get the sequences of bytes */ - if(H5S_SELECT_GET_SEQ_LIST(space, 0, iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) + if(H5S_SELECT_ITER_GET_SEQ_LIST(iter, (size_t)H5D_IO_VECTOR_SIZE, max_elem, &nseq, &nelem, off, len) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL, "sequence length generation failed") /* Loop over sequences */ @@ -2528,12 +2512,13 @@ H5S_select_subtract(H5S_t *space, H5S_t *subtract_space) if(H5S_select_none(space) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't change selection") } /* end if */ + /* If either selection is a point selection, fail currently */ + else if((subtract_space->select.type->type == H5S_SEL_POINTS) || + (space->select.type->type == H5S_SEL_POINTS)) { + HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "point selections not currently supported") + } /* end if */ else { - /* Check for point selection in subtract_space, convert to hyperslab */ - if(subtract_space->select.type->type == H5S_SEL_POINTS) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "point selections not currently supported") - - /* Check for point or all selection in space, convert to hyperslab */ + /* Check for all selection in space, convert to hyperslab */ if(space->select.type->type == H5S_SEL_ALL) { /* Convert current "all" selection to "real" hyperslab selection */ /* Then allow operation to proceed */ @@ -2555,14 +2540,12 @@ H5S_select_subtract(H5S_t *space, H5S_t *subtract_space) if(H5S_select_hyperslab(space, H5S_SELECT_SET, tmp_start, tmp_stride, tmp_count, tmp_block) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTSELECT, FAIL, "can't convert selection") } /* end if */ - else if(space->select.type->type == H5S_SEL_POINTS) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNSUPPORTED, FAIL, "point selections not currently supported") HDassert(space->select.type->type == H5S_SEL_HYPERSLABS); HDassert(subtract_space->select.type->type == H5S_SEL_HYPERSLABS); /* Both spaces are now hyperslabs, perform the operation */ - if(H5S__hyper_subtract(space, subtract_space) < 0) + if(H5S__modify_select(space, H5S_SELECT_NOTB, subtract_space) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCLIP, FAIL, "can't subtract hyperslab") } /* end else */ } /* end if */ diff --git a/src/H5Stest.c b/src/H5Stest.c index 50f5fa9263..2c42713875 100644 --- a/src/H5Stest.c +++ b/src/H5Stest.c @@ -112,12 +112,18 @@ done: NAME H5S__get_rebuild_status_test PURPOSE - Determine the status of hyperslab rebuild + Determine the status of the diminfo_valid field (whether we know the + selection information for an equivalent single hyperslab selection) + before and after calling H5S__hyper_rebuild. USAGE - htri_t H5S__get_rebuild_status_test(hid_t space_id) + herr_t H5S__get_rebuild_status_test(space_id, status1, status2) hid_t space_id; IN: dataspace id + H5S_diminfo_valid_t *status1; OUT: status before calling + H5S__hyper_rebuild + H5S_diminfo_valid_t *status2; OUT: status after calling + H5S__hyper_rebuild RETURNS - Non-negative TRUE/FALSE on success, negative on failure + Non-negative on success, negative on failure DESCRIPTION Query the status of rebuilding the hyperslab GLOBAL VARIABLES @@ -126,11 +132,271 @@ done: EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -htri_t -H5S__get_rebuild_status_test(hid_t space_id) +herr_t +H5S__get_rebuild_status_test(hid_t space_id, H5S_diminfo_valid_t *status1, + H5S_diminfo_valid_t *status2) { H5S_t *space; /* Pointer to 1st dataspace */ - htri_t ret_value = FAIL; /* Return value */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + HDassert(status1); + HDassert(status2); + + /* Get dataspace structures */ + if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + *status1 = space->select.sel_info.hslab->diminfo_valid; + + /* Fully rebuild diminfo, if necessary */ + if(*status1 == H5S_DIMINFO_VALID_NO) + H5S__hyper_rebuild(space); + + *status2 = space->select.sel_info.hslab->diminfo_valid; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__get_rebuild_status_test() */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__get_diminfo_status_test + PURPOSE + Determine the status of the diminfo_valid field (whether we know the + selection information for an equivalent single hyperslab selection) + USAGE + herr_t H5S__get_diminfo_status_test(space_id, status) + hid_t space_id; IN: dataspace id + H5S_diminfo_valid_t *status; OUT: status of diminfo_valid + RETURNS + Non-negative on success, negative on failure + DESCRIPTION + Query the status of rebuilding the hyperslab + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + DO NOT USE THIS FUNCTION FOR ANYTHING EXCEPT TESTING + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +herr_t +H5S__get_diminfo_status_test(hid_t space_id, H5S_diminfo_valid_t *status) +{ + H5S_t *space; /* Pointer to 1st dataspace */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_PACKAGE + + HDassert(status); + + /* Get dataspace structures */ + if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") + + *status = space->select.sel_info.hslab->diminfo_valid; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__get_diminfo_status_test() */ + +/*-------------------------------------------------------------------------- + NAME + H5S__check_spans_tail_ptr + PURPOSE + Determine if the tail pointer of the spans are correctly set + USAGE + herr_t H5S__check_spans_tail_ptr(span_lst) + const H5S_hyper_span_info_t *span_lst; IN: the spans to check for taill pointers + RETURNS + SUCCEED/FAIL + DESCRIPTION + Checks to see if the current selection in the dataspaces has tail pointers of each + dimension correctly set. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + Only check the hyperslab selection + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__check_spans_tail_ptr(const H5S_hyper_span_info_t *span_lst) +{ + H5S_hyper_span_t *cur_elem; + H5S_hyper_span_t *actual_tail = NULL; + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC + + HDassert(span_lst); + + cur_elem = span_lst->head; + while(cur_elem) { + actual_tail = cur_elem; + + /* check the next dimension of lower order */ + if(NULL != cur_elem->down) + if((ret_value = H5S__check_spans_tail_ptr(cur_elem->down)) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the seletion has inconsistent tail pointers") + + cur_elem = cur_elem->next; + } /* end while */ + if(actual_tail != span_lst->tail) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the seletion has inconsistent tail pointers") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__check_spans_tail_ptr */ + +/*-------------------------------------------------------------------------- + NAME + H5S__check_points_tail_ptr + PURPOSE + Determine if the tail pointer of the points list are correctly set + USAGE + herr_t H5S__check_points_tail_ptr(pnt_lst) + const H5S_pnt_list_t *pnt_lst; IN: the points list to check for taill pointers + RETURNS + SUCCEED/FAIL + DESCRIPTION + Checks to see if the current selection in the dataspaces has tail pointers correctly set. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + Only check the points selection + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__check_points_tail_ptr(const H5S_pnt_list_t *pnt_lst) +{ + H5S_pnt_node_t *cur_elem; + H5S_pnt_node_t *actual_tail = NULL; + htri_t ret_value = TRUE; /* Return value */ + + FUNC_ENTER_STATIC + + HDassert(pnt_lst); + + cur_elem = pnt_lst->head; + while(cur_elem) { + actual_tail = cur_elem; + cur_elem = cur_elem->next; + } /* end while */ + if(actual_tail != pnt_lst->tail) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the seletion has inconsistent tail pointers") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__check_points_tail_ptr */ + + +/*-------------------------------------------------------------------------- + NAME + H5S__check_internal_consistency + PURPOSE + Determine if internal data structures are consistent + USAGE + herr_t H5S__check_internal_consistency(space) + const H5S_t *space; IN: 1st Dataspace pointer to compare + RETURNS + SUCCEED/FAIL + DESCRIPTION + Checks to see if the current selection in the dataspaces has consistent + state of internal data structure. + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + Currently only check the hyperslab selection + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +static herr_t +H5S__check_internal_consistency(const H5S_t *space) +{ + hsize_t low_bounds[H5S_MAX_RANK]; + hsize_t high_bounds[H5S_MAX_RANK]; + unsigned u; + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Check args */ + HDassert(space); + + if(space->select.type->type == H5S_SEL_NONE) + HGOTO_DONE(ret_value); + + /* Initialize the inputs */ + for(u = 0; u < space->extent.rank; u++) { + low_bounds[u] = HSIZET_MAX; + high_bounds[u] = 0; + } /* end for */ + + /* Check the bound box */ + if(H5S_get_select_bounds(space, low_bounds, high_bounds) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the bound box could not be retrieved") + + if(space->select.type->type == H5S_SEL_HYPERSLABS) { + H5S_hyper_sel_t *hslab = space->select.sel_info.hslab; + + if(space->select.sel_info.hslab->diminfo_valid == H5S_DIMINFO_VALID_YES) { + for(u = 0; u < space->extent.rank; u++) { + if((hsize_t)((hssize_t)hslab->diminfo.low_bounds[u] + space->select.offset[u]) != low_bounds[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the lower bound box of the selection is inconsistent") + if((hsize_t)((hssize_t)hslab->diminfo.high_bounds[u] + space->select.offset[u]) != high_bounds[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the higher bound box of the selection is inconsistent") + } /* end for */ + } /* end if */ + else { + for(u = 0; u < space->extent.rank; u++) { + if((hsize_t)((hssize_t)hslab->span_lst->low_bounds[u] + space->select.offset[u]) != low_bounds[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the lower bound box of the selection is inconsistent") + if((hsize_t)((hssize_t)hslab->span_lst->high_bounds[u] + space->select.offset[u]) != high_bounds[u]) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the higher bound box of the selection is inconsistent") + } /* end for */ + } /* end else */ + + /* check the tail pointer */ + if((NULL != hslab) && (NULL != hslab->span_lst)) + if(H5S__check_spans_tail_ptr(hslab->span_lst) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the seletion has inconsistent tail pointers") + } /* end if */ + else if(space->select.type->type == H5S_SEL_POINTS) { + H5S_pnt_list_t *pnt_lst = space->select.sel_info.pnt_lst; + + if(NULL != pnt_lst) + if(H5S__check_points_tail_ptr(pnt_lst) < 0) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "the seletion has inconsistent tail pointers") + } /* end else-if */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* H5S__check_internal_consistency */ + +/*-------------------------------------------------------------------------- + NAME + H5S__internal_consistency_test + PURPOSE + Determine if states of internal data structures are consistent + USAGE + htri_t H5S__internal_consistency_test(hid_t space_id) + hid_t space_id; IN: dataspace id + RETURNS + Non-negative TRUE/FALSE on success, negative on failure + DESCRIPTION + Check the states of internal data structures of the hyperslab, and see + whether they are consistent or not + GLOBAL VARIABLES + COMMENTS, BUGS, ASSUMPTIONS + DO NOT USE THIS FUNCTION FOR ANYTHING EXCEPT TESTING + EXAMPLES + REVISION LOG +--------------------------------------------------------------------------*/ +htri_t +H5S__internal_consistency_test(hid_t space_id) +{ + H5S_t *space; /* Pointer to 1st dataspace */ + htri_t ret_value = TRUE; /* Return value */ FUNC_ENTER_PACKAGE @@ -138,9 +404,11 @@ H5S__get_rebuild_status_test(hid_t space_id) if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace") - ret_value = (htri_t)space->select.sel_info.hslab->diminfo_valid; + /* Check if the dataspace selections are the same shape */ + if(FAIL == H5S__check_internal_consistency(space)) + HGOTO_ERROR(H5E_DATASPACE, H5E_INCONSISTENTSTATE, FAIL, "The dataspace has inconsistent internal state") done: FUNC_LEAVE_NOAPI(ret_value) -} /* H5S__get_rebuild_status_test() */ +} /* H5S__internal_consistency_test() */ diff --git a/src/H5TS.c b/src/H5TS.c index 10e14d5ee2..f386421dda 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -35,6 +35,7 @@ H5TS_once_t H5TS_first_init_g = PTHREAD_ONCE_INIT; H5TS_key_t H5TS_errstk_key_g; H5TS_key_t H5TS_funcstk_key_g; H5TS_key_t H5TS_apictx_key_g; +H5TS_key_t H5TS_hyper_op_gen_key_g; H5TS_key_t H5TS_cancel_key_g; @@ -113,6 +114,9 @@ H5TS_pthread_first_thread_init(void) /* initialize key for thread-specific API contexts */ pthread_key_create(&H5TS_apictx_key_g, H5TS_key_destructor); + /* initialize key for thread-specific hyperslab operation generation */ + pthread_key_create(&H5TS_hyper_op_gen_key_g, H5TS_key_destructor); + /* initialize key for thread cancellability mechanism */ pthread_key_create(&H5TS_cancel_key_g, H5TS_key_destructor); } @@ -362,6 +366,9 @@ H5TS_win32_process_enter(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex) if(TLS_OUT_OF_INDEXES == (H5TS_apictx_key_g = TlsAlloc())) ret_value = FALSE; + if(TLS_OUT_OF_INDEXES == (H5TS_hyper_op_gen_key_g = TlsAlloc())) + ret_value = FALSE; + return ret_value; } /* H5TS_win32_process_enter() */ #endif /* H5_HAVE_WIN_THREADS */ @@ -431,6 +438,7 @@ H5TS_win32_process_exit(void) TlsFree(H5TS_funcstk_key_g); #endif /* H5_HAVE_CODESTACK */ TlsFree(H5TS_apictx_key_g); + TlsFree(H5TS_hyper_op_gen_key_g); return; } /* H5TS_win32_process_exit() */ @@ -479,6 +487,10 @@ H5TS_win32_thread_exit(void) if(lpvData) LocalFree((HLOCAL)lpvData); + lpvData = TlsGetValue(H5TS_hyper_op_gen_key_g); + if(lpvData) + LocalFree((HLOCAL)lpvData); + return ret_value; } /* H5TS_win32_thread_exit() */ #endif /* H5_HAVE_WIN_THREADS */ diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index 9e093a68af..94791bc113 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -110,6 +110,7 @@ extern H5TS_once_t H5TS_first_init_g; extern H5TS_key_t H5TS_errstk_key_g; extern H5TS_key_t H5TS_funcstk_key_g; extern H5TS_key_t H5TS_apictx_key_g; +extern H5TS_key_t H5TS_hyper_op_gen_key_g; #if defined c_plusplus || defined __cplusplus extern "C" diff --git a/src/H5err.txt b/src/H5err.txt index 93a3abdef8..4eedc0f7d9 100644 --- a/src/H5err.txt +++ b/src/H5err.txt @@ -226,6 +226,7 @@ MINOR, DSPACE, H5E_CANTSELECT, Can't select hyperslab MINOR, DSPACE, H5E_CANTNEXT, Can't move to next iterator location MINOR, DSPACE, H5E_BADSELECT, Invalid selection MINOR, DSPACE, H5E_CANTCOMPARE, Can't compare objects +MINOR, DSPACE, H5E_INCONSISTENTSTATE, Internal states are inconsistent MINOR, DSPACE, H5E_CANTAPPEND, Can't append object # Property list errors diff --git a/test/tselect.c b/test/tselect.c index 424c1445b9..842fe17db3 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -157,6 +157,12 @@ #define SPACERE5_DIM3 12 #define SPACERE5_DIM4 8 +/* Information for Space update diminfo test */ +#define SPACEUD1_DIM0 20 +#define SPACEUD3_DIM0 9 +#define SPACEUD3_DIM1 12 +#define SPACEUD3_DIM2 13 + /* #defines for shape same / different rank tests */ #define SS_DR_MAX_RANK 5 @@ -11489,7 +11495,8 @@ test_space_rebuild(void) hid_t sid_irreg1,sid_irreg2,sid_irreg3,sid_irreg4,sid_irreg5; /* rebuild status state */ - htri_t rebuild_stat,rebuild_check; + H5S_diminfo_valid_t rebuild_stat1,rebuild_stat2; + htri_t rebuild_check; herr_t ret; /* dimensions of rank 1 to rank 5 */ @@ -11558,19 +11565,23 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_reg1,H5S_SELECT_OR,start1,stride1,count1,block1); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_reg1); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_reg1,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - } - else { + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + if(ret != FAIL) { /* In this case, rebuild_check should be TRUE. */ rebuild_check = H5S__select_shape_same_test(sid_reg1,sid_reg_ori1); CHECK(rebuild_check,FALSE,"H5S_hyper_rebuild"); - } + } /* end if */ /* For irregular hyperslab */ sid_irreg1 = H5Screate_simple(SPACERE1_RANK,dims1,NULL); @@ -11590,14 +11601,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_irreg1,H5S_SELECT_OR,start1,stride1,count1,block1); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_irreg1); - assert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_irreg1,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ MESSAGE(7, ("Testing functionality to rebuild 2-D hyperslab selection\n")); @@ -11637,19 +11653,23 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_reg2,H5S_SELECT_OR,start2,stride2,count2,block2); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_reg2); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_reg2,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - } - else { + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + if(ret != FAIL) { /* In this case, rebuild_check should be TRUE. */ rebuild_check = H5S__select_shape_same_test(sid_reg2,sid_reg_ori2); CHECK(rebuild_check,FALSE,"H5S_hyper_rebuild"); - } + } /* end if */ /* 2-D irregular case */ sid_irreg2 = H5Screate_simple(SPACERE2_RANK,dims2,NULL); @@ -11674,14 +11694,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_irreg2,H5S_SELECT_OR,start2,stride2,count2,block2); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_irreg2); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_irreg2,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ MESSAGE(7, ("Testing functionality to rebuild 3-D hyperslab selection\n")); @@ -11726,20 +11751,23 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_reg3,H5S_SELECT_OR,start3,stride3,count3,block3); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_reg3); - HDassert(rebuild_stat!=FAIL); - - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_reg3,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - } - else { + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + if(ret != FAIL) { /* In this case, rebuild_check should be TRUE. */ rebuild_check = H5S__select_shape_same_test(sid_reg3,sid_reg_ori3); CHECK(rebuild_check,FALSE,"H5S_hyper_rebuild"); - } + } /* end if */ sid_irreg3 = H5Screate_simple(SPACERE3_RANK,dims3,NULL); @@ -11769,14 +11797,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_irreg3,H5S_SELECT_OR,start3,stride3,count3,block3); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_irreg3); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_irreg3,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ MESSAGE(7, ("Testing functionality to rebuild 4-D hyperslab selection\n")); @@ -11829,19 +11862,23 @@ test_space_rebuild(void) CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_reg4); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_reg4,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - } - else { + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + if(ret != FAIL) { /* In this case, rebuild_check should be TRUE. */ rebuild_check = H5S__select_shape_same_test(sid_reg4,sid_reg_ori4); CHECK(rebuild_check,FALSE,"H5S_hyper_rebuild"); - } + } /* end if */ /* Testing irregular selection */ sid_irreg4 = H5Screate_simple(SPACERE4_RANK,dims4,NULL); @@ -11882,14 +11919,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_irreg4,H5S_SELECT_OR,start4,stride4,count4,block4); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_irreg4); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_irreg4,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ MESSAGE(7, ("Testing functionality to rebuild 5-D hyperslab selection\n")); @@ -11946,19 +11988,23 @@ test_space_rebuild(void) CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_reg5); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_reg5,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - } - else { + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + if(ret != FAIL) { /* In this case, rebuild_check should be TRUE. */ rebuild_check = H5S__select_shape_same_test(sid_reg5,sid_reg_ori5); CHECK(rebuild_check,FALSE,"H5S_hyper_rebuild"); - } + } /* end if */ sid_irreg5 = H5Screate_simple(SPACERE5_RANK,dims5,NULL); @@ -12004,14 +12050,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_irreg5,H5S_SELECT_OR,start5,stride5,count5,block5); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_irreg5); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_irreg5,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ /* We use 5-D to test a special case with rebuilding routine TRUE, FALSE and TRUE */ @@ -12045,13 +12096,20 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_spec,H5S_SELECT_SET,start5,stride5,count5,block5); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_spec); - /* In this case, rebuild_stat should be TRUE. */ - if(!rebuild_stat){ + + ret = H5S__get_rebuild_status_test(sid_spec,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 and rebuild_stat2 should both be + * H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_YES) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ /* Adding some selections to make it real irregular */ start5[3] = 1; @@ -12067,14 +12125,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_spec,H5S_SELECT_OR,start5,stride5,count5,block5); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = TRUE; - rebuild_stat = H5S__get_rebuild_status_test(sid_spec); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_spec,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_IMPOSSIBLE. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ /* Add more selections to make it regular again */ start5[3] = 5; @@ -12090,14 +12153,19 @@ test_space_rebuild(void) ret = H5Sselect_hyperslab(sid_spec,H5S_SELECT_OR,start5,stride5,count5,block5); CHECK(ret, FAIL, "H5Sselect_hyperslab"); - rebuild_stat = FALSE; - rebuild_stat = H5S__get_rebuild_status_test(sid_spec); - HDassert(rebuild_stat!=FAIL); - /* In this case, rebuild_stat should be FALSE. */ - if(!rebuild_stat){ + ret = H5S__get_rebuild_status_test(sid_spec,&rebuild_stat1,&rebuild_stat2); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + /* In this case, rebuild_stat1 should be H5S_DIMINFO_VALID_NO and + * rebuild_stat2 should be H5S_DIMINFO_VALID_YES. */ + if(rebuild_stat1 != H5S_DIMINFO_VALID_NO) { ret = FAIL; CHECK(ret,FAIL,"H5S_hyper_rebuild"); - }/* No need to do shape comparision */ + } /* end if */ + if(rebuild_stat2 != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret,FAIL,"H5S_hyper_rebuild"); + } /* end if */ + /* No need to do shape comparision */ H5Sclose(sid_reg1); CHECK(ret, FAIL, "H5Sclose"); @@ -12128,6 +12196,791 @@ test_space_rebuild(void) CHECK(ret, FAIL, "H5Sclose"); } + +/**************************************************************** +** +** test_space_update_diminfo(): Tests selection diminfo update +** routine. We will test whether regular selections can be +** quickly updated when the selection is modified. +** +** +****************************************************************/ +static void +test_space_update_diminfo(void) +{ + hid_t space_id; /* Dataspace id */ + H5S_diminfo_valid_t diminfo_valid; /* Diminfo status */ + H5S_diminfo_valid_t rebuild_status; /* Diminfo status after rebuid */ + H5S_sel_type sel_type; /* Selection type */ + herr_t ret; /* Return value */ + + /* dimensions of rank 1 to rank 5 */ + hsize_t dims1[] ={SPACEUD1_DIM0}; + hsize_t dims3[] ={SPACEUD3_DIM0, SPACEUD3_DIM1, SPACEUD3_DIM2}; + + /* The start of the hyperslab */ + hsize_t start1[1], start3[3]; + + /* The stride of the hyperslab */ + hsize_t stride1[1], stride3[3]; + + /* The number of blocks for the hyperslab */ + hsize_t count1[1], count3[3]; + + /* The size of each block for the hyperslab */ + hsize_t block1[1], block3[3]; + + + /* Output message about test being performed */ + MESSAGE(6, ("Testing functionality to update hyperslab dimension info\n")); + + + MESSAGE(7, ("Testing functionality to update 1-D hyperslab dimension info\n")); + + /* + * Test adding regularly spaced distinct blocks + */ + + /* Create 1-D dataspace */ + space_id = H5Screate_simple(1, dims1, NULL); + + /* Create single block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block after first, with OR */ + start1[0] = 6; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block before first, this time with XOR */ + start1[0] = 0; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add two blocks after current block */ + start1[0] = 9; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add two blocks overlapping current block, with OR */ + start1[0] = 9; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add two blocks partially overlapping current block, with OR */ + start1[0] = 12; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add two blocks partially overlapping current block, with XOR */ + start1[0] = 15; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO, after rebuild it should be IMPOSSIBLE */ + ret = H5S__get_rebuild_status_test(space_id, &diminfo_valid, + &rebuild_status); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + if(rebuild_status != H5S_DIMINFO_VALID_IMPOSSIBLE) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_rebuild"); + } /* end if */ + + /* Fill in missing block */ + start1[0] = 15; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO, after rebuild it should be YES */ + ret = H5S__get_rebuild_status_test(space_id, &diminfo_valid, + &rebuild_status); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + if(rebuild_status != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_rebuild"); + } /* end if */ + + /* + * Test adding contiguous blocks + */ + + /* Create single block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block immediately after first, with OR */ + start1[0] = 5; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block immediately before first, with XOR */ + start1[0] = 1; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add differently size block immediately after current, with OR */ + start1[0] = 7; + count1[0] = 1; + block1[0] = 7; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* + * Test adding overlapping blocks + */ + + /* Create single block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block completely overlapping first, with OR */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block parially overlapping first, with OR */ + start1[0] = 4; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block completely enclosing current, with OR */ + start1[0] = 2; + count1[0] = 1; + block1[0] = 5; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add block completely enclosed by current, with OR */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add equally sized block parially overlapping current, with XOR */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 5; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Fill in hole in block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 4; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO, after rebuild it should be YES */ + ret = H5S__get_rebuild_status_test(space_id, &diminfo_valid, + &rebuild_status); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + if(rebuild_status != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_rebuild"); + } /* end if */ + + /* Add differently sized block parially overlapping current, with XOR */ + start1[0] = 4; + count1[0] = 1; + block1[0] = 5; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Fill in hole in block */ + start1[0] = 4; + count1[0] = 1; + block1[0] = 4; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO, after rebuild it should be YES */ + ret = H5S__get_rebuild_status_test(space_id, &diminfo_valid, + &rebuild_status); + CHECK(ret, FAIL, "H5S__get_rebuild_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + if(rebuild_status != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_rebuild"); + } /* end if */ + + /* Add block completely overlapping current, with XOR */ + start1[0] = 2; + count1[0] = 1; + block1[0] = 7; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_XOR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + sel_type = H5Sget_select_type(space_id); + VERIFY(sel_type, H5S_SEL_NONE, "H5Sget_select_type"); + + /* + * Test various conditions that break the fast algorithm + */ + + /* Create multiple blocks */ + start1[0] = 3; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create single block with start out of phase */ + start1[0] = 8; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start1[0] = 3; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks with start out of phase */ + start1[0] = 8; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start1[0] = 3; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks with wrong stride */ + start1[0] = 9; + stride1[0] = 4; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create single block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create single block with wrong size */ + start1[0] = 6; + count1[0] = 1; + block1[0] = 1; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create single block */ + start1[0] = 3; + count1[0] = 1; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks with wrong size */ + start1[0] = 6; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 1; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start1[0] = 3; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create single block with wrong size */ + start1[0] = 9; + count1[0] = 1; + block1[0] = 1; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, NULL, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start1[0] = 3; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks with wrong size */ + start1[0] = 9; + stride1[0] = 3; + count1[0] = 2; + block1[0] = 1; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start1, stride1, count1, block1); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + ret = H5Sclose(space_id); + CHECK(ret, FAIL, "H5Sclose"); + + + MESSAGE(7, ("Testing functionality to update 3-D hyperslab dimension info\n")); + + /* Create 3-D dataspace */ + space_id = H5Screate_simple(3, dims3, NULL); + + /* Create multiple blocks */ + start3[0] = 0; + start3[1] = 1; + start3[2] = 2; + stride3[0] = 2; + stride3[1] = 3; + stride3[2] = 4; + count3[0] = 4; + count3[1] = 3; + count3[2] = 2; + block3[0] = 1; + block3[1] = 2; + block3[2] = 3; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add blocks with same values in all dimensions */ + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add blocks with same values in two dimensions */ + start3[0] = 8; + stride3[0] = 1; + count3[0] = 1; + block3[0] = 1; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start3[0] = 0; + start3[1] = 1; + start3[2] = 2; + stride3[0] = 2; + stride3[1] = 3; + stride3[2] = 4; + count3[0] = 4; + count3[1] = 3; + count3[2] = 2; + block3[0] = 1; + block3[1] = 2; + block3[2] = 3; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add blocks with same values in one dimension */ + start3[0] = 8; + start3[1] = 10; + stride3[0] = 1; + stride3[1] = 1; + count3[0] = 1; + count3[1] = 1; + block3[0] = 1; + block3[1] = 2; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Create multiple blocks */ + start3[0] = 0; + start3[1] = 1; + start3[2] = 2; + stride3[0] = 2; + stride3[1] = 3; + stride3[2] = 4; + count3[0] = 4; + count3[1] = 3; + count3[2] = 2; + block3[0] = 1; + block3[1] = 2; + block3[2] = 3; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be YES */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_YES) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + /* Add blocks with same values in no dimensions */ + start3[0] = 8; + start3[1] = 10; + start3[2] = 10; + stride3[0] = 1; + stride3[1] = 1; + stride3[2] = 1; + count3[0] = 1; + count3[1] = 1; + count3[2] = 1; + block3[0] = 1; + block3[1] = 2; + block3[2] = 3; + ret = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, start3, stride3, count3, block3); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* diminfo_valid should be NO */ + ret = H5S__get_diminfo_status_test(space_id, &diminfo_valid); + CHECK(ret, FAIL, "H5S__get_diminfo_status_test"); + if(diminfo_valid != H5S_DIMINFO_VALID_NO) { + ret = FAIL; + CHECK(ret, FAIL, "H5S_hyper_update_diminfo"); + } /* end if */ + + ret = H5Sclose(space_id); + CHECK(ret, FAIL, "H5Sclose"); +} /* end test_space_update_diminfo() */ + /**************************************************************** ** @@ -13239,6 +14092,365 @@ test_hyper_unlim(void) CHECK(ret, FAIL, "H5Sclose"); } /* end test_hyper_unlim() */ +/**************************************************************** +** +** test_internal_consistency(): Tests selections on dataspace, then +** verify that internal states of data structures of selections are +** consistent. +** +****************************************************************/ +static void +test_internal_consistency(void) +{ + hid_t all_sid; /* Dataspace ID with "all" selection */ + hid_t none_sid; /* Dataspace ID with "none" selection */ + hid_t single_pt_sid; /* Dataspace ID with single point selection */ + hid_t mult_pt_sid; /* Dataspace ID with multiple point selection */ + hid_t single_hyper_sid; /* Dataspace ID with single block hyperslab selection */ + hid_t single_hyper_all_sid; /* Dataspace ID with single block hyperslab + * selection that is the entire dataspace + */ + hid_t single_hyper_pt_sid; /* Dataspace ID with single block hyperslab + * selection that is the same as the single + * point selection + */ + hid_t regular_hyper_sid; /* Dataspace ID with regular hyperslab selection */ + hid_t irreg_hyper_sid; /* Dataspace ID with irregular hyperslab selection */ + hid_t none_hyper_sid; /* Dataspace ID with "no hyperslabs" selection */ + hid_t scalar_all_sid; /* ID for scalar dataspace with "all" selection */ + hid_t scalar_none_sid; /* ID for scalar dataspace with "none" selection */ + hid_t tmp_sid; /* Temporary dataspace ID */ + hsize_t dims[] = {SPACE9_DIM1, SPACE9_DIM2}; + hsize_t coord1[1][SPACE2_RANK]; /* Coordinates for single point selection */ + hsize_t coord2[SPACE9_DIM2][SPACE9_RANK]; /* Coordinates for multiple point selection */ + hsize_t start[SPACE9_RANK]; /* Hyperslab start */ + hsize_t stride[SPACE9_RANK]; /* Hyperslab stride */ + hsize_t count[SPACE9_RANK]; /* Hyperslab block count */ + hsize_t block[SPACE9_RANK]; /* Hyperslab block size */ + htri_t check; /* Shape comparison return value */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(6, ("Testing Consistency of Internal States\n")); + assert(SPACE9_DIM2>=POINT1_NPOINTS); + + /* Create dataspace for "all" selection */ + all_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(all_sid, FAIL, "H5Screate_simple"); + + /* Select entire extent for dataspace */ + ret = H5Sselect_all(all_sid); + CHECK(ret, FAIL, "H5Sselect_all"); + + /* Create dataspace for "none" selection */ + none_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(none_sid, FAIL, "H5Screate_simple"); + + /* Un-Select entire extent for dataspace */ + ret = H5Sselect_none(none_sid); + CHECK(ret, FAIL, "H5Sselect_none"); + + /* Create dataspace for single point selection */ + single_pt_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(single_pt_sid, FAIL, "H5Screate_simple"); + + /* Select sequence of ten points for multiple point selection */ + coord1[0][0] = 2; coord1[0][1] = 2; + ret = H5Sselect_elements(single_pt_sid, H5S_SELECT_SET, (size_t)1, (const hsize_t *)coord1); + CHECK(ret, FAIL, "H5Sselect_elements"); + + /* Create dataspace for multiple point selection */ + mult_pt_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(mult_pt_sid, FAIL, "H5Screate_simple"); + + /* Select sequence of ten points for multiple point selection */ + coord2[0][0]=2; coord2[0][1]=2; + coord2[1][0]=7; coord2[1][1]=2; + coord2[2][0]=1; coord2[2][1]=4; + coord2[3][0]=2; coord2[3][1]=6; + coord2[4][0]=0; coord2[4][1]=8; + coord2[5][0]=3; coord2[5][1]=2; + coord2[6][0]=4; coord2[6][1]=4; + coord2[7][0]=1; coord2[7][1]=0; + coord2[8][0]=5; coord2[8][1]=1; + coord2[9][0]=9; coord2[9][1]=3; + ret = H5Sselect_elements(mult_pt_sid, H5S_SELECT_SET, (size_t)POINT1_NPOINTS, (const hsize_t *)coord2); + CHECK(ret, FAIL, "H5Sselect_elements"); + + /* Create dataspace for single hyperslab selection */ + single_hyper_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(single_hyper_sid, FAIL, "H5Screate_simple"); + + /* Select 10x10 hyperslab for single hyperslab selection */ + start[0]=1; start[1]=1; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=(SPACE9_DIM1-2); block[1]=(SPACE9_DIM2-2); + ret = H5Sselect_hyperslab(single_hyper_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create dataspace for single hyperslab selection with entire extent selected */ + single_hyper_all_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(single_hyper_all_sid, FAIL, "H5Screate_simple"); + + /* Select entire extent for hyperslab selection */ + start[0]=0; start[1]=0; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=SPACE9_DIM1; block[1]=SPACE9_DIM2; + ret = H5Sselect_hyperslab(single_hyper_all_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create dataspace for single hyperslab selection with single point selected */ + single_hyper_pt_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(single_hyper_pt_sid, FAIL, "H5Screate_simple"); + + /* Select entire extent for hyperslab selection */ + start[0]=2; start[1]=2; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(single_hyper_pt_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create dataspace for regular hyperslab selection */ + regular_hyper_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(regular_hyper_sid, FAIL, "H5Screate_simple"); + + /* Select regular, strided hyperslab selection */ + start[0]=2; start[1]=2; + stride[0]=2; stride[1]=2; + count[0]=5; count[1]=2; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(regular_hyper_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create dataspace for irregular hyperslab selection */ + irreg_hyper_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(irreg_hyper_sid, FAIL, "H5Screate_simple"); + + /* Create irregular hyperslab selection by OR'ing two blocks together */ + start[0]=2; start[1]=2; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(irreg_hyper_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + start[0]=4; start[1]=4; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=3; block[1]=3; + ret = H5Sselect_hyperslab(irreg_hyper_sid,H5S_SELECT_OR,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create dataspace for "no" hyperslab selection */ + none_hyper_sid = H5Screate_simple(SPACE9_RANK, dims, NULL); + CHECK(none_hyper_sid, FAIL, "H5Screate_simple"); + + /* Create "no" hyperslab selection by XOR'ing same blocks together */ + start[0]=2; start[1]=2; + stride[0]=1; stride[1]=1; + count[0]=1; count[1]=1; + block[0]=1; block[1]=1; + ret = H5Sselect_hyperslab(none_hyper_sid,H5S_SELECT_SET,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + ret = H5Sselect_hyperslab(none_hyper_sid,H5S_SELECT_XOR,start,stride,count,block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create scalar dataspace for "all" selection */ + scalar_all_sid = H5Screate(H5S_SCALAR); + CHECK(scalar_all_sid, FAIL, "H5Screate"); + + /* Create scalar dataspace for "none" selection */ + scalar_none_sid = H5Screate(H5S_SCALAR); + CHECK(scalar_none_sid, FAIL, "H5Screate"); + + /* Un-Select entire extent for dataspace */ + ret = H5Sselect_none(scalar_none_sid); + CHECK(ret, FAIL, "H5Sselect_none"); + + /* Test all the selections created */ + + /* Test the copy of itself */ + tmp_sid=H5Scopy(all_sid); + CHECK(tmp_sid, FAIL, "H5Scopy"); + + check = H5S__internal_consistency_test(tmp_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + ret = H5Sclose(tmp_sid); + CHECK(ret, FAIL, "H5Sclose"); + + /* Test "none" selection */ + check = H5S__internal_consistency_test(none_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test single point selection */ + check = H5S__internal_consistency_test(single_pt_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test multiple point selection */ + check = H5S__internal_consistency_test(mult_pt_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test "plain" single hyperslab selection */ + check = H5S__internal_consistency_test(single_hyper_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test "all" single hyperslab selection */ + check = H5S__internal_consistency_test(single_hyper_all_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test "single point" single hyperslab selection */ + check = H5S__internal_consistency_test(single_hyper_pt_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test regular, strided hyperslab selection */ + check = H5S__internal_consistency_test(regular_hyper_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test irregular hyperslab selection */ + check = H5S__internal_consistency_test(irreg_hyper_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test "no" hyperslab selection */ + check = H5S__internal_consistency_test(none_hyper_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test scalar "all" hyperslab selection */ + check = H5S__internal_consistency_test(scalar_all_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Test scalar "none" hyperslab selection */ + check = H5S__internal_consistency_test(scalar_none_sid); + VERIFY(check, TRUE, "H5S__internal_consistency_test"); + + /* Close dataspaces */ + ret = H5Sclose(all_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(none_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(single_pt_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(mult_pt_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(single_hyper_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(single_hyper_all_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(single_hyper_pt_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(regular_hyper_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(irreg_hyper_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(none_hyper_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(scalar_all_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(scalar_none_sid); + CHECK(ret, FAIL, "H5Sclose"); +} /* test_internal_consistency() */ + +/**************************************************************** +** +** test_irreg_io(): Tests unusual selections on datasets, to stress the +** new hyperslab code. +** +****************************************************************/ +static void +test_irreg_io(void) +{ + hid_t fid; /* File ID */ + hid_t did; /* Dataset ID */ + hid_t dcpl_id; /* Dataset creation property list ID */ + hid_t sid; /* File dataspace ID */ + hid_t mem_sid; /* Memory dataspace ID */ + hsize_t dims[] = {6, 12}; /* Dataspace dimensions */ + hsize_t chunk_dims[] = {2, 2}; /* Chunk dimensions */ + hsize_t mem_dims[] = {32}; /* Memory dataspace dimensions */ + hsize_t start[2]; /* Hyperslab start */ + hsize_t stride[2]; /* Hyperslab stride */ + hsize_t count[2]; /* Hyperslab block count */ + hsize_t block[2]; /* Hyperslab block size */ + unsigned char wbuf[72]; /* Write buffer */ + unsigned char rbuf[32]; /* Read buffer */ + unsigned u; /* Local index variable */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(6, ("Testing Irregular Hyperslab I/O\n")); + + /* Create file */ + fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset */ + sid = H5Screate_simple(2, dims, NULL); + CHECK(sid, FAIL, "H5Screate_simple"); + + /* Set chunk dimensions for dataset */ + dcpl_id = H5Pcreate(H5P_DATASET_CREATE); + CHECK(dcpl_id, FAIL, "H5Pcreate"); + ret = H5Pset_chunk(dcpl_id, 2, chunk_dims); + CHECK(ret, FAIL, "H5Pset_chunk"); + + /* Create a dataset */ + did = H5Dcreate2(fid, SPACE1_NAME, H5T_NATIVE_UCHAR, sid, H5P_DEFAULT, dcpl_id, H5P_DEFAULT); + CHECK(did, FAIL, "H5Dcreate2"); + + /* Initialize the write buffer */ + for(u = 0; u < 72; u++) + wbuf[u] = (unsigned char)u; + + /* Write entire dataset to disk */ + ret = H5Dwrite(did, H5T_NATIVE_UCHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Close the DCPL */ + ret = H5Pclose(dcpl_id); + CHECK(ret, FAIL, "H5Pclose"); + + /* Create dataspace for memory selection */ + mem_sid = H5Screate_simple(1, mem_dims, NULL); + CHECK(mem_sid, FAIL, "H5Screate_simple"); + + /* Select 'L'-shaped region within dataset */ + start[0] = 0; start[1] = 10; + stride[0] = 1; stride[1] = 1; + count[0] = 4; count[1] = 2; + block[0] = 1; block[1] = 1; + ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, start, stride, count, block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + start[0] = 4; start[1] = 0; + stride[0] = 1; stride[1] = 1; + count[0] = 2; count[1] = 12; + block[0] = 1; block[1] = 1; + ret = H5Sselect_hyperslab(sid, H5S_SELECT_OR, start, stride, count, block); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Reset the buffer */ + HDmemset(rbuf, 0, sizeof(rbuf)); + + /* Read selection from disk */ + ret = H5Dread(did, H5T_NATIVE_UCHAR, mem_sid, sid, H5P_DEFAULT, rbuf); + CHECK(ret, FAIL, "H5Dread"); + + + /* Close everything */ + ret = H5Sclose(mem_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Dclose(did); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_irreg_io() */ + /**************************************************************** ** ** test_select(): Main H5S selection testing routine. @@ -13382,6 +14594,8 @@ test_select(void) /* Test "re-build" routine */ test_space_rebuild(); + /* Test "update diminfo" routine */ + test_space_update_diminfo(); /* Test point selections in chunked datasets */ test_select_point_chunk(); @@ -13402,6 +14616,12 @@ test_select(void) /* Test unlimited hyperslab selections */ test_hyper_unlim(); + /* Test the consistency of internal data structures of selection */ + test_internal_consistency(); + + /* Test irregular selection I/O */ + test_irreg_io(); + } /* test_select() */ From adb09288274ab1e622d691afd8e090c8f0ac92e0 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 19 Mar 2019 16:40:07 -0500 Subject: [PATCH 02/32] Remove thread-local copy of hyperslab operation generation value. --- src/H5Shyper.c | 89 +++-------------------------------------------- src/H5TS.c | 12 ------- src/H5TSprivate.h | 1 - 3 files changed, 4 insertions(+), 98 deletions(-) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 478a0e2fe0..17c3d65586 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -83,24 +83,6 @@ (curr_span) = saved_next_span; \ } while(0) -#ifdef H5_HAVE_THREADSAFE -/* - * The per-thread operation generation. pthread_once() initializes a special - * key that will be used by all threads to create a stack specific to - * each thread individually. The association of operation generations to threads - * will be handled by the pthread library. - * - * In order for this macro to work, H5S_hyper_get_my_op_gen() must be preceeded - * by "uint64_t *gen =". - */ -#define H5S_hyper_get_my_op_gen() H5S__hyper_op_gen() -#else /* H5_HAVE_THREADSAFE */ -/* - * The current operation generation. - */ -#define H5S_hyper_get_my_op_gen() (&H5S_hyper_op_gen_g) -#endif /* H5_HAVE_THREADSAFE */ - /******************/ /* Local Typedefs */ @@ -114,9 +96,6 @@ typedef hsize_t hbounds_t; /********************/ /* Local Prototypes */ /********************/ -#ifdef H5_HAVE_THREADSAFE -static uint64_t *H5S__hyper_op_gen(void); -#endif /* H5_HAVE_THREADSAFE */ static H5S_hyper_span_t *H5S__hyper_new_span(hsize_t low, hsize_t high, H5S_hyper_span_info_t *down, H5S_hyper_span_t *next); static H5S_hyper_span_info_t *H5S__hyper_new_span_info(unsigned rank); @@ -285,10 +264,9 @@ H5FL_BARR_DEFINE_STATIC(H5S_hyper_span_info_t, hbounds_t, H5S_MAX_RANK * 2); /* Declare extern free list to manage the H5S_sel_iter_t struct */ H5FL_EXTERN(H5S_sel_iter_t); -#ifndef H5_HAVE_THREADSAFE -static uint64_t H5S_hyper_op_gen_g = 1; /* Current operation generation */ - /* (Use '1' to avoid clashing with '0' value in newly allocated structs) */ -#endif /* H5_HAVE_THREADSAFE */ +/* Current operation generation */ +/* (Start with '1' to avoid clashing with '0' value in newly allocated structs) */ +static uint64_t H5S_hyper_op_gen_g = 1; /* Uncomment this, to provide the debugging routines for printing selection info */ @@ -518,60 +496,6 @@ H5S__hyper_print_space_dfs(FILE *f, const H5S_t *space) } /* end H5S__hyper_print_space_dfs() */ #endif /* H5S_HYPER_DEBUG */ -#ifdef H5_HAVE_THREADSAFE - -/*------------------------------------------------------------------------- - * Function: H5S__hyper_op_gen - * - * Purpose: Support function for H5S_hyper_get_my_op_gen() to initialize and - * acquire per-thread hyperslab operation generation. - * - * Return: Success: Non-NULL pointer to hyperslab operation generation for thread - * Failure: NULL - * - * Programmer: Quincey Koziol - * January 19, 2019 - * - *------------------------------------------------------------------------- - */ -static uint64_t * -H5S__hyper_op_gen(void) -{ - uint64_t *op_gen = NULL; - - FUNC_ENTER_STATIC_NOERR - - op_gen = (uint64_t *)H5TS_get_thread_local_value(H5TS_hyper_op_gen_key_g); - - if(!op_gen) { - /* No associated value with current thread - create one */ -#ifdef H5_HAVE_WIN_THREADS - /* Win32 has to use LocalAlloc to match the LocalFree in DllMain */ - op_gen = (uint64_t *)LocalAlloc(LPTR, sizeof(uint64_t)); -#else - /* Use HDmalloc here since this has to match the HDfree in the - * destructor and we want to avoid the codestack there. - */ - op_gen = (uint64_t *)HDmalloc(sizeof(uint64_t)); -#endif /* H5_HAVE_WIN_THREADS */ - HDassert(op_gen); - - /* Reset the thread-specific info */ - /* (Use '1' to avoid clashing with '0' value in newly allocated structs) */ - *op_gen = 1; - - /* (It's not necessary to release this in this API, it is - * released by the "key destructor" set up in the H5TS - * routines. See calls to pthread_key_create() in H5TS.c -QAK) - */ - H5TS_set_thread_local_value(H5TS_hyper_op_gen_key_g, (void *)op_gen); - } /* end if */ - - /* Set return value */ - FUNC_LEAVE_NOAPI(op_gen) -} /* end H5S__hyper_op_gen() */ -#endif /* H5_HAVE_THREADSAFE */ - /*------------------------------------------------------------------------- * Function: H5S__hyper_get_op_gen @@ -591,14 +515,9 @@ H5S__hyper_op_gen(void) uint64_t H5S__hyper_get_op_gen(void) { - uint64_t *op_gen = H5S_hyper_get_my_op_gen(); /* Get the pointer to the hyperslab operation generation, for this thread */ - FUNC_ENTER_PACKAGE_NOERR - /* Check args */ - HDassert(op_gen); - - FUNC_LEAVE_NOAPI((*op_gen)++); + FUNC_LEAVE_NOAPI(H5S_hyper_op_gen_g++); } /* end H5S__hyper_op_gen() */ diff --git a/src/H5TS.c b/src/H5TS.c index f386421dda..10e14d5ee2 100644 --- a/src/H5TS.c +++ b/src/H5TS.c @@ -35,7 +35,6 @@ H5TS_once_t H5TS_first_init_g = PTHREAD_ONCE_INIT; H5TS_key_t H5TS_errstk_key_g; H5TS_key_t H5TS_funcstk_key_g; H5TS_key_t H5TS_apictx_key_g; -H5TS_key_t H5TS_hyper_op_gen_key_g; H5TS_key_t H5TS_cancel_key_g; @@ -114,9 +113,6 @@ H5TS_pthread_first_thread_init(void) /* initialize key for thread-specific API contexts */ pthread_key_create(&H5TS_apictx_key_g, H5TS_key_destructor); - /* initialize key for thread-specific hyperslab operation generation */ - pthread_key_create(&H5TS_hyper_op_gen_key_g, H5TS_key_destructor); - /* initialize key for thread cancellability mechanism */ pthread_key_create(&H5TS_cancel_key_g, H5TS_key_destructor); } @@ -366,9 +362,6 @@ H5TS_win32_process_enter(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex) if(TLS_OUT_OF_INDEXES == (H5TS_apictx_key_g = TlsAlloc())) ret_value = FALSE; - if(TLS_OUT_OF_INDEXES == (H5TS_hyper_op_gen_key_g = TlsAlloc())) - ret_value = FALSE; - return ret_value; } /* H5TS_win32_process_enter() */ #endif /* H5_HAVE_WIN_THREADS */ @@ -438,7 +431,6 @@ H5TS_win32_process_exit(void) TlsFree(H5TS_funcstk_key_g); #endif /* H5_HAVE_CODESTACK */ TlsFree(H5TS_apictx_key_g); - TlsFree(H5TS_hyper_op_gen_key_g); return; } /* H5TS_win32_process_exit() */ @@ -487,10 +479,6 @@ H5TS_win32_thread_exit(void) if(lpvData) LocalFree((HLOCAL)lpvData); - lpvData = TlsGetValue(H5TS_hyper_op_gen_key_g); - if(lpvData) - LocalFree((HLOCAL)lpvData); - return ret_value; } /* H5TS_win32_thread_exit() */ #endif /* H5_HAVE_WIN_THREADS */ diff --git a/src/H5TSprivate.h b/src/H5TSprivate.h index 94791bc113..9e093a68af 100644 --- a/src/H5TSprivate.h +++ b/src/H5TSprivate.h @@ -110,7 +110,6 @@ extern H5TS_once_t H5TS_first_init_g; extern H5TS_key_t H5TS_errstk_key_g; extern H5TS_key_t H5TS_funcstk_key_g; extern H5TS_key_t H5TS_apictx_key_g; -extern H5TS_key_t H5TS_hyper_op_gen_key_g; #if defined c_plusplus || defined __cplusplus extern "C" From 4f8a844a00b476217b88aa00109fa0147c5b41e8 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 20 Mar 2019 17:13:48 -0500 Subject: [PATCH 03/32] Clean up if-else chain. --- src/H5Shyper.c | 52 ++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 17c3d65586..60fcf5adf9 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -4877,37 +4877,35 @@ H5S__hyper_spans_shape_same_helper(const H5S_hyper_span_info_t *span_info1, /* Check for both spans being NULL */ if(span1 == NULL && span2 == NULL) HGOTO_DONE(TRUE) - else { - /* Check for one span being NULL */ - if(span1 == NULL || span2 == NULL) - HGOTO_DONE(FALSE) - else { - /* Check if the actual low & high span information is the same */ - if((hsize_t)((hssize_t)span1->low + offset[0]) != span2->low || (hsize_t)((hssize_t)span1->high + offset[0]) != span2->high) + + /* Check for one span being NULL */ + if(span1 == NULL || span2 == NULL) + HGOTO_DONE(FALSE) + + /* Check if the actual low & high span information is the same */ + if((hsize_t)((hssize_t)span1->low + offset[0]) != span2->low || (hsize_t)((hssize_t)span1->high + offset[0]) != span2->high) + HGOTO_DONE(FALSE) + + /* Check for down tree for this span */ + if(span1->down != NULL || span2->down != NULL) { + /* If the rest of the span trees have a zero offset, use the faster comparison routine */ + if(rest_zeros[0]) { + if(!H5S__hyper_cmp_spans(span1->down, span2->down)) HGOTO_DONE(FALSE) else { - if(span1->down != NULL || span2->down != NULL) { - /* If the rest of the span trees have a zero offset, use the faster comparison routine */ - if(rest_zeros[0]) { - if(!H5S__hyper_cmp_spans(span1->down, span2->down)) - HGOTO_DONE(FALSE) - else { - /* Keep going... */ - } /* end else */ - } /* end if */ - else { - if(!H5S__hyper_spans_shape_same_helper(span1->down, span2->down, &offset[1], &rest_zeros[1])) - HGOTO_DONE(FALSE) - else { - /* Keep going... */ - } /* end else */ - } /* end else */ - } /* end if */ - else { - /* Keep going... */ - } /* end else */ + /* Keep going... */ + } /* end else */ + } /* end if */ + else { + if(!H5S__hyper_spans_shape_same_helper(span1->down, span2->down, &offset[1], &rest_zeros[1])) + HGOTO_DONE(FALSE) + else { + /* Keep going... */ } /* end else */ } /* end else */ + } /* end if */ + else { + /* Keep going... */ } /* end else */ /* Advance to the next nodes in the span list */ From 62198c2436ac3787afb49fa990d1ba8204264dba Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sun, 21 Apr 2019 14:45:54 -0500 Subject: [PATCH 04/32] Add an 'unwrap' VOL callback, so that connectors can unwrap an underlying object without closing it. (Especially needed for pass-through connectors) --- src/H5Dvirtual.c | 2 +- src/H5I.c | 2 +- src/H5VLcallback.c | 209 +++++++++++++++++++++++++------------- src/H5VLint.c | 28 ++++- src/H5VLnative.c | 1 + src/H5VLpassthru.c | 67 ++++++++++-- src/H5VLprivate.h | 6 +- src/H5VLpublic.h | 2 + test/null_vol_connector.c | 25 +++-- test/vol.c | 1 + 10 files changed, 251 insertions(+), 92 deletions(-) diff --git a/src/H5Dvirtual.c b/src/H5Dvirtual.c index d38df1b510..e3e0aa5e3e 100644 --- a/src/H5Dvirtual.c +++ b/src/H5Dvirtual.c @@ -3035,7 +3035,7 @@ H5D__virtual_refresh_source_dset(H5D_t **dset) /* Discard the identifier & replace the dataset */ if(NULL == (vol_obj = (H5VL_object_t *)H5I_remove(temp_id))) HGOTO_ERROR(H5E_DATASET, H5E_CANTREMOVE, FAIL, "can't unregister source dataset ID") - if(NULL == (*dset = (H5D_t *)H5VL_object_data(vol_obj))) + if(NULL == (*dset = (H5D_t *)H5VL_object_unwrap(vol_obj))) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't retrieve library object from VOL object") vol_obj->data = NULL; diff --git a/src/H5I.c b/src/H5I.c index 345c0102d1..2edea9bf71 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -1134,7 +1134,7 @@ done: * *------------------------------------------------------------------------- */ -void * +static void * H5I__remove_verify(hid_t id, H5I_type_t id_type) { void * ret_value = NULL; /*return value */ diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 03828fa6a2..b785747426 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -738,6 +738,145 @@ done: FUNC_LEAVE_API_NOINIT(ret_value) } /* H5VLget_wrap_ctx() */ + +/*------------------------------------------------------------------------- + * Function: H5VL_wrap_object + * + * Purpose: Wrap an object with connector + * + * Return: Success: Non-NULL + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +void * +H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, + H5I_type_t obj_type) +{ + void *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(NULL) + + /* Sanity checks */ + HDassert(connector); + HDassert(obj); + + /* Only wrap object if there's a wrap context */ + if(wrap_ctx) { + /* Ask the connector to wrap the object */ + if(NULL == (ret_value = (connector->wrap_cls.wrap_object)(obj, obj_type, wrap_ctx))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") + } /* end if */ + else + ret_value = obj; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_wrap_object() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLwrap_object + * + * Purpose: Asks a connector to wrap an underlying object. + * + * Return: Success: Non-NULL + * Failure: NULL + * + *--------------------------------------------------------------------------- + */ +void * +H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + void *ret_value = NULL; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE4("*x", "*xIti*x", obj, obj_type, connector_id, wrap_ctx); + + /* Check args and get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid object") + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") + + /* Wrap the object */ + if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj, obj_type))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to wrap object") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLwrap_object */ + + +/*------------------------------------------------------------------------- + * Function: H5VL_unwrap_object + * + * Purpose: Unwrap an object from connector + * + * Return: Success: Non-NULL + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +void * +H5VL_unwrap_object(const H5VL_class_t *connector, void *obj) +{ + void *ret_value; /* Return value */ + + FUNC_ENTER_NOAPI(NULL) + + /* Sanity checks */ + HDassert(connector); + HDassert(obj); + + /* Only unwrap object if there's an unwrap callback */ + if(connector->wrap_cls.wrap_object) { + /* Ask the connector to unwrap the object */ + if(NULL == (ret_value = (connector->wrap_cls.unwrap_object)(obj))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't unwrap object") + } /* end if */ + else + ret_value = obj; + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_unwrap_object() */ + + +/*--------------------------------------------------------------------------- + * Function: H5VLunwrap_object + * + * Purpose: Unwrap an object from connector + * + * Return: Success: Non-NULL + * Failure: NULL + * + *--------------------------------------------------------------------------- + */ +void * +H5VLunwrap_object(void *obj, hid_t connector_id) +{ + H5VL_class_t *cls; /* VOL connector's class struct */ + void *ret_value = NULL; /* Return value */ + + FUNC_ENTER_API_NOINIT + H5TRACE2("*x", "*xi", obj, connector_id); + + /* Check args and get class pointer */ + if(NULL == obj) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid object") + if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") + + /* Unwrap the object */ + if(NULL == (ret_value = H5VL_unwrap_object(cls, obj))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to unwrap object") + +done: + FUNC_LEAVE_API_NOINIT(ret_value) +} /* H5VLunwrap_object */ + /*------------------------------------------------------------------------- * Function: H5VL_free_wrap_ctx @@ -802,76 +941,6 @@ done: FUNC_LEAVE_API_NOINIT(ret_value) } /* H5VLfree_wrap_ctx() */ - -/*------------------------------------------------------------------------- - * Function: H5VL_wrap_object - * - * Purpose: Wrap an object with connector - * - * Return: Success: Non-negative - * Failure: Negative - * - *------------------------------------------------------------------------- - */ -void * -H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, - H5I_type_t obj_type) -{ - void *ret_value = SUCCEED; /* Return value */ - - FUNC_ENTER_NOAPI(NULL) - - /* Sanity checks */ - HDassert(connector); - HDassert(obj); - - /* Only wrap object if there's a wrap context */ - if(wrap_ctx) { - /* Ask the connector to wrap the object */ - if(NULL == (ret_value = (connector->wrap_cls.wrap_object)(obj, obj_type, wrap_ctx))) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object") - } /* end if */ - else - ret_value = obj; - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_wrap_object() */ - - -/*--------------------------------------------------------------------------- - * Function: H5VLwrap_object - * - * Purpose: Asks a connector to wrap an underlying object. - * - * Return: Success: Non-NULL - * Failure: NULL - * - *--------------------------------------------------------------------------- - */ -void * -H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx) -{ - H5VL_class_t *cls; /* VOL connector's class struct */ - void *ret_value = NULL; /* Return value */ - - FUNC_ENTER_API_NOINIT - H5TRACE4("*x", "*xIti*x", obj, obj_type, connector_id, wrap_ctx); - - /* Check args and get class pointer */ - if(NULL == obj) - HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, NULL, "invalid object") - if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") - - /* Wrap the object */ - if(NULL == (ret_value = H5VL_wrap_object(cls, wrap_ctx, obj, obj_type))) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "unable to wrap object") - -done: - FUNC_LEAVE_API_NOINIT(ret_value) -} /* H5VLwrap_object */ - /*------------------------------------------------------------------------- * Function: H5VL__attr_create diff --git a/src/H5VLint.c b/src/H5VLint.c index fda4443d65..1b735f5319 100644 --- a/src/H5VLint.c +++ b/src/H5VLint.c @@ -1356,6 +1356,32 @@ H5VL_object_data(const H5VL_object_t *vol_obj) FUNC_LEAVE_NOAPI(ret_value) } /* end H5VL_object_data() */ + +/*------------------------------------------------------------------------- + * Function: H5VL_object_unwrap + * + * Purpose: Correctly unwrap the 'data' field for a VOL object (H5VL_object), + * even for nested / stacked VOL connectors. + * + * Return: Success: Object pointer + * Failure: NULL + * + *------------------------------------------------------------------------- + */ +void * +H5VL_object_unwrap(const H5VL_object_t *vol_obj) +{ + void *ret_value = NULL; + + FUNC_ENTER_NOAPI(NULL) + + if(NULL == (ret_value = H5VL_unwrap_object(vol_obj->connector->cls, vol_obj->data))) + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't unwrap object") + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL_object_unwrap() */ + /*------------------------------------------------------------------------- * Function: H5VL__object @@ -1444,7 +1470,7 @@ H5VL_object(hid_t id) /* Get the underlying object */ if(NULL == (ret_value = H5VL__object(id, H5I_get_type(id)))) - HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, NULL, "can't retrieve object for ID") + HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't retrieve object for ID") done: FUNC_LEAVE_NOAPI(ret_value) diff --git a/src/H5VLnative.c b/src/H5VLnative.c index f4f3b5f784..7848c5d552 100644 --- a/src/H5VLnative.c +++ b/src/H5VLnative.c @@ -50,6 +50,7 @@ static H5VL_class_t H5VL_native_cls_g = { NULL, /* get_object */ NULL, /* get_wrap_ctx */ NULL, /* wrap_object */ + NULL, /* unwrap_object */ NULL /* free_wrap_ctx */ }, { /* attribute_cls */ diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index a4c85ccc26..85a934641f 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -98,9 +98,10 @@ static herr_t H5VL_pass_through_str_to_info(const char *str, void **info); /* VOL object wrap / retrieval callbacks */ static void *H5VL_pass_through_get_object(const void *obj); static herr_t H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx); -static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); static void *H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, void *wrap_ctx); +static void *H5VL_pass_through_unwrap_object(void *obj); +static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); /* Attribute callbacks */ static void *H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); @@ -194,6 +195,7 @@ static const H5VL_class_t H5VL_pass_through_g = { H5VL_pass_through_get_object, /* get_object */ H5VL_pass_through_get_wrap_ctx, /* get_wrap_ctx */ H5VL_pass_through_wrap_object, /* wrap_object */ + H5VL_pass_through_unwrap_object, /* unwrap_object */ H5VL_pass_through_free_wrap_ctx, /* free_wrap_ctx */ }, { /* attribute_cls */ @@ -683,8 +685,8 @@ H5VL_pass_through_get_wrap_ctx(const void *obj, void **wrap_ctx) * * Purpose: Use a "wrapper context" to wrap a data object * - * Return: Success: 0 - * Failure: -1 + * Return: Success: Pointer to wrapped object + * Failure: NULL * *--------------------------------------------------------------------------- */ @@ -709,6 +711,37 @@ H5VL_pass_through_wrap_object(void *obj, H5I_type_t obj_type, void *_wrap_ctx) return new_obj; } /* end H5VL_pass_through_wrap_object() */ + +/*--------------------------------------------------------------------------- + * Function: H5VL_pass_through_unwrap_object + * + * Purpose: Unwrap a wrapped object, discarding the wrapper, but returning + * underlying object. + * + * Return: Success: Pointer to unwrapped object + * Failure: NULL + * + *--------------------------------------------------------------------------- + */ +static void * +H5VL_pass_through_unwrap_object(void *obj) +{ + H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + void *under; + +#ifdef ENABLE_PASSTHRU_LOGGING + printf("------- PASS THROUGH VOL UNWRAP Object\n"); +#endif + + /* Unrap the object with the underlying VOL */ + under = H5VLunwrap_object(o->under_object, o->under_vol_id); + + if(under) + H5VL_pass_through_free_obj(o); + + return under; +} /* end H5VL_pass_through_unwrap_object() */ + /*--------------------------------------------------------------------------- * Function: H5VL_pass_through_free_wrap_ctx @@ -1194,17 +1227,22 @@ H5VL_pass_through_dataset_specific(void *obj, H5VL_dataset_specific_t specific_t hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL H5Dspecific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLdataset_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_dataset_specific() */ @@ -1396,17 +1434,22 @@ H5VL_pass_through_datatype_specific(void *obj, H5VL_datatype_specific_t specific hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL DATATYPE Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLdatatype_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_datatype_specific() */ @@ -1936,17 +1979,22 @@ H5VL_pass_through_group_specific(void *obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL GROUP Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLgroup_specific(o->under_object, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_group_specific() */ @@ -2372,17 +2420,22 @@ H5VL_pass_through_object_specific(void *obj, const H5VL_loc_params_t *loc_params va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; + hid_t under_vol_id; herr_t ret_value; #ifdef ENABLE_PASSTHRU_LOGGING printf("------- PASS THROUGH VOL OBJECT Specific\n"); #endif + // Save copy of underlying VOL connector ID and prov helper, in case of + // refresh destroying the current object + under_vol_id = o->under_vol_id; + ret_value = H5VLobject_specific(o->under_object, loc_params, o->under_vol_id, specific_type, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) - *req = H5VL_pass_through_new_obj(*req, o->under_vol_id); + *req = H5VL_pass_through_new_obj(*req, under_vol_id); return ret_value; } /* end H5VL_pass_through_object_specific() */ diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index dc4f9c5b4d..04cc982c4b 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -86,6 +86,7 @@ H5_DLL hid_t H5VL_register_connector(const void *cls, hbool_t app_ref, hid_t vip /* Functions that manipulate VOL objects */ H5_DLL void *H5VL_object(hid_t id); H5_DLL void *H5VL_object_data(const H5VL_object_t *vol_obj); +H5_DLL void *H5VL_object_unwrap(const H5VL_object_t *vol_obj); H5_DLL void *H5VL_object_verify(hid_t id, H5I_type_t obj_type); H5_DLL H5VL_object_t *H5VL_vol_object(hid_t id); H5_DLL herr_t H5VL_free_object(H5VL_object_t *obj); @@ -93,13 +94,14 @@ H5_DLL herr_t H5VL_free_object(H5VL_object_t *obj); /* Functions that wrap / unwrap VOL objects */ H5_DLL herr_t H5VL_get_wrap_ctx(const H5VL_class_t *connector, void *obj, void **wrap_ctx); +H5_DLL void * H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, + void *obj, H5I_type_t obj_type); +H5_DLL void * H5VL_unwrap_object(const H5VL_class_t *connector, void *obj); H5_DLL herr_t H5VL_free_wrap_ctx(const H5VL_class_t *connector, void *wrap_ctx); H5_DLL herr_t H5VL_set_vol_wrapper(void *obj, H5VL_t *vol_connector); H5_DLL herr_t H5VL_inc_vol_wrapper(void *vol_wrap_ctx); H5_DLL herr_t H5VL_dec_vol_wrapper(void *vol_wrap_ctx); H5_DLL herr_t H5VL_reset_vol_wrapper(void); -H5_DLL void * H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, - void *obj, H5I_type_t obj_type); /* Library state functions */ H5_DLL herr_t H5VL_retrieve_lib_state(void **state); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index da31a97164..56e703c358 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -253,6 +253,7 @@ typedef struct H5VL_wrap_class_t { void * (*get_object)(const void *obj); /* Callback to retrieve underlying object */ herr_t (*get_wrap_ctx)(const void *obj, void **wrap_ctx); /* Callback to retrieve the object wrapping context for the connector */ void * (*wrap_object)(void *obj, H5I_type_t obj_type, void *wrap_ctx); /* Callback to wrap a library object */ + void * (*unwrap_object)(void *obj); /* Callback to unwrap a library object */ herr_t (*free_wrap_ctx)(void *wrap_ctx); /* Callback to release the object wrapping context for the connector */ } H5VL_wrap_class_t; @@ -472,6 +473,7 @@ H5_DLL void *H5VLget_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLget_wrap_ctx(void *obj, hid_t connector_id, void **wrap_ctx); H5_DLL void *H5VLwrap_object(void *obj, H5I_type_t obj_type, hid_t connector_id, void *wrap_ctx); +H5_DLL void *H5VLunwrap_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id); /* Public wrappers for attribute callbacks */ diff --git a/test/null_vol_connector.c b/test/null_vol_connector.c index b62b37017a..b78e859c44 100644 --- a/test/null_vol_connector.c +++ b/test/null_vol_connector.c @@ -27,16 +27,21 @@ static const H5VL_class_t null_vol_g = { 0, /* capability flags */ NULL, /* initialize */ NULL, /* terminate */ - (size_t)0, /* info size */ - NULL, /* info copy */ - NULL, /* info compare */ - NULL, /* info free */ - NULL, /* info to str */ - NULL, /* str to info */ - NULL, /* get_object */ - NULL, /* get_wrap_ctx */ - NULL, /* wrap_object */ - NULL, /* free_wrap_ctx */ + { /* info_cls */ + (size_t)0, /* size */ + NULL, /* copy */ + NULL, /* compare */ + NULL, /* free */ + NULL, /* to_str */ + NULL, /* from_str */ + }, + { /* wrap_cls */ + NULL, /* get_object */ + NULL, /* get_wrap_ctx */ + NULL, /* wrap_object */ + NULL, /* unwrap_object */ + NULL, /* free_wrap_ctx */ + }, { /* attribute_cls */ NULL, /* create */ NULL, /* open */ diff --git a/test/vol.c b/test/vol.c index e267084b43..3f6afaa089 100644 --- a/test/vol.c +++ b/test/vol.c @@ -61,6 +61,7 @@ static const H5VL_class_t fake_vol_g = { NULL, /* get_object */ NULL, /* get_wrap_ctx */ NULL, /* wrap_object */ + NULL, /* unwrap_object */ NULL, /* free_wrap_ctx */ }, { /* attribute_cls */ From 2c47094d4004c916d16667a23efe018db2c0558d Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Mon, 22 Apr 2019 10:23:38 -0500 Subject: [PATCH 05/32] Changing file names to avoid possible conflicts during parallel test. --- test/external.c | 12 ++++++------ test/external_common.c | 12 +++++++++--- test/external_common.h | 2 +- test/external_env.c | 22 ++++++++++------------ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/test/external.c b/test/external.c index af454452a2..6aa9d1b133 100644 --- a/test/external.c +++ b/test/external.c @@ -635,7 +635,7 @@ test_read_file_set(hid_t fapl) TEST_ERROR /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the file and an initial group. This causes messages about @@ -775,7 +775,7 @@ test_write_file_set(hid_t fapl) } /* end for */ /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the dataset */ @@ -876,7 +876,7 @@ test_path_absolute(hid_t fapl) FAIL_STACK_ERROR /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the dcpl */ @@ -972,7 +972,7 @@ test_path_relative(hid_t fapl) FAIL_STACK_ERROR; /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the dataset */ @@ -1067,7 +1067,7 @@ test_path_relative_cwd(hid_t fapl) FAIL_STACK_ERROR; /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the dataset */ @@ -1209,7 +1209,7 @@ test_h5d_get_access_plist(hid_t fapl_id) TEST_ERROR /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(0) < 0) TEST_ERROR /* Create the file */ diff --git a/test/external_common.c b/test/external_common.c index e43a713313..c3aa455cd8 100644 --- a/test/external_common.c +++ b/test/external_common.c @@ -35,7 +35,7 @@ *------------------------------------------------------------------------- */ herr_t -reset_raw_data_files(void) +reset_raw_data_files(int is_env) { int fd = 0; /* external file descriptor */ size_t i, j; /* iterators */ @@ -59,7 +59,10 @@ reset_raw_data_files(void) for(i = 0; i < N_EXT_FILES; i++) { /* Open file */ - HDsprintf(filename, "extern_%lur.raw", (unsigned long)i + 1); + if(is_env) + HDsprintf(filename, "extern_env_%lur.raw", (unsigned long)i + 1); + else + HDsprintf(filename, "extern_%lur.raw", (unsigned long)i + 1); if((fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) goto error; @@ -93,7 +96,10 @@ reset_raw_data_files(void) for(i = 0; i < N_EXT_FILES; i++) { /* Open file */ - HDsprintf(filename, "extern_%luw.raw", (unsigned long)i + 1); + if(is_env) + HDsprintf(filename, "extern_env_%luw.raw", (unsigned long)i + 1); + else + HDsprintf(filename, "extern_%luw.raw", (unsigned long)i + 1); if((fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) goto error; diff --git a/test/external_common.h b/test/external_common.h index 50f6e6d3b9..1e4fe7abe9 100644 --- a/test/external_common.h +++ b/test/external_common.h @@ -41,5 +41,5 @@ static const char *EXT_FNAME[] = { #define TOTAL_SIZE 100 #define GARBAGE_PER_FILE 10 -H5TEST_DLL herr_t reset_raw_data_files(void); +H5TEST_DLL herr_t reset_raw_data_files(int); #endif /* _EXTERNAL_COMMON_H */ diff --git a/test/external_env.c b/test/external_env.c index 0f8c9ec40e..a62e08548c 100644 --- a/test/external_env.c +++ b/test/external_env.c @@ -64,7 +64,7 @@ test_path_env(hid_t fapl) FAIL_STACK_ERROR /* Reset the raw data files */ - if(reset_raw_data_files() < 0) + if(reset_raw_data_files(1) < 0) TEST_ERROR /* Create the dataset */ @@ -73,7 +73,7 @@ test_path_env(hid_t fapl) if(NULL == HDgetcwd(cwdpath, sizeof(cwdpath))) TEST_ERROR for(i = 0; i < N_EXT_FILES; i++) { - HDsnprintf(filename, sizeof(filename), "..%sextern_%dr.raw", H5_DIR_SEPS, (int) i + 1); + HDsnprintf(filename, sizeof(filename), "..%sextern_env_%dr.raw", H5_DIR_SEPS, (int) i + 1); if(H5Pset_external(dcpl, filename, (off_t)(i * GARBAGE_PER_FILE), (hsize_t)sizeof(part)) < 0) FAIL_STACK_ERROR } /* end for */ @@ -144,7 +144,6 @@ main(void) hid_t fapl_id_new = -1; /* file access properties (new format) */ hid_t fid = -1; /* file for test_1* functions */ hid_t gid = -1; /* group to emit diagnostics */ - char filename[1024]; /* file name for test_1* funcs */ unsigned latest_format; /* default or latest file format */ int nerrors = 0; /* number of errors */ @@ -152,7 +151,6 @@ main(void) /* Get a fapl for the old (default) file format */ fapl_id_old = h5_fileaccess(); - h5_fixname(EXT_FNAME[0], fapl_id_old, filename, sizeof(filename)); /* Copy and set up a fapl for the latest file format */ if((fapl_id_new = H5Pcopy(fapl_id_old)) < 0) @@ -186,15 +184,15 @@ main(void) /* Clean up files used by file set tests */ if(h5_cleanup(EXT_FNAME, fapl_id_old)) { - HDremove("extern_1r.raw"); - HDremove("extern_2r.raw"); - HDremove("extern_3r.raw"); - HDremove("extern_4r.raw"); + HDremove("extern_env_1r.raw"); + HDremove("extern_env_2r.raw"); + HDremove("extern_env_3r.raw"); + HDremove("extern_env_4r.raw"); - HDremove("extern_1w.raw"); - HDremove("extern_2w.raw"); - HDremove("extern_3w.raw"); - HDremove("extern_4w.raw"); + HDremove("extern_env_1w.raw"); + HDremove("extern_env_2w.raw"); + HDremove("extern_env_3w.raw"); + HDremove("extern_env_4w.raw"); HDrmdir("extern_dir"); } /* end if */ From 4a4c0bc3972cde177c0a6e2a191b1fa187846c08 Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Tue, 23 Apr 2019 14:12:58 -0500 Subject: [PATCH 06/32] Fix issue with H5Iiterate always stopping with an error after the first iteration --- src/H5I.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/H5I.c b/src/H5I.c index 2edea9bf71..93c9e98b37 100644 --- a/src/H5I.c +++ b/src/H5I.c @@ -1943,6 +1943,8 @@ H5I__iterate_pub_cb(void H5_ATTR_UNUSED *obj, hid_t id, void *_udata) ret_value = H5_ITER_STOP; /* terminate iteration early */ else if(cb_ret_val < 0) ret_value = H5_ITER_ERROR; /* indicate failure (which terminates iteration) */ + else + ret_value = H5_ITER_CONT; /* continue iteration */ FUNC_LEAVE_NOAPI(ret_value) } /* end H5I__iterate_pub_cb() */ From 562e8ec915c18f14390558399186aba7e3ead9c1 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Tue, 23 Apr 2019 16:40:02 -0500 Subject: [PATCH 07/32] Changing file names and directory names to avoid possible conflict during parallel 'make check'. --- test/external_common.h | 5 +++++ test/external_env.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/external_common.h b/test/external_common.h index 1e4fe7abe9..cc2b5fb929 100644 --- a/test/external_common.h +++ b/test/external_common.h @@ -33,6 +33,11 @@ static const char *EXT_FNAME[] = { NULL }; +static const char *EXT_ENV_FNAME[] = { + "extern_env_dir/env_file_1", + NULL +}; + /* A similar collection of files is used for the tests that * perform file I/O. */ diff --git a/test/external_env.c b/test/external_env.c index a62e08548c..55f68beebd 100644 --- a/test/external_env.c +++ b/test/external_env.c @@ -56,10 +56,10 @@ test_path_env(hid_t fapl) TESTING("prefix in HDF5_EXTFILE_PREFIX"); - if(HDmkdir("extern_dir", (mode_t)0755) < 0 && errno != EEXIST) + if(HDmkdir("extern_env_dir", (mode_t)0755) < 0 && errno != EEXIST) TEST_ERROR; - h5_fixname(EXT_FNAME[4], fapl, filename, sizeof(filename)); + h5_fixname(EXT_ENV_FNAME[0], fapl, filename, sizeof(filename)); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) FAIL_STACK_ERROR @@ -194,7 +194,7 @@ main(void) HDremove("extern_env_3w.raw"); HDremove("extern_env_4w.raw"); - HDrmdir("extern_dir"); + HDrmdir("extern_env_dir"); } /* end if */ return EXIT_SUCCESS; From 0ca6b1305f4a882f760bdf71e6df383e31136e1e Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 24 Apr 2019 22:31:36 -0500 Subject: [PATCH 08/32] Refactor dataset creation parameters out of the dataset creation property list and pass them as regular function parameters. --- src/H5D.c | 36 ++++++------------------------------ src/H5Ddeprec.c | 15 +-------------- src/H5Pdcpl.c | 15 --------------- src/H5VLcallback.c | 23 +++++++++++++---------- src/H5VLnative_dataset.c | 14 ++------------ src/H5VLnative_private.h | 2 +- src/H5VLpassthru.c | 7 ++++--- src/H5VLprivate.h | 2 +- src/H5VLpublic.h | 10 +++------- 9 files changed, 31 insertions(+), 93 deletions(-) diff --git a/src/H5D.c b/src/H5D.c index 413be3708a..5ceee11f6f 100644 --- a/src/H5D.c +++ b/src/H5D.c @@ -105,11 +105,10 @@ hid_t H5Dcreate2(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t lcpl_id, hid_t dcpl_id, hid_t dapl_id) { - void *dset = NULL; /* New dataset's info */ - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ + void *dset = NULL; /* New dataset's info */ + H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist = NULL; /* Property list pointer */ - hid_t ret_value = H5I_INVALID_HID; /* Return value */ + hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) H5TRACE7("i", "i*siiiii", loc_id, name, type_id, space_id, lcpl_id, dcpl_id, @@ -142,28 +141,16 @@ H5Dcreate2(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, if(H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - /* Get the property list structure for the dcpl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - /* Get the location object */ if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_DSET_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_DSET_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - if(H5P_set(plist, H5VL_PROP_DSET_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for lcpl id") - /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); /* Create the dataset */ - if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, name, dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, name, lcpl_id, type_id, space_id, dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, H5I_INVALID_HID, "unable to create dataset") /* Get an atom for the dataset */ @@ -216,9 +203,8 @@ H5Dcreate_anon(hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id) { void *dset = NULL; /* dset token from VOL connector */ - H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ + H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) @@ -242,22 +228,12 @@ H5Dcreate_anon(hid_t loc_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_DSET_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_DSET_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); /* Create the dataset */ - if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, NULL, dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, NULL, H5P_LINK_CREATE_DEFAULT, type_id, space_id, dcpl_id, dapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, H5I_INVALID_HID, "unable to create dataset") /* Get an atom for the dataset */ diff --git a/src/H5Ddeprec.c b/src/H5Ddeprec.c index 85371ae8ce..6380bee598 100644 --- a/src/H5Ddeprec.c +++ b/src/H5Ddeprec.c @@ -116,7 +116,6 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, void *dset = NULL; /* dset token from VOL connector */ H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; hid_t dapl_id = H5P_DEFAULT; /* DAPL used by library */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ @@ -143,18 +142,6 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, if(H5CX_set_apl(&dapl_id, H5P_CLS_DACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_DSET_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_DSET_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - if(H5P_set(plist, H5VL_PROP_DSET_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for lcpl id") - /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); @@ -164,7 +151,7 @@ H5Dcreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Create the dataset through the VOL */ - if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, name, dcpl_id, H5P_DATASET_ACCESS_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (dset = H5VL_dataset_create(vol_obj, &loc_params, name, lcpl_id, type_id, space_id, dcpl_id, H5P_DATASET_ACCESS_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, H5I_INVALID_HID, "unable to create dataset") /* Get an atom for the dataset */ diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index 41d7c7829a..9999adbe1a 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -283,21 +283,6 @@ H5P__dcrt_reg_prop(H5P_genclass_t *pclass) NULL, NULL, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - /* Register the type ID property*/ - if(H5P__register_real(pclass, H5VL_PROP_DSET_TYPE_ID, sizeof(hid_t), &type_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, H5P_ignore_cmp, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - /* Register the space ID property */ - if(H5P__register_real(pclass, H5VL_PROP_DSET_SPACE_ID, sizeof(hid_t), &space_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, H5P_ignore_cmp, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - /* Register the lcpl ID property */ - if(H5P__register_real(pclass, H5VL_PROP_DSET_LCPL_ID, sizeof(hid_t), &lcpl_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, H5P_ignore_cmp, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__dcrt_reg_prop() */ diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index b785747426..96a281c656 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -76,8 +76,8 @@ static herr_t H5VL__attr_optional(void *obj, const H5VL_class_t *cls, hid_t dxpl static herr_t H5VL__attr_close(void *obj, const H5VL_class_t *cls, hid_t dxpl_id, void **req); static void *H5VL__dataset_create(void *obj, const H5VL_loc_params_t *loc_params, - const H5VL_class_t *cls, const char *name, hid_t dcpl_id, hid_t dapl_id, - hid_t dxpl_id, void **req); + const H5VL_class_t *cls, const char *name, hid_t lcpl_id, hid_t type_id, + hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); static void *H5VL__dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); @@ -1794,7 +1794,8 @@ done: */ static void * H5VL__dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, - const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, + hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) { void *ret_value = NULL; /* Return value */ @@ -1805,7 +1806,7 @@ H5VL__dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_ HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "VOL connector has no 'dataset create' method") /* Call the corresponding VOL callback */ - if(NULL == (ret_value = (cls->dataset_cls.create)(obj, loc_params, name, dcpl_id, dapl_id, dxpl_id, req))) + if(NULL == (ret_value = (cls->dataset_cls.create)(obj, loc_params, name, lcpl_id, type_id, space_id, dcpl_id, dapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "dataset create failed") done: @@ -1825,7 +1826,8 @@ done: */ void * H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, + hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) { hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ void *ret_value = NULL; /* Return value */ @@ -1838,7 +1840,7 @@ H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_p vol_wrapper_set = TRUE; /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__dataset_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, dcpl_id, dapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__dataset_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, lcpl_id, type_id, space_id, dcpl_id, dapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "dataset create failed") done: @@ -1862,14 +1864,15 @@ done: */ void * H5VLdataset_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, - const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, + hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) { H5VL_class_t *cls; /* VOL connector's class struct */ void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE8("*x", "*x*xi*siii**x", obj, loc_params, connector_id, name, dcpl_id, - dapl_id, dxpl_id, req); + H5TRACE11("*x", "*x*xi*siiiiii**x", obj, loc_params, connector_id, name, + lcpl_id, type_id, space_id, dcpl_id, dapl_id, dxpl_id, req); /* Check args and get class pointer */ if(NULL == obj) @@ -1878,7 +1881,7 @@ H5VLdataset_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connect HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__dataset_create(obj, loc_params, cls, name, dcpl_id, dapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__dataset_create(obj, loc_params, cls, name, lcpl_id, type_id, space_id, dcpl_id, dapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "unable to create dataset") done: diff --git a/src/H5VLnative_dataset.c b/src/H5VLnative_dataset.c index 8f7351ceeb..ffa37541c9 100644 --- a/src/H5VLnative_dataset.c +++ b/src/H5VLnative_dataset.c @@ -43,14 +43,12 @@ */ void * H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t H5_ATTR_UNUSED dxpl_id, + const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, + hid_t dcpl_id, hid_t dapl_id, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) { H5P_genplist_t *plist; /* Property list pointer */ H5G_loc_t loc; /* Object location to insert dataset into */ - hid_t type_id = H5I_INVALID_HID; - hid_t space_id = H5I_INVALID_HID; - hid_t lcpl_id = H5I_INVALID_HID; H5D_t *dset = NULL; /* New dataset's info */ const H5S_t *space; /* Dataspace for dataset */ void *ret_value; @@ -61,14 +59,6 @@ H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") - /* Get creation properties */ - if(H5P_get(plist, H5VL_PROP_DSET_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for datatype id") - if(H5P_get(plist, H5VL_PROP_DSET_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for space id") - if(H5P_get(plist, H5VL_PROP_DSET_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for lcpl id") - /* Check arguments */ if(H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object") diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index 1bf4da244b..5fa25bee05 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -34,7 +34,7 @@ H5_DLL herr_t H5VL__native_attr_optional(void *obj, hid_t dxpl_id, void **req, v H5_DLL herr_t H5VL__native_attr_close(void *attr, hid_t dxpl_id, void **req); /* Dataset callbacks */ -H5_DLL void *H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL__native_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_dataset_read(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf, void **req); H5_DLL herr_t H5VL__native_dataset_write(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf, void **req); diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 85a934641f..ae03d9e5cd 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -114,7 +114,7 @@ static herr_t H5VL_pass_through_attr_optional(void *obj, hid_t dxpl_id, void **r static herr_t H5VL_pass_through_attr_close(void *attr, hid_t dxpl_id, void **req); /* Dataset callbacks */ -static void *H5VL_pass_through_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); +static void *H5VL_pass_through_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); static void *H5VL_pass_through_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_dataset_read(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf, void **req); @@ -1057,7 +1057,8 @@ H5VL_pass_through_attr_close(void *attr, hid_t dxpl_id, void **req) */ static void * H5VL_pass_through_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, + hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req) { H5VL_pass_through_t *dset; H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; @@ -1067,7 +1068,7 @@ H5VL_pass_through_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, printf("------- PASS THROUGH VOL DATASET Create\n"); #endif - under = H5VLdataset_create(o->under_object, loc_params, o->under_vol_id, name, dcpl_id, dapl_id, dxpl_id, req); + under = H5VLdataset_create(o->under_object, loc_params, o->under_vol_id, name, lcpl_id, type_id, space_id, dcpl_id, dapl_id, dxpl_id, req); if(under) { dset = H5VL_pass_through_new_obj(under, o->under_vol_id); diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 04cc982c4b..5a5229ede1 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -137,7 +137,7 @@ H5_DLL herr_t H5VL_attr_optional(const H5VL_object_t *vol_obj, hid_t dxpl_id, vo H5_DLL herr_t H5VL_attr_close(const H5VL_object_t *vol_obj, hid_t dxpl_id, void **req); /* Dataset functions */ -H5_DLL void *H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL_dataset_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL_dataset_open(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_dataset_read(const H5VL_object_t *vol_obj, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf, void **req); H5_DLL herr_t H5VL_dataset_write(const H5VL_object_t *vol_obj, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf, void **req); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index 56e703c358..8943997dfa 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -32,11 +32,6 @@ /* Public Macros */ /*****************/ -/* Dataset creation property names */ -#define H5VL_PROP_DSET_TYPE_ID "dataset_type_id" -#define H5VL_PROP_DSET_SPACE_ID "dataset_space_id" -#define H5VL_PROP_DSET_LCPL_ID "dataset_lcpl_id" - /* Attribute creation property names */ #define H5VL_PROP_ATTR_TYPE_ID "attr_type_id" #define H5VL_PROP_ATTR_SPACE_ID "attr_space_id" @@ -275,7 +270,8 @@ typedef struct H5VL_attr_class_t { /* H5D routines */ typedef struct H5VL_dataset_class_t { void *(*create)(void *obj, const H5VL_loc_params_t *loc_params, const char *name, - hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); + hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, + hid_t dapl_id, hid_t dxpl_id, void **req); void *(*open)(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); herr_t (*read)(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, @@ -487,7 +483,7 @@ H5_DLL herr_t H5VLattr_optional(void *obj, hid_t connector_id, hid_t dxpl_id, vo H5_DLL herr_t H5VLattr_close(void *attr, hid_t connector_id, hid_t dxpl_id, void **req); /* Public wrappers for dataset callbacks */ -H5_DLL void *H5VLdataset_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VLdataset_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t lcpl_id, hid_t type_id, hid_t space_id, hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VLdataset_open(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VLdataset_read(void *dset, hid_t connector_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, void *buf, void **req); H5_DLL herr_t H5VLdataset_write(void *dset, hid_t connector_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf, void **req); From 59635ab747f2a9bb83a19ad0d97915bc68ad7129 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 24 Apr 2019 23:22:28 -0500 Subject: [PATCH 09/32] A few minor cleanups --- src/H5Pdcpl.c | 3 --- src/H5VLnative_dataset.c | 5 ----- 2 files changed, 8 deletions(-) diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index 9999adbe1a..6b9edf1acc 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -246,9 +246,6 @@ static hbool_t H5P_dcrt_def_layout_init_g = FALSE; static herr_t H5P__dcrt_reg_prop(H5P_genclass_t *pclass) { - hid_t type_id = H5I_INVALID_HID; - hid_t space_id = H5I_INVALID_HID; - hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC diff --git a/src/H5VLnative_dataset.c b/src/H5VLnative_dataset.c index ffa37541c9..1e3d263ff4 100644 --- a/src/H5VLnative_dataset.c +++ b/src/H5VLnative_dataset.c @@ -47,7 +47,6 @@ H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t dcpl_id, hid_t dapl_id, hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) { - H5P_genplist_t *plist; /* Property list pointer */ H5G_loc_t loc; /* Object location to insert dataset into */ H5D_t *dset = NULL; /* New dataset's info */ const H5S_t *space; /* Dataspace for dataset */ @@ -55,10 +54,6 @@ H5VL__native_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, FUNC_ENTER_PACKAGE - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(dcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") - /* Check arguments */ if(H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object") From 9fadb39656f0d3c6a9392cae70d7a59bb7140bcc Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 24 Apr 2019 23:33:56 -0500 Subject: [PATCH 10/32] Refactor attribute creation parameters to move parameters out of creation property list and into function parameters. --- src/H5A.c | 26 ++---------------------- src/H5Adeprec.c | 13 +----------- src/H5Pacpl.c | 43 +--------------------------------------- src/H5VLcallback.c | 29 +++++++++++++++------------ src/H5VLnative_attr.c | 16 ++------------- src/H5VLnative_private.h | 2 +- src/H5VLpassthru.c | 7 ++++--- src/H5VLprivate.h | 2 +- src/H5VLpublic.h | 10 +++------- 9 files changed, 31 insertions(+), 117 deletions(-) diff --git a/src/H5A.c b/src/H5A.c index 9c3ad7e5e7..abf869495e 100644 --- a/src/H5A.c +++ b/src/H5A.c @@ -254,7 +254,6 @@ H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, { void *attr = NULL; /* Attribute created */ H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ - H5P_genplist_t *plist; /* Property list pointer */ H5VL_loc_params_t loc_params; hid_t ret_value = H5I_INVALID_HID; /* Return value */ @@ -277,16 +276,6 @@ H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - /* Get the property list structure for the acpl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_ATTR_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_ATTR_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - /* Get the location object */ if(NULL == (vol_obj = H5VL_vol_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") @@ -296,7 +285,7 @@ H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id, loc_params.obj_type = H5I_get_type(loc_id); /* Create the attribute */ - if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, attr_name, acpl_id, aapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, attr_name, type_id, space_id, acpl_id, aapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5I_INVALID_HID, "unable to create attribute") /* Register the new attribute and get an ID for it */ @@ -350,7 +339,6 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, { void *attr = NULL; /* attr token from VOL connector */ H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ - H5P_genplist_t *plist; /* Property list pointer */ H5VL_loc_params_t loc_params; hid_t ret_value = H5I_INVALID_HID; /* Return value */ @@ -380,16 +368,6 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, H5CX_set_lapl(lapl_id); } - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_ATTR_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_ATTR_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - /* Set up location struct */ loc_params.type = H5VL_OBJECT_BY_NAME; loc_params.obj_type = H5I_get_type(loc_id); @@ -401,7 +379,7 @@ H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Create the attribute */ - if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, attr_name, acpl_id, aapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, attr_name, type_id, space_id, acpl_id, aapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5I_INVALID_HID, "unable to create attribute") /* Register the new attribute and get an ID for it */ diff --git a/src/H5Adeprec.c b/src/H5Adeprec.c index b438cd2416..8d0e33c3cf 100644 --- a/src/H5Adeprec.c +++ b/src/H5Adeprec.c @@ -119,7 +119,6 @@ H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, void *attr = NULL; /* attr token from VOL connector */ H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) @@ -139,16 +138,6 @@ H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, if(H5P_DEFAULT == acpl_id) acpl_id = H5P_ATTRIBUTE_CREATE_DEFAULT; - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_ATTR_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for datatype id") - if(H5P_set(plist, H5VL_PROP_ATTR_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't set property value for space id") - /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); @@ -158,7 +147,7 @@ H5Acreate1(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Create the attribute */ - if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, name, acpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (attr = H5VL_attr_create(vol_obj, &loc_params, name, type_id, space_id, acpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, H5I_INVALID_HID, "unable to create attribute") /* Register the new attribute and get an ID for it */ diff --git a/src/H5Pacpl.c b/src/H5Pacpl.c index 2322c762ca..23fd261f83 100644 --- a/src/H5Pacpl.c +++ b/src/H5Pacpl.c @@ -76,7 +76,7 @@ const H5P_libclass_t H5P_CLS_ACRT[1] = {{ &H5P_CLS_ATTRIBUTE_CREATE_g, /* Pointer to class */ &H5P_CLS_ATTRIBUTE_CREATE_ID_g, /* Pointer to class ID */ &H5P_LST_ATTRIBUTE_CREATE_ID_g, /* Pointer to default property list ID */ - H5P_acrt_reg_prop, /* Default property registration routine */ + NULL, /* Default property registration routine */ NULL, /* Class creation callback */ NULL, /* Class creation callback info */ @@ -91,44 +91,3 @@ const H5P_libclass_t H5P_CLS_ACRT[1] = {{ /* Library Private Variables */ /*****************************/ - -/*------------------------------------------------------------------------- - * Function: H5P_acrt_reg_prop - * - * Purpose: Register the attribute creation property list class's properties - * - * Return: SUCCEED/FAIL - * - *------------------------------------------------------------------------- - */ -static herr_t -H5P_acrt_reg_prop(H5P_genclass_t *pclass) -{ - hid_t type_id = H5I_INVALID_HID; - hid_t space_id = H5I_INVALID_HID; - H5VL_loc_params_t loc_params; - herr_t ret_value = SUCCEED; - - FUNC_ENTER_NOAPI_NOINIT - - /* Register the type ID property*/ - if(H5P__register_real(pclass, H5VL_PROP_ATTR_TYPE_ID, sizeof(hid_t), &type_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - /* Register the space ID property */ - if(H5P__register_real(pclass, H5VL_PROP_ATTR_SPACE_ID, sizeof(hid_t), &space_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - /* Register the lcpl ID property */ - HDmemset(&loc_params, 0, sizeof(H5VL_loc_params_t)); - loc_params.obj_type = H5A_CRT_LOCATION_DEF; - if(H5P__register_real(pclass, H5VL_PROP_ATTR_LOC_PARAMS, H5A_CRT_LOCATION_SIZE, &loc_params, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* end H5P_acrt_reg_prop() */ - diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 96a281c656..548667fa37 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -57,8 +57,8 @@ /* Local Prototypes */ /********************/ static void *H5VL__attr_create(void *obj, const H5VL_loc_params_t *loc_params, - const H5VL_class_t *cls, const char *name, hid_t acpl_id, hid_t aapl_id, - hid_t dxpl_id, void **req); + const H5VL_class_t *cls, const char *name, hid_t type_id, hid_t space_id, + hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); static void *H5VL__attr_open(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req); @@ -753,7 +753,7 @@ void * H5VL_wrap_object(const H5VL_class_t *connector, void *wrap_ctx, void *obj, H5I_type_t obj_type) { - void *ret_value; /* Return value */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(NULL) @@ -822,7 +822,7 @@ done: void * H5VL_unwrap_object(const H5VL_class_t *connector, void *obj) { - void *ret_value; /* Return value */ + void *ret_value = NULL; /* Return value */ FUNC_ENTER_NOAPI(NULL) @@ -954,7 +954,8 @@ done: */ static void * H5VL__attr_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, - const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, + hid_t aapl_id, hid_t dxpl_id, void **req) { void *ret_value = NULL; /* Return value */ @@ -965,12 +966,12 @@ H5VL__attr_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_cla HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "VOL connector has no 'attr create' method") /* Call the corresponding VOL callback */ - if(NULL == (ret_value = (cls->attr_cls.create)(obj, loc_params, name, acpl_id, aapl_id, dxpl_id, req))) + if(NULL == (ret_value = (cls->attr_cls.create)(obj, loc_params, name, type_id, space_id, acpl_id, aapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "attribute create failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5VL_attr_create() */ +} /* end H5VL__attr_create() */ /*------------------------------------------------------------------------- @@ -985,7 +986,8 @@ done: */ void * H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, + hid_t aapl_id, hid_t dxpl_id, void **req) { hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ void *ret_value = NULL; /* Return value */ @@ -998,7 +1000,7 @@ H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_para vol_wrapper_set = TRUE; /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__attr_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, acpl_id, aapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__attr_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, type_id, space_id, acpl_id, aapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "attribute create failed") done: @@ -1022,14 +1024,15 @@ done: */ void * H5VLattr_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, - const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, + hid_t aapl_id, hid_t dxpl_id, void **req) { H5VL_class_t *cls; /* VOL connector's class struct */ void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE8("*x", "*x*xi*siii**x", obj, loc_params, connector_id, name, acpl_id, - aapl_id, dxpl_id, req); + H5TRACE10("*x", "*x*xi*siiiii**x", obj, loc_params, connector_id, name, + type_id, space_id, acpl_id, aapl_id, dxpl_id, req); /* Check args and get class pointer */ if(NULL == obj) @@ -1038,7 +1041,7 @@ H5VLattr_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_ HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__attr_create(obj, loc_params, cls, name, acpl_id, aapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__attr_create(obj, loc_params, cls, name, type_id, space_id, acpl_id, aapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "unable to create attribute") done: diff --git a/src/H5VLnative_attr.c b/src/H5VLnative_attr.c index 7d9f0acb5a..85af320bac 100644 --- a/src/H5VLnative_attr.c +++ b/src/H5VLnative_attr.c @@ -44,14 +44,12 @@ */ void * H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, - hid_t acpl_id, hid_t H5_ATTR_UNUSED aapl_id, hid_t H5_ATTR_UNUSED dxpl_id, - void H5_ATTR_UNUSED **req) + hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t H5_ATTR_UNUSED aapl_id, + hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) { H5G_loc_t loc; /* Object location */ H5G_loc_t obj_loc; /* Location used to open group */ hbool_t loc_found = FALSE; - H5P_genplist_t *plist; /* Property list pointer */ - hid_t type_id, space_id; H5T_t *type, *dt; /* Datatype to use for attribute */ H5S_t *space; /* Dataspace to use for attribute */ H5A_t *attr = NULL; @@ -59,16 +57,6 @@ H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const c FUNC_ENTER_PACKAGE - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(acpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") - - /* get creation properties */ - if(H5P_get(plist, H5VL_PROP_ATTR_TYPE_ID, &type_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for datatype id") - if(H5P_get(plist, H5VL_PROP_ATTR_SPACE_ID, &space_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for space id") - if(H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object") if(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR)) diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index 5fa25bee05..e91bc3f2f9 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -24,7 +24,7 @@ extern "C" { #endif /* Atrribute callbacks */ -H5_DLL void *H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL__native_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); void *H5VL__native_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_attr_read(void *attr, hid_t dtype_id, void *buf, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_attr_write(void *attr, hid_t dtype_id, const void *buf, hid_t dxpl_id, void **req); diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index ae03d9e5cd..8ba00f0e17 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -104,7 +104,7 @@ static void *H5VL_pass_through_unwrap_object(void *obj); static herr_t H5VL_pass_through_free_wrap_ctx(void *obj); /* Attribute callbacks */ -static void *H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); +static void *H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); static void *H5VL_pass_through_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_attr_read(void *attr, hid_t mem_type_id, void *buf, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_attr_write(void *attr, hid_t mem_type_id, const void *buf, hid_t dxpl_id, void **req); @@ -794,7 +794,8 @@ H5VL_pass_through_free_wrap_ctx(void *_wrap_ctx) */ static void * H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id, + hid_t aapl_id, hid_t dxpl_id, void **req) { H5VL_pass_through_t *attr; H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; @@ -804,7 +805,7 @@ H5VL_pass_through_attr_create(void *obj, const H5VL_loc_params_t *loc_params, printf("------- PASS THROUGH VOL ATTRIBUTE Create\n"); #endif - under = H5VLattr_create(o->under_object, loc_params, o->under_vol_id, name, acpl_id, aapl_id, dxpl_id, req); + under = H5VLattr_create(o->under_object, loc_params, o->under_vol_id, name, type_id, space_id, acpl_id, aapl_id, dxpl_id, req); if(under) { attr = H5VL_pass_through_new_obj(under, o->under_vol_id); diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 5a5229ede1..a916055cba 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -127,7 +127,7 @@ H5_DLL herr_t H5VL_cmp_connector_info(const H5VL_class_t *connector, int *cmp_va H5_DLL herr_t H5VL_free_connector_info(hid_t connector_id, void *info); /* Attribute functions */ -H5_DLL void *H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL_attr_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL_attr_open(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_attr_read(const H5VL_object_t *vol_obj, hid_t dtype_id, void *buf, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_attr_write(const H5VL_object_t *vol_obj, hid_t dtype_id, const void *buf, hid_t dxpl_id, void **req); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index 8943997dfa..ed34e1a2e1 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -32,11 +32,6 @@ /* Public Macros */ /*****************/ -/* Attribute creation property names */ -#define H5VL_PROP_ATTR_TYPE_ID "attr_type_id" -#define H5VL_PROP_ATTR_SPACE_ID "attr_space_id" -#define H5VL_PROP_ATTR_LOC_PARAMS "attr_location" - /* Link creation property names */ #define H5VL_PROP_LINK_TARGET "target_location_object" #define H5VL_PROP_LINK_TARGET_LOC_PARAMS "target_params" @@ -255,7 +250,8 @@ typedef struct H5VL_wrap_class_t { /* H5A routines */ typedef struct H5VL_attr_class_t { void *(*create)(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, - hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); + hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, + hid_t dxpl_id, void **req); void *(*open)(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_name, hid_t aapl_id, hid_t dxpl_id, void **req); herr_t (*read)(void *attr, hid_t mem_type_id, void *buf, hid_t dxpl_id, void **req); @@ -473,7 +469,7 @@ H5_DLL void *H5VLunwrap_object(void *obj, hid_t connector_id); H5_DLL herr_t H5VLfree_wrap_ctx(void *wrap_ctx, hid_t connector_id); /* Public wrappers for attribute callbacks */ -H5_DLL void *H5VLattr_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *attr_name, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VLattr_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *attr_name, hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VLattr_open(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VLattr_read(void *attr, hid_t connector_id, hid_t dtype_id, void *buf, hid_t dxpl_id, void **req); H5_DLL herr_t H5VLattr_write(void *attr, hid_t connector_id, hid_t dtype_id, const void *buf, hid_t dxpl_id, void **req); From 07c3a39bf582b1bc2cc2aec97181d6d1d452ff71 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 25 Apr 2019 00:53:16 -0500 Subject: [PATCH 11/32] Minor cleanups --- src/H5Pacpl.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/H5Pacpl.c b/src/H5Pacpl.c index 23fd261f83..53e68fac3a 100644 --- a/src/H5Pacpl.c +++ b/src/H5Pacpl.c @@ -40,10 +40,6 @@ /* Local Macros */ /****************/ -/* Definitions for locations parameters */ -#define H5A_CRT_LOCATION_SIZE sizeof(H5VL_loc_params_t) -#define H5A_CRT_LOCATION_DEF H5I_BADID - /******************/ /* Local Typedefs */ @@ -59,9 +55,6 @@ /* Local Prototypes */ /********************/ -/* Property class callbacks */ -static herr_t H5P_acrt_reg_prop(H5P_genclass_t *pclass); - /*********************/ /* Package Variables */ From b8bb6aec7e0efe6281f7a12367c647fd855e3ad0 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 25 Apr 2019 00:53:58 -0500 Subject: [PATCH 12/32] Refactor link creation parameters from being passing as properties in the link creation property list to vararg function parameters. --- src/H5Gdeprec.c | 38 +++------------------------- src/H5L.c | 39 +++-------------------------- src/H5Lexternal.c | 15 +---------- src/H5O.c | 13 +--------- src/H5Plcpl.c | 54 ---------------------------------------- src/H5VLcallback.c | 41 +++++++++++++++++++----------- src/H5VLnative_link.c | 32 ++++++------------------ src/H5VLnative_private.h | 2 +- src/H5VLpassthru.c | 50 +++++++++++++++++++++++++++++++------ src/H5VLprivate.h | 2 +- src/H5VLpublic.h | 12 ++------- 11 files changed, 90 insertions(+), 208 deletions(-) diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index cb03b5e476..85a964ed4d 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -323,7 +323,6 @@ herr_t H5Glink(hid_t cur_loc_id, H5G_link_t type, const char *cur_name, const char *new_name) { hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; - H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -339,10 +338,6 @@ H5Glink(hid_t cur_loc_id, H5G_link_t type, const char *cur_name, const char *new if(H5CX_set_loc(cur_loc_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set collective metadata read info") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - /* Create link */ if(type == H5L_TYPE_HARD) { H5VL_object_t *vol_obj; /* Object token of loc_id */ @@ -363,18 +358,12 @@ H5Glink(hid_t cur_loc_id, H5G_link_t type, const char *cur_name, const char *new if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(cur_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET, &vol_obj->data) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target") - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_LOC_PARAMS, &loc_params1) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target loc params") - /* Construct a temporary VOL object */ tmp_vol_obj.data = NULL; tmp_vol_obj.connector = vol_obj->connector; /* Create the link through the VOL */ - if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, vol_obj->data, loc_params1) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create link") } /* end if */ else if(type == H5L_TYPE_SOFT) { @@ -390,12 +379,8 @@ H5Glink(hid_t cur_loc_id, H5G_link_t type, const char *cur_name, const char *new if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(cur_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_NAME, &cur_name) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for target name") - /* Create the link through the VOL */ - if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, cur_name) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create link") } /* end else-if */ else @@ -419,7 +404,6 @@ H5Glink2(hid_t cur_loc_id, const char *cur_name, H5G_link_t type, hid_t new_loc_id, const char *new_name) { hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; - H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -435,10 +419,6 @@ H5Glink2(hid_t cur_loc_id, const char *cur_name, H5G_link_t type, if(H5CX_set_loc(cur_loc_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTSET, FAIL, "can't set collective metadata read info") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - /* Create the appropriate kind of link */ if(type == H5L_TYPE_HARD) { H5VL_object_t *vol_obj1; /* Object token of loc_id */ @@ -462,14 +442,8 @@ H5Glink2(hid_t cur_loc_id, const char *cur_name, H5G_link_t type, if(NULL == (vol_obj2 = (H5VL_object_t *)H5I_object(new_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET, &vol_obj1->data) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target id") - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_LOC_PARAMS, &loc_params1) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target name") - /* Create the link through the VOL */ - if(H5VL_link_create(H5VL_LINK_CREATE_HARD, vol_obj2, &loc_params2, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_HARD, vol_obj2, &loc_params2, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, vol_obj1->data, loc_params1) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create link") } /* end if */ else if(type == H5L_TYPE_SOFT) { @@ -490,12 +464,8 @@ H5Glink2(hid_t cur_loc_id, const char *cur_name, H5G_link_t type, if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(new_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_NAME, &cur_name) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for target name") - /* Create the link through the VOL */ - if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, H5P_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, cur_name) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "unable to create link") } /* end else-if */ else diff --git a/src/H5L.c b/src/H5L.c index da0bc7d1c0..183fee4436 100644 --- a/src/H5L.c +++ b/src/H5L.c @@ -449,7 +449,6 @@ H5Lcreate_soft(const char *link_target, hid_t link_loc_id, const char *link_name { H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist = NULL; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -483,20 +482,12 @@ H5Lcreate_soft(const char *link_target, hid_t link_loc_id, const char *link_name if(NULL == (vol_obj = (H5VL_object_t *)H5VL_vol_object(link_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_NAME, &link_target) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for target name") - /* Verify access property list and set up collective metadata if appropriate */ if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, link_loc_id, TRUE) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTSET, FAIL, "can't set access property list info") /* Create the link */ - if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_SOFT, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, link_target) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTCREATE, FAIL, "unable to create soft link") done: @@ -529,7 +520,6 @@ H5Lcreate_hard(hid_t cur_loc_id, const char *cur_name, H5VL_object_t tmp_vol_obj; /* Temporary object token of */ H5VL_loc_params_t loc_params1; H5VL_loc_params_t loc_params2; - H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -583,22 +573,12 @@ H5Lcreate_hard(hid_t cur_loc_id, const char *cur_name, if(vol_obj1->connector->cls->value != vol_obj2->connector->cls->value) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "Objects are accessed through different VOL connectors and can't be linked") - /* Get the link creation plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_LINK, H5E_BADATOM, FAIL, "can't find object for ID") - - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET, (vol_obj1 ? &(vol_obj1->data) : NULL)) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't set property value for target id") - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_LOC_PARAMS, &loc_params1) < 0) - HGOTO_ERROR(H5E_LINK, H5E_CANTGET, FAIL, "can't set property value for target name") - /* Construct a temporary VOL object */ tmp_vol_obj.data = (vol_obj2 ? (vol_obj2->data) : NULL); tmp_vol_obj.connector = (vol_obj1 != NULL ? vol_obj1->connector : vol_obj2->connector); /* Create the link */ - if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, (vol_obj1 ? vol_obj1->data : NULL), loc_params1) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTCREATE, FAIL, "unable to create hard link") done: @@ -636,7 +616,6 @@ H5Lcreate_ud(hid_t link_loc_id, const char *link_name, H5L_type_t link_type, { H5VL_object_t *vol_obj = NULL; /* Object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -668,20 +647,8 @@ H5Lcreate_ud(hid_t link_loc_id, const char *link_name, H5L_type_t link_type, if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(link_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TYPE, &link_type) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - if(H5P_set(plist, H5VL_PROP_LINK_UDATA, &udata) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - if(H5P_set(plist, H5VL_PROP_LINK_UDATA_SIZE, &udata_size) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - /* Create external link */ - if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, link_type, udata, udata_size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") done: diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index d838d77d85..a0d7282945 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -349,7 +349,6 @@ H5Lcreate_external(const char *file_name, const char *obj_name, size_t file_name_len; /* Length of file name string */ size_t norm_obj_name_len; /* Length of normalized object name string */ uint8_t *p; /* Pointer into external link buffer */ - H5P_genplist_t *plist; /* Property list pointer */ H5L_type_t link_type = H5L_TYPE_EXTERNAL; herr_t ret_value = SUCCEED; /* Return value */ @@ -400,20 +399,8 @@ H5Lcreate_external(const char *file_name, const char *obj_name, if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(link_loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* Set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TYPE, &link_type) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - if(H5P_set(plist, H5VL_PROP_LINK_UDATA, &ext_link_buf) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - if(H5P_set(plist, H5VL_PROP_LINK_UDATA_SIZE, &buf_size) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value from plist") - /* Create an external link */ - if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, link_type, ext_link_buf, buf_size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create external link") done: diff --git a/src/H5O.c b/src/H5O.c index 4e2f603a6d..0fdb9beb5f 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -314,7 +314,6 @@ H5Olink(hid_t obj_id, hid_t new_loc_id, const char *new_name, hid_t lcpl_id, H5VL_object_t tmp_vol_obj; /* Temporary object token of */ H5VL_loc_params_t loc_params1; H5VL_loc_params_t loc_params2; - H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API(FAIL) @@ -363,22 +362,12 @@ H5Olink(hid_t obj_id, hid_t new_loc_id, const char *new_name, hid_t lcpl_id, if (vol_obj1->connector->cls->value != vol_obj2->connector->cls->value) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "Objects are accessed through different VOL connectors and can't be linked") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID") - - /* set creation properties */ - if(H5P_set(plist, H5VL_PROP_LINK_TARGET, &vol_obj1->data) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target id") - if(H5P_set(plist, H5VL_PROP_LINK_TARGET_LOC_PARAMS, &loc_params1) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't set property value for target id") - /* Construct a temporary VOL object */ tmp_vol_obj.data = vol_obj2->data; tmp_vol_obj.connector = (vol_obj1 != NULL ? vol_obj1->connector : vol_obj2->connector); /* Create a link to the object */ - if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_HARD, &tmp_vol_obj, &loc_params2, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, vol_obj1->data, loc_params1) < 0) HGOTO_ERROR(H5E_OHDR, H5E_CANTCREATE, FAIL, "unable to create link") done: diff --git a/src/H5Plcpl.c b/src/H5Plcpl.c index 16be52aabc..ace853a94b 100644 --- a/src/H5Plcpl.c +++ b/src/H5Plcpl.c @@ -48,30 +48,6 @@ #define H5L_CRT_INTERMEDIATE_GROUP_ENC H5P__encode_unsigned #define H5L_CRT_INTERMEDIATE_GROUP_DEC H5P__decode_unsigned -/* ======== VOL specific properties ========= */ -/* Definitions for target object ID */ -#define H5L_CRT_TARGET_SIZE sizeof(void *) -#define H5L_CRT_TARGET_DEF NULL - -/* Definitions for Location params */ -#define H5L_CRT_LOCATION_SIZE sizeof(H5VL_loc_params_t) -#define H5L_CRT_LOCATION_DEF {H5I_BADID, H5VL_OBJECT_BY_SELF, {{HADDR_UNDEF}}} - -/* Definitions for target object NAME */ -#define H5L_CRT_TARGET_NAME_SIZE sizeof(char *) -#define H5L_CRT_TARGET_NAME_DEF NULL - -/* Definitions for link type */ -#define H5L_CRT_LINK_TYPE_SIZE sizeof(link_type) -#define H5L_CRT_LINK_TYPE_DEF H5L_TYPE_ERROR - -/* Definitions for UDATA */ -#define H5L_CRT_UDATA_SIZE sizeof(void *) -#define H5L_CRT_UDATA_DEF NULL - -/* Definitions for UDATA_SIZE */ -#define H5L_CRT_UDATA_SIZE_SIZE sizeof(size_t) -#define H5L_CRT_UDATA_SIZE_DEF 0 /******************/ /* Local Typedefs */ @@ -143,12 +119,6 @@ static const unsigned H5L_def_intmd_group_g = H5L_CRT_INTERMEDIATE_GROUP_DEF; herr_t H5P_lcrt_reg_prop(H5P_genclass_t *pclass) { - void* target = H5L_CRT_TARGET_DEF; - H5VL_loc_params_t loc_params = H5L_CRT_LOCATION_DEF; - char *target_name = H5L_CRT_TARGET_NAME_DEF; - H5L_type_t link_type = H5L_CRT_LINK_TYPE_DEF; - void *udata = H5L_CRT_UDATA_DEF; - size_t udata_size = H5L_CRT_UDATA_SIZE_DEF; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) @@ -159,30 +129,6 @@ H5P_lcrt_reg_prop(H5P_genclass_t *pclass) NULL, NULL, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - if(H5P__register_real(pclass, H5VL_PROP_LINK_TARGET, H5L_CRT_TARGET_SIZE, &target, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - if(H5P__register_real(pclass, H5VL_PROP_LINK_TARGET_LOC_PARAMS, H5L_CRT_LOCATION_SIZE, &loc_params, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - if(H5P__register_real(pclass, H5VL_PROP_LINK_TARGET_NAME, H5L_CRT_TARGET_NAME_SIZE, &target_name, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - if(H5P__register_real(pclass, H5VL_PROP_LINK_TYPE, H5L_CRT_LINK_TYPE_SIZE, &link_type, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - if(H5P__register_real(pclass, H5VL_PROP_LINK_UDATA, H5L_CRT_UDATA_SIZE, &udata, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - - if(H5P__register_real(pclass, H5VL_PROP_LINK_UDATA_SIZE, H5L_CRT_UDATA_SIZE_SIZE, &udata_size, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P_lcrt_reg_prop() */ diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 548667fa37..48ca3b15f8 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -123,7 +123,7 @@ static herr_t H5VL__group_close(void *obj, const H5VL_class_t *cls, hid_t dxpl_id, void **req); static herr_t H5VL__link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, hid_t lcpl_id, - hid_t lapl_id, hid_t dxpl_id, void **req); + hid_t lapl_id, hid_t dxpl_id, void **req, va_list arguments); static herr_t H5VL__link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, const H5VL_class_t *cls, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); @@ -4002,7 +4002,8 @@ done: */ static herr_t H5VL__link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, - const H5VL_class_t *cls, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req) + const H5VL_class_t *cls, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, + va_list arguments) { herr_t ret_value = SUCCEED; /* Return value */ @@ -4013,7 +4014,7 @@ H5VL__link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "VOL connector has no 'link create' method") /* Call the corresponding VOL callback */ - if((cls->link_cls.create)(create_type, obj, loc_params, lcpl_id, lapl_id, dxpl_id, req) < 0) + if((cls->link_cls.create)(create_type, obj, loc_params, lcpl_id, lapl_id, dxpl_id, req, arguments) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "link create failed") done: @@ -4034,23 +4035,28 @@ done: herr_t H5VL_link_create(H5VL_link_create_type_t create_type, const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, - void **req) + void **req, ...) { H5VL_object_t tmp_vol_obj; /* Temporary object token of */ + va_list arguments; /* Argument list passed from the API call */ + hbool_t arg_started = FALSE; /* Whether the va_list has been started */ hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_NOAPI(FAIL) + /* Start the varargs, so they can be copied */ + HDva_start(arguments, req); + arg_started = TRUE; + /* Special case for hard links */ if(H5VL_LINK_CREATE_HARD == create_type && NULL == vol_obj->data) { - H5P_genplist_t *plist; /* Property list pointer */ + va_list tmp_arguments; /* Copy of argument list passed in */ - /* Get the VOL data pointer from the fapl */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(lcpl_id))) - HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a file access property list") - if(H5P_peek(plist, H5VL_PROP_LINK_TARGET, &tmp_vol_obj.data) < 0) - HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL connector info") + /* Get the VOL data pointer from the varargs */ + HDva_copy(tmp_arguments, arguments); + tmp_vol_obj.data = HDva_arg(tmp_arguments, void *); + HDva_end(tmp_arguments); } /* end if */ else /* Use the VOL object passed in */ @@ -4063,10 +4069,14 @@ H5VL_link_create(H5VL_link_create_type_t create_type, const H5VL_object_t *vol_o vol_wrapper_set = TRUE; /* Call the corresponding internal VOL routine */ - if(H5VL__link_create(create_type, vol_obj->data, loc_params, vol_obj->connector->cls, lcpl_id, lapl_id, dxpl_id, req) < 0) + if(H5VL__link_create(create_type, vol_obj->data, loc_params, vol_obj->connector->cls, lcpl_id, lapl_id, dxpl_id, req, arguments) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "link create failed") done: + /* End access to the va_list, if we started it */ + if(arg_started) + HDva_end(arguments); + /* Reset object wrapping info in API context */ if(vol_wrapper_set && H5VL_reset_vol_wrapper() < 0) HDONE_ERROR(H5E_VOL, H5E_CANTRESET, FAIL, "can't reset VOL wrapper info") @@ -4089,21 +4099,22 @@ done: */ herr_t H5VLlink_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, - hid_t connector_id, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req) + hid_t connector_id, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, + va_list arguments) { H5VL_class_t *cls; /* VOL connector's class struct */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE8("e", "Vk*x*xiiii**x", create_type, obj, loc_params, connector_id, - lcpl_id, lapl_id, dxpl_id, req); + H5TRACE9("e", "Vk*x*xiiii**xx", create_type, obj, loc_params, connector_id, + lcpl_id, lapl_id, dxpl_id, req, arguments); /* Get class pointer */ if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a VOL connector ID") /* Call the corresponding internal VOL routine */ - if(H5VL__link_create(create_type, obj, loc_params, cls, lcpl_id, lapl_id, dxpl_id, req) < 0) + if(H5VL__link_create(create_type, obj, loc_params, cls, lcpl_id, lapl_id, dxpl_id, req, arguments) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "unable to create link") done: diff --git a/src/H5VLnative_link.c b/src/H5VLnative_link.c index 98d2ccd3a8..2977e48cea 100644 --- a/src/H5VLnative_link.c +++ b/src/H5VLnative_link.c @@ -41,7 +41,7 @@ herr_t H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t H5_ATTR_UNUSED lapl_id, - hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) + hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req, va_list arguments) { H5P_genplist_t *plist; /* Property list pointer */ herr_t ret_value = SUCCEED; /* Return value */ @@ -57,13 +57,8 @@ H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, { H5G_loc_t cur_loc; H5G_loc_t link_loc; - void *cur_obj; - H5VL_loc_params_t cur_params; - - if(H5P_get(plist, H5VL_PROP_LINK_TARGET, &cur_obj) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for current location id") - if(H5P_get(plist, H5VL_PROP_LINK_TARGET_LOC_PARAMS, &cur_params) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for current name") + void *cur_obj = HDva_arg(arguments, void *); + H5VL_loc_params_t cur_params = HDva_arg(arguments, H5VL_loc_params_t); if(NULL != cur_obj && H5G_loc_real(cur_obj, cur_params.obj_type, &cur_loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") @@ -99,15 +94,12 @@ H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, case H5VL_LINK_CREATE_SOFT: { - char *target_name; + char *target_name = HDva_arg(arguments, char *); H5G_loc_t link_loc; /* Group location for new link */ if(H5G_loc_real(obj, loc_params->obj_type, &link_loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(H5P_get(plist, H5VL_PROP_LINK_TARGET_NAME, &target_name) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for targe name") - /* Create the link */ if((ret_value = H5L_create_soft(target_name, &link_loc, loc_params->loc_data.loc_by_name.name, lcpl_id)) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") @@ -117,23 +109,15 @@ H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, case H5VL_LINK_CREATE_UD: { H5G_loc_t link_loc; /* Group location for new link */ - H5L_type_t link_type; - void *udata; - size_t udata_size; + H5L_type_t link_type = HDva_arg(arguments, H5L_type_t); + void *udata = HDva_arg(arguments, void *); + size_t udata_size = HDva_arg(arguments, size_t); if(H5G_loc_real(obj, loc_params->obj_type, &link_loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file or file object") - if(H5P_get(plist, H5VL_PROP_LINK_TYPE, &link_type) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for link type") - if(H5P_get(plist, H5VL_PROP_LINK_UDATA, &udata) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for udata") - if(H5P_get(plist, H5VL_PROP_LINK_UDATA_SIZE, &udata_size) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get property value for udata size") - /* Create link */ - if(H5L__create_ud(&link_loc, loc_params->loc_data.loc_by_name.name, udata, udata_size, - link_type, lcpl_id) < 0) + if(H5L__create_ud(&link_loc, loc_params->loc_data.loc_by_name.name, udata, udata_size, link_type, lcpl_id) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") break; } diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index e91bc3f2f9..785da85b72 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -60,7 +60,7 @@ H5_DLL herr_t H5VL__native_group_optional(void *obj, hid_t dxpl_id, void **req, H5_DLL herr_t H5VL__native_group_close(void *grp, hid_t dxpl_id, void **req); /* Link callbacks */ -H5_DLL herr_t H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); +H5_DLL herr_t H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, va_list arguments); H5_DLL herr_t H5VL__native_link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_link_move(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 8ba00f0e17..3023770253 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -80,6 +80,9 @@ static herr_t H5VL_pass_through_file_specific_reissue(void *obj, hid_t connector H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, ...); static herr_t H5VL_pass_through_request_specific_reissue(void *obj, hid_t connector_id, H5VL_request_specific_t specific_type, ...); +static herr_t H5VL_pass_through_link_create_reissue(H5VL_link_create_type_t create_type, + void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, + hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, ...); static H5VL_pass_through_t *H5VL_pass_through_new_obj(void *under_obj, hid_t under_vol_id); static herr_t H5VL_pass_through_free_obj(H5VL_pass_through_t *obj); @@ -149,7 +152,7 @@ static herr_t H5VL_pass_through_group_optional(void *obj, hid_t dxpl_id, void ** static herr_t H5VL_pass_through_group_close(void *grp, hid_t dxpl_id, void **req); /* Link callbacks */ -static herr_t H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); +static herr_t H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, va_list arguments); static herr_t H5VL_pass_through_link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_link_move(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); @@ -2067,6 +2070,32 @@ H5VL_pass_through_group_close(void *grp, hid_t dxpl_id, void **req) } /* end H5VL_pass_through_group_close() */ +/*------------------------------------------------------------------------- + * Function: H5VL_pass_through_link_create_reissue + * + * Purpose: Re-wrap vararg arguments into a va_list and reissue the + * link create callback to the underlying VOL connector. + * + * Return: Success: 0 + * Failure: -1 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL_pass_through_link_create_reissue(H5VL_link_create_type_t create_type, + void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, + hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, ...) +{ + va_list arguments; + herr_t ret_value; + + va_start(arguments, req); + ret_value = H5VLlink_create(create_type, obj, loc_params, connector_id, lcpl_id, lapl_id, dxpl_id, req, arguments); + va_end(arguments); + + return ret_value; +} /* end H5VL_pass_through_link_create_reissue() */ + /*------------------------------------------------------------------------- * Function: H5VL_pass_through_link_create * @@ -2078,7 +2107,9 @@ H5VL_pass_through_group_close(void *grp, hid_t dxpl_id, void **req) *------------------------------------------------------------------------- */ static herr_t -H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req) +H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, + const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, + hid_t dxpl_id, void **req, va_list arguments) { H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; hid_t under_vol_id = -1; @@ -2095,9 +2126,11 @@ H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, co /* Fix up the link target object for hard link creation */ if(H5VL_LINK_CREATE_HARD == create_type) { void *cur_obj; + H5VL_loc_params_t cur_params; - /* Retrieve the object for the link target */ - H5Pget(lcpl_id, H5VL_PROP_LINK_TARGET, &cur_obj); + /* Retrieve the object & loc params for the link target */ + cur_obj = va_arg(arguments, void *); + cur_params = va_arg(arguments, H5VL_loc_params_t); /* If it's a non-NULL pointer, find the 'under object' and re-set the property */ if(cur_obj) { @@ -2106,11 +2139,14 @@ H5VL_pass_through_link_create(H5VL_link_create_type_t create_type, void *obj, co under_vol_id = ((H5VL_pass_through_t *)cur_obj)->under_vol_id; /* Set the object for the link target */ - H5Pset(lcpl_id, H5VL_PROP_LINK_TARGET, &(((H5VL_pass_through_t *)cur_obj)->under_object)); + cur_obj = ((H5VL_pass_through_t *)cur_obj)->under_object; } /* end if */ - } /* end if */ - ret_value = H5VLlink_create(create_type, (o ? o->under_object : NULL), loc_params, under_vol_id, lcpl_id, lapl_id, dxpl_id, req); + /* Re-issue 'link create' call, using the unwrapped pieces */ + ret_value = H5VL_pass_through_link_create_reissue(create_type, (o ? o->under_object : NULL), loc_params, under_vol_id, lcpl_id, lapl_id, dxpl_id, req, cur_obj, cur_params); + } /* end if */ + else + ret_value = H5VLlink_create(create_type, (o ? o->under_object : NULL), loc_params, under_vol_id, lcpl_id, lapl_id, dxpl_id, req, arguments); /* Check for async request */ if(req && *req) diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index a916055cba..50b2bfaf0f 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -163,7 +163,7 @@ H5_DLL herr_t H5VL_group_optional(const H5VL_object_t *vol_obj, hid_t dxpl_id, v H5_DLL herr_t H5VL_group_close(const H5VL_object_t *vol_obj, hid_t dxpl_id, void **req); /* Link functions */ -H5_DLL herr_t H5VL_link_create(H5VL_link_create_type_t create_type, const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); +H5_DLL herr_t H5VL_link_create(H5VL_link_create_type_t create_type, const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, ...); H5_DLL herr_t H5VL_link_copy(const H5VL_object_t *src_vol_obj, const H5VL_loc_params_t *loc_params1, const H5VL_object_t *dst_vol_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_link_move(const H5VL_object_t *src_vol_obj, const H5VL_loc_params_t *loc_params1, const H5VL_object_t *dst_vol_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_link_get(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_t get_type, hid_t dxpl_id, void **req, ...); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index ed34e1a2e1..cfcd892955 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -32,14 +32,6 @@ /* Public Macros */ /*****************/ -/* Link creation property names */ -#define H5VL_PROP_LINK_TARGET "target_location_object" -#define H5VL_PROP_LINK_TARGET_LOC_PARAMS "target_params" -#define H5VL_PROP_LINK_TARGET_NAME "target_name" -#define H5VL_PROP_LINK_TYPE "link type" -#define H5VL_PROP_LINK_UDATA "udata" -#define H5VL_PROP_LINK_UDATA_SIZE "udata size" - /* Group creation property names */ #define H5VL_PROP_GRP_LCPL_ID "group_lcpl_id" @@ -322,7 +314,7 @@ typedef struct H5VL_group_class_t { /* H5L routines */ typedef struct H5VL_link_class_t { herr_t (*create)(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, - hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); + hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, va_list argumenmts); herr_t (*copy)(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl, hid_t lapl, hid_t dxpl_id, void **req); @@ -505,7 +497,7 @@ H5_DLL herr_t H5VLgroup_optional(void *obj, hid_t connector_id, hid_t dxpl_id, v H5_DLL herr_t H5VLgroup_close(void *grp, hid_t connector_id, hid_t dxpl_id, void **req); /* Public wrappers for link callbacks */ -H5_DLL herr_t H5VLlink_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); +H5_DLL herr_t H5VLlink_create(H5VL_link_create_type_t create_type, void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req, va_list arguments); H5_DLL herr_t H5VLlink_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t connector_id, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req); From ff0b56fa384345331cd16db7c12afa0966959084 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 25 Apr 2019 01:12:28 -0500 Subject: [PATCH 13/32] Warning cleanup --- src/H5Lexternal.c | 2 +- src/H5Pdeprec.c | 1 + src/H5Rint.c | 1 + src/H5VLnative_link.c | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/H5Lexternal.c b/src/H5Lexternal.c index a0d7282945..3c4ffcc047 100644 --- a/src/H5Lexternal.c +++ b/src/H5Lexternal.c @@ -400,7 +400,7 @@ H5Lcreate_external(const char *file_name, const char *obj_name, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid object identifier") /* Create an external link */ - if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, link_type, ext_link_buf, buf_size) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, (int)link_type, ext_link_buf, buf_size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create external link") done: diff --git a/src/H5Pdeprec.c b/src/H5Pdeprec.c index f6c2a3cd9f..1b5f58173a 100644 --- a/src/H5Pdeprec.c +++ b/src/H5Pdeprec.c @@ -36,6 +36,7 @@ /* Headers */ /***********/ #include "H5private.h" /* Generic Functions */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Eprivate.h" /* Error handling */ #include "H5Fprivate.h" /* Files */ #include "H5Iprivate.h" /* IDs */ diff --git a/src/H5Rint.c b/src/H5Rint.c index 9098a03c60..8109ac0288 100644 --- a/src/H5Rint.c +++ b/src/H5Rint.c @@ -23,6 +23,7 @@ /***********/ #include "H5private.h" /* Generic Functions */ #include "H5ACprivate.h" /* Metadata cache */ +#include "H5CXprivate.h" /* API Contexts */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ #include "H5Gprivate.h" /* Groups */ diff --git a/src/H5VLnative_link.c b/src/H5VLnative_link.c index 2977e48cea..4709eb380a 100644 --- a/src/H5VLnative_link.c +++ b/src/H5VLnative_link.c @@ -109,7 +109,7 @@ H5VL__native_link_create(H5VL_link_create_type_t create_type, void *obj, case H5VL_LINK_CREATE_UD: { H5G_loc_t link_loc; /* Group location for new link */ - H5L_type_t link_type = HDva_arg(arguments, H5L_type_t); + H5L_type_t link_type = (H5L_type_t)HDva_arg(arguments, int); void *udata = HDva_arg(arguments, void *); size_t udata_size = HDva_arg(arguments, size_t); From 6d912bf0b5c9613acaf216616b59ae1aec3f7e1f Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 25 Apr 2019 01:12:46 -0500 Subject: [PATCH 14/32] Refactor group creation parameters to take them out of the group creation property list and pass them as normal function parameters. --- src/H5G.c | 11 ++--------- src/H5Gdeprec.c | 11 +---------- src/H5Pgcpl.c | 6 ------ src/H5VLcallback.c | 25 ++++++++++++++----------- src/H5VLnative_group.c | 14 ++------------ src/H5VLnative_private.h | 2 +- src/H5VLpassthru.c | 7 ++++--- src/H5VLprivate.h | 2 +- src/H5VLpublic.h | 7 ++----- 9 files changed, 27 insertions(+), 58 deletions(-) diff --git a/src/H5G.c b/src/H5G.c index 20df130864..fdf613cf1f 100644 --- a/src/H5G.c +++ b/src/H5G.c @@ -320,7 +320,6 @@ H5Gcreate2(hid_t loc_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, void *grp = NULL; /* Structure for new group */ H5VL_object_t *vol_obj = NULL; /* object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ hid_t ret_value = H5I_INVALID_HID; /* Return value */ FUNC_ENTER_API(H5I_INVALID_HID) @@ -350,12 +349,6 @@ H5Gcreate2(hid_t loc_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, if(H5CX_set_apl(&gapl_id, H5P_CLS_GACC, loc_id, TRUE) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info") - /* Get the gcpl structure and set the link properties on it */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(gcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - if(H5P_set(plist, H5VL_PROP_GRP_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, H5I_INVALID_HID, "can't set property value for lcpl id") - /* Get the location object */ if(NULL == (vol_obj = (H5VL_object_t *)H5I_object(loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") @@ -365,7 +358,7 @@ H5Gcreate2(hid_t loc_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, loc_params.obj_type = H5I_get_type(loc_id); /* Create the group */ - if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, name, gcpl_id, gapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, name, lcpl_id, gcpl_id, gapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, H5I_INVALID_HID, "unable to create group") /* Get an atom for the group */ @@ -444,7 +437,7 @@ H5Gcreate_anon(hid_t loc_id, hid_t gcpl_id, hid_t gapl_id) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Create the group */ - if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, NULL, gcpl_id, gapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, NULL, H5P_LINK_CREATE_DEFAULT, gcpl_id, gapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, H5I_INVALID_HID, "unable to create group") /* Get an atom for the group */ diff --git a/src/H5Gdeprec.c b/src/H5Gdeprec.c index 85a964ed4d..95627d26af 100644 --- a/src/H5Gdeprec.c +++ b/src/H5Gdeprec.c @@ -172,7 +172,6 @@ H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) void *grp = NULL; /* New group created */ H5VL_object_t *vol_obj; /* Object token of loc_id */ H5VL_loc_params_t loc_params; - H5P_genplist_t *plist; /* Property list pointer */ hid_t tmp_gcpl = H5I_INVALID_HID; /* Temporary group creation property list */ hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; hid_t ret_value = H5I_INVALID_HID; /* Return value */ @@ -217,14 +216,6 @@ H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) if(H5CX_set_loc(loc_id) < 0) HGOTO_ERROR(H5E_SYM, H5E_CANTSET, H5I_INVALID_HID, "can't set collective metadata read info") - /* Get the plist structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(tmp_gcpl))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, H5I_INVALID_HID, "can't find object for ID") - - /* get creation properties */ - if(H5P_set(plist, H5VL_PROP_GRP_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5I_INVALID_HID, "can't get property value for lcpl id") - /* Set location parameters */ loc_params.type = H5VL_OBJECT_BY_SELF; loc_params.obj_type = H5I_get_type(loc_id); @@ -234,7 +225,7 @@ H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, H5I_INVALID_HID, "invalid location identifier") /* Create the group */ - if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, name, tmp_gcpl, H5P_GROUP_ACCESS_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) + if(NULL == (grp = H5VL_group_create(vol_obj, &loc_params, name, lcpl_id, tmp_gcpl, H5P_GROUP_ACCESS_DEFAULT, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL))) HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, H5I_INVALID_HID, "unable to create group") /* Get an atom for the group */ diff --git a/src/H5Pgcpl.c b/src/H5Pgcpl.c index ab289e4324..e2fdcea5a0 100644 --- a/src/H5Pgcpl.c +++ b/src/H5Pgcpl.c @@ -128,7 +128,6 @@ static const H5O_linfo_t H5G_def_linfo_g = H5G_CRT_LINK_INFO_DEF; /* Defaul static herr_t H5P__gcrt_reg_prop(H5P_genclass_t *pclass) { - hid_t lcpl_id = H5P_LINK_CREATE_DEFAULT; herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -145,11 +144,6 @@ H5P__gcrt_reg_prop(H5P_genclass_t *pclass) NULL, NULL, NULL, NULL) < 0) HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - /* Register the lcpl ID property */ - if(H5P__register_real(pclass, H5VL_PROP_GRP_LCPL_ID, sizeof(hid_t), &lcpl_id, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTINSERT, FAIL, "can't insert property into class") - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5P__gcrt_reg_prop() */ diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 48ca3b15f8..2d1274cea0 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -108,8 +108,8 @@ static herr_t H5VL__file_optional(void *obj, const H5VL_class_t *cls, hid_t dxpl static herr_t H5VL__file_close(void *obj, const H5VL_class_t *cls, hid_t dxpl_id, void **req); static void *H5VL__group_create(void *obj, const H5VL_loc_params_t *loc_params, - const H5VL_class_t *cls, const char *name, hid_t gcpl_id, hid_t gapl_id, - hid_t dxpl_id, void **req); + const H5VL_class_t *cls, const char *name, hid_t lcpl_id, hid_t gcpl_id, + hid_t gapl_id, hid_t dxpl_id, void **req); static void *H5VL__group_open(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); @@ -3354,7 +3354,8 @@ done: */ static void * H5VL__group_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_class_t *cls, - const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, + hid_t dxpl_id, void **req) { void *ret_value = NULL; /* Return value */ @@ -3365,7 +3366,7 @@ H5VL__group_create(void *obj, const H5VL_loc_params_t *loc_params, const H5VL_cl HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, NULL, "VOL connector has no 'group create' method") /* Call the corresponding VOL callback */ - if(NULL == (ret_value = (cls->group_cls.create)(obj, loc_params, name, gcpl_id, gapl_id, dxpl_id, req))) + if(NULL == (ret_value = (cls->group_cls.create)(obj, loc_params, name, lcpl_id, gcpl_id, gapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "group create failed") done: @@ -3385,7 +3386,8 @@ done: */ void * H5VL_group_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, + void **req) { hbool_t vol_wrapper_set = FALSE; /* Whether the VOL object wrapping context was set up */ void *ret_value = NULL; /* Return value */ @@ -3398,7 +3400,7 @@ H5VL_group_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_par vol_wrapper_set = TRUE; /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__group_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, gcpl_id, gapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__group_create(vol_obj->data, loc_params, vol_obj->connector->cls, name, lcpl_id, gcpl_id, gapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "group create failed") done: @@ -3421,15 +3423,16 @@ done: *------------------------------------------------------------------------- */ void * -H5VLgroup_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, - hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req) +H5VLgroup_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, + const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id,hid_t dxpl_id, + void **req) { H5VL_class_t *cls; /* VOL connector's class struct */ void *ret_value = NULL; /* Return value */ FUNC_ENTER_API_NOINIT - H5TRACE8("*x", "*x*xi*siii**x", obj, loc_params, connector_id, name, gcpl_id, - gapl_id, dxpl_id, req); + H5TRACE9("*x", "*x*xi*siiii**x", obj, loc_params, connector_id, name, lcpl_id, + gcpl_id, gapl_id, dxpl_id, req); /* Check args and get class pointer */ if(NULL == obj) @@ -3438,7 +3441,7 @@ H5VLgroup_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a VOL connector ID") /* Call the corresponding internal VOL routine */ - if(NULL == (ret_value = H5VL__group_create(obj, loc_params, cls, name, gcpl_id, gapl_id, dxpl_id, req))) + if(NULL == (ret_value = H5VL__group_create(obj, loc_params, cls, name, lcpl_id, gcpl_id, gapl_id, dxpl_id, req))) HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "unable to create group") done: diff --git a/src/H5VLnative_group.c b/src/H5VLnative_group.c index 9c07b3de02..b6bef7f6a5 100644 --- a/src/H5VLnative_group.c +++ b/src/H5VLnative_group.c @@ -41,25 +41,15 @@ */ void * H5VL__native_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, - hid_t gcpl_id, hid_t H5_ATTR_UNUSED gapl_id, hid_t H5_ATTR_UNUSED dxpl_id, - void H5_ATTR_UNUSED **req) + hid_t lcpl_id, hid_t gcpl_id, hid_t H5_ATTR_UNUSED gapl_id, + hid_t H5_ATTR_UNUSED dxpl_id, void H5_ATTR_UNUSED **req) { - H5P_genplist_t *plist; /* Property list pointer */ H5G_loc_t loc; /* Location to create group */ H5G_t *grp = NULL; /* New group created */ - hid_t lcpl_id; void *ret_value; FUNC_ENTER_PACKAGE - /* Get the property list structure */ - if(NULL == (plist = (H5P_genplist_t *)H5I_object(gcpl_id))) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, NULL, "can't find object for ID") - - /* Get creation properties */ - if(H5P_get(plist, H5VL_PROP_GRP_LCPL_ID, &lcpl_id) < 0) - HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get property value for lcpl id") - /* Set up the location */ if(H5G_loc_real(obj, loc_params->obj_type, &loc) < 0) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a file or file object") diff --git a/src/H5VLnative_private.h b/src/H5VLnative_private.h index 785da85b72..714b73c950 100644 --- a/src/H5VLnative_private.h +++ b/src/H5VLnative_private.h @@ -52,7 +52,7 @@ H5_DLL herr_t H5VL__native_file_optional(void *file, hid_t dxpl_id, void **req, H5_DLL herr_t H5VL__native_file_close(void *file, hid_t dxpl_id, void **req); /* Group callbacks */ -H5_DLL void *H5VL__native_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL__native_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL__native_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL__native_group_get(void *obj, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); H5_DLL herr_t H5VL__native_group_specific(void *obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments); diff --git a/src/H5VLpassthru.c b/src/H5VLpassthru.c index 3023770253..ef92ddbcad 100644 --- a/src/H5VLpassthru.c +++ b/src/H5VLpassthru.c @@ -144,7 +144,7 @@ static herr_t H5VL_pass_through_file_optional(void *file, hid_t dxpl_id, void ** static herr_t H5VL_pass_through_file_close(void *file, hid_t dxpl_id, void **req); /* Group callbacks */ -static void *H5VL_pass_through_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); +static void *H5VL_pass_through_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); static void *H5VL_pass_through_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); static herr_t H5VL_pass_through_group_get(void *obj, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); static herr_t H5VL_pass_through_group_specific(void *obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments); @@ -1876,7 +1876,8 @@ H5VL_pass_through_file_close(void *file, hid_t dxpl_id, void **req) */ static void * H5VL_pass_through_group_create(void *obj, const H5VL_loc_params_t *loc_params, - const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req) + const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, + hid_t dxpl_id, void **req) { H5VL_pass_through_t *group; H5VL_pass_through_t *o = (H5VL_pass_through_t *)obj; @@ -1886,7 +1887,7 @@ H5VL_pass_through_group_create(void *obj, const H5VL_loc_params_t *loc_params, printf("------- PASS THROUGH VOL GROUP Create\n"); #endif - under = H5VLgroup_create(o->under_object, loc_params, o->under_vol_id, name, gcpl_id, gapl_id, dxpl_id, req); + under = H5VLgroup_create(o->under_object, loc_params, o->under_vol_id, name, lcpl_id, gcpl_id, gapl_id, dxpl_id, req); if(under) { group = H5VL_pass_through_new_obj(under, o->under_vol_id); diff --git a/src/H5VLprivate.h b/src/H5VLprivate.h index 50b2bfaf0f..91fa762632 100644 --- a/src/H5VLprivate.h +++ b/src/H5VLprivate.h @@ -155,7 +155,7 @@ H5_DLL herr_t H5VL_file_optional(const H5VL_object_t *vol_obj, hid_t dxpl_id, vo H5_DLL herr_t H5VL_file_close(const H5VL_object_t *vol_obj, hid_t dxpl_id, void **req); /* Group functions */ -H5_DLL void *H5VL_group_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VL_group_create(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VL_group_open(const H5VL_object_t *vol_obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VL_group_get(const H5VL_object_t *vol_obj, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, ...); H5_DLL herr_t H5VL_group_specific(const H5VL_object_t *vol_obj, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, ...); diff --git a/src/H5VLpublic.h b/src/H5VLpublic.h index cfcd892955..45fd0226dc 100644 --- a/src/H5VLpublic.h +++ b/src/H5VLpublic.h @@ -32,9 +32,6 @@ /* Public Macros */ /*****************/ -/* Group creation property names */ -#define H5VL_PROP_GRP_LCPL_ID "group_lcpl_id" - /* Default VOL connector value */ #define H5VL_VOL_DEFAULT 0 @@ -301,7 +298,7 @@ typedef struct H5VL_file_class_t { /* H5G routines */ typedef struct H5VL_group_class_t { void *(*create)(void *obj, const H5VL_loc_params_t *loc_params, const char *name, - hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); + hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); void *(*open)(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); herr_t (*get)(void *obj, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); @@ -489,7 +486,7 @@ H5_DLL herr_t H5VLfile_optional(void *obj, hid_t connector_id, hid_t dxpl_id, vo H5_DLL herr_t H5VLfile_close(void *file, hid_t connector_id, hid_t dxpl_id, void **req); /* Public wrappers for group callbacks */ -H5_DLL void *H5VLgroup_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); +H5_DLL void *H5VLgroup_create(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL void *H5VLgroup_open(void *obj, const H5VL_loc_params_t *loc_params, hid_t connector_id, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req); H5_DLL herr_t H5VLgroup_get(void *obj, hid_t connector_id, H5VL_group_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); H5_DLL herr_t H5VLgroup_specific(void *obj, hid_t connector_id, H5VL_group_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments); From 568c3624de786dd3240fbddea4f5035febe6ee01 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Thu, 25 Apr 2019 01:07:42 -0700 Subject: [PATCH 15/32] Improvements to the H5Fis_accessible() and H5Fis_hdf5() tests in tfile.c. * General code tidying. * Expanded tests to work with multi-file VFDs. --- src/H5FDfamily.c | 4 +- src/H5FDmulti.c | 52 +++++----- src/H5Fint.c | 2 +- test/h5test.c | 56 ++++++++--- test/h5test.h | 1 + test/tfile.c | 247 +++++++++++++++++++++++++++++------------------ 6 files changed, 227 insertions(+), 135 deletions(-) diff --git a/src/H5FDfamily.c b/src/H5FDfamily.c index 047fb2595a..c8893f9002 100644 --- a/src/H5FDfamily.c +++ b/src/H5FDfamily.c @@ -715,7 +715,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, (0==file->nmembs ? flags : t_flags), file->memb_fapl_id, HADDR_UNDEF); } H5E_END_TRY; if (!file->memb[file->nmembs]) { - if (0==file->nmembs) + if (0 == file->nmembs) HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, NULL, "unable to open member file") H5E_clear_stack(NULL); break; @@ -723,7 +723,7 @@ H5FD_family_open(const char *name, unsigned flags, hid_t fapl_id, file->nmembs++; } - /* If the file is reopened and there's only one member file existing, this file maybe + /* If the file is reopened and there's only one member file existing, this file may be * smaller than the size specified through H5Pset_fapl_family(). Update the actual * member size. */ diff --git a/src/H5FDmulti.c b/src/H5FDmulti.c index fac0909088..6cfef55f92 100644 --- a/src/H5FDmulti.c +++ b/src/H5FDmulti.c @@ -981,8 +981,7 @@ H5FD_multi_fapl_free(void *_fa) *------------------------------------------------------------------------- */ static H5FD_t * -H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, - haddr_t maxaddr) +H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxaddr) { H5FD_multi_t *file=NULL; hid_t close_fapl=-1; @@ -996,7 +995,7 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, /* Check arguments */ if (!name || !*name) H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADVALUE, "invalid file name", NULL) - if (0==maxaddr || HADDR_UNDEF==maxaddr) + if (0 == maxaddr || HADDR_UNDEF == maxaddr) H5Epush_ret(func, H5E_ERR_CLS, H5E_ARGS, H5E_BADRANGE, "bogus maxaddr", NULL) /* @@ -1007,41 +1006,41 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, */ if(NULL == (file = (H5FD_multi_t *)calloc((size_t)1, sizeof(H5FD_multi_t)))) H5Epush_ret(func, H5E_ERR_CLS, H5E_RESOURCE, H5E_NOSPACE, "memory allocation failed", NULL) - if(H5P_FILE_ACCESS_DEFAULT==fapl_id || H5FD_MULTI!=H5Pget_driver(fapl_id)) { + if(H5P_FILE_ACCESS_DEFAULT == fapl_id || H5FD_MULTI != H5Pget_driver(fapl_id)) { close_fapl = fapl_id = H5Pcreate(H5P_FILE_ACCESS); - if(H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE)<0) + if(H5Pset_fapl_multi(fapl_id, NULL, NULL, NULL, NULL, TRUE) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTSET, "can't set property value", error) } fa = (const H5FD_multi_fapl_t *)H5Pget_driver_info(fapl_id); assert(fa); ALL_MEMBERS(mt) { - file->fa.memb_map[mt] = fa->memb_map[mt]; - file->fa.memb_addr[mt] = fa->memb_addr[mt]; - if (fa->memb_fapl[mt]>=0) - H5Iinc_ref(fa->memb_fapl[mt]); + file->fa.memb_map[mt] = fa->memb_map[mt]; + file->fa.memb_addr[mt] = fa->memb_addr[mt]; + if (fa->memb_fapl[mt] >= 0) + H5Iinc_ref(fa->memb_fapl[mt]); file->fa.memb_fapl[mt] = fa->memb_fapl[mt]; - if (fa->memb_name[mt]) - file->fa.memb_name[mt] = my_strdup(fa->memb_name[mt]); - else - file->fa.memb_name[mt] = NULL; + if (fa->memb_name[mt]) + file->fa.memb_name[mt] = my_strdup(fa->memb_name[mt]); + else + file->fa.memb_name[mt] = NULL; } END_MEMBERS; file->fa.relax = fa->relax; file->flags = flags; file->name = my_strdup(name); - if (close_fapl>=0) - if(H5Pclose(close_fapl)<0) + if (close_fapl >= 0) + if(H5Pclose(close_fapl) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_FILE, H5E_CANTCLOSEOBJ, "can't close property list", error) /* Compute derived properties and open member files */ - if (compute_next(file)<0) + if (compute_next(file) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "compute_next() failed", error); - if (open_members(file)<0) + if (open_members(file) < 0) H5Epush_goto(func, H5E_ERR_CLS, H5E_INTERNAL, H5E_BADVALUE, "open_members() failed", error); /* We must have opened at least the superblock file */ - if (H5FD_MEM_DEFAULT==(m=file->fa.memb_map[H5FD_MEM_SUPER])) + if (H5FD_MEM_DEFAULT == (m = file->fa.memb_map[H5FD_MEM_SUPER])) m = H5FD_MEM_SUPER; - if (NULL==file->memb[m]) + if (NULL == file->memb[m]) goto error; return (H5FD_t*)file; @@ -1049,13 +1048,14 @@ H5FD_multi_open(const char *name, unsigned flags, hid_t fapl_id, error: /* Cleanup and fail */ if (file) { - ALL_MEMBERS(mt) { - if (file->memb[mt]) (void)H5FDclose(file->memb[mt]); - if (file->fa.memb_fapl[mt]>=0) (void)H5Idec_ref(file->fa.memb_fapl[mt]); - if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); - } END_MEMBERS; - if (file->name) free(file->name); - free(file); + ALL_MEMBERS(mt) { + if (file->memb[mt]) (void)H5FDclose(file->memb[mt]); + if (file->fa.memb_fapl[mt] >= 0) (void)H5Idec_ref(file->fa.memb_fapl[mt]); + if (file->fa.memb_name[mt]) free(file->fa.memb_name[mt]); + } END_MEMBERS; + if (file->name) + free(file->name); + free(file); } return NULL; } diff --git a/src/H5Fint.c b/src/H5Fint.c index 5d03b3ba20..2e8771c797 100644 --- a/src/H5Fint.c +++ b/src/H5Fint.c @@ -853,7 +853,7 @@ htri_t H5F__is_hdf5(const char *name, hid_t fapl_id) { H5FD_t *file = NULL; /* Low-level file struct */ - haddr_t sig_addr; /* Addess of hdf5 file signature */ + haddr_t sig_addr = HADDR_UNDEF; /* Addess of hdf5 file signature */ htri_t ret_value = FAIL; /* Return value */ FUNC_ENTER_PACKAGE diff --git a/test/h5test.c b/test/h5test.c index 8634a4da29..3b17c72033 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -115,8 +115,8 @@ const char *LIBVER_NAMES[] = { static H5E_auto2_t err_func = NULL; static herr_t h5_errors(hid_t estack, void *client_data); -static char * h5_fixname_real(const char *base_name, hid_t fapl, const char *suffix, - char *fullname, size_t size, hbool_t nest_printf); +static char *h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, + char *fullname, size_t size, hbool_t nest_printf, hbool_t subst_for_superblock); /*------------------------------------------------------------------------- @@ -471,7 +471,33 @@ h5_test_init(void) char * h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, FALSE)); + return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, FALSE, FALSE)); +} + + +/*------------------------------------------------------------------------- + * Function: h5_fixname_superblock + * + * Purpose: Like h5_fixname() but returns the name of the file you'd + * open to find the superblock. Useful for when you have to + * open a file with open(2) but the h5_fixname() string + * contains stuff like format strings. + * + * Return: Success: The FULLNAME pointer. + * + * Failure: NULL if BASENAME or FULLNAME is the null + * pointer or if FULLNAME isn't large enough for + * the result. + * + * Programmer: Dana Robinson + * Spring 2019 + * + *------------------------------------------------------------------------- + */ +char * +h5_fixname_superblock(const char *base_name, hid_t fapl_id, char *fullname, size_t size) +{ + return (h5_fixname_real(base_name, fapl_id, ".h5", fullname, size, FALSE, TRUE)); } @@ -491,7 +517,7 @@ h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size) char * h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, NULL, fullname, size, FALSE)); + return (h5_fixname_real(base_name, fapl, NULL, fullname, size, FALSE, FALSE)); } @@ -517,7 +543,7 @@ h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t s char * h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size) { - return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, TRUE)); + return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, TRUE, FALSE)); } @@ -545,7 +571,7 @@ h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size */ static char * h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, - char *fullname, size_t size, hbool_t nest_printf) + char *fullname, size_t size, hbool_t nest_printf, hbool_t subst_for_superblock) { const char *prefix = NULL; char *ptr, last = '\0'; @@ -565,17 +591,25 @@ h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, return NULL; if(suffix) { - if(H5FD_FAMILY == driver) - suffix = nest_printf ? "%%05d.h5" : "%05d.h5"; - else if (H5FD_MULTI == driver) - suffix = NULL; + if(H5FD_FAMILY == driver) { + if(subst_for_superblock) + suffix = "00000.h5"; + else + suffix = nest_printf ? "%%05d.h5" : "%05d.h5"; + } + else if (H5FD_MULTI == driver) { + if(subst_for_superblock) + suffix = "-s.h5"; + else + suffix = NULL; + } } } /* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX * could be of value -1 if it is not defined. */ - isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO==driver); + isppdriver = H5P_DEFAULT != fapl && (H5FD_MPIO == driver); /* Check HDF5_NOCLEANUP environment setting. * (The #ifdef is needed to prevent compile failure in case MPI is not diff --git a/test/h5test.h b/test/h5test.h index ada52ad719..448813e12d 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -133,6 +133,7 @@ extern "C" { H5TEST_DLL void h5_clean_files(const char *base_name[], hid_t fapl); H5TEST_DLL int h5_cleanup(const char *base_name[], hid_t fapl); H5TEST_DLL char *h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size); +H5TEST_DLL char *h5_fixname_superblock(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL char *h5_fixname_no_suffix(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL char *h5_fixname_printf(const char *base_name, hid_t fapl, char *fullname, size_t size); H5TEST_DLL hid_t h5_fileaccess(void); diff --git a/test/tfile.c b/test/tfile.c index acf2bd68cf..adeec942b4 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1594,54 +1594,72 @@ test_file_perm2(void) ** H5Fis_accessible() API call. ** *****************************************************************/ +#define FILE_IS_ACCESSIBLE "tfile_is_accessible" static void test_file_is_accessible(const char *env_h5_drvr) { - hid_t fid; /* File opened with read-write permission */ - hid_t fcpl_id; /* File creation property list */ - hid_t fapl = -1; /* File access property list */ - int fd; /* POSIX file descriptor */ - char filename[FILENAME_LEN]; /* Filename to use */ - ssize_t nbytes; /* Number of bytes written */ - unsigned u; /* Local index variable */ - unsigned char buf[1024]; /* Buffer of data to write */ - htri_t status; /* Whether a file is an HDF5 file */ - hbool_t single_file_vfd; /* Whether VFD used is a single file */ - herr_t ret; + hid_t fid = H5I_INVALID_HID; /* File opened with read-write permission */ + hid_t fcpl_id = H5I_INVALID_HID; /* File creation property list */ + hid_t fapl_id = H5I_INVALID_HID; /* File access property list */ + int fd; /* POSIX file descriptor */ + char filename[FILENAME_LEN]; /* Filename to use */ + char sb_filename[FILENAME_LEN]; /* Name of file w/ superblock */ + ssize_t nbytes; /* Number of bytes written */ + unsigned u; /* Local index variable */ + unsigned char buf[1024]; /* Buffer of data to write */ + htri_t is_hdf5; /* Whether a file is an HDF5 file */ + int posix_ret; /* Return value from POSIX calls */ + herr_t ret; /* Return value from HDF5 calls */ /* Output message about test being performed */ MESSAGE(5, ("Testing Detection of HDF5 Files\n")); /* Get FAPL */ - fapl = h5_fileaccess(); - CHECK(fapl, FAIL, "H5Pcreate"); - h5_fixname(FILE1, fapl, filename, sizeof filename); + fapl_id = h5_fileaccess(); + CHECK(fapl_id, H5I_INVALID_HID, "H5Pcreate"); + + /* Fix up filenames + * For VFDs that create multiple files, we also need the name + * of the file with the superblock. With single-file VFDs, this + * will be equal to the one from h5_fixname(). + */ + h5_fixname(FILE_IS_ACCESSIBLE, fapl_id, filename, sizeof(filename)); + h5_fixname_superblock(FILE_IS_ACCESSIBLE, fapl_id, sb_filename, sizeof(filename)); + + /****************/ + /* Normal usage */ + /****************/ /* Create a file */ - fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); - CHECK(fid, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Close file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, TRUE, "H5Fis_accessible"); + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); + /*******************************/ + /* Non-default user block size */ + /*******************************/ - /* This test is not currently working for the family VFD */ + /* This test is not currently working for the family VFD. + * There are failures when creating files with userblocks. + */ if(0 != HDstrcmp(env_h5_drvr, "family")) { /* Create a file creation property list with a non-default user block size */ fcpl_id = H5Pcreate(H5P_FILE_CREATE); - CHECK(fcpl_id, FAIL, "H5Pcreate"); + CHECK(fcpl_id, H5I_INVALID_HID, "H5Pcreate"); ret = H5Pset_userblock(fcpl_id, (hsize_t)2048); CHECK(ret, FAIL, "H5Pset_userblock"); /* Create file with non-default user block */ - fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl); - CHECK(fid, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Release file-creation property list */ ret = H5Pclose(fcpl_id); @@ -1652,37 +1670,53 @@ test_file_is_accessible(const char *env_h5_drvr) CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, TRUE, "H5Fis_accessible"); + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, TRUE, "H5Fis_accessible"); } /* end if */ + /***********************/ + /* EMPTY non-HDF5 file */ + /***********************/ - /* This test only works for VFDs with a single file */ - single_file_vfd = (hbool_t)(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")); - if(single_file_vfd) { - /* Create non-HDF5 file and check it */ - fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW); - CHECK(fd, FAIL, "HDopen"); + /* Create non-HDF5 file and check it */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); - /* Initialize information to write */ - for (u=0; u<1024; u++) - buf[u]=(unsigned char)u; + /* Close the file */ + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); - /* Write some information */ - nbytes = HDwrite(fd, buf, (size_t)1024); - VERIFY(nbytes, 1024, "HDwrite"); + /* Verify that the file is NOT an HDF5 file */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, FALSE, "H5Fis_accessible (empty non-HDF5 file)"); - /* Close the file */ - ret = HDclose(fd); - CHECK(ret, FAIL, "HDclose"); + /***************************/ + /* Non-empty non-HDF5 file */ + /***************************/ + + /* Create non-HDF5 file and check it */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); + + /* Initialize information to write */ + for (u = 0; u < 1024; u++) + buf[u]=(unsigned char)u; + + /* Write some information */ + nbytes = HDwrite(fd, buf, (size_t)1024); + VERIFY(nbytes, 1024, "HDwrite"); + + /* Close the file */ + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); + + /* Verify that the file is not an HDF5 file */ + is_hdf5 = H5Fis_accessible(filename, fapl_id); + VERIFY(is_hdf5, FALSE, "H5Fis_accessible (non-HDF5 file)"); - /* Verify that the file is not an HDF5 file */ - status = H5Fis_accessible(filename, fapl); - VERIFY(status, FALSE, "H5Fis_accessible"); - } /* end if */ /* Close property list */ - ret = H5Pclose(fapl); + ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); } /* end test_file_is_accessible() */ @@ -1697,70 +1731,97 @@ test_file_is_accessible(const char *env_h5_drvr) *****************************************************************/ #ifndef H5_NO_DEPRECATED_SYMBOLS static void -test_file_ishdf5(void) +test_file_ishdf5(const char *env_h5_drvr) { - hid_t file; /* File opened with read-write permission */ - hid_t fcpl; /* File creation property list */ - hid_t fapl = -1; /* File access property list */ - int fd; /* File Descriptor */ - char filename[FILENAME_LEN]; /* Filename to use */ - ssize_t nbytes; /* Number of bytes written */ - unsigned u; /* Local index variable */ - unsigned char buf[1024]; /* Buffer of data to write */ - htri_t status; /* Whether a file is an HDF5 file */ - herr_t ret; + hid_t fid = H5I_INVALID_HID; /* File opened with read-write permission */ + hid_t fcpl_id = H5I_INVALID_HID; /* File creation property list */ + hid_t fapl_id = H5I_INVALID_HID; /* File access property list */ + int fd; /* POSIX file descriptor */ + char filename[FILENAME_LEN]; /* Filename to use */ + char sb_filename[FILENAME_LEN]; /* Name of file w/ superblock */ + ssize_t nbytes; /* Number of bytes written */ + unsigned u; /* Local index variable */ + unsigned char buf[1024]; /* Buffer of data to write */ + htri_t is_hdf5; /* Whether a file is an HDF5 file */ + int posix_ret; /* Return value from POSIX calls */ + herr_t ret; /* Return value from HDF5 calls */ /* Output message about test being performed */ MESSAGE(5, ("Testing Detection of HDF5 Files (using deprecated H5Fis_hdf5() call)\n")); /* Get FAPL */ - fapl = h5_fileaccess(); - CHECK(fapl, FAIL, "H5Pcreate"); - h5_fixname(FILE1, fapl, filename, sizeof filename); + fapl_id = h5_fileaccess(); + CHECK(fapl_id, H5I_INVALID_HID, "H5Pcreate"); + + /* Fix up filenames + * For VFDs that create multiple files, we also need the name + * of the file with the superblock. With single-file VFDs, this + * will be equal to the one from h5_fixname(). + */ + h5_fixname(FILE_IS_ACCESSIBLE, fapl_id, filename, sizeof(filename)); + h5_fixname_superblock(FILE_IS_ACCESSIBLE, fapl_id, sb_filename, sizeof(filename)); + + /****************/ + /* Normal usage */ + /****************/ /* Create a file */ - file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); - CHECK(file, FAIL, "H5Fcreate"); + fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); /* Close file */ - ret = H5Fclose(file); + ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); /* Verify that the file is an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, TRUE, "H5Fis_hdf5"); + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, TRUE, "H5Fis_hdf5"); + /*******************************/ + /* Non-default user block size */ + /*******************************/ - /* Create a file creation property list with a non-default user block size */ - fcpl = H5Pcreate(H5P_FILE_CREATE); - CHECK(fcpl, FAIL, "H5Pcreate"); + /* This test is not currently working for the family VFD. + * There are failures when creating files with userblocks. + */ + if(0 != HDstrcmp(env_h5_drvr, "family")) { + /* Create a file creation property list with a non-default user block size */ + fcpl_id = H5Pcreate(H5P_FILE_CREATE); + CHECK(fcpl_id, H5I_INVALID_HID, "H5Pcreate"); - ret = H5Pset_userblock(fcpl, (hsize_t)2048); - CHECK(ret, FAIL, "H5Pset_userblock"); + ret = H5Pset_userblock(fcpl_id, (hsize_t)2048); + CHECK(ret, FAIL, "H5Pset_userblock"); - /* Create file with non-default user block */ - file = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl); - CHECK(file, FAIL, "H5Fcreate"); + /* Create file with non-default user block */ + fid = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, fapl_id); + CHECK(fid, H5I_INVALID_HID, "H5Fcreate"); - /* Release file-creation property list */ - ret = H5Pclose(fcpl); - CHECK(ret, FAIL, "H5Pclose"); + /* Release file creation property list */ + ret = H5Pclose(fcpl_id); + CHECK(ret, FAIL, "H5Pclose"); - /* Close file */ - ret = H5Fclose(file); - CHECK(ret, FAIL, "H5Fclose"); + /* Close file */ + ret = H5Fclose(fid); + CHECK(ret, FAIL, "H5Fclose"); - /* Verify that the file is an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, TRUE, "H5Fis_hdf5"); + /* Verify that the file is an HDF5 file */ + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, TRUE, "H5Fis_hdf5"); + } /* end if */ + /***************************/ + /* Non-empty non-HDF5 file */ + /***************************/ - /* Create non-HDF5 file and check it */ - fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW); - CHECK(fd, FAIL, "HDopen"); + /* Create non-HDF5 file. Use the calculated superblock + * filename to avoid the format strings that will make + * open(2) sad. + */ + fd = HDopen(sb_filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW); + CHECK(fd, (-1), "HDopen"); /* Initialize information to write */ - for(u=0; u<1024; u++) + for(u = 0; u < 1024; u++) buf[u]=(unsigned char)u; /* Write some information */ @@ -1768,15 +1829,16 @@ test_file_ishdf5(void) VERIFY(nbytes, 1024, "HDwrite"); /* Close the file */ - ret = HDclose(fd); - CHECK(ret, FAIL, "HDclose"); + posix_ret = HDclose(fd); + CHECK(posix_ret, (-1), "HDclose"); /* Verify that the file is not an HDF5 file */ - status = H5Fis_hdf5(filename); - VERIFY(status, FALSE, "H5Fis_hdf5"); + is_hdf5 = H5Fis_hdf5(sb_filename); + VERIFY(is_hdf5, FALSE, "H5Fis_hdf5"); + /* Close property list */ - ret = H5Pclose(fapl); + ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); } /* end test_file_ishdf5() */ @@ -7537,7 +7599,6 @@ test_deprec(void) void test_file(void) { - hbool_t single_file_vfd; /* Whether VFD used is a single file */ const char *env_h5_drvr; /* File Driver value from environment */ /* Output message about test being performed */ @@ -7547,7 +7608,6 @@ test_file(void) env_h5_drvr = HDgetenv("HDF5_DRIVER"); if(env_h5_drvr == NULL) env_h5_drvr = "nomatch"; - single_file_vfd = (hbool_t)(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family")); test_file_create(); /* Test file creation(also creation templates)*/ test_file_open(); /* Test file opening */ @@ -7593,10 +7653,7 @@ test_file(void) test_incr_filesize(); /* Test H5Fincrement_filesize() and H5Fget_eoa() */ test_min_dset_ohdr(); /* Test datset object header minimization */ #ifndef H5_NO_DEPRECATED_SYMBOLS - if(single_file_vfd) - test_file_ishdf5(); /* Test detecting HDF5 files correctly */ - else - MESSAGE(5, ("Skipping testing detection of HDF5 Files (using deprecated H5Fis_hdf5() call for non-single file VFDs)\n")); + test_file_ishdf5(env_h5_drvr); /* Test detecting HDF5 files correctly */ test_deprec(); /* Test deprecated routines */ #endif /* H5_NO_DEPRECATED_SYMBOLS */ } /* test_file() */ From e2eaac93386feadef194962cb258e660038d39f1 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 25 Apr 2019 10:43:54 -0500 Subject: [PATCH 16/32] ESE-97 add vol_plugin test to CMake builds --- test/CMakeLists.txt | 21 +++++++++++++++++++-- test/CMakeTests.cmake | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0b9911f9c5..c7888b8923 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -62,7 +62,7 @@ if (BUILD_SHARED_LIBS) endif () ################################################################################# -# If filter plugin tests can be tested +# If filter and vol plugin tests can be tested ################################################################################# if (BUILD_SHARED_LIBS) # make plugins dir @@ -131,6 +131,11 @@ if (BUILD_SHARED_LIBS) ) endforeach () + ################################################################################# + # make vol plugins dir + ################################################################################# + file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/null_vol_plugin_dir") + #----------------------------------------------------------------------------- # Define VOL Plugin Test Sources #----------------------------------------------------------------------------- @@ -159,7 +164,7 @@ if (BUILD_SHARED_LIBS) COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different "$" - "${CMAKE_BINARY_DIR}/vol/$" + "${CMAKE_BINARY_DIR}/null_vol_plugin_dir/$" ) endforeach () endif () @@ -458,12 +463,24 @@ if (BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (filter_plugin SHARED) target_link_libraries (filter_plugin PRIVATE ${HDF5_TEST_LIB_TARGET}) set_target_properties (filter_plugin PROPERTIES FOLDER test) + + add_executable (vol_plugin ${HDF5_TEST_SOURCE_DIR}/vol_plugin.c) + target_include_directories(vol_plugin PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") + TARGET_C_PROPERTIES (vol_plugin SHARED) + target_link_libraries (vol_plugin PRIVATE ${HDF5_TEST_LIB_TARGET}) + set_target_properties (vol_plugin PROPERTIES FOLDER test) else () add_executable (filter_plugin ${HDF5_TEST_SOURCE_DIR}/filter_plugin.c) target_include_directories(filter_plugin PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") TARGET_C_PROPERTIES (filter_plugin STATIC) target_link_libraries (filter_plugin PRIVATE ${HDF5_TEST_LIB_TARGET}) set_target_properties (filter_plugin PROPERTIES FOLDER test) + + add_executable (vol_plugin ${HDF5_TEST_SOURCE_DIR}/vol_plugin.c) + target_include_directories(vol_plugin PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") + TARGET_C_PROPERTIES (vol_plugin STATIC) + target_link_libraries (vol_plugin PRIVATE ${HDF5_TEST_LIB_TARGET}) + set_target_properties (vol_plugin PROPERTIES FOLDER test) endif () ############################################################################## diff --git a/test/CMakeTests.cmake b/test/CMakeTests.cmake index 8c4e1ceb4d..3e6add011e 100644 --- a/test/CMakeTests.cmake +++ b/test/CMakeTests.cmake @@ -1293,6 +1293,25 @@ endif () ############################################################################## ############################################################################## +############################################################################## +### V O L P L U G I N T E S T S +############################################################################## +if (BUILD_SHARED_LIBS) + if (WIN32) + set (CMAKE_SEP "\;") + set (BIN_REL_PATH "../../") + else () + set (CMAKE_SEP ":") + set (BIN_REL_PATH "../") + endif () + + add_test (NAME H5PLUGIN-vol_plugin COMMAND $) + set_tests_properties (H5PLUGIN-vol_plugin PROPERTIES + ENVIRONMENT "HDF5_PLUGIN_PATH=${CMAKE_BINARY_DIR}/null_vol_plugin_dir;srcdir=${HDF5_TEST_BINARY_DIR}" + WORKING_DIRECTORY ${HDF5_TEST_BINARY_DIR} + ) +endif () + if (HDF5_TEST_PASSTHROUGH_VOL) include (CMakePassthroughVOLTests.cmake) endif () From 2c9025dcb96e5445ce878fa9e1d05fca738ae328 Mon Sep 17 00:00:00 2001 From: Songyu Lu Date: Thu, 25 Apr 2019 11:55:45 -0500 Subject: [PATCH 17/32] HDFFV-10760 Skipping external_env.c and vds_env.c for CMake to do VOL check and VFD check. Temporarily skipping external_env.c and vds_env.c for VFD check and VOL check in CMake following the example of links_env. Leave them for future work. --- test/CMakePassthroughVOLTests.cmake | 2 ++ test/CMakeVFDTests.cmake | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/CMakePassthroughVOLTests.cmake b/test/CMakePassthroughVOLTests.cmake index 8c7d7979e7..928654e652 100644 --- a/test/CMakePassthroughVOLTests.cmake +++ b/test/CMakePassthroughVOLTests.cmake @@ -99,6 +99,8 @@ endif () tcheck_version testmeta links_env + external_env + vds_env ) if (NOT CYGWIN) list (REMOVE_ITEM H5_VOL_SKIP_TESTS big cache) diff --git a/test/CMakeVFDTests.cmake b/test/CMakeVFDTests.cmake index 64ccacd1ec..383b2f4212 100644 --- a/test/CMakeVFDTests.cmake +++ b/test/CMakeVFDTests.cmake @@ -102,6 +102,8 @@ endif () tcheck_version testmeta links_env + external_env + vds_env ) if (NOT CYGWIN) list (REMOVE_ITEM H5_VFD_SKIP_TESTS big cache) From 53ffbf4bf89350b5d6b90c11585f39af94209754 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 25 Apr 2019 12:57:23 -0500 Subject: [PATCH 18/32] Cast enum to int, for strict varargs handling. --- src/H5L.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/H5L.c b/src/H5L.c index 183fee4436..98976a6bb4 100644 --- a/src/H5L.c +++ b/src/H5L.c @@ -648,7 +648,7 @@ H5Lcreate_ud(hid_t link_loc_id, const char *link_name, H5L_type_t link_type, HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "invalid location identifier") /* Create external link */ - if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, link_type, udata, udata_size) < 0) + if(H5VL_link_create(H5VL_LINK_CREATE_UD, vol_obj, &loc_params, lcpl_id, lapl_id, H5P_DATASET_XFER_DEFAULT, H5_REQUEST_NULL, (int)link_type, udata, udata_size) < 0) HGOTO_ERROR(H5E_LINK, H5E_CANTINIT, FAIL, "unable to create link") done: From e66bf948a7acba0ddc76239f6d02f17c8b10eb0f Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 26 Apr 2019 12:10:54 -0700 Subject: [PATCH 19/32] Fix for split VFD and file cleanup when testing H5Fis_hdf5 and H5Fis_accessible in tfile.c. --- test/h5test.c | 30 ++++++++++++++++++++++++++---- test/tfile.c | 6 ++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/test/h5test.c b/test/h5test.c index 3b17c72033..dba8cf7082 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -574,6 +574,7 @@ h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, char *fullname, size_t size, hbool_t nest_printf, hbool_t subst_for_superblock) { const char *prefix = NULL; + const char *env = NULL; /* HDF5_DRIVER environment variable */ char *ptr, last = '\0'; const char *suffix = _suffix; size_t i, j; @@ -598,10 +599,31 @@ h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, suffix = nest_printf ? "%%05d.h5" : "%05d.h5"; } else if (H5FD_MULTI == driver) { - if(subst_for_superblock) - suffix = "-s.h5"; - else - suffix = NULL; + + /* Get the environment variable, if it exists, in case + * we are using the split driver since both of those + * use the multi VFD under the hood. + */ + env = HDgetenv("HDF5_DRIVER"); +#ifdef HDF5_DRIVER + /* Use the environment variable, then the compile-time constant */ + if(!env) + env = HDF5_DRIVER; +#endif + if(!HDstrcmp(env, "split")) { + /* split VFD */ + if(subst_for_superblock) + suffix = "-m.h5"; + else + suffix = NULL; + } + else { + /* multi VFD */ + if(subst_for_superblock) + suffix = "-s.h5"; + else + suffix = NULL; + } } } } diff --git a/test/tfile.c b/test/tfile.c index adeec942b4..695d43791e 100644 --- a/test/tfile.c +++ b/test/tfile.c @@ -1715,6 +1715,9 @@ test_file_is_accessible(const char *env_h5_drvr) VERIFY(is_hdf5, FALSE, "H5Fis_accessible (non-HDF5 file)"); + /* Clean up files */ + h5_delete_test_file(filename, fapl_id); + /* Close property list */ ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); @@ -1837,6 +1840,9 @@ test_file_ishdf5(const char *env_h5_drvr) VERIFY(is_hdf5, FALSE, "H5Fis_hdf5"); + /* Clean up files */ + h5_delete_test_file(filename, fapl_id); + /* Close property list */ ret = H5Pclose(fapl_id); CHECK(ret, FAIL, "H5Pclose"); From 0c896fcdf9ebde870ead2dcee9a82e135554c28d Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 29 Apr 2019 14:50:13 -0700 Subject: [PATCH 20/32] Missed an env check before strcmp. --- test/h5test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/h5test.c b/test/h5test.c index dba8cf7082..59ccfe4612 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -610,7 +610,7 @@ h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, if(!env) env = HDF5_DRIVER; #endif - if(!HDstrcmp(env, "split")) { + if(env && !HDstrcmp(env, "split")) { /* split VFD */ if(subst_for_superblock) suffix = "-m.h5"; From 0a73ce19a4e7f57fe1bb06ca5be8d4697fe079aa Mon Sep 17 00:00:00 2001 From: Jordan Henderson Date: Tue, 30 Apr 2019 15:28:30 -0500 Subject: [PATCH 21/32] Fix Java JUnit-TestH5P failure on 32-bit arch --- java/src/jni/h5pFCPLImp.c | 2 +- release_docs/RELEASE.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/java/src/jni/h5pFCPLImp.c b/java/src/jni/h5pFCPLImp.c index 9c82ba6480..2160496a4d 100644 --- a/java/src/jni/h5pFCPLImp.c +++ b/java/src/jni/h5pFCPLImp.c @@ -201,7 +201,7 @@ Java_hdf_hdf5lib_H5_H5Pget_1sym_1k done: if (theArray) - UNPIN_LONG_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); + UNPIN_INT_ARRAY(ENVONLY, size, theArray, (status < 0) ? JNI_ABORT : 0); return (jint)status; } /* end Java_hdf_hdf5lib_H5_H5Pget_1sym_1k */ diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index db0629cd0e..30e3ed906a 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -197,6 +197,10 @@ New Features Java Library: ---------------- + - Fix a failure in JUnit-TestH5P on 32-bit architectures + + (JTH - 2019/04/30) + - Duplicate the data read/write functions of Datasets for Attributes. Region references could not be displayed for attributes as they could From 87e491da88d49134e20418733f64a3307b5cd74c Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Tue, 30 Apr 2019 16:42:08 -0500 Subject: [PATCH 22/32] HDFFV-10776 missing compiler flags --- config/gnu-flags | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/gnu-flags b/config/gnu-flags index 225f07252a..7df72c7c93 100644 --- a/config/gnu-flags +++ b/config/gnu-flags @@ -1,4 +1,4 @@ -# -*- shell-script -*- +# -*- shell-script -*- # # Copyright by The HDF Group. # Copyright by the Board of Trustees of the University of Illinois. @@ -37,10 +37,10 @@ if test X = "X$cc_flags_set"; then cc_vendor=`echo $cc_version |sed 's/\([a-z]*\).*/\1/'` cc_version=`echo $cc_version |sed 's/[-a-z]//g'` if test X = "X$cc_vendor" -a X != "X$cc_version"; then - cc_vendor=gcc + cc_vendor=gcc fi if test "-" != "$cc_vendor-$cc_version"; then - echo "compiler '$CC' is GNU $cc_vendor-$cc_version" + echo "compiler '$CC' is GNU $cc_vendor-$cc_version" fi # Some version numbers @@ -87,7 +87,7 @@ case "$cc_vendor-$cc_version" in case "$host_os-$host_cpu" in # cygwin needs the "-std=c99" flag removed, so make # a specific case for Cygwin without the flag and a default - # case to add the flag everywhere else + # case to add the flag everywhere else cygwin-*) ;; @@ -111,7 +111,7 @@ case "$cc_vendor-$cc_version" in # know if they do start showing up. # # NOTE: Don't add -Wpadded here since we can't/won't fix the (many) - # warnings that are emitted. If you need it, add it from the + # warnings that are emitted. If you need it, add it from the # environment variable at configure time. H5_CFLAGS="$H5_CFLAGS $arch -pedantic -Wall -Wextra -Wbad-function-cast -Wc++-compat -Wcast-align" H5_CFLAGS="$H5_CFLAGS -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdisabled-optimization -Wfloat-equal" @@ -126,7 +126,7 @@ case "$cc_vendor-$cc_version" in gcc-4.*) PROD_CFLAGS= ;; - gcc-[56].*) + gcc-[56789].*) PROD_CFLAGS="-fstdarg-opt" ;; *) @@ -140,7 +140,7 @@ case "$cc_vendor-$cc_version" in # NDEBUG is handled explicitly by the configure script # -g is handled by the symbols flags case "$cc_vendor-$cc_version" in - gcc-[56].*) + gcc-[56789].*) DEBUG_CFLAGS="-ftrapv -fno-common" ;; *) @@ -165,7 +165,7 @@ case "$cc_vendor-$cc_version" in HIGH_OPT_CFLAGS="-O3" DEBUG_OPT_CFLAGS= ;; - gcc-[56].*) + gcc-[56789].*) HIGH_OPT_CFLAGS="-O3" DEBUG_OPT_CFLAGS="-Og" ;; @@ -190,7 +190,7 @@ case "$cc_vendor-$cc_version" in # When the gcc 7.x release is out, we should check for additional flags to # include and break it out into it's own section, like the other versions # below. -QAK - gcc-6*) + gcc-[6789].*) # Append warning flags that only gcc 4.2+ knows about # (none, or incorporated in -Wall / -Wextra now) From e0de04d355287d37187e707d03cc309c66d17510 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 1 May 2019 12:31:55 -0500 Subject: [PATCH 23/32] Separate out MPI tests that fail on MPI version --- testpar/CMakeTests.cmake | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index 214801b032..e4f6dfb8b8 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -25,10 +25,14 @@ add_test (NAME MPI_TEST-clear-testphdf5-objects ) set_tests_properties (MPI_TEST-clear-testphdf5-objects PROPERTIES FIXTURES_SETUP par_clear_testphdf5) +set (SKIP_testphdf5 + cchunk3 + tldsc +) set (SKIP_testphdf5 "") -#if (HDF5_OPENMPI_VERSION_SKIP) -# set (SKIP_testphdf5 "${SKIP_testphdf5};-x;ecdsetw") -#endif () +foreach (skiptest SKIP_testphdf5) + set (SKIP_testphdf5 "${SKIP_testphdf5};-x;${skiptest}") +endforeach () add_test (NAME MPI_TEST_testphdf5 COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} ${SKIP_testphdf5}) set_tests_properties (MPI_TEST_testphdf5 PROPERTIES @@ -41,6 +45,20 @@ if (last_test) endif () set (last_test "MPI_TEST_testphdf5") +#execute the skipped tests +foreach (skiptest SKIP_testphdf5) + add_test (NAME MPI_TEST_testphdf5_${skiptest} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} -o ${skiptest}) + set_tests_properties (MPI_TEST_testphdf5_${skiptest} PROPERTIES + FIXTURES_REQUIRED par_clear_testphdf5 + ENVIRONMENT "HDF5_ALARM_SECONDS=3600;srcdir=${HDF5_TEST_PAR_BINARY_DIR}" + WORKING_DIRECTORY ${HDF5_TEST_PAR_BINARY_DIR} + ) + if (last_test) + set_tests_properties (MPI_TEST_testphdf5_${skiptest} PROPERTIES DEPENDS ${last_test}) + endif () + set (last_test "MPI_TEST_testphdf5_${skiptest}") +endforeach () + #if (HDF5_OPENMPI_VERSION_SKIP) # list (REMOVE_ITEM H5P_TESTS t_shapesame) #endif () From 725f75baa7d85b9b269c9da07e24994c71dab728 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 1 May 2019 13:24:02 -0500 Subject: [PATCH 24/32] Correct varname --- testpar/CMakeTests.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index e4f6dfb8b8..aaaa4a4564 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -25,12 +25,12 @@ add_test (NAME MPI_TEST-clear-testphdf5-objects ) set_tests_properties (MPI_TEST-clear-testphdf5-objects PROPERTIES FIXTURES_SETUP par_clear_testphdf5) -set (SKIP_testphdf5 +set (SKIP_tests cchunk3 tldsc ) set (SKIP_testphdf5 "") -foreach (skiptest SKIP_testphdf5) +foreach (skiptest SKIP_tests) set (SKIP_testphdf5 "${SKIP_testphdf5};-x;${skiptest}") endforeach () @@ -46,7 +46,7 @@ endif () set (last_test "MPI_TEST_testphdf5") #execute the skipped tests -foreach (skiptest SKIP_testphdf5) +foreach (skiptest SKIP_tests) add_test (NAME MPI_TEST_testphdf5_${skiptest} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} -o ${skiptest}) set_tests_properties (MPI_TEST_testphdf5_${skiptest} PROPERTIES FIXTURES_REQUIRED par_clear_testphdf5 From 854223e3fcf5e90ad5fae25ff05deb4276ce001b Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 1 May 2019 14:09:06 -0500 Subject: [PATCH 25/32] Add missing default --- config/cmake/scripts/HDF5config.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index 805aee1a46..3c1271f722 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -177,6 +177,7 @@ if (NOT DEFINED HPC) endif () endif () else () + set (CTEST_SITE "HPC.XXXX") set (CTEST_CMAKE_GENERATOR "Unix Makefiles") include (${CTEST_SOURCE_DIRECTORY}/config/cmake/scripts/HPC/${HPC}-HDF5options.cmake) endif () From c030a7123d1f7365c9ab069ba76192186cfe9d33 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 1 May 2019 14:46:13 -0500 Subject: [PATCH 26/32] Correct var usage syntax --- testpar/CMakeTests.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index aaaa4a4564..4faa86b89b 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -30,7 +30,7 @@ set (SKIP_tests tldsc ) set (SKIP_testphdf5 "") -foreach (skiptest SKIP_tests) +foreach (skiptest ${SKIP_tests}) set (SKIP_testphdf5 "${SKIP_testphdf5};-x;${skiptest}") endforeach () @@ -46,7 +46,7 @@ endif () set (last_test "MPI_TEST_testphdf5") #execute the skipped tests -foreach (skiptest SKIP_tests) +foreach (skiptest ${SKIP_tests}) add_test (NAME MPI_TEST_testphdf5_${skiptest} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $ ${MPIEXEC_POSTFLAGS} -o ${skiptest}) set_tests_properties (MPI_TEST_testphdf5_${skiptest} PROPERTIES FIXTURES_REQUIRED par_clear_testphdf5 From ee35fb8a7fe3804e4146c54020b6e2272ab251e3 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Wed, 1 May 2019 16:23:08 -0500 Subject: [PATCH 27/32] Change default for HPC --- config/cmake/scripts/HDF5config.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index 3c1271f722..8262829d09 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -177,7 +177,7 @@ if (NOT DEFINED HPC) endif () endif () else () - set (CTEST_SITE "HPC.XXXX") + set (CTEST_SITE "${SITE_OS_NAME}") set (CTEST_CMAKE_GENERATOR "Unix Makefiles") include (${CTEST_SOURCE_DIRECTORY}/config/cmake/scripts/HPC/${HPC}-HDF5options.cmake) endif () From c643cc05316e11471c4bef30cd09b9d4437f85fd Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 2 May 2019 10:27:49 -0500 Subject: [PATCH 28/32] Pull out another failing test --- testpar/CMakeTests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index 4faa86b89b..20959257bb 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -27,6 +27,7 @@ set_tests_properties (MPI_TEST-clear-testphdf5-objects PROPERTIES FIXTURES_SETUP set (SKIP_tests cchunk3 + ecdsetw tldsc ) set (SKIP_testphdf5 "") From 1cec61a775901d549d67e522d8eb91c600a6dc0b Mon Sep 17 00:00:00 2001 From: hdftest Date: Thu, 2 May 2019 10:42:53 -0500 Subject: [PATCH 29/32] Snapshot version 1.11 release 5. Update version to 1.11.6. --- README.txt | 2 +- c++/src/cpp_doc_config | 2 +- config/cmake/scripts/HDF5config.cmake | 2 +- configure.ac | 2 +- java/src/hdf/hdf5lib/H5.java | 4 ++-- java/test/TestH5.java | 4 ++-- release_docs/RELEASE.txt | 2 +- src/H5public.h | 4 ++-- .../h5repack_layout.h5-plugin_version_test.ddl | 14 +++++++------- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.txt b/README.txt index d3d85cf74d..64f1345d3c 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -HDF5 version 1.11.5 currently under development +HDF5 version 1.11.6 currently under development ------------------------------------------------------------------------------ Please refer to the release_docs/INSTALL file for installation instructions. diff --git a/c++/src/cpp_doc_config b/c++/src/cpp_doc_config index c1961ec287..14ca90cf6e 100644 --- a/c++/src/cpp_doc_config +++ b/c++/src/cpp_doc_config @@ -38,7 +38,7 @@ PROJECT_NAME = # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = "1.11.5" +PROJECT_NUMBER = "1.11.6" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/config/cmake/scripts/HDF5config.cmake b/config/cmake/scripts/HDF5config.cmake index 8262829d09..0d85b4225d 100644 --- a/config/cmake/scripts/HDF5config.cmake +++ b/config/cmake/scripts/HDF5config.cmake @@ -34,7 +34,7 @@ cmake_minimum_required (VERSION 3.10) # CTEST_SOURCE_NAME - source folder ############################################################################## -set (CTEST_SOURCE_VERSION "1.11.5") +set (CTEST_SOURCE_VERSION "1.11.6") set (CTEST_SOURCE_VERSEXT "") ############################################################################## diff --git a/configure.ac b/configure.ac index 0d0e0df630..cf9cd64e3c 100644 --- a/configure.ac +++ b/configure.ac @@ -24,7 +24,7 @@ AC_PREREQ([2.69]) ## NOTE: Do not forget to change the version number here when we do a ## release!!! ## -AC_INIT([HDF5], [1.11.5], [help@hdfgroup.org]) +AC_INIT([HDF5], [1.11.6], [help@hdfgroup.org]) AC_CONFIG_SRCDIR([src/H5.c]) AC_CONFIG_HEADERS([src/H5config.h]) diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index e874732725..a1a8ede806 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -212,7 +212,7 @@ import hdf.hdf5lib.structs.H5O_info_t; * exception handlers to print out the HDF-5 error stack. *
* - * @version HDF5 1.11.5
+ * @version HDF5 1.11.6
* See also: hdf.hdf5lib.HDFArray
* hdf.hdf5lib.HDF5Constants
* hdf.hdf5lib.HDF5CDataTypes
@@ -235,7 +235,7 @@ public class H5 implements java.io.Serializable { * * Make sure to update the versions number when a different library is used. */ - public final static int LIB_VERSION[] = { 1, 11, 5 }; + public final static int LIB_VERSION[] = { 1, 11, 6 }; public final static String H5PATH_PROPERTY_KEY = "hdf.hdf5lib.H5.hdf5lib"; diff --git a/java/test/TestH5.java b/java/test/TestH5.java index 1d24724e76..d63ef01468 100644 --- a/java/test/TestH5.java +++ b/java/test/TestH5.java @@ -162,7 +162,7 @@ public class TestH5 { */ @Test public void testH5get_libversion() { - int libversion[] = { 1, 11, 5 }; + int libversion[] = { 1, 11, 6 }; try { H5.H5get_libversion(libversion); @@ -201,7 +201,7 @@ public class TestH5 { */ @Test public void testH5check_version() { - int majnum = 1, minnum = 11, relnum = 5; + int majnum = 1, minnum = 11, relnum = 6; try { H5.H5check_version(majnum, minnum, relnum); diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 30e3ed906a..deaa8715a6 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -1,4 +1,4 @@ -HDF5 version 1.11.5 currently under development +HDF5 version 1.11.6 currently under development ================================================================================ diff --git a/src/H5public.h b/src/H5public.h index 3b53e00981..a7e21f689e 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -93,10 +93,10 @@ extern "C" { /* Version numbers */ #define H5_VERS_MAJOR 1 /* For major interface/format changes */ #define H5_VERS_MINOR 11 /* For minor interface/format changes */ -#define H5_VERS_RELEASE 5 /* For tweaks, bug-fixes, or development */ +#define H5_VERS_RELEASE 6 /* For tweaks, bug-fixes, or development */ #define H5_VERS_SUBRELEASE "" /* For pre-releases like snap0 */ /* Empty string for real releases. */ -#define H5_VERS_INFO "HDF5 library version: 1.11.5" /* Full version string */ +#define H5_VERS_INFO "HDF5 library version: 1.11.6" /* Full version string */ #define H5check() H5check_version(H5_VERS_MAJOR,H5_VERS_MINOR, \ H5_VERS_RELEASE) diff --git a/tools/test/h5repack/testfiles/h5repack_layout.h5-plugin_version_test.ddl b/tools/test/h5repack/testfiles/h5repack_layout.h5-plugin_version_test.ddl index cbf8164a54..3ff2170784 100644 --- a/tools/test/h5repack/testfiles/h5repack_layout.h5-plugin_version_test.ddl +++ b/tools/test/h5repack/testfiles/h5repack_layout.h5-plugin_version_test.ddl @@ -11,7 +11,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -33,7 +33,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -55,7 +55,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -77,7 +77,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -99,7 +99,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -121,7 +121,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { @@ -143,7 +143,7 @@ GROUP "/" { USER_DEFINED_FILTER { FILTER_ID 260 COMMENT dynlib4 - PARAMS { 9 1 11 5 } + PARAMS { 9 1 11 6 } } } FILLVALUE { From b6bebb245b043fae546390c00288a069da785868 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 2 May 2019 12:07:23 -0500 Subject: [PATCH 30/32] Pull a test from default testphdf5 --- testpar/CMakeTests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index 20959257bb..5b601d15e5 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -28,6 +28,7 @@ set_tests_properties (MPI_TEST-clear-testphdf5-objects PROPERTIES FIXTURES_SETUP set (SKIP_tests cchunk3 ecdsetw + eidsetw2 tldsc ) set (SKIP_testphdf5 "") From 813d8fd597b030a248db6316dd98f738c0c61ea8 Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Thu, 2 May 2019 16:18:58 -0500 Subject: [PATCH 31/32] Add final list of single testphdf5 tests --- testpar/CMakeTests.cmake | 10 + testpar/testphdf5.c | 408 +++++++++++++++++++-------------------- 2 files changed, 214 insertions(+), 204 deletions(-) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index 5b601d15e5..4b738c19a2 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -26,10 +26,20 @@ add_test (NAME MPI_TEST-clear-testphdf5-objects set_tests_properties (MPI_TEST-clear-testphdf5-objects PROPERTIES FIXTURES_SETUP par_clear_testphdf5) set (SKIP_tests + cchunk1 + cchunk2 cchunk3 + cchunk4 ecdsetw eidsetw2 + selnone + cngrpw + ingrpr + cschunkw + ccchunkw tldsc + actualio + MC_coll_MD_read ) set (SKIP_testphdf5 "") foreach (skiptest ${SKIP_tests}) diff --git a/testpar/testphdf5.c b/testpar/testphdf5.c index 999e17a2c9..4269066c84 100644 --- a/testpar/testphdf5.c +++ b/testpar/testphdf5.c @@ -26,15 +26,15 @@ int dim0; int dim1; int chunkdim0; int chunkdim1; -int nerrors = 0; /* errors count */ -int ndatasets = 300; /* number of datasets to create*/ +int nerrors = 0; /* errors count */ +int ndatasets = 300; /* number of datasets to create*/ int ngroups = 512; /* number of groups to create in root * group. */ -int facc_type = FACC_MPIO; /*Test file access type */ +int facc_type = FACC_MPIO; /*Test file access type */ int dxfer_coll_type = DXFER_COLLECTIVE_IO; -H5E_auto2_t old_func; /* previous error handler */ -void *old_client_data; /* previous error handler arg.*/ +H5E_auto2_t old_func; /* previous error handler */ +void *old_client_data; /* previous error handler arg.*/ /* other option flags */ @@ -46,10 +46,10 @@ void *old_client_data; /* previous error handler arg.*/ #define NFILENAME 2 #define PARATESTFILE filenames[0] const char *FILENAME[NFILENAME]={ - "ParaTest", - NULL}; -char filenames[NFILENAME][PATH_MAX]; -hid_t fapl; /* file access property list */ + "ParaTest", + NULL}; +char filenames[NFILENAME][PATH_MAX]; +hid_t fapl; /* file access property list */ #ifdef USE_PAUSE /* pause the process for a moment to allow debugger to attach if desired. */ @@ -62,7 +62,7 @@ void pause_proc(void) { int pid; - h5_stat_t statbuf; + h5_stat_t statbuf; char greenlight[] = "go"; int maxloop = 10; int loops = 0; @@ -80,14 +80,14 @@ void pause_proc(void) if (MAINPROCESS) while ((HDstat(greenlight, &statbuf) == -1) && loops < maxloop){ - if (!loops++){ - printf("Proc %d (%*s, %d): to debug, attach %d\n", - mpi_rank, mpi_namelen, mpi_name, pid, pid); - } - printf("waiting(%ds) for file %s ...\n", time_int, greenlight); - fflush(stdout); + if (!loops++){ + printf("Proc %d (%*s, %d): to debug, attach %d\n", + mpi_rank, mpi_namelen, mpi_name, pid, pid); + } + printf("waiting(%ds) for file %s ...\n", time_int, greenlight); + fflush(stdout); HDsleep(time_int); - } + } MPI_Barrier(MPI_COMM_WORLD); } @@ -99,7 +99,7 @@ int MPI_Init(int *argc, char ***argv) pause_proc(); return (ret_code); } -#endif /* USE_PAUSE */ +#endif /* USE_PAUSE */ /* @@ -109,15 +109,15 @@ static void usage(void) { printf(" [-r] [-w] [-m] [-n] " - "[-o] [-f ] [-d ]\n"); + "[-o] [-f ] [-d ]\n"); printf("\t-m" - "\tset number of datasets for the multiple dataset test\n"); + "\tset number of datasets for the multiple dataset test\n"); printf("\t-n" "\tset number of groups for the multiple group test\n"); printf("\t-f \tfilename prefix\n"); printf("\t-2\t\tuse Split-file together with MPIO\n"); printf("\t-d \tdataset dimensions factors. Defaults (%d,%d)\n", - ROW_FACTOR, COL_FACTOR); + ROW_FACTOR, COL_FACTOR); printf("\t-c \tdataset chunk dimensions. Defaults (dim0/10,dim1/10)\n"); printf("\n"); } @@ -129,7 +129,7 @@ usage(void) static int parse_options(int argc, char **argv) { - int mpi_size, mpi_rank; /* mpi variables */ + int mpi_size, mpi_rank; /* mpi variables */ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size); MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); @@ -140,107 +140,107 @@ parse_options(int argc, char **argv) chunkdim1 = (dim1+9)/10; while (--argc){ - if (**(++argv) != '-'){ - break; - }else{ - switch(*(*argv+1)){ - case 'm': ndatasets = atoi((*argv+1)+1); - if (ndatasets < 0){ - nerrors++; - return(1); - } - break; - case 'n': ngroups = atoi((*argv+1)+1); - if (ngroups < 0){ + if (**(++argv) != '-'){ + break; + }else{ + switch(*(*argv+1)){ + case 'm': ndatasets = atoi((*argv+1)+1); + if (ndatasets < 0){ + nerrors++; + return(1); + } + break; + case 'n': ngroups = atoi((*argv+1)+1); + if (ngroups < 0){ nerrors++; return(1); - } + } break; - case 'f': if (--argc < 1) { - nerrors++; - return(1); - } - if (**(++argv) == '-') { - nerrors++; - return(1); - } - paraprefix = *argv; - break; - case 'i': /* Collective MPI-IO access with independent IO */ - dxfer_coll_type = DXFER_INDEPENDENT_IO; - break; - case '2': /* Use the split-file driver with MPIO access */ - /* Can use $HDF5_METAPREFIX to define the */ - /* meta-file-prefix. */ - facc_type = FACC_MPIO | FACC_SPLIT; - break; - case 'd': /* dimensizes */ - if (--argc < 2){ - nerrors++; - return(1); - } - dim0 = atoi(*(++argv))*mpi_size; - argc--; - dim1 = atoi(*(++argv))*mpi_size; - /* set default chunkdim sizes too */ - chunkdim0 = (dim0+9)/10; - chunkdim1 = (dim1+9)/10; - break; - case 'c': /* chunk dimensions */ - if (--argc < 2){ - nerrors++; - return(1); - } - chunkdim0 = atoi(*(++argv)); - argc--; - chunkdim1 = atoi(*(++argv)); - break; - case 'h': /* print help message--return with nerrors set */ - return(1); - default: printf("Illegal option(%s)\n", *argv); - nerrors++; - return(1); - } - } + case 'f': if (--argc < 1) { + nerrors++; + return(1); + } + if (**(++argv) == '-') { + nerrors++; + return(1); + } + paraprefix = *argv; + break; + case 'i': /* Collective MPI-IO access with independent IO */ + dxfer_coll_type = DXFER_INDEPENDENT_IO; + break; + case '2': /* Use the split-file driver with MPIO access */ + /* Can use $HDF5_METAPREFIX to define the */ + /* meta-file-prefix. */ + facc_type = FACC_MPIO | FACC_SPLIT; + break; + case 'd': /* dimensizes */ + if (--argc < 2){ + nerrors++; + return(1); + } + dim0 = atoi(*(++argv))*mpi_size; + argc--; + dim1 = atoi(*(++argv))*mpi_size; + /* set default chunkdim sizes too */ + chunkdim0 = (dim0+9)/10; + chunkdim1 = (dim1+9)/10; + break; + case 'c': /* chunk dimensions */ + if (--argc < 2){ + nerrors++; + return(1); + } + chunkdim0 = atoi(*(++argv)); + argc--; + chunkdim1 = atoi(*(++argv)); + break; + case 'h': /* print help message--return with nerrors set */ + return(1); + default: printf("Illegal option(%s)\n", *argv); + nerrors++; + return(1); + } + } } /*while*/ /* check validity of dimension and chunk sizes */ if (dim0 <= 0 || dim1 <= 0){ - printf("Illegal dim sizes (%d, %d)\n", dim0, dim1); - nerrors++; - return(1); + printf("Illegal dim sizes (%d, %d)\n", dim0, dim1); + nerrors++; + return(1); } if (chunkdim0 <= 0 || chunkdim1 <= 0){ - printf("Illegal chunkdim sizes (%d, %d)\n", chunkdim0, chunkdim1); - nerrors++; - return(1); + printf("Illegal chunkdim sizes (%d, %d)\n", chunkdim0, chunkdim1); + nerrors++; + return(1); } /* Make sure datasets can be divided into equal portions by the processes */ if ((dim0 % mpi_size) || (dim1 % mpi_size)){ - if (MAINPROCESS) - printf("dim0(%d) and dim1(%d) must be multiples of processes(%d)\n", - dim0, dim1, mpi_size); - nerrors++; - return(1); + if (MAINPROCESS) + printf("dim0(%d) and dim1(%d) must be multiples of processes(%d)\n", + dim0, dim1, mpi_size); + nerrors++; + return(1); } /* compose the test filenames */ { - int i, n; + int i, n; - n = sizeof(FILENAME)/sizeof(FILENAME[0]) - 1; /* exclude the NULL */ + n = sizeof(FILENAME)/sizeof(FILENAME[0]) - 1; /* exclude the NULL */ - for (i=0; i < n; i++) - if (h5_fixname(FILENAME[i],fapl,filenames[i],sizeof(filenames[i])) - == NULL){ - printf("h5_fixname failed\n"); - nerrors++; - return(1); - } - printf("Test filenames are:\n"); - for (i=0; i < n; i++) - printf(" %s\n", filenames[i]); + for (i=0; i < n; i++) + if (h5_fixname(FILENAME[i],fapl,filenames[i],sizeof(filenames[i])) + == NULL){ + printf("h5_fixname failed\n"); + nerrors++; + return(1); + } + printf("Test filenames are:\n"); + for (i=0; i < n; i++) + printf(" %s\n", filenames[i]); } return(0); @@ -255,7 +255,7 @@ create_faccess_plist(MPI_Comm comm, MPI_Info info, int l_facc_type) { hid_t ret_pl = -1; herr_t ret; /* generic return value */ - int mpi_rank; /* mpi variables */ + int mpi_rank; /* mpi variables */ /* need the rank for error checking macros */ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); @@ -264,36 +264,36 @@ create_faccess_plist(MPI_Comm comm, MPI_Info info, int l_facc_type) VRFY((ret_pl >= 0), "H5P_FILE_ACCESS"); if (l_facc_type == FACC_DEFAULT) - return (ret_pl); + return (ret_pl); if (l_facc_type == FACC_MPIO){ - /* set Parallel access with communicator */ - ret = H5Pset_fapl_mpio(ret_pl, comm, info); - VRFY((ret >= 0), ""); + /* set Parallel access with communicator */ + ret = H5Pset_fapl_mpio(ret_pl, comm, info); + VRFY((ret >= 0), ""); ret = H5Pset_all_coll_metadata_ops(ret_pl, TRUE); - VRFY((ret >= 0), ""); + VRFY((ret >= 0), ""); ret = H5Pset_coll_metadata_write(ret_pl, TRUE); - VRFY((ret >= 0), ""); - return(ret_pl); + VRFY((ret >= 0), ""); + return(ret_pl); } if (l_facc_type == (FACC_MPIO | FACC_SPLIT)){ - hid_t mpio_pl; + hid_t mpio_pl; - mpio_pl = H5Pcreate (H5P_FILE_ACCESS); - VRFY((mpio_pl >= 0), ""); - /* set Parallel access with communicator */ - ret = H5Pset_fapl_mpio(mpio_pl, comm, info); - VRFY((ret >= 0), ""); + mpio_pl = H5Pcreate (H5P_FILE_ACCESS); + VRFY((mpio_pl >= 0), ""); + /* set Parallel access with communicator */ + ret = H5Pset_fapl_mpio(mpio_pl, comm, info); + VRFY((ret >= 0), ""); - /* setup file access template */ - ret_pl = H5Pcreate (H5P_FILE_ACCESS); - VRFY((ret_pl >= 0), ""); - /* set Parallel access with communicator */ - ret = H5Pset_fapl_split(ret_pl, ".meta", mpio_pl, ".raw", mpio_pl); - VRFY((ret >= 0), "H5Pset_fapl_split succeeded"); - H5Pclose(mpio_pl); - return(ret_pl); + /* setup file access template */ + ret_pl = H5Pcreate (H5P_FILE_ACCESS); + VRFY((ret_pl >= 0), ""); + /* set Parallel access with communicator */ + ret = H5Pset_fapl_split(ret_pl, ".meta", mpio_pl, ".raw", mpio_pl); + VRFY((ret >= 0), "H5Pset_fapl_split succeeded"); + H5Pclose(mpio_pl); + return(ret_pl); } /* unknown file access types */ @@ -303,7 +303,7 @@ create_faccess_plist(MPI_Comm comm, MPI_Info info, int l_facc_type) int main(int argc, char **argv) { - int mpi_size, mpi_rank; /* mpi variables */ + int mpi_size, mpi_rank; /* mpi variables */ H5Ptest_param_t ndsets_params, ngroups_params; H5Ptest_param_t collngroups_params; H5Ptest_param_t io_mode_confusion_params; @@ -323,9 +323,9 @@ int main(int argc, char **argv) dim1 = COL_FACTOR*mpi_size; if (MAINPROCESS){ - printf("===================================\n"); - printf("PHDF5 TESTS START\n"); - printf("===================================\n"); + printf("===================================\n"); + printf("PHDF5 TESTS START\n"); + printf("===================================\n"); } /* Attempt to turn off atexit post processing so that in case errors @@ -334,7 +334,7 @@ int main(int argc, char **argv) * calls. By then, MPI calls may not work. */ if (H5dont_atexit() < 0){ - printf("Failed to turn off atexit processing. Continue.\n"); + printf("Failed to turn off atexit processing. Continue.\n"); }; H5open(); h5_show_hostname(); @@ -344,10 +344,10 @@ int main(int argc, char **argv) /* Tests are generally arranged from least to most complexity... */ AddTest("mpiodup", test_fapl_mpio_dup, NULL, - "fapl_mpio duplicate", NULL); + "fapl_mpio duplicate", NULL); AddTest("split", test_split_comm_access, NULL, - "dataset using split communicators", PARATESTFILE); + "dataset using split communicators", PARATESTFILE); #ifdef PB_OUT /* temporary: disable page buffering when parallel */ AddTest("page_buffer", test_page_buffer_access, NULL, @@ -355,64 +355,64 @@ int main(int argc, char **argv) #endif AddTest("props", test_file_properties, NULL, - "Coll Metadata file property settings", PARATESTFILE); + "Coll Metadata file property settings", PARATESTFILE); AddTest("idsetw", dataset_writeInd, NULL, - "dataset independent write", PARATESTFILE); + "dataset independent write", PARATESTFILE); AddTest("idsetr", dataset_readInd, NULL, - "dataset independent read", PARATESTFILE); + "dataset independent read", PARATESTFILE); AddTest("cdsetw", dataset_writeAll, NULL, - "dataset collective write", PARATESTFILE); + "dataset collective write", PARATESTFILE); AddTest("cdsetr", dataset_readAll, NULL, - "dataset collective read", PARATESTFILE); + "dataset collective read", PARATESTFILE); AddTest("eidsetw", extend_writeInd, NULL, - "extendible dataset independent write", PARATESTFILE); + "extendible dataset independent write", PARATESTFILE); AddTest("eidsetr", extend_readInd, NULL, - "extendible dataset independent read", PARATESTFILE); + "extendible dataset independent read", PARATESTFILE); AddTest("ecdsetw", extend_writeAll, NULL, - "extendible dataset collective write", PARATESTFILE); + "extendible dataset collective write", PARATESTFILE); AddTest("ecdsetr", extend_readAll, NULL, - "extendible dataset collective read", PARATESTFILE); + "extendible dataset collective read", PARATESTFILE); AddTest("eidsetw2", extend_writeInd2, NULL, - "extendible dataset independent write #2", PARATESTFILE); + "extendible dataset independent write #2", PARATESTFILE); AddTest("selnone", none_selection_chunk, NULL, "chunked dataset with none-selection", PARATESTFILE); AddTest("calloc", test_chunk_alloc, NULL, "parallel extend Chunked allocation on serial file", PARATESTFILE); AddTest("fltread", test_filter_read, NULL, - "parallel read of dataset written serially with filters", PARATESTFILE); + "parallel read of dataset written serially with filters", PARATESTFILE); #ifdef H5_HAVE_FILTER_DEFLATE AddTest("cmpdsetr", compress_readAll, NULL, - "compressed dataset collective read", PARATESTFILE); + "compressed dataset collective read", PARATESTFILE); #endif /* H5_HAVE_FILTER_DEFLATE */ AddTest("zerodsetr", zero_dim_dset, NULL, - "zero dim dset", PARATESTFILE); + "zero dim dset", PARATESTFILE); ndsets_params.name = PARATESTFILE; ndsets_params.count = ndatasets; AddTest("ndsetw", multiple_dset_write, NULL, - "multiple datasets write", &ndsets_params); + "multiple datasets write", &ndsets_params); ngroups_params.name = PARATESTFILE; ngroups_params.count = ngroups; AddTest("ngrpw", multiple_group_write, NULL, - "multiple groups write", &ngroups_params); + "multiple groups write", &ngroups_params); AddTest("ngrpr", multiple_group_read, NULL, - "multiple groups read", &ngroups_params); + "multiple groups read", &ngroups_params); AddTest("compact", compact_dataset, NULL, - "compact dataset test", PARATESTFILE); + "compact dataset test", PARATESTFILE); collngroups_params.name = PARATESTFILE; collngroups_params.count = ngroups; AddTest("cngrpw", collective_group_write, NULL, - "collective group and dataset write", &collngroups_params); + "collective group and dataset write", &collngroups_params); AddTest("ingrpr", independent_group_read, NULL, - "independent group and dataset read", &collngroups_params); + "independent group and dataset read", &collngroups_params); #ifndef H5_HAVE_WIN32_API AddTest("bigdset", big_dataset, NULL, "big dataset test", PARATESTFILE); @@ -420,71 +420,71 @@ int main(int argc, char **argv) printf("big dataset test will be skipped on Windows (JIRA HDDFV-8064)\n"); #endif AddTest("fill", dataset_fillvalue, NULL, - "dataset fill value", PARATESTFILE); + "dataset fill value", PARATESTFILE); AddTest("cchunk1", - coll_chunk1,NULL, "simple collective chunk io",PARATESTFILE); + coll_chunk1,NULL, "simple collective chunk io",PARATESTFILE); AddTest("cchunk2", - coll_chunk2,NULL, "noncontiguous collective chunk io",PARATESTFILE); + coll_chunk2,NULL, "noncontiguous collective chunk io",PARATESTFILE); AddTest("cchunk3", - coll_chunk3,NULL, "multi-chunk collective chunk io",PARATESTFILE); + coll_chunk3,NULL, "multi-chunk collective chunk io",PARATESTFILE); AddTest("cchunk4", coll_chunk4,NULL, "collective chunk io with partial non-selection ",PARATESTFILE); if((mpi_size < 3)&& MAINPROCESS ) { - printf("Collective chunk IO optimization APIs "); - printf("needs at least 3 processes to participate\n"); - printf("Collective chunk IO API tests will be skipped \n"); + printf("Collective chunk IO optimization APIs "); + printf("needs at least 3 processes to participate\n"); + printf("Collective chunk IO API tests will be skipped \n"); } AddTest((mpi_size <3)? "-cchunk5":"cchunk5" , coll_chunk5,NULL, - "linked chunk collective IO without optimization",PARATESTFILE); + "linked chunk collective IO without optimization",PARATESTFILE); AddTest((mpi_size < 3)? "-cchunk6" : "cchunk6", - coll_chunk6,NULL, - "multi-chunk collective IO with direct request",PARATESTFILE); + coll_chunk6,NULL, + "multi-chunk collective IO with direct request",PARATESTFILE); AddTest((mpi_size < 3)? "-cchunk7" : "cchunk7", - coll_chunk7,NULL, - "linked chunk collective IO with optimization",PARATESTFILE); + coll_chunk7,NULL, + "linked chunk collective IO with optimization",PARATESTFILE); AddTest((mpi_size < 3)? "-cchunk8" : "cchunk8", - coll_chunk8,NULL, - "linked chunk collective IO transferring to multi-chunk",PARATESTFILE); + coll_chunk8,NULL, + "linked chunk collective IO transferring to multi-chunk",PARATESTFILE); AddTest((mpi_size < 3)? "-cchunk9" : "cchunk9", - coll_chunk9,NULL, - "multiple chunk collective IO with optimization",PARATESTFILE); + coll_chunk9,NULL, + "multiple chunk collective IO with optimization",PARATESTFILE); AddTest((mpi_size < 3)? "-cchunk10" : "cchunk10", - coll_chunk10,NULL, - "multiple chunk collective IO transferring to independent IO",PARATESTFILE); + coll_chunk10,NULL, + "multiple chunk collective IO transferring to independent IO",PARATESTFILE); /* irregular collective IO tests*/ AddTest("ccontw", - coll_irregular_cont_write,NULL, - "collective irregular contiguous write",PARATESTFILE); + coll_irregular_cont_write,NULL, + "collective irregular contiguous write",PARATESTFILE); AddTest("ccontr", - coll_irregular_cont_read,NULL, - "collective irregular contiguous read",PARATESTFILE); + coll_irregular_cont_read,NULL, + "collective irregular contiguous read",PARATESTFILE); AddTest("cschunkw", - coll_irregular_simple_chunk_write,NULL, - "collective irregular simple chunk write",PARATESTFILE); + coll_irregular_simple_chunk_write,NULL, + "collective irregular simple chunk write",PARATESTFILE); AddTest("cschunkr", - coll_irregular_simple_chunk_read,NULL, - "collective irregular simple chunk read",PARATESTFILE); + coll_irregular_simple_chunk_read,NULL, + "collective irregular simple chunk read",PARATESTFILE); AddTest("ccchunkw", - coll_irregular_complex_chunk_write,NULL, - "collective irregular complex chunk write",PARATESTFILE); + coll_irregular_complex_chunk_write,NULL, + "collective irregular complex chunk write",PARATESTFILE); AddTest("ccchunkr", - coll_irregular_complex_chunk_read,NULL, - "collective irregular complex chunk read",PARATESTFILE); + coll_irregular_complex_chunk_read,NULL, + "collective irregular complex chunk read",PARATESTFILE); AddTest("null", null_dataset, NULL, - "null dataset test", PARATESTFILE); + "null dataset test", PARATESTFILE); io_mode_confusion_params.name = PARATESTFILE; io_mode_confusion_params.count = 0; /* value not used */ AddTest("I/Omodeconf", io_mode_confusion, NULL, - "I/O mode confusion test -- hangs quickly on failure", + "I/O mode confusion test -- hangs quickly on failure", &io_mode_confusion_params); if((mpi_size < 3) && MAINPROCESS) { @@ -506,12 +506,12 @@ int main(int argc, char **argv) AddTest("tldsc", lower_dim_size_comp_test, NULL, - "test lower dim size comp in span tree to mpi derived type", + "test lower dim size comp in span tree to mpi derived type", PARATESTFILE); AddTest("lccio", link_chunk_collective_io_test, NULL, - "test mpi derived type management", + "test mpi derived type management", PARATESTFILE); AddTest("actualio", actual_io_mode_tests, NULL, @@ -523,7 +523,7 @@ int main(int argc, char **argv) PARATESTFILE); AddTest("edpl", test_plist_ed, NULL, - "encode/decode Property Lists", NULL); + "encode/decode Property Lists", NULL); if((mpi_size < 2) && MAINPROCESS) { printf("File Image Ops daisy chain test needs at least 2 processes.\n"); @@ -533,11 +533,11 @@ int main(int argc, char **argv) "file image ops daisy chain", NULL); if((mpi_size < 2)&& MAINPROCESS ) { - printf("Atomicity tests need at least 2 processes to participate\n"); - printf("8 is more recommended.. Atomicity tests will be skipped \n"); + printf("Atomicity tests need at least 2 processes to participate\n"); + printf("8 is more recommended.. Atomicity tests will be skipped \n"); } else if (facc_type != FACC_MPIO && MAINPROCESS) { - printf("Atomicity tests will not work with a non MPIO VFD\n"); + printf("Atomicity tests will not work with a non MPIO VFD\n"); } else if(mpi_size >= 2 && facc_type == FACC_MPIO){ AddTest("atomicity", dataset_atomicity, NULL, @@ -545,13 +545,13 @@ int main(int argc, char **argv) } AddTest("denseattr", test_dense_attr, NULL, - "Store Dense Attributes", PARATESTFILE); + "Store Dense Attributes", PARATESTFILE); AddTest("noselcollmdread", test_partial_no_selection_coll_md_read, NULL, "Collective Metadata read with some ranks having no selection", PARATESTFILE); - AddTest("MC coll MD read", test_multi_chunk_io_addrmap_issue, NULL, + AddTest("MC_coll_MD_read", test_multi_chunk_io_addrmap_issue, NULL, "Collective MD read with multi chunk I/O (H5D__chunk_addrmap)", PARATESTFILE); - AddTest("LC coll MD read", test_link_chunk_io_sort_chunk_issue, NULL, + AddTest("LC_coll_MD_read", test_link_chunk_io_sort_chunk_issue, NULL, "Collective MD read with link chunk I/O (H5D__sort_chunk)", PARATESTFILE); /* Display testing information */ @@ -565,9 +565,9 @@ int main(int argc, char **argv) TestParseCmdLine(argc, argv); if (dxfer_coll_type == DXFER_INDEPENDENT_IO && MAINPROCESS){ - printf("===================================\n" - " Using Independent I/O with file set view to replace collective I/O \n" - "===================================\n"); + printf("===================================\n" + " Using Independent I/O with file set view to replace collective I/O \n" + "===================================\n"); } @@ -592,16 +592,16 @@ int main(int argc, char **argv) { int temp; MPI_Allreduce(&nerrors, &temp, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); - nerrors=temp; + nerrors=temp; } - if (MAINPROCESS){ /* only process 0 reports */ - printf("===================================\n"); - if (nerrors) - printf("***PHDF5 tests detected %d errors***\n", nerrors); - else - printf("PHDF5 tests finished with no errors\n"); - printf("===================================\n"); + if (MAINPROCESS){ /* only process 0 reports */ + printf("===================================\n"); + if (nerrors) + printf("***PHDF5 tests detected %d errors***\n", nerrors); + else + printf("PHDF5 tests finished with no errors\n"); + printf("===================================\n"); } /* close HDF5 library */ From 8a4f679fda20577c4528977d0ee9a7e4c5bee055 Mon Sep 17 00:00:00 2001 From: Larry Knox Date: Fri, 3 May 2019 16:08:22 -0500 Subject: [PATCH 32/32] Combine "collective group and dataset write" and "independent group and dataset read" tests into one test. The second test is dependent on the file created by the first test, and will not pass when run by itself. --- testpar/CMakeTests.cmake | 3 +-- testpar/t_mdset.c | 7 +++++++ testpar/testphdf5.c | 8 ++++---- testpar/testphdf5.h | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/testpar/CMakeTests.cmake b/testpar/CMakeTests.cmake index 4b738c19a2..b4c811182e 100644 --- a/testpar/CMakeTests.cmake +++ b/testpar/CMakeTests.cmake @@ -33,8 +33,7 @@ set (SKIP_tests ecdsetw eidsetw2 selnone - cngrpw - ingrpr + cngrpw-ingrpr cschunkw ccchunkw tldsc diff --git a/testpar/t_mdset.c b/testpar/t_mdset.c index 16eb13c910..7f75d20fa4 100644 --- a/testpar/t_mdset.c +++ b/testpar/t_mdset.c @@ -838,6 +838,13 @@ void dataset_fillvalue(void) HDfree(wdata); } +/* combined cngrpw and ingrpr tests because ingrpr reads file created by cngrpw. */ +void collective_group_write_independent_group_read(void) +{ + collective_group_write(); + independent_group_read(); +} + /* Write multiple groups with a chunked dataset in each group collectively. * These groups and datasets are for testing independent read later. * diff --git a/testpar/testphdf5.c b/testpar/testphdf5.c index 4269066c84..e1ccbed1f5 100644 --- a/testpar/testphdf5.c +++ b/testpar/testphdf5.c @@ -409,10 +409,10 @@ int main(int argc, char **argv) collngroups_params.name = PARATESTFILE; collngroups_params.count = ngroups; - AddTest("cngrpw", collective_group_write, NULL, - "collective group and dataset write", &collngroups_params); - AddTest("ingrpr", independent_group_read, NULL, - "independent group and dataset read", &collngroups_params); + /* combined cngrpw and ingrpr tests because ingrpr reads file created by cngrpw. */ + AddTest("cngrpw-ingrpr", collective_group_write_independent_group_read, NULL, + "collective grp/dset write - independent grp/dset read", + &collngroups_params); #ifndef H5_HAVE_WIN32_API AddTest("bigdset", big_dataset, NULL, "big dataset test", PARATESTFILE); diff --git a/testpar/testphdf5.h b/testpar/testphdf5.h index 4409221608..9fece120a1 100644 --- a/testpar/testphdf5.h +++ b/testpar/testphdf5.h @@ -240,6 +240,7 @@ void test_file_properties(void); void multiple_dset_write(void); void multiple_group_write(void); void multiple_group_read(void); +void collective_group_write_independent_group_read(void); void collective_group_write(void); void independent_group_read(void); void test_fapl_mpio_dup(void);