diff options
author | Neil Fortner <nfortne2@hdfgroup.org> | 2022-03-18 20:43:30 (GMT) |
---|---|---|
committer | Neil Fortner <nfortne2@hdfgroup.org> | 2022-03-18 20:43:30 (GMT) |
commit | b03e65ec000ca6622d711438417c6ae5431ebf77 (patch) | |
tree | e68b4748d28823a76ae03d88238f3b30b7ea9abf | |
parent | c1c4ecd9c8b2616af23d5b58336fb9e44e72b4ae (diff) | |
download | hdf5-b03e65ec000ca6622d711438417c6ae5431ebf77.zip hdf5-b03e65ec000ca6622d711438417c6ae5431ebf77.tar.gz hdf5-b03e65ec000ca6622d711438417c6ae5431ebf77.tar.bz2 |
Fix bugs in selection I/O code.
-rw-r--r-- | src/H5FDint.c | 44 | ||||
-rw-r--r-- | src/H5FDmpio.c | 31 |
2 files changed, 45 insertions, 30 deletions
diff --git a/src/H5FDint.c b/src/H5FDint.c index 8deec48..65e090a 100644 --- a/src/H5FDint.c +++ b/src/H5FDint.c @@ -795,6 +795,12 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin /* Check if we're using vector I/O */ use_vector = file->cls->read_vector != NULL; + /* Allocate sequence lists for memory and file spaces */ + if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") + if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") + /* Loop over dataspaces */ for (i = 0; i < count; i++) { @@ -827,12 +833,6 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin } } - /* Allocate sequence lists for memory and file spaces */ - if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) - HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") - if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) - HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") - /* Initialize sequence lists for memory and file spaces */ if (H5S_select_iter_init(file_iter, file_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for file space") @@ -970,6 +970,14 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin /* Make sure both memory and file sequences terminated at the same time */ if (mem_seq_i < mem_nseq) HGOTO_ERROR(H5E_INTERNAL, H5E_BADVALUE, FAIL, "file selection terminated before memory selection") + + /* Terminate iterators */ + if (H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") + file_iter_init = FALSE; + if (H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") + mem_iter_init = FALSE; } /* Issue vector read call if appropriate */ @@ -981,7 +989,7 @@ H5FD__read_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, uin } done: - /* Terminate iterators */ + /* Terminate and free iterators */ if (file_iter) { if (file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") @@ -1430,6 +1438,12 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui /* Check if we're using vector I/O */ use_vector = file->cls->write_vector != NULL; + /* Allocate sequence lists for memory and file spaces */ + if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") + if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) + HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") + /* Loop over dataspaces */ for (i = 0; i < count; i++) { @@ -1462,12 +1476,6 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui } } - /* Allocate sequence lists for memory and file spaces */ - if (NULL == (file_iter = H5FL_MALLOC(H5S_sel_iter_t))) - HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate file selection iterator") - if (NULL == (mem_iter = H5FL_MALLOC(H5S_sel_iter_t))) - HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "couldn't allocate memory selection iterator") - /* Initialize sequence lists for memory and file spaces */ if (H5S_select_iter_init(file_iter, file_spaces[i], element_size, 0) < 0) HGOTO_ERROR(H5E_VFL, H5E_CANTINIT, FAIL, "can't initialize sequence list for file space") @@ -1605,6 +1613,14 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui /* Make sure both memory and file sequences terminated at the same time */ if (mem_seq_i < mem_nseq) HGOTO_ERROR(H5E_INTERNAL, H5E_BADVALUE, FAIL, "file selection terminated before memory selection") + + /* Terminate iterators */ + if (H5S_SELECT_ITER_RELEASE(file_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") + file_iter_init = FALSE; + if (H5S_SELECT_ITER_RELEASE(mem_iter) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release memory selection iterator") + mem_iter_init = FALSE; } /* Issue vector write call if appropriate */ @@ -1616,7 +1632,7 @@ H5FD__write_selection_translate(H5FD_t *file, H5FD_mem_t type, hid_t dxpl_id, ui } done: - /* Terminate iterators */ + /* Terminate and free iterators */ if (file_iter) { if (file_iter_init && H5S_SELECT_ITER_RELEASE(file_iter) < 0) HGOTO_ERROR(H5E_INTERNAL, H5E_CANTFREE, FAIL, "can't release file selection iterator") diff --git a/src/H5FDmpio.c b/src/H5FDmpio.c index 1d96979..5a279d0 100644 --- a/src/H5FDmpio.c +++ b/src/H5FDmpio.c @@ -1711,7 +1711,9 @@ H5FD__mpio_vector_build_types(uint32_t count, H5FD_mem_t types[], haddr_t addrs[ *file_type = MPI_BYTE; *mpi_bufs_base = bufs[0]; - /* Setup s_sizes and s_bufs (needed for incomplete read filling code) */ + /* Setup s_addrs, s_sizes and s_bufs (needed for incomplete read filling code and eof + * calculation code) */ + *s_addrs = addrs; *s_sizes = sizes; *s_bufs = bufs; @@ -1792,8 +1794,9 @@ H5FD__mpio_vector_build_types(uint32_t count, H5FD_mem_t types[], haddr_t addrs[ /* Determine size of this vector element */ if (!fixed_size) { if ((*s_sizes)[i] == 0) { + HDassert(vector_was_sorted); fixed_size = TRUE; - size = (*s_sizes)[i - 1]; + size = sizes[i - 1]; } else { size = (*s_sizes)[i]; @@ -2369,11 +2372,6 @@ done: } } - /* Make sure we cleaned up */ - HDassert(!s_addrs); - HDassert(!s_sizes); - HDassert(!s_bufs); - #ifdef H5FDmpio_DEBUG if (H5FD_mpio_debug_t_flag) HDfprintf(stdout, "%s: Leaving, proc %d: ret_value = %d\n", __func__, file->mpi_rank, ret_value); @@ -2428,7 +2426,7 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co hbool_t vector_was_sorted = TRUE; haddr_t * s_addrs = NULL; size_t * s_sizes = NULL; - void ** s_bufs = NULL; + const void ** s_bufs = NULL; char unused = 0; /* Unused, except for non-NULL pointer value */ const void * mpi_bufs_base = NULL; MPI_Datatype buf_type = MPI_BYTE; /* MPI description of the selection in memory */ @@ -2495,7 +2493,8 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co HGOTO_ERROR(H5E_VFL, H5E_CANTGET, FAIL, "can't build MPI datatypes for I/O") /* Compute max addr writted to */ - max_addr = s_addrs[count - 1] + (haddr_t)(s_sizes[count - 1]); + if (count > 0) + max_addr = s_addrs[count - 1] + (haddr_t)(s_sizes[count - 1]); /* free sorted vectors if they exist */ if (!vector_was_sorted) { @@ -2516,10 +2515,6 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co /* Portably initialize MPI status variable */ HDmemset(&mpi_stat, 0, sizeof(MPI_Status)); - /* some numeric conversions */ - if (H5FD_mpi_haddr_to_MPIOff((haddr_t)0, &mpi_off) < 0) - HGOTO_ERROR(H5E_INTERNAL, H5E_BADRANGE, FAIL, "can't set MPI off to 0") - #ifdef H5FDmpio_DEBUG if (H5FD_mpio_debug_w_flag) HDfprintf(stdout, "%s: mpi_off = %ld size_i = %d\n", __func__, (long)mpi_off, size_i); @@ -2530,6 +2525,10 @@ H5FD__mpio_write_vector(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, uint32_t co H5FD_mpi_native_g, file->info))) HMPI_GOTO_ERROR(FAIL, "MPI_File_set_view failed", mpi_code) + /* Reset mpi_off to 0 since the view now starts at the data offset */ + if (H5FD_mpi_haddr_to_MPIOff((haddr_t)0, &mpi_off) < 0) + HGOTO_ERROR(H5E_INTERNAL, H5E_BADRANGE, FAIL, "can't set MPI off to 0") + /* Get the collective_opt property to check whether the application wants to do IO individually. */ if (H5CX_get_mpio_coll_opt(&coll_opt_mode) < 0) @@ -2668,9 +2667,9 @@ done: } /* Make sure we cleaned up */ - HDassert(!s_addrs); - HDassert(!s_sizes); - HDassert(!s_bufs); + HDassert(vector_was_sorted || !s_addrs); + HDassert(vector_was_sorted || !s_sizes); + HDassert(vector_was_sorted || !s_bufs); #ifdef H5FDmpio_DEBUG if (H5FD_mpio_debug_t_flag) |