From 68203c788ab9266b28a4e95dd061434fa94e501d Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Wed, 16 Aug 2000 15:08:23 -0500 Subject: [svn-r2472] Combine object header prefix and first object header chunk when possible. --- src/H5O.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/src/H5O.c b/src/H5O.c index 5d1fe99..a064da1 100644 --- a/src/H5O.c +++ b/src/H5O.c @@ -542,6 +542,7 @@ H5O_flush(H5F_t *f, hbool_t destroy, haddr_t addr, H5O_t *oh) intn i, id; H5O_cont_t *cont = NULL; herr_t (*encode)(H5F_t*, uint8_t*, const void*) = NULL; + uintn combine=0; /* Whether to combine the object header prefix & the first chunk */ FUNC_ENTER(H5O_flush, FAIL); @@ -572,16 +573,22 @@ H5O_flush(H5F_t *f, hbool_t destroy, haddr_t addr, H5O_t *oh) /* zero to alignment */ HDmemset (p, 0, H5O_SIZEOF_HDR(f)-12); - /* write the object header header */ + /* write the object header prefix */ + /* Check if we can combine the object header prefix & the first chunk into one I/O operation */ + if(oh->chunk[0].dirty && (addr+H5O_SIZEOF_HDR(f))==oh->chunk[0].addr) { + combine=1; + } /* end if */ + else { #ifdef H5_HAVE_PARALLEL - if (IS_H5FD_MPIO(f)) - H5FD_mpio_tas_allsame(f->shared->lf, TRUE); /*only p0 will write*/ + if (IS_H5FD_MPIO(f)) + H5FD_mpio_tas_allsame(f->shared->lf, TRUE); /*only p0 will write*/ #endif /* H5_HAVE_PARALLEL */ - if (H5F_block_write(f, addr, (hsize_t)H5O_SIZEOF_HDR(f), - H5P_DEFAULT, buf) < 0) { - HRETURN_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, - "unable to write object header hdr to disk"); - } + if (H5F_block_write(f, addr, (hsize_t)H5O_SIZEOF_HDR(f), + H5P_DEFAULT, buf) < 0) { + HRETURN_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, + "unable to write object header hdr to disk"); + } + } /* end else */ /* encode messages */ for (i = 0; i < oh->nmesgs; i++) { @@ -649,20 +656,48 @@ H5O_flush(H5F_t *f, hbool_t destroy, haddr_t addr, H5O_t *oh) /* write each chunk to disk */ for (i = 0; i < oh->nchunks; i++) { if (oh->chunk[i].dirty) { - assert(H5F_addr_defined(oh->chunk[i].addr)); + assert(H5F_addr_defined(oh->chunk[i].addr)); + if(i==0 && combine) { + /* Allocate space for the combined prefix and first chunk */ + if((p=H5FL_BLK_ALLOC(chunk_image,H5O_SIZEOF_HDR(f)+oh->chunk[i].size,0))==NULL) + HRETURN_ERROR (H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); + + /* Copy in the prefix */ + HDmemcpy(p,buf,H5O_SIZEOF_HDR(f)); + + /* Copy in the first chunk */ + HDmemcpy(p+H5O_SIZEOF_HDR(f),oh->chunk[i].image,oh->chunk[i].size); + + /* Write the combined prefix/chunk out */ #ifdef H5_HAVE_PARALLEL - if (IS_H5FD_MPIO(f)) - H5FD_mpio_tas_allsame(f->shared->lf, TRUE); /*only p0 write*/ + if (IS_H5FD_MPIO(f)) + H5FD_mpio_tas_allsame(f->shared->lf, TRUE); /*only p0 write*/ #endif /* H5_HAVE_PARALLEL */ - if (H5F_block_write(f, oh->chunk[i].addr, - (hsize_t)(oh->chunk[i].size), - H5P_DEFAULT, oh->chunk[i].image) < 0) { - HRETURN_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, - "unable to write object header data to disk"); - } - oh->chunk[i].dirty = FALSE; - } - } + if (H5F_block_write(f, addr, + (hsize_t)(H5O_SIZEOF_HDR(f)+oh->chunk[i].size), + H5P_DEFAULT, p) < 0) { + HRETURN_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, + "unable to write object header data to disk"); + } /* end if */ + + /* Release the memory for the combined prefix/chunk */ + p = H5FL_BLK_FREE(chunk_image,p); + } /* end if */ + else { +#ifdef H5_HAVE_PARALLEL + if (IS_H5FD_MPIO(f)) + H5FD_mpio_tas_allsame(f->shared->lf, TRUE); /*only p0 write*/ +#endif /* H5_HAVE_PARALLEL */ + if (H5F_block_write(f, oh->chunk[i].addr, + (hsize_t)(oh->chunk[i].size), + H5P_DEFAULT, oh->chunk[i].image) < 0) { + HRETURN_ERROR(H5E_OHDR, H5E_WRITEERROR, FAIL, + "unable to write object header data to disk"); + } /* end if */ + } /* end else */ + oh->chunk[i].dirty = FALSE; + } /* end if */ + } /* end for */ oh->dirty = FALSE; } -- cgit v0.12