From 7de719287a6449cec0eab1e381d9a90f2ac8b8d1 Mon Sep 17 00:00:00 2001 From: Neil Fortner Date: Mon, 8 Aug 2016 16:56:50 -0500 Subject: [svn-r30270] Fix an issue that could occur when allocating a chunked dataset in parallel, with an alignment threshold set to be larger than the chunk size but smaller than the size of the small data aggregator. Tested: koala, ostrich (h5committest); jelly, ummon --- src/H5MFaggr.c | 24 ++++++++++++--- testpar/t_mdset.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ testpar/testphdf5.c | 5 ++++ testpar/testphdf5.h | 1 + 4 files changed, 112 insertions(+), 4 deletions(-) diff --git a/src/H5MFaggr.c b/src/H5MFaggr.c index f9bad97..c45b473 100644 --- a/src/H5MFaggr.c +++ b/src/H5MFaggr.c @@ -295,10 +295,26 @@ HDfprintf(stderr, "%s: Allocating block\n", FUNC); if(H5MF_xfree(f, alloc_type, dxpl_id, aggr->addr, aggr->size) < 0) HGOTO_ERROR(H5E_RESOURCE, H5E_CANTFREE, HADDR_UNDEF, "can't free aggregation block") - /* Point the aggregator at the newly allocated block */ - aggr->addr = new_space; - aggr->size = aggr->alloc_size; - aggr->tot_size = aggr->alloc_size; + /* If the block is not to be aligned, fold the eoa fragment + * into the newly allocated aggregator, as it could have + * been allocated in an aligned manner if the aggregator + * block is larger than the threshold */ + if(eoa_frag_size && !alignment) { + HDassert(eoa_frag_addr + eoa_frag_size == new_space); + aggr->addr = eoa_frag_addr; + aggr->size = aggr->alloc_size + eoa_frag_size; + aggr->tot_size = aggr->size; + + /* Reset EOA fragment */ + eoa_frag_addr = HADDR_UNDEF; + eoa_frag_size = 0; + } /* end if */ + else { + /* Point the aggregator at the newly allocated block */ + aggr->addr = new_space; + aggr->size = aggr->alloc_size; + aggr->tot_size = aggr->alloc_size; + } } /* end else */ /* Allocate space out of the metadata block */ diff --git a/testpar/t_mdset.c b/testpar/t_mdset.c index c88cb86..7077081 100644 --- a/testpar/t_mdset.c +++ b/testpar/t_mdset.c @@ -2610,6 +2610,92 @@ void rr_obj_hdr_flush_confusion_reader(MPI_Comm comm) #undef Writer_Root #undef Reader_Root + +/* + * Test creating a chunked dataset in parallel in a file with an alignment set + * and an alignment threshold large enough to avoid aligning the chunks but + * small enough that the raw data aggregator will be aligned if it is treated as + * an object that must be aligned by the library + */ +#define CHUNK_SIZE 72 +#define NCHUNKS 32 +#define AGGR_SIZE 2048 +#define EXTRA_ALIGN 100 + + void chunk_align_bug_1(void) + { + int mpi_rank; + hid_t file_id, dset_id, fapl_id, dcpl_id, space_id; + hsize_t dims = CHUNK_SIZE * NCHUNKS, cdims = CHUNK_SIZE; + h5_stat_size_t file_size; + hsize_t align; + herr_t ret; + const char *filename; + + MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); + + filename = (const char *)GetTestParameters(); + + /* Create file without alignment */ + fapl_id = create_faccess_plist(MPI_COMM_WORLD, MPI_INFO_NULL, facc_type); + VRFY((fapl_id >= 0), "create_faccess_plist succeeded"); + file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); + VRFY((file_id >= 0), "H5Fcreate succeeded"); + + /* Close file */ + ret = H5Fclose(file_id); + VRFY((ret >= 0), "H5Fclose succeeded"); + + /* Get file size */ + file_size = h5_get_file_size(filename, fapl_id); + VRFY((file_size >= 0), "h5_get_file_size succeeded"); + + /* Calculate alignment value, set to allow a chunk to squeak in between the + * original EOF and the aligned location of the aggregator. Add some space + * for the dataset metadata */ + align = (hsize_t)file_size + CHUNK_SIZE + EXTRA_ALIGN; + + /* Set aggregator size and alignment, disable metadata aggregator */ + HDassert(AGGR_SIZE > CHUNK_SIZE); + ret = H5Pset_small_data_block_size(fapl_id, AGGR_SIZE); + VRFY((ret >= 0), "H5Pset_small_data_block_size succeeded"); + ret = H5Pset_meta_block_size(fapl_id, 0); + VRFY((ret >= 0), "H5Pset_meta_block_size succeeded"); + ret = H5Pset_alignment(fapl_id, CHUNK_SIZE + 1, align); + VRFY((ret >= 0), "H5Pset_small_data_block_size succeeded"); + + /* Reopen file with new settings */ + file_id = H5Fopen(filename, H5F_ACC_RDWR, fapl_id); + VRFY((file_id >= 0), "H5Fopen succeeded"); + + /* Create dataset */ + space_id = H5Screate_simple(1, &dims, NULL); + VRFY((space_id >= 0), "H5Screate_simple succeeded"); + dcpl_id = H5Pcreate(H5P_DATASET_CREATE); + VRFY((dcpl_id >= 0), "H5Pcreate succeeded"); + ret = H5Pset_chunk(dcpl_id, 1, &cdims); + VRFY((ret >= 0), "H5Pset_chunk succeeded"); + dset_id = H5Dcreate2(file_id, "dset", H5T_NATIVE_CHAR, space_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT); + VRFY((dset_id >= 0), "H5Dcreate2 succeeded"); + + /* Close ids */ + ret = H5Dclose(dset_id); + VRFY((dset_id >= 0), "H5Dclose succeeded"); + ret = H5Sclose(space_id); + VRFY((space_id >= 0), "H5Sclose succeeded"); + ret = H5Pclose(dcpl_id); + VRFY((dcpl_id >= 0), "H5Pclose succeeded"); + ret = H5Pclose(fapl_id); + VRFY((fapl_id >= 0), "H5Pclose succeeded"); + + /* Close file */ + ret = H5Fclose(file_id); + VRFY((ret >= 0), "H5Fclose succeeded"); + + return; +} /* end chunk_align_bug_1() */ + + /*============================================================================= * End of t_mdset.c *===========================================================================*/ diff --git a/testpar/testphdf5.c b/testpar/testphdf5.c index 7818101..c54cb5e 100644 --- a/testpar/testphdf5.c +++ b/testpar/testphdf5.c @@ -496,6 +496,11 @@ int main(int argc, char **argv) &rr_obj_flush_confusion_params); } + AddTest("alnbg1", + chunk_align_bug_1, NULL, + "Chunk allocation with alignment bug.", + PARATESTFILE); + AddTest("tldsc", lower_dim_size_comp_test, NULL, "test lower dim size comp in span tree to mpi derived type", diff --git a/testpar/testphdf5.h b/testpar/testphdf5.h index 7d6ff22..9838673 100644 --- a/testpar/testphdf5.h +++ b/testpar/testphdf5.h @@ -285,6 +285,7 @@ void io_mode_confusion(void); void rr_obj_hdr_flush_confusion(void); void rr_obj_hdr_flush_confusion_reader(MPI_Comm comm); void rr_obj_hdr_flush_confusion_writer(MPI_Comm comm); +void chunk_align_bug_1(void); void lower_dim_size_comp_test(void); void link_chunk_collective_io_test(void); void contig_hyperslab_dr_pio_test(ShapeSameTestMethods sstest_type); -- cgit v0.12