From 377ea8964b7ada04c406970f0bbcca0a7f9b9012 Mon Sep 17 00:00:00 2001 From: tradke Date: Fri, 26 Apr 2002 15:44:04 +0000 Subject: Moved the I/O request description and parsing routines to IOUtil so that they can be shared by all I/O thorns. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOHDF5Util/trunk@62 7842ec3a-9562-4be5-9c5b-06ba18f2b668 --- src/DumpUtils.c | 130 ++++++++--------- src/DumpVar.c | 220 ++++++++++++++-------------- src/ParseVars.c | 411 ----------------------------------------------------- src/ioHDF5UtilGH.h | 34 +---- src/make.code.defn | 2 +- 5 files changed, 175 insertions(+), 622 deletions(-) delete mode 100644 src/ParseVars.c diff --git a/src/DumpUtils.c b/src/DumpUtils.c index 2045d1a..3c12431 100644 --- a/src/DumpUtils.c +++ b/src/DumpUtils.c @@ -55,29 +55,15 @@ CCTK_FILEVERSION(BetaThorns_IOHDF5Util_DumpUtils_c) @@*/ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) { - int first_vindex, gindex, timelevels, retval; - int *extent_int; + int first_vindex, gindex, retval; cGroup gdata; - ioSlab slab; + char *fullname; + ioRequest *request; DECLARE_CCTK_PARAMETERS retval = 0; - /* set up a hyperslab description for full hyperslabs */ - slab.vdim = CCTK_MaxDim (); - slab.vectors = (CCTK_INT *) calloc ((slab.vdim + 6)*slab.vdim + 1, - sizeof(CCTK_INT)); - slab.hoffset = slab.vectors + 0*slab.vdim; - slab.hsize = slab.vectors + 1*slab.vdim; - slab.hsize_chunk = slab.vectors + 2*slab.vdim; - slab.origin = slab.vectors + 3*slab.vdim + 1; - slab.extent = slab.vectors + 4*slab.vdim + 1; - slab.downsample = slab.vectors + 5*slab.vdim + 1; - slab.direction = slab.vectors + 6*slab.vdim + 1; - - extent_int = (int *) malloc (slab.vdim * sizeof (int)); - /* start CP_PARAMETERS_TIMER timer */ if (timers) { @@ -96,7 +82,7 @@ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) if (verbose) { - CCTK_INFO ("Dumping variables ..."); + CCTK_INFO ("Dumping Grid Variables ..."); } /* stop CP_PARAMETERS_TIMER timer and start CP_VARIABLES_TIMER */ @@ -118,41 +104,44 @@ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) /* dump all timelevels except the oldest (for multi-level groups) */ CCTK_GroupData (gindex, &gdata); - CCTK_GroupgshGI (GH, gdata.dim, extent_int, gindex); - timelevels = gdata.numtimelevels; - if (timelevels > 1) + if (gdata.numtimelevels > 1) { - timelevels--; + gdata.numtimelevels--; } - slab.vdim = gdata.dim; - slab.check_exist = 0; - slab.hdatatype = gdata.vartype; - - /* set the hyperslab extents, the directions (orthogonal to all axes), - and disable downsampling */ - memset (slab.direction, 0, slab.vdim * slab.vdim * sizeof (int)); - for (slab.hdim = 0; slab.hdim < slab.vdim; slab.hdim++) + + first_vindex = CCTK_FirstVarIndexI (gindex); + + /* get the default I/O request for this group */ + request = IOUtil_DefaultIORequest (GH, first_vindex); + + /* disable checking for old data objects, disable datatype conversion + and downsampling */ + request->check_exist = 0; + request->hdatatype = gdata.vartype; + for (request->hdim = 0; request->hdim < request->vdim; request->hdim++) { - slab.extent[slab.hdim] = extent_int[slab.hdim]; - slab.direction[slab.hdim * (slab.vdim + 1)] = 1; - slab.downsample[slab.hdim] = 1; + request->downsample[request->hdim] = 1; } /* loop over all variables in this group */ - first_vindex = CCTK_FirstVarIndexI (gindex); - for (slab.vindex = first_vindex; - slab.vindex < first_vindex + gdata.numvars; - slab.vindex++) + for (request->vindex = first_vindex; + request->vindex < first_vindex + gdata.numvars; + request->vindex++) { - if (verbose && file >= 0) - { - CCTK_VInfo (CCTK_THORNSTRING, " %s", CCTK_VarName (slab.vindex)); - } - /* loop over all timelevels of this variable */ - for (slab.timelevel = 0; slab.timelevel < timelevels; slab.timelevel++) + for (request->timelevel = 0; + request->timelevel < gdata.numtimelevels; + request->timelevel++) { - retval += IOHDF5Util_DumpVar (GH, &slab, file); + if (verbose && file >= 0) + { + fullname = CCTK_FullName (request->vindex); + CCTK_VInfo (CCTK_THORNSTRING, " %s (timelevel %d)", + fullname, request->timelevel); + free (fullname); + } + + retval += IOHDF5Util_DumpVar (GH, request, file); } } /* end of loop over all variables */ @@ -164,9 +153,8 @@ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) CCTK_TimerStopI (timers[CP_VARIABLES_TIMER]); } - /* free temporary resources */ - free (slab.vectors); - free (extent_int); + /* free I/O request */ + IOUtil_FreeIORequest (&request); return (retval); } @@ -194,9 +182,9 @@ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var dataset @@ -205,7 +193,7 @@ int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file) @vio in @endvar @@*/ -void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab, +void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioRequest *request, hid_t object) { int dim, vdim; @@ -220,14 +208,14 @@ void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab, myGH = (ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); /* attributes describing the variable */ - groupname = CCTK_GroupNameFromVarI (slab->vindex); + groupname = CCTK_GroupNameFromVarI (request->vindex); WRITE_ATTRIBUTE ("groupname", groupname, object, myGH, 0, myGH->HDF5_STRING); free (groupname); - attr_int = CCTK_GroupTypeFromVarI (slab->vindex); + attr_int = CCTK_GroupTypeFromVarI (request->vindex); WRITE_ATTRIBUTE ("grouptype", &attr_int, object, myGH, 0, HDF5_INT); - attr_int = CCTK_NumTimeLevelsFromVarI (slab->vindex); + attr_int = CCTK_NumTimeLevelsFromVarI (request->vindex); WRITE_ATTRIBUTE ("ntimelevels", &attr_int, object, myGH, 0, HDF5_INT); - WRITE_ATTRIBUTE ("global_size", slab->hsize, object, myGH, slab->hdim, + WRITE_ATTRIBUTE ("global_size", request->hsize, object, myGH, request->hdim, HDF5_INT); WRITE_ATTRIBUTE ("time", &GH->cctk_time, object, myGH, 0, HDF5_REAL); @@ -237,9 +225,9 @@ void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab, /* FIXME: This is hardcoded for cartesian coordinate systems. A better solution would be to be able to query the coordinate system which is associated with the variable. */ - vdim = CCTK_GroupDimFromVarI (slab->vindex); + vdim = CCTK_GroupDimFromVarI (request->vindex); sprintf (coord_system_name, "cart%dd", vdim); - if (CCTK_GroupTypeFromVarI (slab->vindex) == CCTK_GF && + if (CCTK_GroupTypeFromVarI (request->vindex) == CCTK_GF && CCTK_CoordSystemHandle (coord_system_name) >= 0) { attr_real = (CCTK_REAL *) malloc (2 * vdim * sizeof (CCTK_REAL)); @@ -260,22 +248,22 @@ void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab, #if 0 /* attributes describing the hyperslab */ /* FIXME: what attributes are really needed here ?? ***/ - if (slab) + if (request) { - attr_real = (CCTK_REAL *) malloc (4 * slab->hdim * sizeof (CCTK_REAL)); - for (dim = 0; dim < slab->hdim; dim++) + attr_real = (CCTK_REAL *) malloc (4 * request->hdim * sizeof (CCTK_REAL)); + for (dim = 0; dim < request->hdim; dim++) { - attr_real[dim + 0*slab->hdim] = - slab->origin[slab->direction[dim]] * - GH->cctk_delta_space[slab->direction[dim]]; - attr_real[dim + 1*slab->hdim] = - slab->origin[dim] * GH->cctk_delta_space[dim]; - attr_real[dim + 2*slab->hdim] = - (slab->origin[dim] + slab->actlen[dim]-1) * - GH->cctk_delta_space[dim] * slab->downsample[dim]; - attr_real[dim + 3*slab->hdim] = - GH->cctk_delta_space[slab->direction[dim]] * - slab->downsample[slab->direction[dim]]; + attr_real[dim + 0*request->hdim] = + request->origin[request->direction[dim]] * + GH->cctk_delta_space[request->direction[dim]]; + attr_real[dim + 1*request->hdim] = + request->origin[dim] * GH->cctk_delta_space[dim]; + attr_real[dim + 2*request->hdim] = + (request->origin[dim] + request->actlen[dim]-1) * + GH->cctk_delta_space[dim] * request->downsample[dim]; + attr_real[dim + 3*request->hdim] = + GH->cctk_delta_space[request->direction[dim]] * + request->downsample[request->direction[dim]]; } WRITE_ATTRIBUTE ("origin_slab", attr_real + 0*dim, object, myGH, dim, HDF5_REAL); diff --git a/src/DumpVar.c b/src/DumpVar.c index 6492f58..db8fb2f 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -37,14 +37,14 @@ CCTK_FILEVERSION(BetaThorns_IOHDF5Util_DumpVar_c) /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ -static int WriteGS (const cGH *GH, const ioSlab *slab, const char *name, +static int WriteGS (const cGH *GH, const ioRequest *request, const char *name, hid_t file); -static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, +static int WriteGA (const cGH *GH, const ioRequest *request, const char *name, hid_t file); -static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, +static void WriteData (const cGH *GH, const ioRequest *request,const char *name, const void *data, int proc, hid_t file); #if defined(CCTK_MPI) && defined(H5_HAVE_PARALLEL) -static void WriteDataCollective (const cGH *GH, const ioSlab *slab, +static void WriteDataCollective (const cGH *GH, const ioRequest *request, const char *name, const void *data,hid_t file); #endif @@ -65,9 +65,9 @@ static void WriteDataCollective (const cGH *GH, const ioSlab *slab, @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var file @@ -83,20 +83,20 @@ static void WriteDataCollective (const cGH *GH, const ioSlab *slab, @seeroutine WriteGA @endreturndesc @@*/ -int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file) +int IOHDF5Util_DumpVar (const cGH *GH, const ioRequest *request, hid_t file) { int gtype, retval; char *fullname, *objectname; /* build the unique name for the file object to write */ - fullname = CCTK_FullName (slab->vindex); + fullname = CCTK_FullName (request->vindex); objectname = (char *) malloc (strlen (fullname) + 80); sprintf (objectname, "%s timelevel %d at iteration %d", - fullname, slab->timelevel, GH->cctk_iteration); + fullname, request->timelevel, GH->cctk_iteration); /* check whether the object already exists */ - if (slab->check_exist && file >= 0) + if (request->check_exist && file >= 0) { H5E_BEGIN_TRY { @@ -105,14 +105,14 @@ int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file) } /* branch to the appropriate dump routine */ - gtype = CCTK_GroupTypeFromVarI (slab->vindex); + gtype = CCTK_GroupTypeFromVarI (request->vindex); if (gtype == CCTK_SCALAR) { - retval = WriteGS (GH, slab, objectname, file); + retval = WriteGS (GH, request, objectname, file); } else if (gtype == CCTK_ARRAY || gtype == CCTK_GF) { - retval = WriteGA (GH, slab, objectname, file); + retval = WriteGA (GH, request, objectname, file); } else { @@ -144,9 +144,9 @@ int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file) @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var name @@ -165,18 +165,16 @@ int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file) 0 for success, or -1 if file handle is invalid @endreturndesc @@*/ -static int WriteGS (const cGH *GH, const ioSlab *slab, const char *name, +static int WriteGS (const cGH *GH, const ioRequest *request, const char *name, hid_t file) { - ioGH *ioUtilGH; - ioHDF5UtilGH *myGH; + const ioGH *ioUtilGH; + const ioHDF5UtilGH *myGH; hid_t dataset, hdf5type; - ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); - myGH = (ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); - /* only I/O processors write data */ + ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); if (CCTK_MyProc (GH) != ioUtilGH->ioproc) { return (0); @@ -188,15 +186,17 @@ static int WriteGS (const cGH *GH, const ioSlab *slab, const char *name, return (-1); } - hdf5type = IOHDF5Util_DataType (myGH, slab->hdatatype); + 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, slab->timelevel, slab->vindex))); + CCTK_VarDataPtrI (GH, request->timelevel, + request->vindex))); /* scalars have size 0 */ - slab->hsize[0] = 0; - IOHDF5Util_DumpCommonAttributes (GH, slab, dataset); + request->hsize[0] = 0; + IOHDF5Util_DumpCommonAttributes (GH, request, dataset); HDF5_ERROR (H5Dclose (dataset)); @@ -223,9 +223,9 @@ static int WriteGS (const cGH *GH, const ioSlab *slab, const char *name, @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var name @@ -246,15 +246,15 @@ static int WriteGS (const cGH *GH, const ioSlab *slab, const char *name, -2 if hyperslab couldn't be extracted @endreturndesc @@*/ -static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, +static int WriteGA (const cGH *GH, const ioRequest *request, const char *name, hid_t file) { - ioGH *ioUtilGH; - ioHDF5UtilGH *myGH; - int i, myproc, nprocs, mapping, hdatasize, retval; + const ioGH *ioUtilGH; + int i, myproc, mapping, hdatasize, retval; void *hdata; char *fullname; #ifdef CCTK_MPI + int nprocs; void *tmpd; MPI_Comm comm; MPI_Status ms; @@ -263,21 +263,20 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, DECLARE_CCTK_PARAMETERS - myGH = (ioHDF5UtilGH *) CCTK_GHExtension (GH, "IOHDF5Util"); - ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); - - myproc = CCTK_MyProc (GH); - nprocs = CCTK_nProcs (GH); - /* define the hyperslab mapping */ - mapping = Hyperslab_DefineLocalMappingByIndex (GH, slab->vindex, slab->hdim, - slab->direction, slab->origin, - slab->extent, slab->downsample, - -1, NULL, slab->hsize_chunk, - slab->hsize, slab->hoffset); + mapping = Hyperslab_DefineLocalMappingByIndex (GH, request->vindex, + request->hdim, + request->direction, + request->origin, + request->extent, + request->downsample, + -1, NULL, + request->hsize_chunk, + request->hsize, + request->hoffset); if (mapping < 0) { - fullname = CCTK_FullName (slab->vindex); + fullname = CCTK_FullName (request->vindex); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to define hyperslab mapping for variable '%s'", fullname); @@ -286,25 +285,25 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, } /* calculate the size of the hyperslab */ - slab->hsize_chunk[slab->hdim] = 1; - for (i = 0; i < slab->hdim; i++) + request->hsize_chunk[request->hdim] = 1; + for (i = 0; i < request->hdim; i++) { - slab->hsize_chunk[slab->hdim] *= slab->hsize_chunk[i]; + request->hsize_chunk[request->hdim] *= request->hsize_chunk[i]; } /* get the hyperslab */ - hdatasize = CCTK_VarTypeSize (slab->hdatatype); - hdata = slab->hsize_chunk[slab->hdim] > 0 ? - malloc (slab->hsize_chunk[slab->hdim] * hdatasize) : NULL; - retval = Hyperslab_Get (GH, mapping, -1, slab->vindex, slab->timelevel, - slab->hdatatype, hdata); + hdatasize = CCTK_VarTypeSize (request->hdatatype); + hdata = request->hsize_chunk[request->hdim] > 0 ? + malloc (request->hsize_chunk[request->hdim] * hdatasize) : NULL; + retval = Hyperslab_Get (GH, mapping, -1, request->vindex, request->timelevel, + request->hdatatype, hdata); /* release the mapping structure */ Hyperslab_FreeMapping (mapping); if (retval) { - fullname = CCTK_FullName (slab->vindex); + fullname = CCTK_FullName (request->vindex); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Failed to extract hyperslab for variable '%s'", fullname); free (fullname); @@ -315,11 +314,13 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, return (-2); } + ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); + #ifdef CCTK_MPI #ifdef H5_HAVE_PARALLEL if (ioUtilGH->unchunked) { - WriteDataCollective (GH, slab, name, hdata, file); + WriteDataCollective (GH, request, name, hdata, file); if (hdata) { free (hdata); @@ -330,13 +331,15 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, #endif /* dump data held on I/O processor */ + myproc = CCTK_MyProc (GH); if (myproc == ioUtilGH->ioproc) { - WriteData (GH, slab, name, hdata, myproc, file); + WriteData (GH, request, name, hdata, myproc, file); } #ifdef CCTK_MPI + nprocs = CCTK_nProcs (GH); comm = PUGH_pGH (GH)->PUGH_COMM_WORLD; - mpitype = PUGH_MPIDataType (PUGH_pGH (GH), slab->hdatatype); + mpitype = PUGH_MPIDataType (PUGH_pGH (GH), request->hdatatype); if (myproc == ioUtilGH->ioproc) { @@ -345,20 +348,21 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, { /* receive geometry (this assumes the geometry arrays to be contiguous starting at hoffset */ - CACTUS_MPI_ERROR (MPI_Recv (slab->hoffset, 3*slab->hdim + 1, PUGH_MPI_INT, - i, 2*i + MPITAGBASE + 1, comm, &ms)); + CACTUS_MPI_ERROR (MPI_Recv (request->hoffset, 3*request->hdim + 1, + PUGH_MPI_INT, i, 2*i + MPITAGBASE + 1, + comm, &ms)); /* receive data */ tmpd = NULL; - if (slab->hsize_chunk[slab->hdim] > 0) + if (request->hsize_chunk[request->hdim] > 0) { - tmpd = malloc (slab->hsize_chunk[slab->hdim] * hdatasize); - CACTUS_MPI_ERROR (MPI_Recv (tmpd, slab->hsize_chunk[slab->hdim], + tmpd = malloc (request->hsize_chunk[request->hdim] * hdatasize); + CACTUS_MPI_ERROR (MPI_Recv (tmpd, request->hsize_chunk[request->hdim], mpitype, i, 2*i + MPITAGBASE, comm, &ms)); } /* write data */ - WriteData (GH, slab, name, tmpd, i, file); + WriteData (GH, request, name, tmpd, i, file); if (tmpd) { @@ -372,18 +376,18 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, { /* send geometry (this assumes the geometry arrays to be contiguous starting at hoffset) */ - CACTUS_MPI_ERROR (MPI_Send (slab->hoffset, 3*slab->hdim + 1, PUGH_MPI_INT, - ioUtilGH->ioproc, 2*myproc + MPITAGBASE + 1, - comm)); + CACTUS_MPI_ERROR (MPI_Send (request->hoffset, 3*request->hdim + 1, + PUGH_MPI_INT, ioUtilGH->ioproc, + 2*myproc + MPITAGBASE + 1, comm)); /* send data */ - if (slab->hsize_chunk[slab->hdim] > 0) + if (request->hsize_chunk[request->hdim] > 0) { - CACTUS_MPI_ERROR (MPI_Send (hdata, slab->hsize_chunk[slab->hdim], mpitype, - ioUtilGH->ioproc, 2*myproc + MPITAGBASE, - comm)); + CACTUS_MPI_ERROR (MPI_Send (hdata, request->hsize_chunk[request->hdim], + mpitype, ioUtilGH->ioproc, + 2*myproc + MPITAGBASE, comm)); #ifdef IOHDF5UTIL_DEBUG printf ("Processor %d sent %d data points\n", - myproc, slab->hsize_chunk[slab->hdim]); + myproc, request->hsize_chunk[request->hdim]); #endif } } @@ -419,9 +423,9 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var name @@ -445,7 +449,7 @@ static int WriteGA (const cGH *GH, const ioSlab *slab, const char *name, @vio in @endvar @@*/ -static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, +static void WriteData (const cGH *GH, const ioRequest *request,const char *name, const void *data, int proc, hid_t file) { int i, myproc; @@ -470,14 +474,14 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, /* copy the size arrays from CCTK_INT to appropriate types note that HDF5 wants elements in reverse order */ - chunk_origin = (hssize_t *) malloc (slab->hdim * sizeof (hssize_t)); - chunk_dims = (hsize_t *) malloc (2*slab->hdim * sizeof (hsize_t)); - file_dims = chunk_dims + slab->hdim; - for (i = 0; i < slab->hdim; i++) + chunk_origin = (hssize_t *) malloc (request->hdim * sizeof (hssize_t)); + chunk_dims = (hsize_t *) malloc (2*request->hdim * sizeof (hsize_t)); + file_dims = chunk_dims + request->hdim; + for (i = 0; i < request->hdim; i++) { - chunk_origin[i] = slab->hoffset[slab->hdim - 1 - i]; - file_dims [i] = slab->hsize[slab->hdim - 1 - i]; - chunk_dims [i] = slab->hsize_chunk[slab->hdim - 1 - i]; + chunk_origin[i] = request->hoffset[request->hdim - 1 - i]; + file_dims [i] = request->hsize[request->hdim - 1 - i]; + chunk_dims [i] = request->hsize_chunk[request->hdim - 1 - i]; } myproc = CCTK_MyProc (GH); @@ -486,14 +490,14 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, if (data) { /* create the memspace according to chunk dims */ - HDF5_ERROR (memspace = H5Screate_simple (slab->hdim, chunk_dims, NULL)); + HDF5_ERROR (memspace = H5Screate_simple (request->hdim, chunk_dims, NULL)); } - hdf5type = IOHDF5Util_DataType (myGH, slab->hdatatype); + hdf5type = IOHDF5Util_DataType (myGH, request->hdatatype); if (ioUtilGH->unchunked) { /* create the (global) filespace and set the hyperslab for the chunk */ - HDF5_ERROR (filespace = H5Screate_simple (slab->hdim, file_dims, NULL)); + HDF5_ERROR (filespace = H5Screate_simple (request->hdim, file_dims, NULL)); HDF5_ERROR (H5Sselect_hyperslab (filespace, H5S_SELECT_SET, chunk_origin, NULL, chunk_dims, NULL)); @@ -505,12 +509,12 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, /* enable compression for chunked dataset if compression was requested */ if (compression_level) { - HDF5_ERROR (H5Pset_chunk (plist, slab->hdim, chunk_dims)); + HDF5_ERROR (H5Pset_chunk (plist, request->hdim, chunk_dims)); HDF5_ERROR (H5Pset_deflate (plist, compression_level)); } HDF5_ERROR (dataset = H5Dcreate (file, name, hdf5type, filespace, plist)); HDF5_ERROR (H5Pclose (plist)); - IOHDF5Util_DumpCommonAttributes (GH, slab, dataset); + IOHDF5Util_DumpCommonAttributes (GH, request, dataset); } else { @@ -543,7 +547,7 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, if (proc == myproc) { HDF5_ERROR (group = H5Gcreate (file, name, 0)); - IOHDF5Util_DumpCommonAttributes (GH, slab, group); + IOHDF5Util_DumpCommonAttributes (GH, request, group); HDF5_ERROR (H5Gclose (group)); } @@ -557,7 +561,7 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, /* enable compression for chunked dataset if compression was requested */ if (compression_level) { - HDF5_ERROR (H5Pset_chunk (plist, slab->hdim, chunk_dims)); + HDF5_ERROR (H5Pset_chunk (plist, request->hdim, chunk_dims)); HDF5_ERROR (H5Pset_deflate (plist, compression_level)); } /* create the chunk dataset and dump the chunk data */ @@ -568,8 +572,8 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, data)); /* add the "origin" attribute for the chunk */ - WRITE_ATTRIBUTE ("chunk_origin", slab->hoffset, dataset, myGH, slab->hdim, - HDF5_INT); + WRITE_ATTRIBUTE ("chunk_origin", request->hoffset, dataset, myGH, + request->hdim, HDF5_INT); free (chunkname); } @@ -607,9 +611,9 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, @vtype const cGH * @vio in @endvar - @var slab - @vdesc reference to the I/O hyperslab description - @vtype const ioSlab * + @var request + @vdesc reference to the I/O request description + @vtype const ioRequest * @vio in @endvar @var name @@ -628,7 +632,7 @@ static void WriteData (const cGH *GH, const ioSlab *slab, const char *name, @vio in @endvar @@*/ -static void WriteDataCollective (const cGH *GH, const ioSlab *slab, +static void WriteDataCollective (const cGH *GH, const ioRequest *request, const char *name, const void *data, hid_t file) { int i, dim; @@ -647,40 +651,40 @@ static void WriteDataCollective (const cGH *GH, const ioSlab *slab, /* copy the size arrays from CCTK_INT to appropriate types note that HDF5 wants elements in reverse order */ - chunk_origin = (hssize_t *) malloc (slab->hdim * sizeof (hssize_t)); - chunk_dims = (hsize_t *) malloc (2*slab->hdim * sizeof (hsize_t)); - file_dims = chunk_dims + slab->hdim; - for (i = 0; i < slab->hdim; i++) + chunk_origin = (hssize_t *) malloc (request->hdim * sizeof (hssize_t)); + chunk_dims = (hsize_t *) malloc (2*request->hdim * sizeof (hsize_t)); + file_dims = chunk_dims + request->hdim; + for (i = 0; i < request->hdim; i++) { - chunk_origin[i] = slab->hoffset[slab->hdim - 1 - i]; - chunk_dims [i] = slab->hsize_chunk[slab->hdim - 1 - i]; - file_dims [i] = slab->hsize_global[slab->hdim - 1 - i]; + chunk_origin[i] = request->hoffset[request->hdim - 1 - i]; + chunk_dims [i] = request->hsize_chunk[request->hdim - 1 - i]; + file_dims [i] = request->hsize_global[request->hdim - 1 - i]; } /* create the memspace according to chunk dims */ - HDF5_ERROR (memspace = H5Screate_simple (slab->hdim, chunk_dims, NULL)); + HDF5_ERROR (memspace = H5Screate_simple (request->hdim, chunk_dims, NULL)); /* create the (global) filespace and set the hyperslab for the chunk */ - HDF5_ERROR (filespace = H5Screate_simple (slab->hdim, file_dims, NULL)); + HDF5_ERROR (filespace = H5Screate_simple (request->hdim, file_dims, NULL)); HDF5_ERROR (H5Sselect_hyperslab (filespace, H5S_SELECT_SET, chunk_origin, NULL, chunk_dims, NULL)); /* the I/O processor creates the dataset and adds the common attributes when writing its own data, otherwise the dataset is reopened */ - hdf5type = IOHDF5Util_DataType (myGH, slab->hdatatype); + hdf5type = IOHDF5Util_DataType (myGH, request->hdatatype); /* enable compression for chunked dataset if compression was requested */ HDF5_ERROR (plist = H5Pcreate (H5P_DATASET_CREATE)); if (compression_level) { - HDF5_ERROR (H5Pset_chunk (plist, slab->hdim, chunk_dims)); + HDF5_ERROR (H5Pset_chunk (plist, request->hdim, chunk_dims)); HDF5_ERROR (H5Pset_deflate (plist, compression_level)); } HDF5_ERROR (dataset = H5Dcreate (file, name, hdf5type, filespace, plist)); HDF5_ERROR (H5Pclose (plist)); if (CCTK_MyProc (GH) == 0) { - IOHDF5Util_DumpCommonAttributes (GH, slab, dataset); + IOHDF5Util_DumpCommonAttributes (GH, request, dataset); } /* increase the buffer size if the default isn't sufficient */ diff --git a/src/ParseVars.c b/src/ParseVars.c deleted file mode 100644 index 2c58703..0000000 --- a/src/ParseVars.c +++ /dev/null @@ -1,411 +0,0 @@ - /*@@ - @file GHExtension.c - @date Tue 9th Feb 1999 - @author Gabrielle Allen - @desc - IOUtil GH extension stuff. - @enddesc - @version $Id$ - @@*/ - -#include -#include - -#include "cctk.h" -#include "util_String.h" -#include "cctk_Parameters.h" -#include "cctk_GNU.h" -#include "CactusBase/IOUtil/src/ioGH.h" -#include "ioHDF5UtilGH.h" - - -/* the rcs ID and its dummy function to use it */ -static const char *rcsid = "$Id$"; -CCTK_FILEVERSION(BetaThorns_IOHDF5Util_ParseVars_c) - - -typedef struct -{ - const cGH *GH; - ioSlab **slablist; -} info_t; - -/* prototypes of routines defined in this source file */ -static void SetOutputVar (int vindex, const char *optstring, void *arg); -static ioSlab *DefaultIOHyperslab (const cGH *GH, int vindex); - -/* prototypes of external routines for which no header files exist */ -int CCTK_RegexMatch (const char *string, - const char *pattern, - const int nmatch, - regmatch_t *pmatch); - - -/* =============================================================== - utility routines used by other IO thorns - ===============================================================*/ - - /*@@ - @routine IOUtil_ParseVarsForOutput - @date Sat March 6 1999 - @author Gabrielle Allen - @desc - Sets each flag in the do_output[] do_output to true - if var[i] could be found in the list of variable names. - var_list my also contain group names of variables as well as the - special keyword "all" which indicates that output is requested - on all variables. - @enddesc - - @var out_vars - @vdesc list of variables and/or group names - @vtype const char * - @vio in - @endvar - @var do_output - @vdesc do_output of flags indicating output was requested for var[i] - @vtype char [] - @vio out - @endvar -@@*/ -void IOHDF5Util_ParseVarsForOutput (const cGH *GH, const char *out_vars, - ioSlab *slablist[]) -{ - int i; - info_t info; - - - /* free current list of hyperslabs */ - for (i = CCTK_NumVars () - 1; i >= 0; i--) - { - if (slablist[i]) - { - free (slablist[i]->vectors); - free (slablist[i]); - slablist[i] = NULL; - } - } - - /* generate new list of hyperslabs */ - info.GH = GH; - info.slablist = slablist; - CCTK_TraverseString (out_vars, SetOutputVar, &info, CCTK_GROUP_OR_VAR); -} - - -static void SetOutputVar (int vindex, const char *optstring, void *arg) -{ - info_t *info; - regmatch_t gmatch[6], *dmatch; - int i, j, bytes, matched; - char *token, *separator, *fullname; - char *substring, *parsestring, *regexstring; - ioSlab *slab; - DECLARE_CCTK_PARAMETERS - - - info = (info_t *) arg; - - /* allocate a new I/O hyperslab structure and initialize it with defaults */ - slab = DefaultIOHyperslab (info->GH, vindex); - - if (! optstring) - { - info->slablist[vindex] = slab; - return; - } - - /* parse the hyperslab information */ - matched = CCTK_RegexMatch (optstring, - "\\{([0-9]*)\\}" /* dimension */ - "\\{([0-9,()]+)*\\}" /* direction */ - "\\{([0-9,]+)*\\}" /* origin */ - "\\{([-0-9,]+)*\\}" /* extent */ - "\\{([0-9,]+)*\\}", /* downsample */ - 6, gmatch); - if (matched <= 0) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't parse hyperslab options '%s' for variable '%s'", - optstring, fullname); - free (fullname); - free (slab); - return; - } - - /* SLAB DIMENSION */ - bytes = (int) (gmatch[1].rm_eo - gmatch[1].rm_so); - if (gmatch[1].rm_so != -1 && bytes > 0) - { - slab->hdim = atoi (optstring + gmatch[1].rm_so); - if (slab->hdim <= 0 || slab->hdim > slab->vdim) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Invalid dimension given %d in hyperslab options '%s' " - "for variable '%s'", slab->hdim, optstring, fullname); - free (fullname); - free (slab); - return; - } - } - - /* DIRECTION */ - bytes = (int) (gmatch[2].rm_eo - gmatch[2].rm_so); - if (gmatch[2].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[2].rm_so); - substring[bytes] = 0; - - dmatch = (regmatch_t *) malloc ((slab->hdim + 1) * - sizeof (regmatch_t)); - regexstring = (char *) malloc (slab->hdim * sizeof ("\\(([0-9,]+)\\)")); - regexstring[0] = 0; - for (i = 0; i < slab->hdim; i++) - { - strcat (regexstring, "\\(([0-9,]+)\\)"); - } - matched = CCTK_RegexMatch (substring, regexstring, slab->hdim + 1, - dmatch); - free (regexstring); - if (matched <= 0) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't parse direction vectors in hyperslab options '%s' " - "for variable '%s'.", optstring, fullname); - free (fullname); - free (dmatch); - free (slab); - return; - } - - for (j = 0; j < slab->hdim; j++) - { - i = 0; - bytes = (int) (dmatch[j + 1].rm_eo - dmatch[j + 1].rm_so); - if (dmatch[j + 1].rm_so != -1 && bytes > 0) - { - parsestring = strdup (substring + dmatch[j + 1].rm_so); - parsestring[bytes] = 0; - - token = parsestring; - while ((separator = strchr (token, ',')) != NULL) - { - *separator = 0; - slab->direction[j * slab->vdim + i] = atoi (token); - if (++i >= slab->vdim) - { - break; - } - token = separator + 1; - } - slab->direction[j * slab->vdim + i++] = atoi (token); - free (parsestring); - } - free (substring); - if (i < slab->vdim) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Direction vectors are incomplete or missing in hyperslab " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); - free (slab); - return; - } - } - } - - /* ORIGIN */ - bytes = (int) (gmatch[3].rm_eo - gmatch[3].rm_so); - if (gmatch[3].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[3].rm_so); - substring[bytes] = 0; - - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) - { - *separator = 0; - slab->origin[i] = atoi (token); - if (++i >= slab->vdim) - { - break; - } - token = separator + 1; - } - slab->origin[i++] = atoi (token); - free (substring); - - if (i < slab->vdim) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Origin vector is incomplete or missing in hyperslab " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); - free (slab); - return; - } - } - - /* LENGTH */ - bytes = (int) (gmatch[4].rm_eo - gmatch[4].rm_so); - if(gmatch[4].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[4].rm_so); - substring[bytes] = 0; - - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) - { - *separator = 0; - slab->extent[i] = atoi (token); - if (++i >= slab->hdim) - { - break; - } - token = separator + 1; - } - slab->extent[i++] = atoi (token); - free (substring); - - if (i < slab->hdim) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Length vector is incomplete or missing in hyperslab " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); - free (slab); - return; - } - } - - /* DOWNSAMPLING */ - bytes = (int) (gmatch[5].rm_eo - gmatch[5].rm_so); - if(gmatch[5].rm_so != -1 && bytes > 0) - { - substring = strdup (optstring + gmatch[5].rm_so); - substring[bytes] = 0; - - i = 0; - token = substring; - while ((separator = strchr (token, ',')) != NULL) - { - *separator = 0; - slab->downsample[i] = atoi (token); - if (++i >= slab->hdim) - { - break; - } - token = separator + 1; - } - slab->downsample[i++] = atoi (token); - free (substring); - - if (i < slab->hdim) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "Downsampling vector is incomplete or missing in hyperslab " - "options '%s' for variable '%s'.", optstring, fullname); - free (fullname); - free (slab); - return; - } - } - - /* assign the new hyperslab */ - info->slablist[vindex] = slab; -} - - -static ioSlab *DefaultIOHyperslab (const cGH *GH, int vindex) -{ - ioSlab *slab; - int *extent_int; - const ioGH *ioUtilGH; - DECLARE_CCTK_PARAMETERS - - - ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); - - /* allocate a new I/O hyperslab structure */ - slab = (ioSlab *) malloc (sizeof (ioSlab)); - - /* fill out the basics */ - slab->vindex = vindex; - slab->timelevel = 0; - slab->check_exist = ioUtilGH->recovered; - - /* get the hyperslab datatype (will be single-precision if requested) */ - slab->hdatatype = CCTK_VarTypeI (vindex); - if (ioUtilGH->out_single) - { - if (slab->hdatatype == CCTK_VARIABLE_REAL) - { - slab->hdatatype = CCTK_VARIABLE_REAL4; - } - else if (slab->hdatatype == CCTK_VARIABLE_COMPLEX) - { - slab->hdatatype = CCTK_VARIABLE_COMPLEX8; - } -#ifdef CCTK_INT2 - else if (slab->hdatatype == CCTK_VARIABLE_INT) - { - slab->hdatatype = CCTK_VARIABLE_INT2; - } -#endif - } - - /* get the variable's dimension and extents */ - slab->vdim = CCTK_GroupDimFromVarI (vindex); - extent_int = (int *) malloc (slab->vdim * sizeof (int)); - CCTK_GroupgshVI (GH, slab->vdim, extent_int, vindex); - - /* allocate the arrays all in one go - only initialize those which are mandatory for the Hyperslab API */ - slab->vectors = (CCTK_INT *) calloc ((slab->vdim + 6) * slab->vdim + 1, - sizeof (CCTK_INT)); - slab->hoffset = slab->vectors + 0*slab->vdim; - slab->hsize = slab->vectors + 1*slab->vdim; - slab->hsize_chunk = slab->vectors + 2*slab->vdim; - slab->origin = slab->vectors + 3*slab->vdim + 1; - slab->extent = slab->vectors + 4*slab->vdim + 1; - slab->downsample = slab->vectors + 5*slab->vdim + 1; - slab->direction = slab->vectors + 6*slab->vdim + 1; - - for (slab->hdim = 0; slab->hdim < slab->vdim; slab->hdim++) - { - slab->extent[slab->hdim] = extent_int[slab->hdim]; - slab->direction[slab->hdim * (slab->vdim + 1)] = 1; - - /* take the downsampling parameters from IOUtil */ - if (slab->hdim == 0) - { - slab->downsample[slab->hdim] = out3D_downsample_x; - } - else if (slab->hdim == 1) - { - slab->downsample[slab->hdim] = out3D_downsample_y; - } - else if (slab->hdim == 2) - { - slab->downsample[slab->hdim] = out3D_downsample_z; - } - else - { - slab->downsample[slab->hdim] = 1; - } - } - - /* clean up */ - free (extent_int); - - return (slab); -} diff --git a/src/ioHDF5UtilGH.h b/src/ioHDF5UtilGH.h index 62dc98a..50f4fdf 100644 --- a/src/ioHDF5UtilGH.h +++ b/src/ioHDF5UtilGH.h @@ -12,6 +12,7 @@ #define _IOUTILHDF5_IOUTILHDF5GH_H_ 1 #include +#include "CactusBase/IOUtil/src/ioutil_Utils.h" /******************************************************************** @@ -190,33 +191,6 @@ extern "C" { #endif -/* structure for hyperslab descriptions of output variables */ -typedef struct -{ - /* index and timelevel of the variable */ - int vindex, timelevel; - - /* dimensionality of the variable and the hyperslab */ - int vdim, hdim; - - /* CCTK datatype for the hyperslab */ - int hdatatype; - - /* flag indicating wheter check whether an object to be written already - exists (and remove it in that case) */ - int check_exist; - - /* pointer to allocated buffers */ - CCTK_INT *vectors; - - /* hyperslab mapping parameters */ - CCTK_INT *origin, *direction, *extent, *downsample; - - /* offset and sizes of hyperslab into the variable's dataspace */ - CCTK_INT *hoffset, *hsize, *hsize_chunk; - -} ioSlab; - /* structure describing a given recovery file */ typedef struct @@ -258,14 +232,12 @@ typedef struct /* exported functions */ hid_t IOHDF5Util_DataType (const ioHDF5UtilGH *myGH, int cctk_type); -void IOHDF5Util_ParseVarsForOutput (const cGH *GH, const char *output_varstring, - ioSlab *output_request_list[]); void IOHDF5Util_DumpParameters (const cGH *GH, int all, hid_t group); void IOHDF5Util_DumpGHExtensions (const cGH *GH, hid_t group); int IOHDF5Util_DumpGH (const cGH *GH, const int *timers, hid_t file); -void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioSlab *slab, +void IOHDF5Util_DumpCommonAttributes (const cGH *GH, const ioRequest *request, hid_t dataset); -int IOHDF5Util_DumpVar (const cGH *GH, const ioSlab *slab, hid_t file); +int IOHDF5Util_DumpVar (const cGH *GH, const ioRequest *request, hid_t file); int IOHDF5Util_RecoverParameters (const fileinfo_t *filenfo); int IOHDF5Util_RecoverGHextensions (cGH *GH, const fileinfo_t *filenfo); diff --git a/src/make.code.defn b/src/make.code.defn index 4b66372..240ca2c 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -2,7 +2,7 @@ # $Header$ # Source files in this directory -SRCS = Startup.c DumpUtils.c DumpVar.c RecoverVar.c ParseVars.c +SRCS = Startup.c DumpUtils.c DumpVar.c RecoverVar.c # Extend CFLAGS if HDF5 library was built with LFS support LFS_support := $(shell grep _LARGEFILE_SOURCE $(strip $(HDF5_LIB_DIRS))/libhdf5.settings) -- cgit v1.2.3