aboutsummaryrefslogtreecommitdiff
path: root/src/DumpVar.c
diff options
context:
space:
mode:
authortradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-04-26 15:44:04 +0000
committertradke <tradke@7842ec3a-9562-4be5-9c5b-06ba18f2b668>2002-04-26 15:44:04 +0000
commit377ea8964b7ada04c406970f0bbcca0a7f9b9012 (patch)
tree972373ad2f10416bcca0809a6b65c106620ed162 /src/DumpVar.c
parentea97ef150dd4042d804e36f68dde2cc80f1ed7ed (diff)
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
Diffstat (limited to 'src/DumpVar.c')
-rw-r--r--src/DumpVar.c220
1 files changed, 112 insertions, 108 deletions
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 */