diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2010-10-01 05:43:11 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2010-10-01 05:43:11 (GMT) |
commit | 0574011fe87d79953d44d0824b0d0da5386b9060 (patch) | |
tree | 46004bc1811257bf0006a1afe9cee8ffc335917c /src/H5Dcontig.c | |
parent | d4927395baf43d3c399d7a708d2bae96a88db494 (diff) | |
download | hdf5-0574011fe87d79953d44d0824b0d0da5386b9060.zip hdf5-0574011fe87d79953d44d0824b0d0da5386b9060.tar.gz hdf5-0574011fe87d79953d44d0824b0d0da5386b9060.tar.bz2 |
[svn-r19499] Description:
Bring r19498 from trunk to 1.8 branch:
Optimize the vector-vector memcpy() routine even further, for a total
of ~2x speedup. :-)
Make a generic vector-vector operation routine and convert other
vector-vector read & write routines to use generic routine instead of multiple
copies of the basic algorithm.
Tested on:
FreeBSD/32 6.3 (duty) in debug mode
(h5committested on trunk)
Diffstat (limited to 'src/H5Dcontig.c')
-rw-r--r-- | src/H5Dcontig.c | 973 |
1 files changed, 516 insertions, 457 deletions
diff --git a/src/H5Dcontig.c b/src/H5Dcontig.c index 78c07e6..9b4f338 100644 --- a/src/H5Dcontig.c +++ b/src/H5Dcontig.c @@ -55,6 +55,40 @@ /* Local Typedefs */ /******************/ +/* Callback info for sieve buffer readvv operation */ +typedef struct H5D_contig_readvv_sieve_ud_t { + H5F_t *file; /* File for dataset */ + H5D_rdcdc_t *dset_contig; /* Cached information about contiguous data */ + const H5D_contig_storage_t *store_contig; /* Contiguous storage info for this I/O operation */ + unsigned char *rbuf; /* Pointer to buffer to fill */ + hid_t dxpl_id; /* DXPL for operation */ +} H5D_contig_readvv_sieve_ud_t; + +/* Callback info for [plain] readvv operation */ +typedef struct H5D_contig_readvv_ud_t { + H5F_t *file; /* File for dataset */ + haddr_t dset_addr; /* Address of dataset */ + unsigned char *rbuf; /* Pointer to buffer to fill */ + hid_t dxpl_id; /* DXPL for operation */ +} H5D_contig_readvv_ud_t; + +/* Callback info for sieve buffer writevv operation */ +typedef struct H5D_contig_writevv_sieve_ud_t { + H5F_t *file; /* File for dataset */ + H5D_rdcdc_t *dset_contig; /* Cached information about contiguous data */ + const H5D_contig_storage_t *store_contig; /* Contiguous storage info for this I/O operation */ + const unsigned char *wbuf; /* Pointer to buffer to write */ + hid_t dxpl_id; /* DXPL for operation */ +} H5D_contig_writevv_sieve_ud_t; + +/* Callback info for [plain] writevv operation */ +typedef struct H5D_contig_writevv_ud_t { + H5F_t *file; /* File for dataset */ + haddr_t dset_addr; /* Address of dataset */ + const unsigned char *wbuf; /* Pointer to buffer to write */ + hid_t dxpl_id; /* DXPL for operation */ +} H5D_contig_writevv_ud_t; + /********************/ /* Local Prototypes */ @@ -65,6 +99,12 @@ static herr_t H5D_contig_construct(H5F_t *f, H5D_t *dset); static herr_t H5D_contig_io_init(const H5D_io_info_t *io_info, const H5D_type_info_t *type_info, hsize_t nelmts, const H5S_t *file_space, const H5S_t *mem_space, H5D_chunk_map_t *cm); +static ssize_t H5D_contig_readvv(const H5D_io_info_t *io_info, + size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_offset_arr[], + size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[]); +static ssize_t H5D_contig_writevv(const H5D_io_info_t *io_info, + size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_offset_arr[], + size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[]); static herr_t H5D_contig_flush(H5D_t *dset, hid_t dxpl_id); /* Helper routines */ @@ -600,572 +640,591 @@ done: /*------------------------------------------------------------------------- - * Function: H5D_contig_readvv + * Function: H5D_contig_readvv_sieve_cb * - * Purpose: Reads some data vectors from a dataset into a buffer. - * The data is contiguous. The address is the start of the dataset, - * relative to the base address for the file and the offsets and - * sequence lengths are in bytes. + * Purpose: Callback operator for H5D_contig_readvv() with sieve buffer. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Friday, May 3, 2001 - * - * Notes: - * Offsets in the sequences must be monotonically increasing + * Thursday, Sept 30, 2010 * *------------------------------------------------------------------------- */ -ssize_t -H5D_contig_readvv(const H5D_io_info_t *io_info, - size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_offset_arr[], - size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[]) +static herr_t +H5D_contig_readvv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, + void *_udata) { - H5F_t *file = io_info->dset->oloc.file; /* File for dataset */ - H5D_rdcdc_t *dset_contig = &(io_info->dset->shared->cache.contig); /* Cached information about contiguous data */ - const H5D_contig_storage_t *store_contig = &(io_info->store->contig); /* Contiguous storage info for this I/O operation */ - unsigned char *buf = (unsigned char *)io_info->u.rbuf; /* Pointer to buffer to fill */ + H5D_contig_readvv_sieve_ud_t *udata = (H5D_contig_readvv_sieve_ud_t *)_udata; /* User data for H5V_opvv() operator */ + H5F_t *file = udata->file; /* File for dataset */ + H5D_rdcdc_t *dset_contig = udata->dset_contig; /* Cached information about contiguous data */ + const H5D_contig_storage_t *store_contig = udata->store_contig; /* Contiguous storage info for this I/O operation */ + unsigned char *buf; /* Pointer to buffer to fill */ haddr_t addr; /* Actual address to read */ - size_t size; /* Size of sequence in bytes */ - size_t u, v; /* Counting variables */ - ssize_t ret_value = 0; /* Return value (Total size of sequence in bytes) */ - - FUNC_ENTER_NOAPI(H5D_contig_readvv, FAIL) -#ifdef QAK -HDfprintf(stderr, "%s: dset_max_nseq = %Zu\n", FUNC, dset_max_nseq); -HDfprintf(stderr, "%s: mem_max_nseq = %Zu\n", FUNC, mem_max_nseq); -HDfprintf(stderr, "%s: *dset_curr_seq= %Zu\n", FUNC, *dset_curr_seq); -HDfprintf(stderr, "%s: *mem_curr_seq= %Zu\n", FUNC, *mem_curr_seq); -for(u = 0; u < dset_max_nseq; u++) - HDfprintf(stderr, "%s: dset_len_arr[%Zu] = %Zu, dset_offset_arr[%Zu] = %Hu\n", FUNC, u, dset_len_arr[u], u, dset_offset_arr[u]); -for(u = 0; u < mem_max_nseq; u++) - HDfprintf(stderr, "%s: mem_len_arr[%Zu] = %Zu, mem_offset_arr[%Zu] = %Hu\n", FUNC, u, mem_len_arr[u], u, mem_offset_arr[u]); -#endif /* QAK */ + haddr_t sieve_start = HADDR_UNDEF, sieve_end = HADDR_UNDEF; /* Start & end locations of sieve buffer */ + haddr_t contig_end; /* End locations of block to write */ + size_t sieve_size = (size_t)-1; /* Size of sieve buffer */ + haddr_t rel_eoa; /* Relative end of file address */ + hsize_t max_data; /* Actual maximum size of data to cache */ + herr_t ret_value = SUCCEED; /* Return value */ - /* Check args */ - HDassert(io_info); - HDassert(io_info->dset); - HDassert(io_info->store); - HDassert(buf); + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_readvv_sieve_cb) - /* Check if data sieving is enabled */ - if(H5F_HAS_FEATURE(file, H5FD_FEAT_DATA_SIEVE)) { - haddr_t sieve_start = HADDR_UNDEF, sieve_end = HADDR_UNDEF; /* Start & end locations of sieve buffer */ - haddr_t contig_end; /* End locations of block to write */ - size_t sieve_size = (size_t)-1; /* size of sieve buffer */ - haddr_t rel_eoa; /* Relative end of file address */ - hsize_t max_data; /* Actual maximum size of data to cache */ - - /* Set offsets in sequence lists */ - u = *dset_curr_seq; - v = *mem_curr_seq; - - /* Stash local copies of these value */ - if(dset_contig->sieve_buf != NULL) { - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start+sieve_size; + /* Stash local copies of these value */ + if(dset_contig->sieve_buf != NULL) { + sieve_start = dset_contig->sieve_loc; + sieve_size = dset_contig->sieve_size; + sieve_end = sieve_start + sieve_size; + } /* end if */ + + /* Compute offset on disk */ + addr = store_contig->dset_addr + dst_off; + + /* Compute offset in memory */ + buf = udata->rbuf + src_off; + + /* Check if the sieve buffer is allocated yet */ + if(NULL == dset_contig->sieve_buf) { + /* Check if we can actually hold the I/O request in the sieve buffer */ + if(len > dset_contig->sieve_buf_size) { + if(H5F_block_read(file, H5FD_MEM_DRAW, addr, len, udata->dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") } /* end if */ + else { + /* Allocate room for the data sieve buffer */ + if(NULL == (dset_contig->sieve_buf = H5FL_BLK_MALLOC(sieve_buf, dset_contig->sieve_buf_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "memory allocation failed") - /* Works through sequences as fast as possible */ - for(; u < dset_max_nseq && v < mem_max_nseq; ) { - /* Choose smallest buffer to write */ - if(mem_len_arr[v] < dset_len_arr[u]) - size = mem_len_arr[v]; - else - size = dset_len_arr[u]; + /* Determine the new sieve buffer size & location */ + dset_contig->sieve_loc = addr; - /* Compute offset on disk */ - addr = store_contig->dset_addr + dset_offset_arr[u]; + /* Make certain we don't read off the end of the file */ + if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to determine file size") - /* Compute offset in memory */ - buf = (unsigned char *)io_info->u.rbuf + mem_offset_arr[v]; + /* Set up the buffer parameters */ + max_data = store_contig->dset_size - dst_off; - /* Check if the sieve buffer is allocated yet */ - if(dset_contig->sieve_buf == NULL) { - /* Check if we can actually hold the I/O request in the sieve buffer */ - if(size>dset_contig->sieve_buf_size) { - if(H5F_block_read(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") - } /* end if */ - else { - /* Allocate room for the data sieve buffer */ - if(NULL == (dset_contig->sieve_buf = H5FL_BLK_MALLOC(sieve_buf, dset_contig->sieve_buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") + /* Compute the size of the sieve buffer */ + H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); - /* Determine the new sieve buffer size & location */ - dset_contig->sieve_loc = addr; + /* Read the new sieve buffer */ + if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") - /* Make certain we don't read off the end of the file */ - if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to determine file size") + /* Grab the data out of the buffer (must be first piece of data in buffer ) */ + HDmemcpy(buf, dset_contig->sieve_buf, len); - /* Set up the buffer parameters */ - max_data = store_contig->dset_size - dset_offset_arr[u]; + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; - /* Compute the size of the sieve buffer */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + /* Stash local copies of these value */ + sieve_start = dset_contig->sieve_loc; + sieve_size = dset_contig->sieve_size; + sieve_end = sieve_start+sieve_size; + } /* end else */ + } /* end if */ + else { + /* Compute end of sequence to retrieve */ + contig_end = addr + len - 1; - /* Read the new sieve buffer */ - if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") + /* If entire read is within the sieve buffer, read it from the buffer */ + if(addr >= sieve_start && contig_end < sieve_end) { + unsigned char *base_sieve_buf = dset_contig->sieve_buf + (addr - sieve_start); - /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(buf, dset_contig->sieve_buf, size); + /* Grab the data out of the buffer */ + HDmemcpy(buf, base_sieve_buf, len); + } /* end if */ + /* Entire request is not within this data sieve buffer */ + else { + /* Check if we can actually hold the I/O request in the sieve buffer */ + if(len > dset_contig->sieve_buf_size) { + /* Check for any overlap with the current sieve buffer */ + if((sieve_start >= addr && sieve_start < (contig_end + 1)) + || ((sieve_end - 1) >= addr && (sieve_end - 1) < (contig_end + 1))) { + /* Flush the sieve buffer, if it's dirty */ + if(dset_contig->sieve_dirty) { + /* Write to file */ + if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; + } /* end if */ + } /* end if */ - /* Stash local copies of these value */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start+sieve_size; - } /* end else */ + /* Read directly into the user's buffer */ + if(H5F_block_read(file, H5FD_MEM_DRAW, addr, len, udata->dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") } /* end if */ + /* Element size fits within the buffer size */ else { - /* Compute end of sequence to retrieve */ - contig_end = addr + size - 1; - - /* If entire read is within the sieve buffer, read it from the buffer */ - if(addr>=sieve_start && contig_end<sieve_end) { - unsigned char *base_sieve_buf=dset_contig->sieve_buf+(addr-sieve_start); + /* Flush the sieve buffer if it's dirty */ + if(dset_contig->sieve_dirty) { + /* Write to file */ + if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") - /* Grab the data out of the buffer */ - HDmemcpy(buf, base_sieve_buf, size); + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; } /* end if */ - /* Entire request is not within this data sieve buffer */ - else { - /* Check if we can actually hold the I/O request in the sieve buffer */ - if(size>dset_contig->sieve_buf_size) { - /* Check for any overlap with the current sieve buffer */ - if((sieve_start >= addr && sieve_start < (contig_end + 1)) - || ((sieve_end - 1) >= addr && (sieve_end - 1) < (contig_end + 1))) { - /* Flush the sieve buffer, if it's dirty */ - if(dset_contig->sieve_dirty) { - /* Write to file */ - if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; - } /* end if */ - } /* end if */ - - /* Read directly into the user's buffer */ - if(H5F_block_read(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") - } /* end if */ - /* Element size fits within the buffer size */ - else { - /* Flush the sieve buffer if it's dirty */ - if(dset_contig->sieve_dirty) { - /* Write to file */ - if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; - } /* end if */ + /* Determine the new sieve buffer size & location */ + dset_contig->sieve_loc = addr; - /* Determine the new sieve buffer size & location */ - dset_contig->sieve_loc = addr; - - /* Make certain we don't read off the end of the file */ - if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to determine file size") + /* Make certain we don't read off the end of the file */ + if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to determine file size") - /* Only need this when resizing sieve buffer */ - max_data = store_contig->dset_size - dset_offset_arr[u]; + /* Only need this when resizing sieve buffer */ + max_data = store_contig->dset_size - dst_off; - /* Compute the size of the sieve buffer */ - /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + /* Compute the size of the sieve buffer */ + /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ + H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; + /* Update local copies of sieve information */ + sieve_start = dset_contig->sieve_loc; + sieve_size = dset_contig->sieve_size; + sieve_end = sieve_start + sieve_size; - /* Read the new sieve buffer */ - if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") + /* Read the new sieve buffer */ + if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") - /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(buf, dset_contig->sieve_buf, size); + /* Grab the data out of the buffer (must be first piece of data in buffer ) */ + HDmemcpy(buf, dset_contig->sieve_buf, len); - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; - } /* end else */ - } /* end else */ + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; } /* end else */ + } /* end else */ + } /* end else */ - /* Update memory information */ - mem_len_arr[v] -= size; - if(mem_len_arr[v] == 0) - v++; - else - mem_offset_arr[v] += size; - - /* Update file information */ - dset_len_arr[u] -= size; - if(dset_len_arr[u] == 0) - u++; - else - dset_offset_arr[u] += size; - - /* Increment number of bytes copied */ - ret_value += (ssize_t)size; - } /* end for */ - } /* end if */ - else { - /* Work through all the sequences */ - for(u = *dset_curr_seq, v = *mem_curr_seq; u < dset_max_nseq && v < mem_max_nseq; ) { - /* Choose smallest buffer to write */ - if(mem_len_arr[v] < dset_len_arr[u]) - size = mem_len_arr[v]; - else - size = dset_len_arr[u]; - - /* Compute offset on disk */ - addr = store_contig->dset_addr + dset_offset_arr[u]; - - /* Compute offset in memory */ - buf = (unsigned char *)io_info->u.rbuf + mem_offset_arr[v]; - - /* Write data */ - if(H5F_block_read(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - - /* Update memory information */ - mem_len_arr[v] -= size; - if(mem_len_arr[v] == 0) - v++; - else - mem_offset_arr[v] += size; +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_contig_readvv_sieve_cb() */ - /* Update file information */ - dset_len_arr[u] -= size; - if(dset_len_arr[u] == 0) - u++; - else - dset_offset_arr[u] += size; + +/*------------------------------------------------------------------------- + * Function: H5D_contig_readvv_cb + * + * Purpose: Callback operator for H5D_contig_readvv() without sieve buffer. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, Sept 30, 2010 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_contig_readvv_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata) +{ + H5D_contig_readvv_ud_t *udata = (H5D_contig_readvv_ud_t *)_udata; /* User data for H5V_opvv() operator */ + herr_t ret_value = SUCCEED; /* Return value */ - /* Increment number of bytes copied */ - ret_value += (ssize_t)size; - } /* end for */ - } /* end else */ + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_readvv_cb) - /* Update current sequence vectors */ - *dset_curr_seq = u; - *mem_curr_seq = v; + /* Write data */ + if(H5F_block_read(udata->file, H5FD_MEM_DRAW, (udata->dset_addr + dst_off), + len, udata->dxpl_id, (udata->rbuf + src_off)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") done: FUNC_LEAVE_NOAPI(ret_value) -} /* end H5D_contig_readvv() */ +} /* end H5D_contig_readvv_cb() */ /*------------------------------------------------------------------------- - * Function: H5D_contig_writevv + * Function: H5D_contig_readvv * - * Purpose: Writes some data vectors into a dataset from vectors into a - * buffer. The address is the start of the dataset, + * Purpose: Reads some data vectors from a dataset into a buffer. + * The data is contiguous. The address is the start of the dataset, * relative to the base address for the file and the offsets and * sequence lengths are in bytes. * * Return: Non-negative on success/Negative on failure * * Programmer: Quincey Koziol - * Friday, May 2, 2003 + * Friday, May 3, 2001 * * Notes: * Offsets in the sequences must be monotonically increasing * *------------------------------------------------------------------------- */ -ssize_t -H5D_contig_writevv(const H5D_io_info_t *io_info, - size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_offset_arr[], - size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_offset_arr[]) +static ssize_t +H5D_contig_readvv(const H5D_io_info_t *io_info, + size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_off_arr[], + size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_off_arr[]) { - H5F_t *file = io_info->dset->oloc.file; /* File for dataset */ - H5D_rdcdc_t *dset_contig = &(io_info->dset->shared->cache.contig); /* Cached information about contiguous data */ - const H5D_contig_storage_t *store_contig = &(io_info->store->contig); /* Contiguous storage info for this I/O operation */ - const unsigned char *buf = (const unsigned char *)io_info->u.wbuf; /* Pointer to buffer to fill */ - haddr_t addr; /* Actual address to read */ - size_t size; /* Size of sequence in bytes */ - size_t u, v; /* Counting variables */ - ssize_t ret_value = 0; /* Return value (Size of sequence in bytes) */ + ssize_t ret_value; /* Return value */ - FUNC_ENTER_NOAPI(H5D_contig_writevv, FAIL) + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_readvv) /* Check args */ HDassert(io_info); - HDassert(io_info->dset); - HDassert(io_info->store); - HDassert(buf); + HDassert(dset_curr_seq); + HDassert(dset_len_arr); + HDassert(dset_off_arr); + HDassert(mem_curr_seq); + HDassert(mem_len_arr); + HDassert(mem_off_arr); /* Check if data sieving is enabled */ - if(H5F_HAS_FEATURE(file, H5FD_FEAT_DATA_SIEVE)) { - haddr_t sieve_start = HADDR_UNDEF, sieve_end = HADDR_UNDEF; /* Start & end locations of sieve buffer */ - haddr_t contig_end; /* End locations of block to write */ - size_t sieve_size = (size_t)-1; /* size of sieve buffer */ - haddr_t rel_eoa; /* Relative end of file address */ - hsize_t max_data; /* Actual maximum size of data to cache */ - - /* Set offsets in sequence lists */ - u = *dset_curr_seq; - v = *mem_curr_seq; - - /* Stash local copies of these values */ - if(dset_contig->sieve_buf != NULL) { + if(H5F_HAS_FEATURE(io_info->dset->oloc.file, H5FD_FEAT_DATA_SIEVE)) { + H5D_contig_readvv_sieve_ud_t udata; /* User data for H5V_opvv() operator */ + + /* Set up user data for H5V_opvv() */ + udata.file = io_info->dset->oloc.file; + udata.dset_contig = &(io_info->dset->shared->cache.contig); + udata.store_contig = &(io_info->store->contig); + udata.rbuf = (unsigned char *)io_info->u.rbuf; + udata.dxpl_id = io_info->dxpl_id; + + /* Call generic sequence operation routine */ + if((ret_value = H5V_opvv(dset_max_nseq, dset_curr_seq, dset_len_arr, dset_off_arr, + mem_max_nseq, mem_curr_seq, mem_len_arr, mem_off_arr, + H5D_contig_readvv_sieve_cb, &udata)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPERATE, FAIL, "can't perform vectorized sieve buffer read") + } /* end if */ + else { + H5D_contig_readvv_ud_t udata; /* User data for H5V_opvv() operator */ + + /* Set up user data for H5V_opvv() */ + udata.file = io_info->dset->oloc.file; + udata.dset_addr = io_info->store->contig.dset_addr; + udata.rbuf = (unsigned char *)io_info->u.rbuf; + udata.dxpl_id = io_info->dxpl_id; + + /* Call generic sequence operation routine */ + if((ret_value = H5V_opvv(dset_max_nseq, dset_curr_seq, dset_len_arr, dset_off_arr, + mem_max_nseq, mem_curr_seq, mem_len_arr, mem_off_arr, + H5D_contig_readvv_cb, &udata)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPERATE, FAIL, "can't perform vectorized read") + } /* end else */ + +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_contig_readvv() */ + + +/*------------------------------------------------------------------------- + * Function: H5D_contig_writevv_sieve_cb + * + * Purpose: Callback operator for H5D_contig_writevv() with sieve buffer. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, Sept 30, 2010 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_contig_writevv_sieve_cb(hsize_t dst_off, hsize_t src_off, size_t len, + void *_udata) +{ + H5D_contig_writevv_sieve_ud_t *udata = (H5D_contig_writevv_sieve_ud_t *)_udata; /* User data for H5V_opvv() operator */ + H5F_t *file = udata->file; /* File for dataset */ + H5D_rdcdc_t *dset_contig = udata->dset_contig; /* Cached information about contiguous data */ + const H5D_contig_storage_t *store_contig = udata->store_contig; /* Contiguous storage info for this I/O operation */ + const unsigned char *buf; /* Pointer to buffer to fill */ + haddr_t addr; /* Actual address to read */ + haddr_t sieve_start = HADDR_UNDEF, sieve_end = HADDR_UNDEF; /* Start & end locations of sieve buffer */ + haddr_t contig_end; /* End locations of block to write */ + size_t sieve_size = (size_t)-1; /* size of sieve buffer */ + haddr_t rel_eoa; /* Relative end of file address */ + hsize_t max_data; /* Actual maximum size of data to cache */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_writevv_sieve_cb) + + /* Stash local copies of these values */ + if(dset_contig->sieve_buf != NULL) { + sieve_start = dset_contig->sieve_loc; + sieve_size = dset_contig->sieve_size; + sieve_end = sieve_start + sieve_size; + } /* end if */ + + /* Compute offset on disk */ + addr = store_contig->dset_addr + dst_off; + + /* Compute offset in memory */ + buf = udata->wbuf + src_off; + + /* No data sieve buffer yet, go allocate one */ + if(NULL == dset_contig->sieve_buf) { + /* Check if we can actually hold the I/O request in the sieve buffer */ + if(len > dset_contig->sieve_buf_size) { + if(H5F_block_write(file, H5FD_MEM_DRAW, addr, len, udata->dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") + } /* end if */ + else { + /* Allocate room for the data sieve buffer */ + if(NULL == (dset_contig->sieve_buf = H5FL_BLK_MALLOC(sieve_buf, dset_contig->sieve_buf_size))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, FAIL, "memory allocation failed") +#ifdef H5_CLEAR_MEMORY +if(dset_contig->sieve_size > len) + HDmemset(dset_contig->sieve_buf + len, 0, (dset_contig->sieve_size - len)); +#endif /* H5_CLEAR_MEMORY */ + + /* Determine the new sieve buffer size & location */ + dset_contig->sieve_loc = addr; + + /* Make certain we don't read off the end of the file */ + if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to determine file size") + + /* Set up the buffer parameters */ + max_data = store_contig->dset_size - dst_off; + + /* Compute the size of the sieve buffer */ + H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); + + /* Check if there is any point in reading the data from the file */ + if(dset_contig->sieve_size > len) { + /* Read the new sieve buffer */ + if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") + } /* end if */ + + /* Grab the data out of the buffer (must be first piece of data in buffer ) */ + HDmemcpy(dset_contig->sieve_buf, buf, len); + + /* Set sieve buffer dirty flag */ + dset_contig->sieve_dirty = TRUE; + + /* Stash local copies of these values */ sieve_start = dset_contig->sieve_loc; sieve_size = dset_contig->sieve_size; sieve_end = sieve_start + sieve_size; + } /* end else */ + } /* end if */ + else { + /* Compute end of sequence to retrieve */ + contig_end = addr + len - 1; + + /* If entire write is within the sieve buffer, write it to the buffer */ + if(addr >= sieve_start && contig_end < sieve_end) { + unsigned char *base_sieve_buf = dset_contig->sieve_buf + (addr - sieve_start); + + /* Put the data into the sieve buffer */ + HDmemcpy(base_sieve_buf, buf, len); + + /* Set sieve buffer dirty flag */ + dset_contig->sieve_dirty = TRUE; } /* end if */ + /* Entire request is not within this data sieve buffer */ + else { + /* Check if we can actually hold the I/O request in the sieve buffer */ + if(len > dset_contig->sieve_buf_size) { + /* Check for any overlap with the current sieve buffer */ + if((sieve_start >= addr && sieve_start < (contig_end + 1)) + || ((sieve_end - 1) >= addr && (sieve_end - 1) < (contig_end + 1))) { + /* Flush the sieve buffer, if it's dirty */ + if(dset_contig->sieve_dirty) { + /* Write to file */ + if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") - /* Works through sequences as fast as possible */ - for(; u < dset_max_nseq && v < mem_max_nseq; ) { - /* Choose smallest buffer to write */ - if(mem_len_arr[v] < dset_len_arr[u]) - size = mem_len_arr[v]; - else - size = dset_len_arr[u]; + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; + } /* end if */ - /* Compute offset on disk */ - addr = store_contig->dset_addr + dset_offset_arr[u]; + /* Force the sieve buffer to be re-read the next time */ + dset_contig->sieve_loc = HADDR_UNDEF; + dset_contig->sieve_size = 0; + } /* end if */ + + /* Write directly from the user's buffer */ + if(H5F_block_write(file, H5FD_MEM_DRAW, addr, len, udata->dxpl_id, buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") + } /* end if */ + /* Element size fits within the buffer size */ + else { + /* Check if it is possible to (exactly) prepend or append to existing (dirty) sieve buffer */ + if(((addr + len) == sieve_start || addr == sieve_end) && + (len + sieve_size) <= dset_contig->sieve_buf_size && + dset_contig->sieve_dirty) { + /* Prepend to existing sieve buffer */ + if((addr + len) == sieve_start) { + /* Move existing sieve information to correct location */ + HDmemmove(dset_contig->sieve_buf + len, dset_contig->sieve_buf, dset_contig->sieve_size); + + /* Copy in new information (must be first in sieve buffer) */ + HDmemcpy(dset_contig->sieve_buf, buf, len); + + /* Adjust sieve location */ + dset_contig->sieve_loc = addr; - /* Compute offset in memory */ - buf = (const unsigned char *)io_info->u.wbuf + mem_offset_arr[v]; + } /* end if */ + /* Append to existing sieve buffer */ + else { + /* Copy in new information */ + HDmemcpy(dset_contig->sieve_buf + sieve_size, buf, len); + } /* end else */ - /* No data sieve buffer yet, go allocate one */ - if(NULL == dset_contig->sieve_buf) { - /* Check if we can actually hold the I/O request in the sieve buffer */ - if(size>dset_contig->sieve_buf_size) { - if(H5F_block_write(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") + /* Adjust sieve size */ + dset_contig->sieve_size += len; + + /* Update local copies of sieve information */ + sieve_start = dset_contig->sieve_loc; + sieve_size = dset_contig->sieve_size; + sieve_end = sieve_start + sieve_size; } /* end if */ + /* Can't add the new data onto the existing sieve buffer */ else { - /* Allocate room for the data sieve buffer */ - if(NULL == (dset_contig->sieve_buf = H5FL_BLK_MALLOC(sieve_buf, dset_contig->sieve_buf_size))) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed") -#ifdef H5_CLEAR_MEMORY -if(dset_contig->sieve_size > size) - HDmemset(dset_contig->sieve_buf + size, 0, (dset_contig->sieve_size - size)); -#endif /* H5_CLEAR_MEMORY */ + /* Flush the sieve buffer if it's dirty */ + if(dset_contig->sieve_dirty) { + /* Write to file */ + if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") + + /* Reset sieve buffer dirty flag */ + dset_contig->sieve_dirty = FALSE; + } /* end if */ /* Determine the new sieve buffer size & location */ dset_contig->sieve_loc = addr; /* Make certain we don't read off the end of the file */ if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to determine file size") + HGOTO_ERROR(H5E_DATASET, H5E_CANTGET, FAIL, "unable to determine file size") - /* Set up the buffer parameters */ - max_data = store_contig->dset_size - dset_offset_arr[u]; + /* Only need this when resizing sieve buffer */ + max_data = store_contig->dset_size - dst_off; /* Compute the size of the sieve buffer */ + /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); - /* Check if there is any point in reading the data from the file */ - if(dset_contig->sieve_size>size) { - /* Read the new sieve buffer */ - if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") - } /* end if */ - - /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(dset_contig->sieve_buf, buf, size); - - /* Set sieve buffer dirty flag */ - dset_contig->sieve_dirty = 1; - - /* Stash local copies of these values */ + /* Update local copies of sieve information */ sieve_start = dset_contig->sieve_loc; sieve_size = dset_contig->sieve_size; sieve_end = sieve_start + sieve_size; - } /* end else */ - } /* end if */ - else { - /* Compute end of sequence to retrieve */ - contig_end = addr + size - 1; - /* If entire write is within the sieve buffer, write it to the buffer */ - if(addr >= sieve_start && contig_end < sieve_end) { - unsigned char *base_sieve_buf = dset_contig->sieve_buf + (addr - sieve_start); + /* Check if there is any point in reading the data from the file */ + if(dset_contig->sieve_size > len) { + /* Read the new sieve buffer */ + if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, udata->dxpl_id, dset_contig->sieve_buf) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_READERROR, FAIL, "block read failed") + } /* end if */ - /* Put the data into the sieve buffer */ - HDmemcpy(base_sieve_buf, buf, size); + /* Grab the data out of the buffer (must be first piece of data in buffer ) */ + HDmemcpy(dset_contig->sieve_buf, buf, len); /* Set sieve buffer dirty flag */ - dset_contig->sieve_dirty = 1; - } /* end if */ - /* Entire request is not within this data sieve buffer */ - else { - /* Check if we can actually hold the I/O request in the sieve buffer */ - if(size>dset_contig->sieve_buf_size) { - /* Check for any overlap with the current sieve buffer */ - if((sieve_start >= addr && sieve_start < (contig_end + 1)) - || ((sieve_end - 1) >= addr && (sieve_end - 1) < (contig_end + 1))) { - /* Flush the sieve buffer, if it's dirty */ - if(dset_contig->sieve_dirty) { - /* Write to file */ - if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; - } /* end if */ - - /* Force the sieve buffer to be re-read the next time */ - dset_contig->sieve_loc = HADDR_UNDEF; - dset_contig->sieve_size = 0; - } /* end if */ - - /* Write directly from the user's buffer */ - if(H5F_block_write(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - } /* end if */ - /* Element size fits within the buffer size */ - else { - /* Check if it is possible to (exactly) prepend or append to existing (dirty) sieve buffer */ - if(((addr + size) == sieve_start || addr == sieve_end) && - (size + sieve_size) <= dset_contig->sieve_buf_size && - dset_contig->sieve_dirty) { - /* Prepend to existing sieve buffer */ - if((addr + size) == sieve_start) { - /* Move existing sieve information to correct location */ - HDmemmove(dset_contig->sieve_buf + size, dset_contig->sieve_buf, dset_contig->sieve_size); - - /* Copy in new information (must be first in sieve buffer) */ - HDmemcpy(dset_contig->sieve_buf, buf, size); - - /* Adjust sieve location */ - dset_contig->sieve_loc = addr; - - } /* end if */ - /* Append to existing sieve buffer */ - else { - /* Copy in new information */ - HDmemcpy(dset_contig->sieve_buf + sieve_size, buf, size); - } /* end else */ - - /* Adjust sieve size */ - dset_contig->sieve_size += size; - - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; - } /* end if */ - /* Can't add the new data onto the existing sieve buffer */ - else { - /* Flush the sieve buffer if it's dirty */ - if(dset_contig->sieve_dirty) { - /* Write to file */ - if(H5F_block_write(file, H5FD_MEM_DRAW, sieve_start, sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") - - /* Reset sieve buffer dirty flag */ - dset_contig->sieve_dirty = 0; - } /* end if */ - - /* Determine the new sieve buffer size & location */ - dset_contig->sieve_loc = addr; - - /* Make certain we don't read off the end of the file */ - if(HADDR_UNDEF == (rel_eoa = H5F_get_eoa(file, H5FD_MEM_DRAW))) - HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "unable to determine file size") - - /* Only need this when resizing sieve buffer */ - max_data = store_contig->dset_size - dset_offset_arr[u]; - - /* Compute the size of the sieve buffer */ - /* Don't read off the end of the file, don't read past the end of the data element and don't read more than the buffer size */ - H5_ASSIGN_OVERFLOW(dset_contig->sieve_size, MIN3(rel_eoa - dset_contig->sieve_loc, max_data, dset_contig->sieve_buf_size), hsize_t, size_t); - - /* Update local copies of sieve information */ - sieve_start = dset_contig->sieve_loc; - sieve_size = dset_contig->sieve_size; - sieve_end = sieve_start + sieve_size; - - /* Check if there is any point in reading the data from the file */ - if(dset_contig->sieve_size > size) { - /* Read the new sieve buffer */ - if(H5F_block_read(file, H5FD_MEM_DRAW, dset_contig->sieve_loc, dset_contig->sieve_size, io_info->dxpl_id, dset_contig->sieve_buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL, "block read failed") - } /* end if */ - - /* Grab the data out of the buffer (must be first piece of data in buffer ) */ - HDmemcpy(dset_contig->sieve_buf, buf, size); - - /* Set sieve buffer dirty flag */ - dset_contig->sieve_dirty = 1; - } /* end else */ - } /* end else */ + dset_contig->sieve_dirty = TRUE; } /* end else */ } /* end else */ + } /* end else */ + } /* end else */ - /* Update memory information */ - mem_len_arr[v] -= size; - if(mem_len_arr[v] == 0) - v++; - else - mem_offset_arr[v] += size; +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_contig_writevv_sieve_cb() */ - /* Update file information */ - dset_len_arr[u] -= size; - if(dset_len_arr[u] == 0) - u++; - else - dset_offset_arr[u] += size; + +/*------------------------------------------------------------------------- + * Function: H5D_contig_writevv_cb + * + * Purpose: Callback operator for H5D_contig_writevv(). + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Thursday, Sept 30, 2010 + * + *------------------------------------------------------------------------- + */ +static herr_t +H5D_contig_writevv_cb(hsize_t dst_off, hsize_t src_off, size_t len, void *_udata) +{ + H5D_contig_writevv_ud_t *udata = (H5D_contig_writevv_ud_t *)_udata; /* User data for H5V_opvv() operator */ + herr_t ret_value = SUCCEED; /* Return value */ - /* Increment number of bytes copied */ - ret_value += (ssize_t)size; - } /* end for */ - } /* end if */ - else { - /* Work through all the sequences */ - for(u = *dset_curr_seq, v = *mem_curr_seq; u < dset_max_nseq && v < mem_max_nseq; ) { - /* Choose smallest buffer to write */ - if(mem_len_arr[v] < dset_len_arr[u]) - size = mem_len_arr[v]; - else - size = dset_len_arr[u]; + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_writevv_cb) - /* Compute offset on disk */ - addr = store_contig->dset_addr + dset_offset_arr[u]; + /* Write data */ + if(H5F_block_write(udata->file, H5FD_MEM_DRAW, (udata->dset_addr + dst_off), len, udata->dxpl_id, (udata->wbuf + src_off)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "block write failed") - /* Compute offset in memory */ - buf = (const unsigned char *)io_info->u.wbuf + mem_offset_arr[v]; +done: + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5D_contig_writevv_cb() */ - /* Write data */ - if(H5F_block_write(file, H5FD_MEM_DRAW, addr, size, io_info->dxpl_id, buf) < 0) - HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL, "block write failed") + +/*------------------------------------------------------------------------- + * Function: H5D_contig_writevv + * + * Purpose: Writes some data vectors into a dataset from vectors into a + * buffer. The address is the start of the dataset, + * relative to the base address for the file and the offsets and + * sequence lengths are in bytes. + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Quincey Koziol + * Friday, May 2, 2003 + * + * Notes: + * Offsets in the sequences must be monotonically increasing + * + *------------------------------------------------------------------------- + */ +static ssize_t +H5D_contig_writevv(const H5D_io_info_t *io_info, + size_t dset_max_nseq, size_t *dset_curr_seq, size_t dset_len_arr[], hsize_t dset_off_arr[], + size_t mem_max_nseq, size_t *mem_curr_seq, size_t mem_len_arr[], hsize_t mem_off_arr[]) +{ + ssize_t ret_value; /* Return value (Size of sequence in bytes) */ - /* Update memory information */ - mem_len_arr[v] -= size; - if(mem_len_arr[v] == 0) - v++; - else - mem_offset_arr[v] += size; + FUNC_ENTER_NOAPI_NOINIT(H5D_contig_writevv) - /* Update file information */ - dset_len_arr[u] -= size; - if(dset_len_arr[u] == 0) - u++; - else - dset_offset_arr[u] += size; + /* Check args */ + HDassert(io_info); + HDassert(dset_curr_seq); + HDassert(dset_len_arr); + HDassert(dset_off_arr); + HDassert(mem_curr_seq); + HDassert(mem_len_arr); + HDassert(mem_off_arr); - /* Increment number of bytes copied */ - ret_value += (ssize_t)size; - } /* end for */ + /* Check if data sieving is enabled */ + if(H5F_HAS_FEATURE(io_info->dset->oloc.file, H5FD_FEAT_DATA_SIEVE)) { + H5D_contig_writevv_sieve_ud_t udata; /* User data for H5V_opvv() operator */ + + /* Set up user data for H5V_opvv() */ + udata.file = io_info->dset->oloc.file; + udata.dset_contig = &(io_info->dset->shared->cache.contig); + udata.store_contig = &(io_info->store->contig); + udata.wbuf = (const unsigned char *)io_info->u.wbuf; + udata.dxpl_id = io_info->dxpl_id; + + /* Call generic sequence operation routine */ + if((ret_value = H5V_opvv(dset_max_nseq, dset_curr_seq, dset_len_arr, dset_off_arr, + mem_max_nseq, mem_curr_seq, mem_len_arr, mem_off_arr, + H5D_contig_writevv_sieve_cb, &udata)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPERATE, FAIL, "can't perform vectorized sieve buffer write") + } /* end if */ + else { + H5D_contig_writevv_ud_t udata; /* User data for H5V_opvv() operator */ + + /* Set up user data for H5V_opvv() */ + udata.file = io_info->dset->oloc.file; + udata.dset_addr = io_info->store->contig.dset_addr; + udata.wbuf = (const unsigned char *)io_info->u.wbuf; + udata.dxpl_id = io_info->dxpl_id; + + /* Call generic sequence operation routine */ + if((ret_value = H5V_opvv(dset_max_nseq, dset_curr_seq, dset_len_arr, dset_off_arr, + mem_max_nseq, mem_curr_seq, mem_len_arr, mem_off_arr, + H5D_contig_writevv_cb, &udata)) < 0) + HGOTO_ERROR(H5E_DATASET, H5E_CANTOPERATE, FAIL, "can't perform vectorized read") } /* end else */ - /* Update current sequence vectors */ - *dset_curr_seq = u; - *mem_curr_seq = v; - done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5D_contig_writevv() */ |