From d0ab15a9d49a932caeb2cedd57c8e0cc0c15191f Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 8 Feb 2002 17:31:10 +0000 Subject: Fixed a bug for chunked I/O when outputting hyperslabs with boundaries cropped off. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@51 7842ec3a-9562-4be5-9c5b-06ba18f2b668 --- src/DumpVar.c | 123 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 52 deletions(-) diff --git a/src/DumpVar.c b/src/DumpVar.c index 96b441d..fdca24a 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -478,9 +478,15 @@ static int IOHDF5Util_DumpGA (const cGH *GH, CACTUS_MPI_ERROR (MPI_Recv (tmpd, incoming, info->mpi_type, i, 2*i + IOTAGBASE, pughGH->PUGH_COMM_WORLD, &ms)); - - IOHDF5Util_procDump (GH, vindex, timelevel, request, tmpd, geom, i, - info->iohdf5_type, check_exisiting_objects, file); + } + else + { + tmpd = NULL; + } + IOHDF5Util_procDump (GH, vindex, timelevel, request, tmpd, geom, i, + info->iohdf5_type, check_exisiting_objects, file); + if (tmpd) + { free (tmpd); } @@ -714,7 +720,6 @@ static void IOHDF5Util_procDump (const cGH *GH, hssize_t *chunk_origin; hsize_t *chunk_dims, *file_dims; hsize_t buffersize; - int locpoints; DECLARE_CCTK_PARAMETERS @@ -724,17 +729,6 @@ static void IOHDF5Util_procDump (const cGH *GH, sdim = request->sdim; myproc = CCTK_MyProc (GH); - /* Check if there are points to output */ - locpoints = geom[sdim]; - for (i = 1; i < sdim; i++) - { - locpoints *= geom[sdim + i]; - } - if (locpoints <= 0) - { - return; - } - chunk_origin = (hssize_t *) malloc (sdim * sizeof (hssize_t)); chunk_dims = (hsize_t *) malloc (2*sdim * sizeof (hsize_t)); file_dims = chunk_dims + sdim; @@ -754,9 +748,6 @@ static void IOHDF5Util_procDump (const cGH *GH, sprintf (datasetname, "%s timelevel %d at iteration %d", fullname, timelevel, GH->cctk_iteration); - /* create the memspace according to chunk dims */ - IOHDF5_ERROR (memspace = H5Screate_simple (sdim, chunk_dims, NULL)); - /* if restart from recovery delete an already existing dataset so that it can be created as anew */ if (proc == myproc && check_exisiting_objects) @@ -766,6 +757,16 @@ static void IOHDF5Util_procDump (const cGH *GH, IOHDF5_ERROR (H5Eset_auto (myGH->print_error_fn, myGH->print_error_fn_arg)); } + if (outme) + { + /* create the memspace according to chunk dims */ + IOHDF5_ERROR (memspace = H5Screate_simple (sdim, chunk_dims, NULL)); + } + else + { + memspace = -1; + } + if (ioUtilGH->unchunked) { /* create the (global) filespace and set the hyperslab for the chunk */ @@ -786,6 +787,7 @@ static void IOHDF5Util_procDump (const cGH *GH, } IOHDF5_ERROR (dataset = H5Dcreate (file, datasetname, iohdf5_type, filespace, plist)); + IOHDF5_ERROR (H5Pclose (plist)); IOHDF5Util_DumpCommonAttributes (GH, vindex, timelevel, &geom[2*sdim], request, dataset); } @@ -794,20 +796,24 @@ static void IOHDF5Util_procDump (const cGH *GH, IOHDF5_ERROR (dataset = H5Dopen (file, datasetname)); } - /* increase the buffer size if the default isn't sufficient */ - IOHDF5_ERROR (plist = H5Pcreate (H5P_DATASET_XFER)); - buffersize = H5Dget_storage_size (dataset); - if (buffersize > H5Pget_buffer (plist, NULL, NULL)) + if (memspace >= 0) { - IOHDF5_ERROR (H5Pset_buffer (plist, buffersize, NULL, NULL)); - } + /* increase the buffer size if the default isn't sufficient */ + IOHDF5_ERROR (plist = H5Pcreate (H5P_DATASET_XFER)); + buffersize = H5Dget_storage_size (dataset); + if (buffersize > H5Pget_buffer (plist, NULL, NULL)) + { + IOHDF5_ERROR (H5Pset_buffer (plist, buffersize, NULL, NULL)); + } - /* write the data */ - IOHDF5_ERROR (H5Dwrite (dataset, iohdf5_type, memspace, filespace, - plist, outme)); + /* write the data */ + IOHDF5_ERROR (H5Dwrite (dataset, iohdf5_type, memspace, filespace, + plist, outme)); - /* and close the transfer property list and the file dataspace */ - IOHDF5_ERROR (H5Pclose (plist)); + /* close the transfer property list */ + IOHDF5_ERROR (H5Pclose (plist)); + } + /* close the file dataspace */ IOHDF5_ERROR (H5Sclose (filespace)); } else @@ -821,33 +827,46 @@ static void IOHDF5Util_procDump (const cGH *GH, IOHDF5_ERROR (H5Gclose (group)); } - /* now the chunk dataset for each processor is created within the group */ - chunkname = (char *) malloc (strlen (datasetname) + 20); - sprintf (chunkname, "%s/chunk%d", datasetname, proc - myproc); - IOHDF5_ERROR (plist = H5Pcreate (H5P_DATASET_CREATE)); - /* enable compression for chunked dataset if compression was requested */ - if (compression_level) + if (memspace >= 0) + { + /* now the chunk dataset for each processor is created within the group */ + chunkname = (char *) malloc (strlen (datasetname) + 20); + sprintf (chunkname, "%s/chunk%d", datasetname, proc - myproc); + IOHDF5_ERROR (plist = H5Pcreate (H5P_DATASET_CREATE)); + /* enable compression for chunked dataset if compression was requested */ + if (compression_level) + { + IOHDF5_ERROR (H5Pset_chunk (plist, sdim, chunk_dims)); + IOHDF5_ERROR (H5Pset_deflate (plist, compression_level)); + } + /* create the chunk dataset and dump the chunk data */ + IOHDF5_ERROR (dataset = H5Dcreate (file, chunkname, + iohdf5_type, memspace, plist)); + IOHDF5_ERROR (H5Pclose (plist)); + IOHDF5_ERROR (H5Dwrite (dataset, iohdf5_type, H5S_ALL, H5S_ALL, + H5P_DEFAULT, outme)); + + /* add the "origin" attribute for the chunk */ + WRITE_ATTRIBUTE ("chunk_origin", geom, dataset, myGH->array_dataspace, + sdim, IOHDF5_INT); + + free (chunkname); + } + else { - IOHDF5_ERROR (H5Pset_chunk (plist, sdim, chunk_dims)); - IOHDF5_ERROR (H5Pset_deflate (plist, compression_level)); - } - /* create the chunk dataset and dump the chunk data */ - IOHDF5_ERROR (dataset = H5Dcreate (file, chunkname, - iohdf5_type, memspace, plist)); - IOHDF5_ERROR (H5Pclose (plist)); - IOHDF5_ERROR (H5Dwrite (dataset, iohdf5_type, H5S_ALL, H5S_ALL, - H5P_DEFAULT, outme)); - - /* add the "origin" attribute for the chunk */ - WRITE_ATTRIBUTE ("chunk_origin", geom, dataset, myGH->array_dataspace, sdim, - IOHDF5_INT); - - free (chunkname); + dataset = -1; + } } /* close the dataset and the memspace */ - IOHDF5_ERROR (H5Dclose (dataset)); - IOHDF5_ERROR (H5Sclose (memspace)); + if (dataset >= 0) + { + IOHDF5_ERROR (H5Dclose (dataset)); + } + if (memspace >= 0) + { + IOHDF5_ERROR (H5Sclose (memspace)); + } /* free allocated resources */ free (datasetname); -- cgit v1.2.3