From 50ef7ff9962051c767aae7ad229b558b7586c59b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Wed, 8 Jul 2020 13:54:37 -0700 Subject: Further normalization of H5S with develop --- src/H5Dchunk.c | 3 +- src/H5Dint.c | 2 +- src/H5Sall.c | 10 ++-- src/H5Shyper.c | 164 ++++++++++--------------------------------------------- src/H5Smpio.c | 70 +++++++++++------------- src/H5Snone.c | 10 ++-- src/H5Spkg.h | 5 +- src/H5Spoint.c | 63 ++++++++++++--------- src/H5Sprivate.h | 11 ++-- 9 files changed, 118 insertions(+), 220 deletions(-) diff --git a/src/H5Dchunk.c b/src/H5Dchunk.c index 0f7bccf..511803e 100644 --- a/src/H5Dchunk.c +++ b/src/H5Dchunk.c @@ -2052,11 +2052,10 @@ H5D__chunk_mem_cb(void H5_ATTR_UNUSED *elem, const H5T_t H5_ATTR_UNUSED *type, u HGOTO_ERROR(H5E_DATASPACE, H5E_NOTFOUND, FAIL, "can't locate chunk in skip list") /* Check if the chunk already has a memory space */ - if(NULL == chunk_info->mspace) { + if(NULL == chunk_info->mspace) /* Copy the template memory chunk dataspace */ if(NULL == (chunk_info->mspace = H5S_copy(fm->mchunk_tmpl, FALSE, FALSE))) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy file space") - } /* end else */ /* Update the "last chunk seen" information */ fm->last_index = chunk_index; diff --git a/src/H5Dint.c b/src/H5Dint.c index 91fde93..6c0fd76 100644 --- a/src/H5Dint.c +++ b/src/H5Dint.c @@ -2704,7 +2704,7 @@ H5D__vlen_get_buf_size(void H5_ATTR_UNUSED *elem, hid_t type_id, HGOTO_ERROR(H5E_DATASET, H5E_NOSPACE, FAIL, "can't resize tbuf") /* Select point to read in */ - if(H5S_select_elements(vlen_bufsize->fspace, H5S_SELECT_SET, (hsize_t)1, point) < 0) + if(H5S_select_elements(vlen_bufsize->fspace, H5S_SELECT_SET, (size_t)1, point) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, FAIL, "can't select point") /* Read in the point (with the custom VL memory allocator) */ diff --git a/src/H5Sall.c b/src/H5Sall.c index da466d0..199213f 100644 --- a/src/H5Sall.c +++ b/src/H5Sall.c @@ -65,7 +65,7 @@ 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 void H5S__all_adjust_u(H5S_t *space, const hsize_t *offset); +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); @@ -850,11 +850,11 @@ H5S__all_is_regular(const H5S_t H5_ATTR_UNUSED *space) PURPOSE Adjust an "all" selection by subtracting an offset USAGE - void H5S__all_adjust_u(space, offset) + herr_t H5S__all_adjust_u(space, offset) H5S_t *space; IN/OUT: Pointer to dataspace to adjust const hsize_t *offset; IN: Offset to subtract RETURNS - None + Non-negative on success, negative on failure DESCRIPTION Moves selection by subtracting an offset from it. GLOBAL VARIABLES @@ -862,7 +862,7 @@ H5S__all_is_regular(const H5S_t H5_ATTR_UNUSED *space) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static void +static herr_t H5S__all_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *offset) { FUNC_ENTER_STATIC_NOERR @@ -871,7 +871,7 @@ H5S__all_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *off HDassert(space); HDassert(offset); - FUNC_LEAVE_NOAPI_VOID + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__all_adjust_u() */ diff --git a/src/H5Shyper.c b/src/H5Shyper.c index e94c66e..771b750 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -114,7 +114,7 @@ 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 void H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset); +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); @@ -4087,125 +4087,6 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5S_hyper_convert() */ -#ifdef LATER - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_intersect_helper - PURPOSE - Helper routine to detect intersections in span trees - USAGE - htri_t H5S_hyper_intersect_helper(spans1, spans2) - H5S_hyper_span_info_t *spans1; IN: First span tree to operate with - H5S_hyper_span_info_t *spans2; IN: Second span tree to operate with - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Quickly detect intersections between two span trees - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -static htri_t -H5S_hyper_intersect_helper (H5S_hyper_span_info_t *spans1, H5S_hyper_span_info_t *spans2) -{ - H5S_hyper_span_t *curr1; /* Pointer to current span in 1st span tree */ - H5S_hyper_span_t *curr2; /* Pointer to current span in 2nd span tree */ - htri_t status; /* Status from recursive call */ - htri_t ret_value=FALSE; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT - - /* Sanity check */ - HDassert((spans1 && spans2) || (spans1 == NULL && spans2 == NULL)); - - /* "NULL" span trees compare as overlapping */ - if(spans1==NULL && spans2==NULL) - HGOTO_DONE(TRUE); - - /* Get the span lists for each span in this tree */ - curr1=spans1->head; - curr2=spans2->head; - - /* Iterate over the spans in each tree */ - while(curr1!=NULL && curr2!=NULL) { - /* Check for 1st span entirely before 2nd span */ - if(curr1->highlow) - curr1=curr1->next; - /* Check for 2nd span entirely before 1st span */ - else if(curr2->highlow) - curr2=curr2->next; - /* Spans must overlap */ - else { - /* Recursively check spans in next dimension down */ - if((status=H5S_hyper_intersect_helper(curr1->down,curr2->down))<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab intersection check") - - /* 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 */ - if(curr1->highhigh) - curr1=curr1->next; - else - curr2=curr2->next; - } /* end else */ - } /* end while */ - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5S_hyper_intersect_helper() */ - - -/*-------------------------------------------------------------------------- - NAME - H5S_hyper_intersect - PURPOSE - Detect intersections in span trees - USAGE - htri_t H5S_hyper_intersect(space1, space2) - H5S_t *space1; IN: First dataspace to operate on span tree - H5S_t *space2; IN: Second dataspace to operate on span tree - RETURNS - Non-negative on success, negative on failure - DESCRIPTION - Quickly detect intersections between two span trees - GLOBAL VARIABLES - COMMENTS, BUGS, ASSUMPTIONS - EXAMPLES - REVISION LOG ---------------------------------------------------------------------------*/ -htri_t -H5S_hyper_intersect (H5S_t *space1, H5S_t *space2) -{ - htri_t ret_value=FAIL; /* Return value */ - - FUNC_ENTER_NOAPI_NOINIT - - /* Sanity check */ - HDassert(space1); - HDassert(space2); - - /* Check that the space selections both have span trees */ - if(space1->select.sel_info.hslab->span_lst==NULL || - space2->select.sel_info.hslab->span_lst==NULL) - HGOTO_ERROR(H5E_DATASPACE, H5E_UNINITIALIZED, FAIL, "dataspace does not have span tree") - - /* Check that the dataspaces are both the same rank */ - if(space1->extent.rank!=space2->extent.rank) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADRANGE, FAIL, "dataspace ranks don't match") - - /* Perform the span-by-span intersection check */ - if((ret_value=H5S_hyper_intersect_helper(space1->select.sel_info.hslab->span_lst,space2->select.sel_info.hslab->span_lst))<0) - HGOTO_ERROR(H5E_DATASPACE, H5E_BADSELECT, FAIL, "can't perform hyperslab intersection check") - -done: - FUNC_LEAVE_NOAPI(ret_value) -} /* H5S_hyper_intersect() */ -#endif /* LATER */ - /*-------------------------------------------------------------------------- NAME @@ -4397,7 +4278,7 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, H5S_t *space; IN/OUT: Pointer to dataspace to adjust const hsize_t *offset; IN: Offset to subtract RETURNS - None + Non-negative on success, negative on failure DESCRIPTION Moves a hyperslab selection by subtracting an offset from it. GLOBAL VARIABLES @@ -4405,34 +4286,45 @@ H5S__hyper_adjust_u_helper(H5S_hyper_span_info_t *spans, EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static void +static herr_t H5S__hyper_adjust_u(H5S_t *space, const hsize_t *offset) { + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ + unsigned u; /* Local index variable */ + FUNC_ENTER_STATIC_NOERR /* Sanity check */ 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; + } - 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]; - } /* 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 */ + if(space->select.sel_info.hslab->diminfo_valid) { + 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]; + } /* 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); + /* 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); - /* Reset the scratch pointers for the next routine which needs them */ - H5S__hyper_span_scratch(space->select.sel_info.hslab->span_lst); + /* Reset the scratch pointers for the next routine which needs them */ + H5S__hyper_span_scratch(space->select.sel_info.hslab->span_lst); + } /* end if */ } /* end if */ - FUNC_LEAVE_NOAPI_VOID + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__hyper_adjust_u() */ diff --git a/src/H5Smpio.c b/src/H5Smpio.c index 3f41be5..28bd253 100644 --- a/src/H5Smpio.c +++ b/src/H5Smpio.c @@ -31,12 +31,7 @@ #include "H5private.h" /* Generic Functions */ #include "H5Dprivate.h" /* Datasets */ #include "H5Eprivate.h" /* Error handling */ -#include "H5Fprivate.h" /* File access */ -#include "H5FDprivate.h" /* File drivers */ -#include "H5Iprivate.h" /* IDs */ #include "H5MMprivate.h" /* Memory management */ -#include "H5Oprivate.h" /* Object headers */ -#include "H5Pprivate.h" /* Property lists */ #include "H5Spkg.h" /* Dataspaces */ #include "H5VMprivate.h" /* Vector and array functions */ @@ -198,10 +193,15 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, { MPI_Datatype elmt_type; /* MPI datatype for individual element */ hbool_t elmt_type_created = FALSE; /* Whether the element MPI datatype was created */ - int mpi_code; /* MPI error code */ + int *inner_blocks = NULL; /* Arrays for MPI datatypes when "large" datatype needed */ + MPI_Aint *inner_disps = NULL; + MPI_Datatype *inner_types = NULL; +#if MPI_VERSION < 3 int *blocks = NULL; /* Array of block sizes for MPI hindexed create call */ hsize_t u; /* Local index variable */ +#endif hsize_t bigio_count; /* Transition point to create derived type */ + int mpi_code; /* MPI error code */ herr_t ret_value = SUCCEED; /* Return value */ FUNC_ENTER_STATIC @@ -246,10 +246,6 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, int num_big_types; hsize_t leftover; - int *inner_blocks; - MPI_Aint *inner_disps; - MPI_Datatype *inner_types = NULL; - /* Calculate how many Big MPI datatypes are needed to represent the buffer */ num_big_types = (int)(num_points / bigio_count); @@ -279,8 +275,8 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, for(i = 0; i < num_big_types; i++) { #if MPI_VERSION >= 3 - if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed_block(bigio_count, - 1, &disp[i*bigio_count], elmt_type, &inner_types[i]))) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed_block((int)bigio_count, + 1, &disp[(hsize_t)i*bigio_count], elmt_type, &inner_types[i]))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hindexed_block failed", mpi_code); #else if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)bigio_count, @@ -294,7 +290,7 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, if(remaining_points) { #if MPI_VERSION >= 3 if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed_block(remaining_points, - 1, &disp[num_big_types*bigio_count], elmt_type, &inner_types[num_big_types]))) + 1, &disp[(hsize_t)num_big_types*bigio_count], elmt_type, &inner_types[num_big_types]))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_create_hindexed_block failed", mpi_code); #else if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hindexed((int)remaining_points, @@ -312,10 +308,6 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, for(i = 0; i < total_types; i++) MPI_Type_free(&inner_types[i]); - H5MM_free(inner_types); - H5MM_free(inner_blocks); - H5MM_free(inner_disps); - /* Commit MPI datatype for later use */ if(MPI_SUCCESS != (mpi_code = MPI_Type_commit(new_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_commit failed", mpi_code) @@ -324,8 +316,16 @@ H5S__mpio_create_point_datatype(size_t elmt_size, hsize_t num_points, done: if(elmt_type_created) MPI_Type_free(&elmt_type); +#if MPI_VERSION < 3 if(blocks) H5MM_free(blocks); +#endif + if(inner_types) + H5MM_free(inner_types); + if(inner_blocks) + H5MM_free(inner_blocks); + if(inner_disps) + H5MM_free(inner_disps); FUNC_LEAVE_NOAPI(ret_value) } /* H5S__mpio_create_point_datatype() */ @@ -1033,6 +1033,7 @@ static herr_t H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, const MPI_Datatype *elmt_type, MPI_Datatype *span_type, size_t elmt_size) { + H5S_hyper_span_t *span; /* Hyperslab span to iterate with */ hsize_t bigio_count; /* Transition point to create derived type */ size_t alloc_count = 0; /* Number of span tree nodes allocated at this level */ size_t outercount = 0; /* Number of span tree nodes at this level */ @@ -1042,7 +1043,7 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, 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 */ @@ -1061,9 +1062,9 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, /* if this is the fastest changing dimension, it is the base case for derived datatype. */ if(NULL == spans->down) { - tspan = spans; + span = spans; outercount = 0; - while(tspan) { + while(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 */ @@ -1082,10 +1083,10 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, } /* end if */ /* 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; + disp[outercount] = (MPI_Aint)elmt_size * span->low; + H5_CHECK_OVERFLOW(span->nelem, hsize_t, int) + blocklen[outercount] = (int)span->nelem; + span = span->next; if (bigio_count < blocklen[outercount]) { large_block = TRUE; /* at least one block type is large, so set this flag to true */ @@ -1146,14 +1147,13 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, } /* 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 = spans; + span = spans; outercount = 0; - while(tspan) { + while(span) { MPI_Datatype down_type; /* Temporary MPI datatype for a span tree node's children */ MPI_Aint stride; /* Distance between inner MPI datatypes */ @@ -1182,17 +1182,17 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, /* 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; + disp[outercount] = span->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) + if(H5S__obtain_datatype(down + 1, span->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]))) { + H5_CHECK_OVERFLOW(span->nelem, hsize_t, int) + if(MPI_SUCCESS != (mpi_code = MPI_Type_create_hvector((int)span->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 */ @@ -1201,7 +1201,7 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, if(MPI_SUCCESS != (mpi_code = MPI_Type_free(&down_type))) HMPI_GOTO_ERROR(FAIL, "MPI_Type_free failed", mpi_code) - tspan = tspan->next; + span = span->next; outercount++; } /* end while */ @@ -1221,14 +1221,10 @@ H5S__obtain_datatype(const hsize_t *down, H5S_hyper_span_t *spans, 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) diff --git a/src/H5Snone.c b/src/H5Snone.c index c17ba40..b9a02a5 100644 --- a/src/H5Snone.c +++ b/src/H5Snone.c @@ -66,7 +66,7 @@ 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 void H5S__none_adjust_u(H5S_t *space, const hsize_t *offset); +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); @@ -801,11 +801,11 @@ H5S__none_is_regular(const H5S_t H5_ATTR_UNUSED *space) PURPOSE Adjust an "none" selection by subtracting an offset USAGE - void H5S__none_adjust_u(space, offset) + herr_t H5S__none_adjust_u(space, offset) H5S_t *space; IN/OUT: Pointer to dataspace to adjust const hsize_t *offset; IN: Offset to subtract RETURNS - None + Non-negative on success, negative on failure DESCRIPTION Moves selection by subtracting an offset from it. GLOBAL VARIABLES @@ -813,7 +813,7 @@ H5S__none_is_regular(const H5S_t H5_ATTR_UNUSED *space) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static void +static herr_t H5S__none_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *offset) { FUNC_ENTER_STATIC_NOERR @@ -822,7 +822,7 @@ H5S__none_adjust_u(H5S_t H5_ATTR_UNUSED *space, const hsize_t H5_ATTR_UNUSED *of HDassert(space); HDassert(offset); - FUNC_LEAVE_NOAPI_VOID + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__none_adjust_u() */ diff --git a/src/H5Spkg.h b/src/H5Spkg.h index 6ba671b..52e683d 100644 --- a/src/H5Spkg.h +++ b/src/H5Spkg.h @@ -29,6 +29,9 @@ /* Get package's private header */ #include "H5Sprivate.h" +/* Other private headers needed by this file */ +#include "H5Oprivate.h" /* Object headers */ + /* Flags to indicate special dataspace features are active */ #define H5S_VALID_MAX 0x01 #define H5S_VALID_PERM 0x02 @@ -187,7 +190,7 @@ 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 adjust a selection by an offset */ -typedef void (*H5S_sel_adjust_u_func_t)(H5S_t *space, const hsize_t *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 */ typedef herr_t (*H5S_sel_project_scalar)(const H5S_t *space, hsize_t *offset); /* Method to construct selection projection onto/into simple dataspace */ diff --git a/src/H5Spoint.c b/src/H5Spoint.c index 2d73dfd..079840e 100644 --- a/src/H5Spoint.c +++ b/src/H5Spoint.c @@ -65,7 +65,7 @@ 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 void H5S__point_adjust_u(H5S_t *space, const hsize_t *offset); +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); @@ -538,7 +538,7 @@ H5S__point_release(H5S_t *space) herr_t H5S_select_elements(dsid, op, num_elem, coord) hid_t dsid; IN: Dataspace ID of selection to modify H5S_seloper_t op; IN: Operation to perform on current selection - hsize_t num_elem; IN: Number of elements in COORD array. + size_t num_elem; IN: Number of elements in COORD array. const hsize_t *coord; IN: The location of each element selected RETURNS Non-negative on success/Negative on failure @@ -560,7 +560,7 @@ H5S__point_release(H5S_t *space) REVISION LOG --------------------------------------------------------------------------*/ herr_t -H5S_select_elements(H5S_t *space, H5S_seloper_t op, hsize_t num_elem, +H5S_select_elements(H5S_t *space, H5S_seloper_t op, size_t num_elem, const hsize_t *coord) { herr_t ret_value = SUCCEED; /* Return value */ @@ -579,9 +579,10 @@ H5S_select_elements(H5S_t *space, H5S_seloper_t op, hsize_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) { 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") + } /* Add points to selection */ if(H5S__point_add(space, op, num_elem, coord) < 0) @@ -1492,11 +1493,11 @@ H5S__point_is_regular(const H5S_t *space) PURPOSE Adjust a "point" selection by subtracting an offset USAGE - void H5S_point_adjust_u(space, offset) + herr_t H5S__point_adjust_u(space, offset) H5S_t *space; IN/OUT: Pointer to dataspace to adjust const hsize_t *offset; IN: Offset to subtract RETURNS - None + Non-negative on success, negative on failure DESCRIPTION Moves a point selection by subtracting an offset from it. GLOBAL VARIABLES @@ -1504,37 +1505,47 @@ H5S__point_is_regular(const H5S_t *space) EXAMPLES REVISION LOG --------------------------------------------------------------------------*/ -static void +static herr_t H5S__point_adjust_u(H5S_t *space, const hsize_t *offset) { + hbool_t non_zero_offset = FALSE; /* Whether any offset is non-zero */ H5S_pnt_node_t *node; /* Point node */ unsigned rank; /* Dataspace rank */ + unsigned u; /* Local index variable */ FUNC_ENTER_STATIC_NOERR HDassert(space); HDassert(offset); - /* Iterate through the nodes, checking the bounds on each element */ - 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 */ - HDassert(node->pnt[u] >= offset[u]); - - /* Adjust node's coordinate location */ - node->pnt[u] -= offset[u]; - } /* end for */ + /* Check for an all-zero offset vector */ + for(u = 0; u < space->extent.rank; u++) + if(0 != offset[u]) { + non_zero_offset = TRUE; + break; + } - /* Advance to next point node in selection */ - node = node->next; - } /* end while */ + /* Only perform operation if the offset is non-zero */ + if(non_zero_offset) { + /* Iterate through the nodes, checking the bounds on each element */ + node = space->select.sel_info.pnt_lst->head; + rank = space->extent.rank; + while(node) { + /* Adjust each coordinate for point node */ + for(u = 0; u < rank; u++) { + /* Check for offset moving selection negative */ + HDassert(node->pnt[u] >= offset[u]); + + /* Adjust node's coordinate location */ + node->pnt[u] -= offset[u]; + } /* end for */ + + /* Advance to next point node in selection */ + node = node->next; + } /* end while */ + } /* end if */ - FUNC_LEAVE_NOAPI_VOID + FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5S__point_adjust_u() */ @@ -1758,7 +1769,7 @@ H5Sselect_elements(hid_t spaceid, H5S_seloper_t op, size_t num_elem, HGOTO_ERROR(H5E_ARGS, H5E_UNSUPPORTED, FAIL, "unsupported operation attempted") /* Call the real element selection routine */ - if((ret_value = H5S_select_elements(space, op, (hsize_t)num_elem, coord)) < 0) + if((ret_value = H5S_select_elements(space, op, num_elem, coord)) < 0) HGOTO_ERROR(H5E_DATASPACE, H5E_CANTDELETE, FAIL, "can't select elements") done: diff --git a/src/H5Sprivate.h b/src/H5Sprivate.h index 588b395..d4f6847 100644 --- a/src/H5Sprivate.h +++ b/src/H5Sprivate.h @@ -17,9 +17,6 @@ #ifndef _H5Sprivate_H #define _H5Sprivate_H -/* Early typedefs to avoid circular dependencies */ -typedef struct H5S_t H5S_t; - /* Include package's public header */ #include "H5Spublic.h" @@ -197,6 +194,9 @@ typedef struct H5S_sel_iter_op_t { #define H5S_SELECT_DESERIALIZE(S,BUF) (H5S_select_deserialize(S,BUF)) +/* Early typedef to avoid circular dependencies */ +typedef struct H5S_t H5S_t; + /* Operations on dataspaces */ H5_DLL H5S_t *H5S_copy(const H5S_t *src, hbool_t share_selection, hbool_t copy_max); H5_DLL herr_t H5S_close(H5S_t *ds); @@ -275,7 +275,7 @@ H5_DLL herr_t H5S_select_none(H5S_t *space); /* Operations on point selections */ H5_DLL herr_t H5S_select_elements(H5S_t *space, H5S_seloper_t op, - hsize_t num_elem, const hsize_t *coord); + size_t num_elem, const hsize_t *coord); /* Operations on hyperslab selections */ H5_DLL herr_t H5S_select_hyperslab(H5S_t *space, H5S_seloper_t op, const hsize_t start[], @@ -284,9 +284,6 @@ 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); -#ifdef LATER -H5_DLL htri_t H5S_hyper_intersect (H5S_t *space1, H5S_t *space2); -#endif /* LATER */ 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); -- cgit v0.12