From 449a55b634ebf71fe6d3fa99745a025b66d34db2 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Sat, 1 May 2004 23:26:05 -0500 Subject: [svn-r8463] Purpose: Code optimization Description: Eliminate redundant B-tree lookups for chunk information. Platforms tested: Solaris 2.7 (arabica) FreeBSD 4.9 (sleipnir) w/parallel too minor to require h5committest --- src/H5Distore.c | 52 ++++++++++++++++++++++++++++++---------------------- src/H5Fistore.c | 52 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/H5Distore.c b/src/H5Distore.c index 7853abd..85bb007 100644 --- a/src/H5Distore.c +++ b/src/H5Distore.c @@ -1352,6 +1352,7 @@ done: static void * H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, const H5O_layout_t *layout, const H5O_pline_t *pline, const H5O_fill_t *fill, H5D_fill_time_t fill_time, + H5F_istore_ud1_t *udata, const hssize_t offset[], hbool_t relax, unsigned *idx_hint/*in,out*/) { @@ -1416,14 +1417,21 @@ H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, con HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); } else { - H5F_istore_ud1_t udata; /*B-tree pass-through */ + H5F_istore_ud1_t tmp_udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Address of chunk on disk */ - /* - * Not in the cache. Read it from the file and count this as a miss - * if it's in the file or an init if it isn't. - */ - chunk_addr = H5F_istore_get_addr(f, dxpl_id, layout, offset, &udata); + if(udata!=NULL) + chunk_addr=udata->addr; + else { + /* Point at temporary storage for B-tree pass through */ + udata=&tmp_udata; + + /* + * Not in the cache. Read it from the file and count this as a miss + * if it's in the file or an init if it isn't. + */ + chunk_addr = H5F_istore_get_addr(f, dxpl_id, layout, offset, udata); + } /* end else */ if (H5F_addr_defined(chunk_addr)) { size_t chunk_alloc=0; /*allocated chunk size */ @@ -1433,13 +1441,13 @@ H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, con */ /* Chunk size on disk isn't [likely] the same size as the final chunk * size in memory, so allocate memory big enough. */ - chunk_alloc = udata.key.nbytes; + chunk_alloc = udata->key.nbytes; if (NULL==(chunk = H5F_istore_chunk_alloc (chunk_alloc,pline))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); - if (H5F_block_read(f, H5FD_MEM_DRAW, chunk_addr, udata.key.nbytes, dxpl_id, chunk)<0) + if (H5F_block_read(f, H5FD_MEM_DRAW, chunk_addr, udata->key.nbytes, dxpl_id, chunk)<0) HGOTO_ERROR (H5E_IO, H5E_READERROR, NULL, "unable to read raw data chunk"); - if (H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &(udata.key.filter_mask), dxpl_cache->err_detect, - dxpl_cache->filter_cb, &(udata.key.nbytes), &chunk_alloc, &chunk)<0) { + if (H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &(udata->key.filter_mask), dxpl_cache->err_detect, + dxpl_cache->filter_cb, &(udata->key.nbytes), &chunk_alloc, &chunk)<0) { HGOTO_ERROR(H5E_PLINE, H5E_READERROR, NULL, "data pipeline read failed"); } rdcc->nmisses++; @@ -1698,6 +1706,7 @@ H5F_istore_readvv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, hid_t dxp size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[], void *buf) { + H5F_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ size_t u; /* Local index variables */ ssize_t ret_value; /* Return value */ @@ -1727,7 +1736,7 @@ HDfprintf(stderr,"%s: chunk_coords={",FUNC); for(u=0; undims; u++) HDfprintf(stderr,"%Hd%s",chunk_coords[u],(u<(layout->ndims-1) ? ", " : "}\n")); #endif /* QAK */ - chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, NULL); + chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, &udata); #ifdef QAK HDfprintf(stderr,"%s: chunk_addr=%a, chunk_size=%Hu\n",FUNC,chunk_addr,layout->chunk_size); HDfprintf(stderr,"%s: chunk_len_arr[%Zu]=%Zu\n",FUNC,*chunk_curr_seq,chunk_len_arr[*chunk_curr_seq]); @@ -1757,7 +1766,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a * chunk. */ if (NULL==(chunk=H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &dcpl_cache->pline, &dcpl_cache->fill, dcpl_cache->fill_time, - chunk_coords, FALSE, &idx_hint))) + &udata, chunk_coords, FALSE, &idx_hint))) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "unable to read raw data chunk"); /* Use the vectorized memory copy routine to do actual work */ @@ -1801,6 +1810,7 @@ H5F_istore_writevv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[], const void *buf) { + H5F_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ size_t u; /* Local index variables */ ssize_t ret_value; /* Return value */ @@ -1830,7 +1840,7 @@ HDfprintf(stderr,"%s: chunk_coords={",FUNC); for(u=0; undims; u++) HDfprintf(stderr,"%Hd%s",chunk_coords[u],(u<(layout->ndims-1) ? ", " : "}\n")); #endif /* QAK */ - chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, NULL); + chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, &udata); #ifdef QAK HDfprintf(stderr,"%s: chunk_addr=%a, chunk_size=%Hu\n",FUNC,chunk_addr,layout->chunk_size); HDfprintf(stderr,"%s: chunk_len_arr[%Zu]=%Zu\n",FUNC,*chunk_curr_seq,chunk_len_arr[*chunk_curr_seq]); @@ -1845,7 +1855,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a * for the chunk has been defined, then don't load the chunk into the * cache, just write the data to it directly. * - * If MPIO, MPIPOSIX, or FPHDF5 is used, must bypass the + * If MPI based VFD is used, must bypass the * chunk-cache scheme because other MPI processes could be * writing to other elements in the same chunk. Do a direct * write-through of only the elements requested. @@ -1878,7 +1888,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a relax = FALSE; if (NULL==(chunk=H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &dcpl_cache->pline, &dcpl_cache->fill, dcpl_cache->fill_time, - chunk_coords, relax, &idx_hint))) + &udata, chunk_coords, relax, &idx_hint))) HGOTO_ERROR (H5E_IO, H5E_WRITEERROR, FAIL, "unable to read raw data chunk"); /* Use the vectorized memory copy routine to do actual work */ @@ -2730,7 +2740,6 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca unsigned idx_hint = 0; /*input value for H5F_istore_lock */ hssize_t chunk_offset[H5O_LAYOUT_NDIMS]; /*logical location of the chunks */ hsize_t idx_cur[H5O_LAYOUT_NDIMS]; /*multi-dimensional counters */ - hsize_t idx_min[H5O_LAYOUT_NDIMS]; hsize_t idx_max[H5O_LAYOUT_NDIMS]; hsize_t sub_size[H5O_LAYOUT_NDIMS]; hsize_t naccessed; /*bytes accessed in chunk */ @@ -2774,7 +2783,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca /* Go get the rank & dimensions */ if((srank = H5S_get_simple_extent_dims(space, curr_dims, NULL)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataset dimensions"); - rank=srank; + H5_ASSIGN_OVERFLOW(rank,srank,int,unsigned); /* Copy current dimensions */ for(u = 0; u < rank; u++) @@ -2786,14 +2795,13 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace"); /* - * Set up multi-dimensional counters (idx_min, idx_max, and idx_cur) and + * Set up multi-dimensional counters (idx_max, and idx_cur) and * loop through the chunks copying each chunk from the application to the * chunk cache. */ for(u = 0; u < layout->ndims; u++) { - idx_min[u] = 0; idx_max[u] = (size[u] - 1) / layout->dim[u] + 1; - idx_cur[u] = idx_min[u]; + idx_cur[u] = 0; } /* end for */ /* Loop over all chunks */ @@ -2822,7 +2830,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca if(found) { if(NULL == (chunk = H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &pline, &fill, fill_time, - chunk_offset, FALSE, &idx_hint))) + NULL, chunk_offset, FALSE, &idx_hint))) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to read raw data chunk"); if(H5S_select_all(space_chunk,1) < 0) @@ -2862,7 +2870,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca /* Increment indices */ for(i = layout->ndims - 1, carry = 1; i >= 0 && carry; --i) { if(++idx_cur[i] >= idx_max[i]) - idx_cur[i] = idx_min[i]; + idx_cur[i] = 0; else carry = 0; } /* end for */ diff --git a/src/H5Fistore.c b/src/H5Fistore.c index 7853abd..85bb007 100644 --- a/src/H5Fistore.c +++ b/src/H5Fistore.c @@ -1352,6 +1352,7 @@ done: static void * H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, const H5O_layout_t *layout, const H5O_pline_t *pline, const H5O_fill_t *fill, H5D_fill_time_t fill_time, + H5F_istore_ud1_t *udata, const hssize_t offset[], hbool_t relax, unsigned *idx_hint/*in,out*/) { @@ -1416,14 +1417,21 @@ H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, con HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); } else { - H5F_istore_ud1_t udata; /*B-tree pass-through */ + H5F_istore_ud1_t tmp_udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Address of chunk on disk */ - /* - * Not in the cache. Read it from the file and count this as a miss - * if it's in the file or an init if it isn't. - */ - chunk_addr = H5F_istore_get_addr(f, dxpl_id, layout, offset, &udata); + if(udata!=NULL) + chunk_addr=udata->addr; + else { + /* Point at temporary storage for B-tree pass through */ + udata=&tmp_udata; + + /* + * Not in the cache. Read it from the file and count this as a miss + * if it's in the file or an init if it isn't. + */ + chunk_addr = H5F_istore_get_addr(f, dxpl_id, layout, offset, udata); + } /* end else */ if (H5F_addr_defined(chunk_addr)) { size_t chunk_alloc=0; /*allocated chunk size */ @@ -1433,13 +1441,13 @@ H5F_istore_lock(H5F_t *f, const H5D_dxpl_cache_t *dxpl_cache, hid_t dxpl_id, con */ /* Chunk size on disk isn't [likely] the same size as the final chunk * size in memory, so allocate memory big enough. */ - chunk_alloc = udata.key.nbytes; + chunk_alloc = udata->key.nbytes; if (NULL==(chunk = H5F_istore_chunk_alloc (chunk_alloc,pline))) HGOTO_ERROR (H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for raw data chunk"); - if (H5F_block_read(f, H5FD_MEM_DRAW, chunk_addr, udata.key.nbytes, dxpl_id, chunk)<0) + if (H5F_block_read(f, H5FD_MEM_DRAW, chunk_addr, udata->key.nbytes, dxpl_id, chunk)<0) HGOTO_ERROR (H5E_IO, H5E_READERROR, NULL, "unable to read raw data chunk"); - if (H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &(udata.key.filter_mask), dxpl_cache->err_detect, - dxpl_cache->filter_cb, &(udata.key.nbytes), &chunk_alloc, &chunk)<0) { + if (H5Z_pipeline(pline, H5Z_FLAG_REVERSE, &(udata->key.filter_mask), dxpl_cache->err_detect, + dxpl_cache->filter_cb, &(udata->key.nbytes), &chunk_alloc, &chunk)<0) { HGOTO_ERROR(H5E_PLINE, H5E_READERROR, NULL, "data pipeline read failed"); } rdcc->nmisses++; @@ -1698,6 +1706,7 @@ H5F_istore_readvv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, hid_t dxp size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[], void *buf) { + H5F_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ size_t u; /* Local index variables */ ssize_t ret_value; /* Return value */ @@ -1727,7 +1736,7 @@ HDfprintf(stderr,"%s: chunk_coords={",FUNC); for(u=0; undims; u++) HDfprintf(stderr,"%Hd%s",chunk_coords[u],(u<(layout->ndims-1) ? ", " : "}\n")); #endif /* QAK */ - chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, NULL); + chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, &udata); #ifdef QAK HDfprintf(stderr,"%s: chunk_addr=%a, chunk_size=%Hu\n",FUNC,chunk_addr,layout->chunk_size); HDfprintf(stderr,"%s: chunk_len_arr[%Zu]=%Zu\n",FUNC,*chunk_curr_seq,chunk_len_arr[*chunk_curr_seq]); @@ -1757,7 +1766,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a * chunk. */ if (NULL==(chunk=H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &dcpl_cache->pline, &dcpl_cache->fill, dcpl_cache->fill_time, - chunk_coords, FALSE, &idx_hint))) + &udata, chunk_coords, FALSE, &idx_hint))) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "unable to read raw data chunk"); /* Use the vectorized memory copy routine to do actual work */ @@ -1801,6 +1810,7 @@ H5F_istore_writevv(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_cache, size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[], const void *buf) { + H5F_istore_ud1_t udata; /*B-tree pass-through */ haddr_t chunk_addr; /* Chunk address on disk */ size_t u; /* Local index variables */ ssize_t ret_value; /* Return value */ @@ -1830,7 +1840,7 @@ HDfprintf(stderr,"%s: chunk_coords={",FUNC); for(u=0; undims; u++) HDfprintf(stderr,"%Hd%s",chunk_coords[u],(u<(layout->ndims-1) ? ", " : "}\n")); #endif /* QAK */ - chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, NULL); + chunk_addr=H5F_istore_get_addr(f, dxpl_id, layout, chunk_coords, &udata); #ifdef QAK HDfprintf(stderr,"%s: chunk_addr=%a, chunk_size=%Hu\n",FUNC,chunk_addr,layout->chunk_size); HDfprintf(stderr,"%s: chunk_len_arr[%Zu]=%Zu\n",FUNC,*chunk_curr_seq,chunk_len_arr[*chunk_curr_seq]); @@ -1845,7 +1855,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a * for the chunk has been defined, then don't load the chunk into the * cache, just write the data to it directly. * - * If MPIO, MPIPOSIX, or FPHDF5 is used, must bypass the + * If MPI based VFD is used, must bypass the * chunk-cache scheme because other MPI processes could be * writing to other elements in the same chunk. Do a direct * write-through of only the elements requested. @@ -1878,7 +1888,7 @@ HDfprintf(stderr,"%s: mem_offset_arr[%Zu]=%Hu\n",FUNC,*mem_curr_seq,mem_offset_a relax = FALSE; if (NULL==(chunk=H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &dcpl_cache->pline, &dcpl_cache->fill, dcpl_cache->fill_time, - chunk_coords, relax, &idx_hint))) + &udata, chunk_coords, relax, &idx_hint))) HGOTO_ERROR (H5E_IO, H5E_WRITEERROR, FAIL, "unable to read raw data chunk"); /* Use the vectorized memory copy routine to do actual work */ @@ -2730,7 +2740,6 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca unsigned idx_hint = 0; /*input value for H5F_istore_lock */ hssize_t chunk_offset[H5O_LAYOUT_NDIMS]; /*logical location of the chunks */ hsize_t idx_cur[H5O_LAYOUT_NDIMS]; /*multi-dimensional counters */ - hsize_t idx_min[H5O_LAYOUT_NDIMS]; hsize_t idx_max[H5O_LAYOUT_NDIMS]; hsize_t sub_size[H5O_LAYOUT_NDIMS]; hsize_t naccessed; /*bytes accessed in chunk */ @@ -2774,7 +2783,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca /* Go get the rank & dimensions */ if((srank = H5S_get_simple_extent_dims(space, curr_dims, NULL)) < 0) HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "can't get dataset dimensions"); - rank=srank; + H5_ASSIGN_OVERFLOW(rank,srank,int,unsigned); /* Copy current dimensions */ for(u = 0; u < rank; u++) @@ -2786,14 +2795,13 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca HGOTO_ERROR(H5E_DATASPACE, H5E_CANTCREATE, FAIL, "can't create simple dataspace"); /* - * Set up multi-dimensional counters (idx_min, idx_max, and idx_cur) and + * Set up multi-dimensional counters (idx_max, and idx_cur) and * loop through the chunks copying each chunk from the application to the * chunk cache. */ for(u = 0; u < layout->ndims; u++) { - idx_min[u] = 0; idx_max[u] = (size[u] - 1) / layout->dim[u] + 1; - idx_cur[u] = idx_min[u]; + idx_cur[u] = 0; } /* end for */ /* Loop over all chunks */ @@ -2822,7 +2830,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca if(found) { if(NULL == (chunk = H5F_istore_lock(f, dxpl_cache, dxpl_id, layout, &pline, &fill, fill_time, - chunk_offset, FALSE, &idx_hint))) + NULL, chunk_offset, FALSE, &idx_hint))) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "unable to read raw data chunk"); if(H5S_select_all(space_chunk,1) < 0) @@ -2862,7 +2870,7 @@ H5F_istore_initialize_by_extent(H5F_t *f, const struct H5D_dxpl_cache_t *dxpl_ca /* Increment indices */ for(i = layout->ndims - 1, carry = 1; i >= 0 && carry; --i) { if(++idx_cur[i] >= idx_max[i]) - idx_cur[i] = idx_min[i]; + idx_cur[i] = 0; else carry = 0; } /* end for */ -- cgit v0.12