From 401f07400f3ce40f037b2695adc43c0279b93b9f Mon Sep 17 00:00:00 2001 From: tradke Date: Tue, 30 Apr 2002 09:23:25 +0000 Subject: Values for CCTK_SCALAR variables are taken only from processor 0. If other processors have different values a warning will be issued. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@63 7842ec3a-9562-4be5-9c5b-06ba18f2b668 --- src/DumpVar.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 19 deletions(-) diff --git a/src/DumpVar.c b/src/DumpVar.c index db8fb2f..9a0afba 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -11,6 +11,7 @@ #include +#include #include "cctk.h" #include "cctk_Parameters.h" @@ -138,7 +139,13 @@ int IOHDF5Util_DumpVar (const cGH *GH, const ioRequest *request, hid_t file) @author Thomas Radke @desc Writes a CCTK_SCALAR type variable into a HDF5 file. + Only the value from processor 0 is written here. + If other processors have different values for this scalar + variable a warning will be issued. @enddesc + + @calls IOHDF5Util_DumpCommonAttributes + @var GH @vdesc pointer to CCTK grid hierarchy @vtype const cGH * @@ -168,39 +175,84 @@ int IOHDF5Util_DumpVar (const cGH *GH, const ioRequest *request, hid_t file) static int WriteGS (const cGH *GH, const ioRequest *request, const char *name, hid_t file) { + int i, myproc, nprocs, hdatatypesize, retval; + char *buffer, *fullname; const ioGH *ioUtilGH; const ioHDF5UtilGH *myGH; hid_t dataset, hdf5type; + /*** FIXME: can CCTK_Reduce() have a 'const cGH *' parameter ?? ***/ + union + { + const cGH *const_ptr; + cGH *non_const_ptr; + } fakeGH; - /* only I/O processors write data */ ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); - if (CCTK_MyProc (GH) != ioUtilGH->ioproc) + myproc = CCTK_MyProc (GH); + nprocs = CCTK_nProcs (GH); + fullname = CCTK_FullName (request->vindex); + + hdatatypesize = CCTK_VarTypeSize (request->hdatatype); + buffer = (char *) calloc (nprocs, hdatatypesize); + memcpy (buffer + myproc*hdatatypesize, + CCTK_VarDataPtrI (GH, request->timelevel, request->vindex), + hdatatypesize); + + i = CCTK_ReductionHandle ("sum"); + fakeGH.const_ptr = GH; + if (CCTK_ReduceArray (fakeGH.non_const_ptr, -1, i, nprocs, request->hdatatype, + buffer, 1, 1, request->hdatatype, nprocs, buffer)) { - return (0); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "WriteGS: Failed to reduce grid scalar '%s'", fullname); } - - /* check if file handle is invalid */ - if (file < 0) + else { - return (-1); + retval = 0; + for (i = 1; i < nprocs; i++) + { + retval |= memcmp (buffer, buffer + i*hdatatypesize, hdatatypesize); + } + if (retval) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "WriteGS: value of grid scalar variable '%s' (timelevel %d) " + "differs between processors, only value from processor 0 " + "will be written", fullname, request->timelevel); + } } - myGH = (const ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); - hdf5type = IOHDF5Util_DataType (myGH, request->hdatatype); - HDF5_ERROR (dataset = H5Dcreate (file, name, hdf5type, myGH->scalar_dataspace, - H5P_DEFAULT)); - HDF5_ERROR (H5Dwrite (dataset, hdf5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, - CCTK_VarDataPtrI (GH, request->timelevel, - request->vindex))); + /* only I/O processors write data */ + if (myproc != ioUtilGH->ioproc) + { + retval = 0; + } + else if (file < 0) + { + retval = -1; + } + else + { + myGH = (const ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); + hdf5type = IOHDF5Util_DataType (myGH, request->hdatatype); + HDF5_ERROR (dataset = H5Dcreate (file, name, hdf5type, + myGH->scalar_dataspace, H5P_DEFAULT)); + HDF5_ERROR (H5Dwrite (dataset, hdf5type, H5S_ALL, H5S_ALL, H5P_DEFAULT, + buffer)); + + /* scalars have size 0 */ + request->hsize[0] = 0; + IOHDF5Util_DumpCommonAttributes (GH, request, dataset); - /* scalars have size 0 */ - request->hsize[0] = 0; - IOHDF5Util_DumpCommonAttributes (GH, request, dataset); + HDF5_ERROR (H5Dclose (dataset)); + retval = 0; + } - HDF5_ERROR (H5Dclose (dataset)); + free (buffer); + free (fullname); - return (0); + return (retval); } -- cgit v1.2.3