aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2002-04-30 09:23:30 +0000
committertradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2002-04-30 09:23:30 +0000
commiteecb2ef6e8756d309afc5dd1a15ea5835745dea6 (patch)
treeba69df5e8f2da4a0546bd0195b6eed6701c8ee78
parent171ad55757d3758a22b835ae6ec430d5132d36b2 (diff)
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/IOFlexIO/trunk@238 ebee0441-1374-4afa-a3b5-247f3ba15b9a
-rw-r--r--src/DumpVar.c74
1 files changed, 61 insertions, 13 deletions
diff --git a/src/DumpVar.c b/src/DumpVar.c
index a27f447..a1bd554 100644
--- a/src/DumpVar.c
+++ b/src/DumpVar.c
@@ -174,7 +174,10 @@ int IOFlexIO_DataType (int cctk_type)
@date 16 Apr 1999
@author Thomas Radke
@desc
- Dumps a SCALAR type variable into a IEEEIO file
+ Writes a CCTK_SCALAR type variable into a IEEEIO 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 AddCommonAttributes
@@ -202,30 +205,75 @@ int IOFlexIO_DataType (int cctk_type)
@@*/
static int WriteGS (const cGH *GH, const ioRequest *request, IOFile file)
{
+ int i, myproc, nprocs, hdatatypesize, retval;
+ char *buffer, *fullname;
/* const */ int dim = 1;
const ioGH *ioUtilGH;
+ /*** 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 = (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);
+ }
+ else
+ {
+ 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);
+ }
}
- /* check if file handle is invalid */
- if (! IOisValid (file))
+ /* only I/O processors write data */
+ if (myproc != ioUtilGH->ioproc)
{
- return (-1);
+ retval = 0;
+ }
+ else if (! IOisValid (file))
+ {
+ retval = -1;
+ }
+ else
+ {
+ /* first dump the data then add the attributes */
+ FLEXIO_ERROR (IOwrite (file, IOFlexIO_DataType (request->hdatatype), dim,
+ &dim, buffer));
+ AddCommonAttributes (GH, request, file);
+ retval = 0;
}
- /* first dump the data then add the attributes */
- FLEXIO_ERROR (IOwrite (file, IOFlexIO_DataType(request->hdatatype), dim, &dim,
- CCTK_VarDataPtrI (GH, request->timelevel,
- request->vindex)));
- AddCommonAttributes (GH, request, file);
+ free (buffer);
+ free (fullname);
- return (0);
+ return (retval);
}