From 1a65aeeade186927cedb625a5b337b361404a651 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Fri, 2 Nov 2001 15:32:11 -0500 Subject: [svn-r4587] Purpose: Code speedups, etc. Description: Add tests for new hyperslab API functions (currently ifdef'd out) Platforms tested: FreeBSD 4.4 (hawkwind) --- test/tselect.c | 590 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 573 insertions(+), 17 deletions(-) diff --git a/test/tselect.c b/test/tselect.c index 6a9d8d1..32b7226 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -38,6 +38,8 @@ #define SPACE2_RANK 2 #define SPACE2_DIM1 30 #define SPACE2_DIM2 26 +#define SPACE2A_RANK 1 +#define SPACE2A_DIM1 (SPACE2_DIM1*SPACE2_DIM2) /* 2-D dataset with fixed dimensions */ #define SPACE3_NAME "Space3" @@ -1041,10 +1043,8 @@ test_select_hyper_stride(void) tbuf2=rbuf+loc2[i]; if(*tbuf!=*tbuf2) { printf("%d: hyperslab values don't match!, loc1[%d]=%d, loc2[%d]=%d\n",__LINE__,i,(int)loc1[i],i,(int)loc2[i]); -#ifndef QAK printf("wbuf=%p, tbuf=%p, rbuf=%p, tbuf2=%p\n",wbuf,tbuf,rbuf,tbuf2); printf("*tbuf=%u, *tbuf2=%u\n",(unsigned)*tbuf,(unsigned)*tbuf2); -#endif /* QAK */ num_errs++; } /* end if */ } /* end for */ @@ -1068,7 +1068,7 @@ test_select_hyper_stride(void) /* Free memory buffers */ free(wbuf); free(rbuf); -} /* test_select_hyper() */ +} /* test_select_hyper_stride() */ /**************************************************************** ** @@ -1931,6 +1931,9 @@ test_select_hyper_union(void) ret = H5Sselect_hyperslab(sid1,H5S_SELECT_SET,start,stride,count,block); CHECK(ret, FAIL, "H5Sselect_hyperslab"); + npoints = H5Sget_select_npoints(sid1); + VERIFY(npoints, 2*15*13, "H5Sget_select_npoints"); + /* Select 8x26 hyperslab for memory dataset */ start[0]=15; start[1]=0; stride[0]=1; stride[1]=1; @@ -2384,10 +2387,12 @@ test_select_hyper_union(void) free(rbuf); } /* test_select_hyper_union() */ +#ifdef NEW_HYPERSLAB_API /**************************************************************** ** ** test_select_hyper_union_stagger(): Test basic H5S (dataspace) selection code. -** Tests unions of staggered hyperslabs +** Tests unions of staggered hyperslabs. (Uses H5Scombine_hyperslab +** and H5Sselect_select instead of H5Sselect_hyperslab) ** ****************************************************************/ static void @@ -2397,6 +2402,8 @@ test_select_hyper_union_stagger(void) hid_t dset_id; /* Dataset ID */ hid_t dataspace; /* File dataspace ID */ hid_t memspace; /* Memory dataspace ID */ + hid_t tmp_space; /* Temporary dataspace ID */ + hid_t tmp2_space; /* Another emporary dataspace ID */ hsize_t dimsm[2]={7,7}; /* Memory array dimensions */ hsize_t dimsf[2]={6,5}; /* File array dimensions */ hsize_t count[2]={3,1}; /* 1st Hyperslab size */ @@ -2479,11 +2486,19 @@ test_select_hyper_union_stagger(void) /* Select the hyperslabs */ error=H5Sselect_hyperslab(dataspace,H5S_SELECT_SET,offset,stride,count,block); CHECK(error, FAIL, "H5Sselect_hyperslab"); - error=H5Sselect_hyperslab(dataspace,H5S_SELECT_OR,offset2,stride,count2,block); - CHECK(error, FAIL, "H5Sselect_hyperslab"); - error=H5Sselect_hyperslab(dataspace,H5S_SELECT_OR,offset3,stride,count3,block); + tmp_space=H5Scombine_hyperslab(dataspace,H5S_SELECT_OR,offset2,stride,count2,block); + CHECK(tmp_space, FAIL, "H5Scombine_hyperslab"); + + /* Copy the file dataspace and select hyperslab */ + tmp2_space=H5Scopy(dataspace); + CHECK(tmp2_space, FAIL, "H5Scopy"); + error=H5Sselect_hyperslab(tmp2_space,H5S_SELECT_SET,offset3,stride,count3,block); CHECK(error, FAIL, "H5Sselect_hyperslab"); + /* Combine the copied dataspace with the temporary dataspace */ + error=H5Sselect_select(tmp_space,H5S_SELECT_OR,tmp2_space); + CHECK(error, FAIL, "H5Sselect_select"); + /* Create Memory Dataspace */ memspace=H5Screate_simple(memrank,dimsm,NULL); CHECK(memspace, FAIL, "H5Screate_simple"); @@ -2493,7 +2508,7 @@ test_select_hyper_union_stagger(void) CHECK(error, FAIL, "H5Sselect_hyperslab"); /* Read File Dataset */ - error=H5Dread(dset_id,H5T_NATIVE_INT,memspace,dataspace,H5P_DEFAULT,data_out); + error=H5Dread(dset_id,H5T_NATIVE_INT,memspace,tmp_space,H5P_DEFAULT,data_out); CHECK(error, FAIL, "H5Dread"); /* Verify input data */ @@ -2509,6 +2524,10 @@ test_select_hyper_union_stagger(void) } /* end for */ /* Close things */ + error=H5Sclose(tmp2_space); + CHECK(error, FAIL, "H5Sclose"); + error=H5Sclose(tmp_space); + CHECK(error, FAIL, "H5Sclose"); error=H5Sclose(dataspace); CHECK(error, FAIL, "H5Sclose"); error=H5Sclose(memspace); @@ -2522,7 +2541,8 @@ test_select_hyper_union_stagger(void) /**************************************************************** ** ** test_select_hyper_union_3d(): Test basic H5S (dataspace) selection code. -** Tests unions of hyperslabs in 3-D +** Tests unions of hyperslabs in 3-D (Uses H5Scombine_hyperslab +** and H5Scombine_select instead of H5Sselect_hyperslab) ** ****************************************************************/ static void @@ -2531,6 +2551,8 @@ test_select_hyper_union_3d(void) hid_t fid1; /* HDF5 File IDs */ hid_t dataset; /* Dataset ID */ hid_t sid1,sid2; /* Dataspace ID */ + hid_t tmp_space; /* Temporary Dataspace ID */ + hid_t tmp2_space; /* Another temporary Dataspace ID */ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE4_DIM1, SPACE4_DIM2, SPACE4_DIM3}; hsize_t dims3[] = {SPACE3_DIM1, SPACE3_DIM2}; @@ -2648,19 +2670,29 @@ test_select_hyper_union_3d(void) stride[0]=1; stride[1]=1; stride[2]=1; count[0]=6; count[1]=6; count[2]=8; block[0]=1; block[1]=1; block[2]=1; - ret = H5Sselect_hyperslab(sid2,H5S_SELECT_OR,start,stride,count,block); - CHECK(ret, FAIL, "H5Sselect_hyperslab"); + tmp_space = H5Scombine_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block); + CHECK(tmp_space, FAIL, "H5Sselect_hyperslab"); - npoints = H5Sget_select_npoints(sid2); + /* Combine dataspaces and create new dataspace */ + tmp2_space = H5Scombine_select(sid2,H5S_SELECT_OR,tmp_space); + CHECK(tmp2_space, FAIL, "H5Scombin_select"); + + npoints = H5Sget_select_npoints(tmp2_space); VERIFY(npoints, 15*26, "H5Sget_select_npoints"); /* Create a dataset */ dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT); /* Write selection to disk */ - ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,sid2,sid1,H5P_DEFAULT,wbuf); + ret=H5Dwrite(dataset,H5T_NATIVE_UCHAR,tmp2_space,sid1,H5P_DEFAULT,wbuf); CHECK(ret, FAIL, "H5Dwrite"); + /* Close temporary dataspaces */ + ret = H5Sclose(tmp_space); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(tmp2_space); + CHECK(ret, FAIL, "H5Sclose"); + /* Close memory dataspace */ ret = H5Sclose(sid2); CHECK(ret, FAIL, "H5Sclose"); @@ -2715,6 +2747,515 @@ test_select_hyper_union_3d(void) /**************************************************************** ** +** test_select_hyper_and_2d(): Test basic H5S (dataspace) selection code. +** Tests 'and' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_and_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with intersection of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i=5 && i<=9) && (j>=5 && j<=9)) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* end for */ + + /* Close memory dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close disk dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + + /* Free memory buffers */ + free(wbuf); + free(rbuf); +} /* test_select_hyper_and_2d() */ + +/**************************************************************** +** +** test_select_hyper_xor_2d(): Test basic H5S (dataspace) selection code. +** Tests 'xor' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_xor_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with XOR of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i=0 && i<=4) && (j>=0 && j<=9)) || + ((i>=5 && i<=9) && ((j>=0 && j<=4) || (j>=10 && j<=14))) || + ((i>=10 && i<=14) && (j>=5 && j<=14))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* end for */ + + /* Close memory dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close disk dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + + /* Free memory buffers */ + free(wbuf); + free(rbuf); +} /* test_select_hyper_xor_2d() */ + +/**************************************************************** +** +** test_select_hyper_notb_2d(): Test basic H5S (dataspace) selection code. +** Tests 'notb' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_notb_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTB of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i=0 && i<=4) && (j>=0 && j<=9)) || + ((i>=5 && i<=9) && (j>=0 && j<=4))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* end for */ + + /* Close memory dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close disk dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + + /* Free memory buffers */ + free(wbuf); + free(rbuf); +} /* test_select_hyper_notb_2d() */ + +/**************************************************************** +** +** test_select_hyper_nota_2d(): Test basic H5S (dataspace) selection code. +** Tests 'nota' of hyperslabs in 2-D +** +****************************************************************/ +static void +test_select_hyper_nota_2d(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims1[] = {SPACE2_DIM1, SPACE2_DIM2}; + hsize_t dims2[] = {SPACE2A_DIM1}; + hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */ + uint8_t *wbuf, /* buffer to write to disk */ + *rbuf, /* buffer read from disk */ + *tbuf, /* temporary buffer pointer */ + *tbuf2; /* temporary buffer pointer */ + int i,j; /* Counters */ + herr_t ret; /* Generic return value */ + hsize_t npoints; /* Number of elements in selection */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Hyperslab Selection Functions with NOTA of 2-D hyperslabs\n")); + + /* Allocate write & read buffers */ + wbuf=malloc(sizeof(uint8_t)*SPACE2_DIM1*SPACE2_DIM2); + rbuf=calloc(sizeof(uint8_t),SPACE2_DIM1*SPACE2_DIM2); + + /* Initialize write buffer */ + for(i=0, tbuf=wbuf; i=10 && i<=14) && (j>=5 && j<=14)) || + ((i>=5 && i<=9) && (j>=10 && j<=14))) { + if(*tbuf!=*tbuf2) + printf("%d: hyperslab values don't match!, i=%d, j=%d, *tbuf=%d, *tbuf2=%d\n",__LINE__,i,j,(int)*tbuf,(int)*tbuf2); + tbuf2++; + } /* end if */ + else { + if(*tbuf!=0) + printf("%d: hyperslab element has wrong value!, i=%d, j=%d, *tbuf=%d\n",__LINE__,i,j,(int)*tbuf); + } /* end else */ + } /* end for */ + + /* Close memory dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close disk dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); + + /* Free memory buffers */ + free(wbuf); + free(rbuf); +} /* test_select_hyper_nota_2d() */ +#endif /* NEW_HYPERSLAB_API */ + +/**************************************************************** +** ** test_select_hyper_iter2(): Iterator for checking hyperslab iteration ** ****************************************************************/ @@ -2735,7 +3276,7 @@ test_select_hyper_iter2(void *_elem, hid_t UNUSED type_id, hsize_t ndim, hssize_ printf(", "); } /* end for */ printf("}\n"); - printf("*tbuf=%d, **tbuf2==%d\n",*tbuf,**tbuf2); + printf("*tbuf=%d, **tbuf2=%d\n",*tbuf,**tbuf2); return(-1); } /* end if */ else { @@ -2812,13 +3353,21 @@ test_select_hyper_union_random_5d(hid_t read_plist) for(test_num=0; test_num