diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2010-05-17 15:01:39 +0200 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2011-12-14 18:21:10 +0000 |
commit | d3d28d5ce4b2896d09b92253a23fda46ee3bdd73 (patch) | |
tree | 03eacc08cf9cc0d4c283db58560017d60a62330e /Carpet/CarpetIOHDF5/src/Output.cc | |
parent | 4b184603a63657af2a63c9c0e1f72ea4a9d998c0 (diff) |
CarpetIOHDF5: Index file support
Scanning the attributes of a large CarpetIOHDF5 output file, as is
necessary in the visitCarpetHDF5 plugin, can be very time consuming.
This commit adds support for writing an "index" HDF5 file at the same
time as the data file, conditional on a parameter
"CarpetIOHDF5::output_index". The index file is the same as the data
file except it contains null datasets, and hence is very small. The
attributes can be read from this index file instead of the data file,
greatly increasing performance. The datasets will have size 1 in the
index file, so an additional attribute (h5space) is added to the
dataset to specify the correct dataset dimensions.
Diffstat (limited to 'Carpet/CarpetIOHDF5/src/Output.cc')
-rw-r--r-- | Carpet/CarpetIOHDF5/src/Output.cc | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/Carpet/CarpetIOHDF5/src/Output.cc b/Carpet/CarpetIOHDF5/src/Output.cc index 1a77b2a39..4967785d6 100644 --- a/Carpet/CarpetIOHDF5/src/Output.cc +++ b/Carpet/CarpetIOHDF5/src/Output.cc @@ -25,7 +25,7 @@ using namespace Carpet; static int AddAttributes (const cGH *const cctkGH, const char *fullname, int vdim, int refinementlevel, const ioRequest* const request, - const ibbox& bbox, hid_t dataset); + const ibbox& bbox, hid_t dataset, bool is_index = false); int WriteVarUnchunked (const cGH* const cctkGH, @@ -486,7 +486,8 @@ int WriteVarChunkedParallel (const cGH* const cctkGH, hid_t outfile, CCTK_REAL & io_bytes, const ioRequest* const request, - bool called_from_checkpoint) + bool called_from_checkpoint, + hid_t indexfile) { DECLARE_CCTK_PARAMETERS; @@ -586,20 +587,24 @@ int WriteVarChunkedParallel (const cGH* const cctkGH, if (request->check_exist) { H5E_BEGIN_TRY { H5Gunlink (outfile, datasetname.str().c_str()); + if (indexfile != -1) + H5Gunlink (indexfile, datasetname.str().c_str()); } H5E_END_TRY; } // Get the shape of the HDF5 dataset (in Fortran index order) hsize_t shape[dim]; + hsize_t index_shape[dim]; hssize_t origin[dim]; for (int d = 0; d < group.dim; ++d) { assert (group.dim-1-d>=0 and group.dim-1-d<dim); origin[group.dim-1-d] = (bbox.lower() / bbox.stride())[d]; shape[group.dim-1-d] = (bbox.shape() / bbox.stride())[d]; + index_shape[group.dim-1-d] = 1; } // Write the component as an individual dataset - hid_t plist, dataspace, dataset; + hid_t plist, dataspace, dataset, index_dataspace, index_dataset; HDF5_ERROR (plist = H5Pcreate (H5P_DATASET_CREATE)); // enable compression if requested const int compression_lvl = request->compression_level >= 0 ? @@ -617,6 +622,14 @@ int WriteVarChunkedParallel (const cGH* const cctkGH, HDF5_ERROR (dataspace = H5Screate_simple (group.dim, shape, NULL)); HDF5_ERROR (dataset = H5Dcreate (outfile, datasetname.str().c_str(), filedatatype, dataspace, plist)); + + if (indexfile != -1) { + HDF5_ERROR (index_dataspace = H5Screate_simple (group.dim, + index_shape, NULL)); + HDF5_ERROR (index_dataset = H5Dcreate (indexfile, datasetname.str().c_str(), + filedatatype, index_dataspace, H5P_DEFAULT)); + } + io_bytes += H5Sget_simple_extent_npoints (dataspace) * H5Tget_size (filedatatype); HDF5_ERROR (H5Pclose (plist)); @@ -627,6 +640,13 @@ int WriteVarChunkedParallel (const cGH* const cctkGH, request, bbox, dataset); HDF5_ERROR (H5Dclose (dataset)); + if (indexfile != -1) { + HDF5_ERROR (H5Sclose (index_dataspace)); + error_count += AddAttributes (cctkGH, fullname, group.dim,refinementlevel, + request, bbox, index_dataset, true); + HDF5_ERROR (H5Dclose (index_dataset)); + } + if (data != mydata) free (data); } END_LOCAL_COMPONENT_LOOP; @@ -643,7 +663,7 @@ int WriteVarChunkedParallel (const cGH* const cctkGH, static int AddAttributes (const cGH *const cctkGH, const char *fullname, int vdim, int refinementlevel, const ioRequest* request, - const ibbox& bbox, hid_t dataset) + const ibbox& bbox, hid_t dataset, bool is_index) { assert (vdim>=0 and vdim<=dim); int error_count = 0; @@ -790,6 +810,19 @@ static int AddAttributes (const cGH *const cctkGH, const char *fullname, HDF5_ERROR (H5Awrite (attr, H5T_NATIVE_INT, &iorigin[0])); HDF5_ERROR (H5Aclose (attr)); + hsize_t shape[vdim]; + for (int d = 0; d < vdim; ++d) { + assert (vdim-1-d>=0 and vdim-1-d<vdim); + shape[vdim-1-d] = (bbox.shape() / bbox.stride())[d]; + } + + if (is_index) { + HDF5_ERROR (attr = H5Acreate (dataset, "h5shape", H5T_NATIVE_HSIZE, + dataspace, H5P_DEFAULT)); + HDF5_ERROR (H5Awrite (attr, H5T_NATIVE_HSIZE, &shape[0])); + HDF5_ERROR (H5Aclose (attr)); + } + HDF5_ERROR (H5Sclose (dataspace)); // return the number of errors that occured during this output |