From ab28d2c820e88b3cf6d13b5ebac96d7e69203d8d Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 4 Jun 2003 13:42:20 -0500 Subject: [svn-r6961] Purpose: Bug fix Description: An earlier checkin changed some of the assumptions about single block hyperslabs, causing them to fail in odd ways. Solution: Fix errors with single block hyperslabs by keying off of count==1 instead of stride==1. Platforms tested: FreeBSD 4.8 (sleipnir) w/parallel h5committested --- src/H5Dcontig.c | 2 +- src/H5Fcontig.c | 2 +- src/H5Shyper.c | 107 +++++++++++++++++++++++++++++++++++++------------------ test/ntypes.c | 2 +- test/trefer.c | 2 +- test/tselect.c | 32 +++++++++++++---- testpar/t_dset.c | 4 +-- 7 files changed, 105 insertions(+), 46 deletions(-) diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 42ed109..d89b4b6 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -264,7 +264,7 @@ H5F_contig_fill(H5F_t *f, hid_t dxpl_id, struct H5O_layout_t *layout, if(using_mpi) { /* Round-robin write the chunks out from only one process */ if(mpi_round==mpi_rank) { - if (H5F_contig_write(f, size, addr, size, dxpl_id, buf)<0) + if (H5F_contig_write(f, (hsize_t)size, addr, size, dxpl_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to write fill value to dataset"); } /* end if */ ++mpi_round; diff --git a/src/H5Fcontig.c b/src/H5Fcontig.c index 42ed109..d89b4b6 100644 --- a/src/H5Fcontig.c +++ b/src/H5Fcontig.c @@ -264,7 +264,7 @@ H5F_contig_fill(H5F_t *f, hid_t dxpl_id, struct H5O_layout_t *layout, if(using_mpi) { /* Round-robin write the chunks out from only one process */ if(mpi_round==mpi_rank) { - if (H5F_contig_write(f, size, addr, size, dxpl_id, buf)<0) + if (H5F_contig_write(f, (hsize_t)size, addr, size, dxpl_id, buf)<0) HGOTO_ERROR(H5E_DATASET, H5E_CANTINIT, FAIL, "unable to write fill value to dataset"); } /* end if */ ++mpi_round; diff --git a/src/H5Shyper.c b/src/H5Shyper.c index 06cb6ae..0bf7791 100644 --- a/src/H5Shyper.c +++ b/src/H5Shyper.c @@ -213,8 +213,8 @@ H5S_hyper_iter_init(H5S_sel_iter_t *iter, const H5S_t *space, size_t elmt_size) else { if((unsigned)i==(cont_dim-1)) { iter->u.hyp.diminfo[i].start = tdiminfo[i].start*acc; - /* Special case for stride==1 regular selections */ - if(tdiminfo[i].stride==1) + /* Special case for single block regular selections */ + if(tdiminfo[i].count==1) iter->u.hyp.diminfo[i].stride = 1; else iter->u.hyp.diminfo[i].stride = tdiminfo[i].stride*acc; @@ -563,7 +563,7 @@ H5S_hyper_iter_next(H5S_sel_iter_t *iter, size_t nelem) /* Calculate the offset and block count for each dimension */ for(i=0; iu.hyp.off[i]-tdiminfo[i].start; iter_count[i]=0; } /* end if */ @@ -778,7 +778,7 @@ H5S_hyper_iter_next_block(H5S_sel_iter_t *iter) /* Calculate the offset and block count for each dimension */ for(u=0; uu.hyp.off[u]-tdiminfo[u].start; iter_count[u]=0; } /* end if */ @@ -2090,14 +2090,8 @@ H5S_hyper_serialize (const H5S_t *space, uint8_t *buf) UINT32ENCODE(buf, (uint32_t)offset[i]); /* Encode hyperslab ending location */ - for(i=0; iextent.u.simple.rank; u++) { tmp_start[u]=0; - tmp_stride[u]=0; + tmp_stride[u]=1; tmp_count[u]=1; tmp_block[u]=space->extent.u.simple.size[u]; } /* end for */ @@ -5223,7 +5213,12 @@ H5S_generate_hyperslab (H5S_t *space, H5S_seloper_t op, block[u]=_block[u]*_count[u]; } else { - stride[u]=_stride[u]; + if(_count[u]==1) + stride[u]=1; + else { + assert(_stride[u]>_block[u]); + stride[u]=_stride[u]; + } /* end else */ count[u]=_count[u]; block[u]=_block[u]; } /* end if */ @@ -5451,7 +5446,7 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Fill in the correct stride values */ if(stride==NULL) { - hssize_t fill=1; + hsize_t fill=1; /* Allocate temporary buffer */ if ((_stride=H5FL_ARR_MALLOC(hsize_t,space->extent.u.simple.rank))==NULL) @@ -5462,7 +5457,7 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Fill in the correct block values */ if(block==NULL) { - hssize_t fill=1; + hsize_t fill=1; /* Allocate temporary buffer */ if ((_block=H5FL_ARR_MALLOC(hsize_t,space->extent.u.simple.rank))==NULL) @@ -5596,7 +5591,12 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, diminfo[u].block=count[u]*block[u]; } /* end if */ else { - diminfo[u].stride=stride[u]; + if(count[u]==1) + diminfo[u].stride=1; + else { + assert(stride[u]>block[u]); + diminfo[u].stride=stride[u]; + } /* end else */ diminfo[u].count=count[u]; diminfo[u].block=block[u]; } /* end else */ @@ -5685,6 +5685,7 @@ H5Sselect_hyperslab(hid_t space_id, H5S_seloper_t op, const hssize_t start[], const hsize_t stride[], const hsize_t count[], const hsize_t block[]) { H5S_t *space = NULL; /* Dataspace to modify selection of */ + unsigned u; /* Local index variable */ herr_t ret_value=SUCCEED; /* Return value */ FUNC_ENTER_API(H5Sselect_hyperslab, FAIL); @@ -5697,9 +5698,22 @@ H5Sselect_hyperslab(hid_t space_id, H5S_seloper_t op, const hssize_t start[], HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "hyperslab doesn't support H5S_SCALAR space"); if(start==NULL || count==NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hyperslab not specified"); - if(!(op>H5S_SELECT_NOOP && opextent.u.simple.rank; u++) { + if(stride[u]==0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid stride==0 value"); + } /* end for */ + if(block!=NULL) { + /* Check for strides smaller than blocks */ + for(u=0; uextent.u.simple.rank; u++) { + if(count[u]>1 && stride[u]_block[u]); + stride[u]=_stride[u]; + } /* end else */ count[u]=_count[u]; block[u]=_block[u]; } /* end if */ @@ -6036,7 +6055,7 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Fill in the correct stride values */ if(stride==NULL) { - hssize_t fill=1; + hsize_t fill=1; /* Allocate temporary buffer */ if ((_stride=H5FL_ARR_MALLOC(hsize_t,space->extent.u.simple.rank))==NULL) @@ -6047,7 +6066,7 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Fill in the correct block values */ if(block==NULL) { - hssize_t fill=1; + hsize_t fill=1; /* Allocate temporary buffer */ if ((_block=H5FL_ARR_MALLOC(hsize_t,space->extent.u.simple.rank))==NULL) @@ -6105,7 +6124,7 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, /* Fill in temporary information for the dimensions */ for(u=0; uextent.u.simple.rank; u++) { tmp_start[u]=0; - tmp_stride[u]=0; + tmp_stride[u]=1; tmp_count[u]=1; tmp_block[u]=space->extent.u.simple.size[u]; } /* end for */ @@ -6182,7 +6201,12 @@ H5S_select_hyperslab (H5S_t *space, H5S_seloper_t op, diminfo[u].block=count[u]*block[u]; } /* end if */ else { - diminfo[u].stride=stride[u]; + if(count[u]==1) + diminfo[u].stride=1; + else { + assert(stride[u]>block[u]); + diminfo[u].stride=stride[u]; + } /* end else */ diminfo[u].count=count[u]; diminfo[u].block=block[u]; } /* end else */ @@ -6263,11 +6287,26 @@ H5Sselect_hyperslab(hid_t space_id, H5S_seloper_t op, const hssize_t start[], /* Check args */ if (NULL == (space=H5I_object_verify(space_id, H5I_DATASPACE))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a data space"); + if (H5S_SCALAR==H5S_get_simple_extent_type(space)) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "hyperslab doesn't support H5S_SCALAR space"); if(start==NULL || count==NULL) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "hyperslab not specified"); - if(!(op>H5S_SELECT_NOOP && opextent.u.simple.rank; u++) { + if(stride[u]==0) + HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid stride==0 value"); + } /* end for */ + if(block!=NULL) { + /* Check for strides smaller than blocks */ + for(u=0; uextent.u.simple.rank; u++) { + if(count[u]>1 && stride[u]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].stride==1)) { + ((iter->u.hyp.off[fast_dim]!=tdiminfo[fast_dim].start) && tdiminfo[fast_dim].count==1)) { size_t leftover; /* The number of elements left over from the last sequence */ /* Calculate the number of elements left in the sequence */ - if(tdiminfo[fast_dim].stride==1) { + if(tdiminfo[fast_dim].count==1) { H5_ASSIGN_OVERFLOW(leftover, tdiminfo[fast_dim].block-(iter->u.hyp.off[fast_dim]-tdiminfo[fast_dim].start) ,hsize_t,size_t); } /* end if */ else { @@ -7172,7 +7211,7 @@ H5S_hyper_get_seq_list_opt(const H5S_t *space,H5S_sel_iter_t *iter, /* Compute the current "counts" for this location */ for(i=0; iu.hyp.off[i]-tdiminfo[i].start; } /* end if */ diff --git a/test/ntypes.c b/test/ntypes.c index 9ddcefc..53276a2 100644 --- a/test/ntypes.c +++ b/test/ntypes.c @@ -1624,7 +1624,7 @@ test_refer_dtype2(hid_t file) /* Create references */ /* Select 6x6 hyperslab for first reference */ start[0]=2; start[1]=2; - stride[0]=0; stride[1]=0; + stride[0]=1; stride[1]=1; count[0]=1; count[1]=1; block[0]=6; block[1]=6; diff --git a/test/trefer.c b/test/trefer.c index bb67a61..7a94d62 100644 --- a/test/trefer.c +++ b/test/trefer.c @@ -385,7 +385,7 @@ test_reference_region(void) /* Select 6x6 hyperslab for first reference */ start[0]=2; start[1]=2; - stride[0]=0; stride[1]=0; + stride[0]=1; stride[1]=1; count[0]=1; count[1]=1; block[0]=6; block[1]=6; ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); diff --git a/test/tselect.c b/test/tselect.c index e3b72ec..c08a611 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -205,6 +205,26 @@ test_select_hyper(hid_t xfer_plist) ext_type = H5Sget_simple_extent_type(sid1); VERIFY(ext_type, H5S_SIMPLE, "H5Sget_simple_extent_type"); + /* Test selecting stride==0 to verify failure */ + start[0]=1; start[1]=0; start[2]=0; + stride[0]=0; stride[1]=0; stride[2]=0; + count[0]=2; count[1]=15; count[2]=13; + block[0]=1; block[1]=1; block[2]=1; + H5E_BEGIN_TRY { + ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); + } H5E_END_TRY; + VERIFY(ret, FAIL, "H5Sselect_hyperslab"); + + /* Test selecting stride