From c6ed9cbbae2ab01129261e3fcfa5b5dc927976ea Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Tue, 19 Aug 2003 07:18:37 -0500 Subject: [svn-r7383] Purpose: Bug fix Description: I/O on chunked datasets with a scalar dataspace for the memory dataspace was not working correctly. Solution: Translate the scalar dataspace into a n-dimensional (where n is the number of dimensions of the file's dataspace) dataspace of dimensions 1x1x1... Platforms tested: FreeBSD 4.8 (sleipnir) h5committest (modulo modi4 which is not working correctly) --- release_docs/RELEASE.txt | 2 ++ src/H5Dio.c | 36 ++++++++++++++++++++----- test/tselect.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/release_docs/RELEASE.txt b/release_docs/RELEASE.txt index 91a7447..340c479 100644 --- a/release_docs/RELEASE.txt +++ b/release_docs/RELEASE.txt @@ -73,6 +73,8 @@ Bug Fixes since HDF5-1.6.0 release Library ------- + - Corrected bug when using scalar dataspace for memory selection and + operating on chunked dataset. QAK - 2003/08/18 - Corrected bugs with multiple '/' characters in names for H5Glink and H5Gunlink. QAK - 2003/08/16 - Corrected bug with user blocks that didn't allow a user block to diff --git a/src/H5Dio.c b/src/H5Dio.c index 4c026b6..131cad1 100644 --- a/src/H5Dio.c +++ b/src/H5Dio.c @@ -2249,6 +2249,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp const H5S_t *mem_space, fm_map *fm) { H5S_t *tmp_mspace=NULL; /* Temporary memory dataspace */ + H5S_t *equiv_mspace=NULL; /* Equivalent memory dataspace */ hid_t f_tid=(-1); /* Temporary copy of file datatype for iteration */ hbool_t iter_init=0; /* Selection iteration info has been initialized */ unsigned f_ndims; /* The number of dimensions of the file's dataspace */ @@ -2277,8 +2278,25 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp /* Get layout for dataset */ fm->layout = &(dataset->layout); - /*make a copy of mem_space*/ - if((tmp_mspace = H5S_copy(mem_space))==NULL) + /* Check if the memory space is scalar & make equivalent memory space */ + if((sm_ndims = H5S_get_simple_extent_ndims(mem_space))<0) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTGET, FAIL, "unable to get dimension number") + if(sm_ndims==0) { + hsize_t dims[H5O_LAYOUT_NDIMS]; /* Temporary dimension information */ + + /* Set up "equivalent" n-dimensional dataspace with size '1' in each dimension */ + for(u=0; ulayout.ndims-1; u++) + dims[u]=1; + if((equiv_mspace = H5S_create_simple(dataset->layout.ndims-1,dims,NULL))==NULL) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCREATE, FAIL, "unable to create equivalent dataspace for scalar space") + } /* end else */ + else { + if((equiv_mspace = H5S_copy(mem_space))==NULL) + HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") + } /* end else */ + + /* Make a copy of equivalent memory space */ + if((tmp_mspace = H5S_copy(equiv_mspace))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory space") /* Get dim number and dimensionality for each dataspace */ @@ -2328,13 +2346,13 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp /* Copy the dataspaces */ if((fm->file_space = H5S_copy(file_space))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy file dataspace") - if((fm->mem_space = H5S_copy(mem_space))==NULL) + if((fm->mem_space = H5S_copy(equiv_mspace))==NULL) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy memory dataspace") /* Get type of selection on disk & in memory */ if((fsel_type=H5S_get_select_type(file_space))<0) HGOTO_ERROR (H5E_DATASET, H5E_BADSELECT, FAIL, "unable to convert from file to memory data space") - if((fm->msel_type=H5S_get_select_type(mem_space))<0) + if((fm->msel_type=H5S_get_select_type(equiv_mspace))<0) HGOTO_ERROR (H5E_DATASET, H5E_BADSELECT, FAIL, "unable to convert from file to memory data space") /* Check if file selection is a point selection */ @@ -2375,7 +2393,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank); time = MPI_Wtime(); HDfprintf(stderr,"%s: rank=%d - After creating file chunk selections, time=%f\n",FUNC,mpi_rank,time); - HDfprintf(stderr,"%s: rank=%d - H5S_select_shape_same=%d\n",FUNC,mpi_rank,H5S_select_shape_same(file_space,mem_space)); + HDfprintf(stderr,"%s: rank=%d - H5S_select_shape_same=%d\n",FUNC,mpi_rank,H5S_select_shape_same(file_space,equiv_mspace)); } #endif /* QAK */ @@ -2398,7 +2416,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp } /* end else */ /* Build the memory selection for each chunk */ - if(fsel_type!=H5S_SEL_POINTS && H5S_select_shape_same(file_space,mem_space)==TRUE) { + if(fsel_type!=H5S_SEL_POINTS && H5S_select_shape_same(file_space,equiv_mspace)==TRUE) { if(H5S_hyper_convert(fm->mem_space)<0) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to convert selection to span trees") @@ -2420,7 +2438,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp /* Create selection iterator for memory selection */ if((elmt_size=H5T_get_size(mem_type))==0) 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), equiv_mspace, elmt_size)<0) HGOTO_ERROR (H5E_DATASPACE, H5E_CANTINIT, FAIL, "unable to initialize selection iterator") iter_init=1; /* Selection iteration info has been initialized */ @@ -2471,6 +2489,10 @@ done: HDONE_ERROR (H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release chunk mapping"); } /* end if */ + if(equiv_mspace) { + if(H5S_close(equiv_mspace)<0) + HDONE_ERROR(H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "can't release memory chunk dataspace template"); + } /* end if */ if(iter_init) { if (H5S_select_iter_release(&(fm->mem_iter))<0) HDONE_ERROR (H5E_DATASPACE, H5E_CANTRELEASE, FAIL, "unable to release selection iterator"); diff --git a/test/tselect.c b/test/tselect.c index 8114c13..d7705f5 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -4186,6 +4186,72 @@ test_select_point_chunk(void) /**************************************************************** ** +** test_select_sclar_chunk(): Test basic H5S (dataspace) selection code. +** Tests using a scalar dataspace (in memory) to access chunked datasets. +** +****************************************************************/ +static void +test_select_scalar_chunk(void) +{ + hid_t file_id; /* File ID */ + hid_t dcpl; /* Dataset creation property list */ + hid_t dsid; /* Dataset ID */ + hid_t sid; /* Dataspace ID */ + hid_t m_sid; /* Memory dataspace */ + hsize_t dims[] = {2}; /* Dataset dimensions */ + hsize_t maxdims[] = {H5S_UNLIMITED}; /* Dataset maximum dimensions */ + hssize_t offset[] = {0}; /* Hyperslab start */ + hsize_t count[] = {1}; /* Hyperslab count */ + unsigned data = 2; /* Data to write */ + herr_t ret; + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Scalar Dataspaces and Chunked Datasets\n")); + + file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(file_id, FAIL, "H5Fcreate"); + + dcpl = H5Pcreate(H5P_DATASET_CREATE); + CHECK(dcpl, FAIL, "H5Pcreate"); + + dims[0] = 1024U; + ret = H5Pset_chunk(dcpl, 1, dims); + CHECK(ret, FAIL, "H5Pset_chunk"); + + /* Create 1-D dataspace */ + sid = H5Screate_simple(1, dims, maxdims); + CHECK(sid, FAIL, "H5Screate_simple"); + + dsid = H5Dcreate(file_id, "dset", H5T_NATIVE_UINT, sid, dcpl); + CHECK(dsid, FAIL, "H5Dcreate"); + + /* Select scalar area (offset 0, count 1) */ + ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, offset, NULL, count, NULL); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Create scalar memory dataspace */ + m_sid = H5Screate(H5S_SCALAR); + CHECK(m_sid, FAIL, "H5Screate"); + + /* Write out data using scalar dataspace for memory dataspace */ + ret = H5Dwrite (dsid, H5T_NATIVE_UINT, m_sid, sid, H5P_DEFAULT, &data); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Close resources */ + ret = H5Sclose(m_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Dclose(dsid); + CHECK(ret, FAIL, "H5Dclose"); + ret = H5Pclose(dcpl); + CHECK(ret, FAIL, "H5Pclose"); + ret = H5Fclose (file_id); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_select_scalar_chunk() */ + +/**************************************************************** +** ** test_select_valid(): Test basic H5S (dataspace) selection code. ** Tests selection validity ** @@ -6468,6 +6534,9 @@ test_select(void) /* Test point selections in chunked datasets */ test_select_point_chunk(); + /* Test scalar dataspaces in chunked datasets */ + test_select_scalar_chunk(); + } /* test_select() */ -- cgit v0.12