summaryrefslogtreecommitdiffstats
path: root/src/H5Dio.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2004-05-01 19:19:46 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2004-05-01 19:19:46 (GMT)
commitcb4b2ad153a91a71eab3d88b43980709add3feee (patch)
tree91abfa5f0cd259eba4f87c569ee688c8d6364180 /src/H5Dio.c
parent050ff9dc1a84b609709822a75f5337485396a9a0 (diff)
downloadhdf5-cb4b2ad153a91a71eab3d88b43980709add3feee.zip
hdf5-cb4b2ad153a91a71eab3d88b43980709add3feee.tar.gz
hdf5-cb4b2ad153a91a71eab3d88b43980709add3feee.tar.bz2
[svn-r8461] Purpose:
Code optimization Description: Reduce the number of times the number of elements in a selection is computed. Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.9 (sleipnir) w/parallel too minor to require h5committest
Diffstat (limited to 'src/H5Dio.c')
-rw-r--r--src/H5Dio.c123
1 files changed, 51 insertions, 72 deletions
diff --git a/src/H5Dio.c b/src/H5Dio.c
index 21f01d4b..37e95a3 100644
--- a/src/H5Dio.c
+++ b/src/H5Dio.c
@@ -43,6 +43,7 @@
/* Structure holding information about a chunk's selection for mapping */
typedef struct H5D_chunk_info_t {
hsize_t index; /* "Index" of chunk in dataset (must be first for TBBT routines) */
+ hsize_t chunk_points; /* Number of elements selected in chunk */
H5S_t *fspace; /* Dataspace describing chunk & selection in it */
hssize_t coords[H5O_LAYOUT_NDIMS]; /* Coordinates of chunk in file dataset's dataspace */
H5S_t *mspace; /* Dataspace describing selection in memory corresponding to this chunk */
@@ -53,11 +54,11 @@ typedef struct H5D_chunk_info_t {
typedef struct fm_map {
H5TB_TREE *fsel; /* TBBT containing file dataspaces for all chunks */
hsize_t last_index; /* Index of last chunk operated on */
+ H5D_chunk_info_t *last_chunk_info; /* Pointer to last chunk's info */
const H5S_t *file_space; /* Pointer to the file dataspace */
const H5S_t *mem_space; /* Pointer to the memory dataspace */
unsigned mem_space_copy; /* Flag to indicate that the memory dataspace must be copied */
hsize_t f_dims[H5O_LAYOUT_NDIMS]; /* File dataspace dimensions */
- H5S_t *last_chunk; /* Pointer to last memory chunk's dataspace */
H5S_t *mchunk_tmpl; /* Dataspace template for new memory chunks */
unsigned f_ndims; /* Number of dimensions for file dataspace */
H5S_sel_iter_t mem_iter; /* Iterator for elements in memory selection */
@@ -883,7 +884,7 @@ H5D_write(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space,
if (!file_space)
file_space = dataset->space;
if (!mem_space)
- mem_space = file_space;
+ mem_space = file_space;
if((snelmts = H5S_get_select_npoints(mem_space))<0)
HGOTO_ERROR (H5E_ARGS, H5E_BADVALUE, FAIL, "src dataspace has invalid selection");
H5_ASSIGN_OVERFLOW(nelmts,snelmts,hssize_t,hsize_t);
@@ -1074,8 +1075,9 @@ H5D_contig_read(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type,
/* Sanity check dataset, then read it */
assert(dataset->layout.addr!=HADDR_UNDEF || dataset->efl.nused>0 ||
dataset->layout.type==H5D_COMPACT);
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
status = (sconv->read)(dataset->ent.file, &(dataset->layout),
- &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), H5T_get_size(dataset->type),
+ &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), (size_t)nelmts, H5T_get_size(dataset->type),
file_space, mem_space, dxpl_cache, dxpl_id, buf/*out*/);
#ifdef H5S_DEBUG
H5_timer_end(&(sconv->stats[1].read_timer), &timer);
@@ -1297,8 +1299,9 @@ H5D_contig_write(hsize_t nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5
#ifdef H5S_DEBUG
H5_timer_begin(&timer);
#endif
+ H5_CHECK_OVERFLOW(nelmts,hsize_t,size_t);
status = (sconv->write)(dataset->ent.file, &(dataset->layout),
- &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), H5T_get_size(dataset->type),
+ &dataset->dcpl_cache, (H5D_storage_t *)&(dataset->efl), (size_t)nelmts, H5T_get_size(dataset->type),
file_space, mem_space, dxpl_cache, dxpl_id, buf);
#ifdef H5S_DEBUG
H5_timer_end(&(sconv->stats[0].write_timer), &timer);
@@ -1505,8 +1508,6 @@ UNUSED
size_t dst_type_size; /*size of destination type*/
size_t target_size; /*desired buffer size */
hsize_t request_nelmts; /*requested strip mine */
- hssize_t schunk_nelmts; /* Number of elements selected in current chunk */
- hsize_t chunk_nelmts; /* Number of elements selected in current chunk */
hsize_t smine_start; /*strip mine start loc */
hsize_t n, smine_nelmts; /*elements per strip */
H5S_sel_iter_t mem_iter; /*memory selection iteration info*/
@@ -1549,20 +1550,12 @@ UNUSED
/* Get the actual chunk information from the tree node */
chunk_info=chunk_node->data;
-#ifdef H5S_DEBUG
- /* Get the number of elements selected in this chunk */
- if((schunk_nelmts=H5S_get_select_npoints(chunk_info->fspace))<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "bad # of elements in selection")
- H5_ASSIGN_OVERFLOW(chunk_nelmts,schunk_nelmts,hssize_t,hsize_t);
- assert(chunk_nelmts<=nelmts);
-#endif /* H5S_DEBUG */
-
/* Pass in chunk's coordinates in a union. */
store.chunk_coords = chunk_info->coords;
/* Perform the actual read operation */
status = (sconv->read)(dataset->ent.file, &(dataset->layout),
- &dataset->dcpl_cache, &store, H5T_get_size(dataset->type),
+ &dataset->dcpl_cache, &store, chunk_info->chunk_points, H5T_get_size(dataset->type),
chunk_info->fspace, chunk_info->mspace, dxpl_cache, dxpl_id, buf);
/* Check return value from optimized read */
@@ -1645,12 +1638,6 @@ UNUSED
/* Get the actual chunk information from the tree nodes */
chunk_info=chunk_node->data;
- /* Get the number of elements selected in this chunk */
- if((schunk_nelmts=H5S_get_select_npoints(chunk_info->fspace))<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "bad # of elements in selection")
- H5_ASSIGN_OVERFLOW(chunk_nelmts,schunk_nelmts,hssize_t,hsize_t);
- assert(chunk_nelmts<=nelmts);
-
/* initialize selection iterator */
if (H5S_select_iter_init(&file_iter, chunk_info->fspace, src_type_size)<0)
HGOTO_ERROR (H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information");
@@ -1665,10 +1652,10 @@ UNUSED
/* Pass in chunk's coordinates in a union*/
store.chunk_coords = chunk_info->coords;
- for (smine_start=0; smine_start<chunk_nelmts; smine_start+=smine_nelmts) {
+ for (smine_start=0; smine_start<chunk_info->chunk_points; smine_start+=smine_nelmts) {
/* Go figure out how many elements to read from the file */
- assert(H5S_select_iter_nelmts(&file_iter)==(chunk_nelmts-smine_start));
- smine_nelmts = MIN(request_nelmts, (chunk_nelmts-smine_start));
+ assert(H5S_select_iter_nelmts(&file_iter)==(chunk_info->chunk_points-smine_start));
+ smine_nelmts = MIN(request_nelmts, (chunk_info->chunk_points-smine_start));
/*
* Gather the data from disk into the data type conversion
@@ -1817,8 +1804,6 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space,
size_t dst_type_size; /*size of destination type*/
size_t target_size; /*desired buffer size */
hsize_t request_nelmts; /*requested strip mine */
- hssize_t schunk_nelmts; /* Number of elements selected in current chunk */
- hsize_t chunk_nelmts; /* Number of elements selected in current chunk */
hsize_t smine_start; /*strip mine start loc */
hsize_t n, smine_nelmts; /*elements per strip */
H5S_sel_iter_t mem_iter; /*memory selection iteration info*/
@@ -1884,20 +1869,12 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space,
/* Get the actual chunk information from the tree node */
chunk_info=chunk_node->data;
-#ifdef H5S_DEBUG
- /* Get the number of elements selected in this chunk */
- if((schunk_nelmts=H5S_get_select_npoints(chunk_info->fspace))<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "bad # of elements in selection")
- H5_ASSIGN_OVERFLOW(chunk_nelmts,schunk_nelmts,hssize_t,hsize_t);
- assert(chunk_nelmts<=nelmts);
-#endif /* H5S_DEBUG */
-
/* Pass in chunk's coordinates in a union. */
store.chunk_coords = chunk_info->coords;
/* Perform the actual write operation */
status = (sconv->write)(dataset->ent.file, &(dataset->layout),
- &dataset->dcpl_cache, &store, H5T_get_size(dataset->type),
+ &dataset->dcpl_cache, &store, chunk_info->chunk_points, H5T_get_size(dataset->type),
chunk_info->fspace, chunk_info->mspace, dxpl_cache, dxpl_id, buf);
/* Check return value from optimized write */
@@ -2000,12 +1977,6 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space,
/* Get the actual chunk information from the tree node */
chunk_info=chunk_node->data;
- /* Get the number of elements selected in this chunk */
- if((schunk_nelmts=H5S_get_select_npoints(chunk_info->fspace))<0)
- HGOTO_ERROR(H5E_DATASET, H5E_CANTCOUNT, FAIL, "bad # of elements in selection")
- H5_ASSIGN_OVERFLOW(chunk_nelmts,schunk_nelmts,hssize_t,hsize_t);
- assert(chunk_nelmts<=nelmts);
-
/* initialize selection iterator */
if (H5S_select_iter_init(&file_iter, chunk_info->fspace, dst_type_size)<0)
HGOTO_ERROR (H5E_DATASET, H5E_CANTINIT, FAIL, "unable to initialize file selection information");
@@ -2020,10 +1991,10 @@ nelmts, H5D_t *dataset, const H5T_t *mem_type, const H5S_t *mem_space,
/*pass in chunk's coordinates in a union*/
store.chunk_coords = chunk_info->coords;
- for (smine_start=0; smine_start<chunk_nelmts; smine_start+=smine_nelmts) {
+ for (smine_start=0; smine_start<chunk_info->chunk_points; smine_start+=smine_nelmts) {
/* Go figure out how many elements to read from the file */
- assert(H5S_select_iter_nelmts(&file_iter)==(chunk_nelmts-smine_start));
- smine_nelmts = MIN(request_nelmts, (chunk_nelmts-smine_start));
+ assert(H5S_select_iter_nelmts(&file_iter)==(chunk_info->chunk_points-smine_start));
+ smine_nelmts = MIN(request_nelmts, (chunk_info->chunk_points-smine_start));
/*
* Gather the data from disk into the data type conversion
@@ -2341,7 +2312,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp
/* Initialize "last chunk" information */
fm->last_index=(hsize_t)-1;
- fm->last_chunk=NULL;
+ fm->last_chunk_info=NULL;
/* Point at the dataspaces */
fm->file_space=file_space;
@@ -2366,7 +2337,7 @@ H5D_create_chunk_map(H5D_t *dataset, const H5T_t *mem_type, const H5S_t *file_sp
/* Reset "last chunk" info */
fm->last_index=(hsize_t)-1;
- fm->last_chunk=NULL;
+ fm->last_chunk_info=NULL;
} /* end if */
else {
#ifdef QAK
@@ -2658,8 +2629,8 @@ H5D_create_chunk_file_map_hyper(const fm_map *fm)
/* Check for intersection of temporary chunk and file selection */
if(H5S_hyper_intersect_block(fm->file_space,coords,end)==TRUE) {
H5S_t *tmp_fchunk; /* Temporary file dataspace */
- H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into tree */
- hssize_t chunk_points; /* Number of elements in chunk selection */
+ H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into tree */
+ hssize_t schunk_points; /* Number of elements in chunk selection */
/* Create "temporary" chunk for selection operations (copy file space) */
if((tmp_fchunk = H5S_copy(fm->file_space))==NULL)
@@ -2722,11 +2693,12 @@ H5D_create_chunk_file_map_hyper(const fm_map *fm)
} /* end if */
/* Get number of elements selected in chunk */
- if((chunk_points=H5S_get_select_npoints(tmp_fchunk))<0)
- HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements");
+ if((schunk_points=H5S_get_select_npoints(tmp_fchunk))<0)
+ HGOTO_ERROR(H5E_DATASPACE, H5E_CANTGET, FAIL, "can't get file selection # of elements")
+ H5_ASSIGN_OVERFLOW(new_chunk_info->chunk_points,schunk_points,hssize_t,hsize_t);
/* Decrement # of points left in file selection */
- sel_points-=chunk_points;
+ sel_points-=schunk_points;
/* Leave if we are done */
if(sel_points==0)
@@ -2973,7 +2945,7 @@ static herr_t
H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_t *coords, void *_fm)
{
fm_map *fm = (fm_map*)_fm; /* File<->memory chunk mapping info */
- H5S_t *fspace; /* Memory chunk's dataspace */
+ H5D_chunk_info_t *chunk_info; /* Chunk information for current chunk */
hssize_t coords_in_chunk[H5O_LAYOUT_NDIMS]; /* Coordinates of element in chunk */
hsize_t chunk_index; /* Chunk index */
unsigned u; /* Local index variable */
@@ -2988,9 +2960,9 @@ H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize
/* Find correct chunk in file & memory TBBTs */
if(chunk_index==fm->last_index) {
/* If the chunk index is the same as the last chunk index we used,
- * get the cached spaces to operate on.
+ * get the cached info to operate on.
*/
- fspace=fm->last_chunk;
+ chunk_info=fm->last_chunk_info;
} /* end if */
else {
H5TB_NODE *chunk_node; /* TBBT node holding chunk information */
@@ -3000,7 +2972,8 @@ H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize
*/
/* Get the chunk node from the TBBT */
if((chunk_node=H5TB_dfind(fm->fsel,&chunk_index,NULL))==NULL) {
- H5D_chunk_info_t *new_chunk_info; /* chunk information to insert into tree */
+ H5D_chunk_info_t *new_chunk_info; /* Chunk information to insert into tree */
+ H5S_t *fspace; /* Memory chunk's dataspace */
/* Allocate the file & memory chunk information */
if (NULL==(new_chunk_info = H5FL_MALLOC (H5D_chunk_info_t)))
@@ -3031,6 +3004,9 @@ H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize
new_chunk_info->mspace=NULL;
new_chunk_info->mspace_shared=0;
+ /* Set the number of selected elements in chunk to zero */
+ new_chunk_info->chunk_points=0;
+
/* Compute the chunk's coordinates */
for(u=0; u<fm->f_ndims; u++) {
H5_CHECK_OVERFLOW(fm->layout->dim[u],hsize_t,hssize_t);
@@ -3043,14 +3019,17 @@ H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize
H5D_free_chunk_info(new_chunk_info);
HGOTO_ERROR(H5E_DATASPACE,H5E_CANTINSERT,FAIL,"can't insert chunk into TBBT")
} /* end if */
+
+ /* Save the chunk info pointer */
+ chunk_info=new_chunk_info;
} /* end if */
else
- /* Get the memory space information from the node */
- fspace=((H5D_chunk_info_t *)(chunk_node->data))->fspace;
+ /* Get the information from the node */
+ chunk_info=(H5D_chunk_info_t *)(chunk_node->data);
/* Update the "last chunk seen" information */
fm->last_index=chunk_index;
- fm->last_chunk=fspace;
+ fm->last_chunk_info=chunk_info;
} /* end else */
/* Get the coordinates of the element in the chunk */
@@ -3058,9 +3037,12 @@ H5D_chunk_file_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize
coords_in_chunk[u]=coords[u]%fm->layout->dim[u];
/* Add point to file selection for chunk */
- if(H5S_select_elements(fspace,H5S_SELECT_APPEND,1,(const hssize_t **)coords_in_chunk)<0)
+ if(H5S_select_elements(chunk_info->fspace,H5S_SELECT_APPEND,1,(const hssize_t **)coords_in_chunk)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSELECT, FAIL, "unable to select element")
+ /* Increment the number of elemented selected in chunk */
+ chunk_info->chunk_points++;
+
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5D_chunk_file_cb() */
@@ -3087,7 +3069,7 @@ static herr_t
H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_t *coords, void *_fm)
{
fm_map *fm = (fm_map*)_fm; /* File<->memory chunk mapping info */
- H5S_t *mspace; /* Memory chunk's dataspace */
+ H5D_chunk_info_t *chunk_info; /* Chunk information for current chunk */
hssize_t coords_in_mem[H5O_LAYOUT_NDIMS]; /* Coordinates of element in memory */
hsize_t chunk_index; /* Chunk index */
herr_t ret_value = SUCCEED; /* Return value */
@@ -3103,7 +3085,7 @@ H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_
/* If the chunk index is the same as the last chunk index we used,
* get the cached spaces to operate on.
*/
- mspace=fm->last_chunk;
+ chunk_info=fm->last_chunk_info;
} /* end if */
else {
H5TB_NODE *chunk_node; /* TBBT node holding chunk information */
@@ -3115,22 +3097,19 @@ H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_
if((chunk_node=H5TB_dfind(fm->fsel,&chunk_index,NULL))==NULL)
HGOTO_ERROR(H5E_DATASPACE,H5E_NOTFOUND,FAIL,"can't locate chunk in TBBT")
- /* Get the memory space information from the node */
- mspace=((H5D_chunk_info_t *)(chunk_node->data))->mspace;
+ /* Get the chunk info pointer */
+ chunk_info=(H5D_chunk_info_t *)(chunk_node->data);
/* Check if the chunk already has a memory space */
- if(mspace==NULL) {
+ if(chunk_info->mspace==NULL) {
/* Copy the template memory chunk dataspace */
- if((mspace = H5S_copy(fm->mchunk_tmpl))==NULL)
+ if((chunk_info->mspace = H5S_copy(fm->mchunk_tmpl))==NULL)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTCOPY, FAIL, "unable to copy file space")
-
- /* Set the chunk's memory dataspace for later use */
- ((H5D_chunk_info_t *)(chunk_node->data))->mspace=mspace;
} /* end else */
/* Update the "last chunk seen" information */
fm->last_index=chunk_index;
- fm->last_chunk=mspace;
+ fm->last_chunk_info=chunk_info;
} /* end else */
/* Get coordinates of selection iterator for memory */
@@ -3139,12 +3118,12 @@ H5D_chunk_mem_cb(void UNUSED *elem, hid_t UNUSED type_id, hsize_t ndims, hssize_
/* Add point to memory selection for chunk */
if(fm->msel_type==H5S_SEL_POINTS) {
- if(H5S_select_elements(mspace,H5S_SELECT_APPEND,1,(const hssize_t **)coords_in_mem)<0)
+ if(H5S_select_elements(chunk_info->mspace,H5S_SELECT_APPEND,1,(const hssize_t **)coords_in_mem)<0)
HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSELECT, FAIL, "unable to select element")
} /* end if */
else {
- if(H5S_hyper_add_span_element(mspace, fm->m_ndims, coords_in_mem)<0)
- HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSELECT, FAIL, "unable to select element");
+ if(H5S_hyper_add_span_element(chunk_info->mspace, fm->m_ndims, coords_in_mem)<0)
+ HGOTO_ERROR (H5E_DATASPACE, H5E_CANTSELECT, FAIL, "unable to select element")
} /* end else */
/* Move memory selection iterator to next element in selection */