aboutsummaryrefslogtreecommitdiff
path: root/src/RecoverGH.c
diff options
context:
space:
mode:
authortradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2000-01-21 18:00:59 +0000
committertradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2000-01-21 18:00:59 +0000
commit400e340a12e6019f91ded50e5ba1791ee04edda0 (patch)
treed1e719baf82aa32efd45d36bf6b3ec7aec66713e /src/RecoverGH.c
parentd58e1c47d498896b0c1f208724c7d138abce6349 (diff)
Added several stuff to IOFlexIO:
- checkpointing/recovery of parameters - made 'out2D_every', 'out2D_vars', 'out3D_every' and 'out3D_vars' steerable - fixed compiler warnings - grdocs git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@78 ebee0441-1374-4afa-a3b5-247f3ba15b9a
Diffstat (limited to 'src/RecoverGH.c')
-rw-r--r--src/RecoverGH.c93
1 files changed, 74 insertions, 19 deletions
diff --git a/src/RecoverGH.c b/src/RecoverGH.c
index f0e8487..0412379 100644
--- a/src/RecoverGH.c
+++ b/src/RecoverGH.c
@@ -8,8 +8,8 @@
Currently can recover from:
(1) One file containing recombined data
(2) Multiple unrecombined files, where the current
- number of processors and outputing processors
- match those used to write the data.
+ number of processors and outputing processors
+ match those used to write the data.
@enddesc
@history
@hauthor Gabrielle Allen @hdate 19 Oct 1998
@@ -21,6 +21,7 @@
static char *rcsid = "$Id$";
#include <stdio.h>
+#include <stdlib.h>
#include "cctk.h"
#include "cctk_Flesh.h"
@@ -28,20 +29,24 @@ static char *rcsid = "$Id$";
#include "cctk_GHExtensions.h"
#include "cctk_WarnLevel.h"
#include "cctk_Comm.h"
+#include "cctk_ParameterFunctions.h"
#include "CactusPUGH/PUGH/src/include/pugh.h"
#include "CactusBase/IOUtil/src/ioGH.h"
#include "ioFlexGH.h"
+/* maximum length of an attribute name */
+#define MAX_ATTRNAME_LEN 256
+
/* this one comes from RestoreFile.c */
int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp,
- int IOrecover_ioproc,
- int IOrecover_ioproc_every,
- int IOrecover_unchunked);
+ int IOrecover_ioproc,
+ int IOrecover_ioproc_every,
+ int IOrecover_unchunked);
/* Local function prototypes */
+static int IOFlexIO_restoreParams (IOFile ifp);
-int IOFlexIO_restoreParams (IOFile ifp, int myproc);
/*@@
@routine IOFlexIO_RecoverGH
@@ -57,7 +62,7 @@ int IOFlexIO_restoreParams (IOFile ifp, int myproc);
@hdate Thu Jul 2 18:17:59 1998
@hdesc Restore the physical time and iteration count, pass myproc to
IEEEIOparamRestore
- Derives the filename from IOUtil_PrepareFilename (in thorn IOUtil)
+ Derives the filename from IOUtil_PrepareFilename (in thorn IOUtil)
@hauthor Gabrielle Allen @hdate Oct 17 1998
@hdesc Added input of (some) GH structure variables
@endhistory
@@ -126,7 +131,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
strcat (fname, ".ieee");
if (verbose)
- printf ("Opening file %s\n", fname);
+ printf ("Opening file '%s' for recovery of variables\n", fname);
/* Open file, make sure the file is valid */
ifp = IEEEopen (fname, "r");
@@ -280,7 +285,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
/* Close the file. */
if (myproc == file_ioproc) {
if (verbose)
- printf ("Closing file '%s' after recovery.\n", fname);
+ printf ("Closing file '%s' after recovery of variables.\n", fname);
IOclose (ifp);
}
@@ -293,13 +298,16 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
/* Only have the file open by one proc at any time. */
if (proc == myproc) {
-
+
/* start timer for restoring parameters */
if (print_timing_info) {
CCTK_TimerResetI (myGH->recoverParamsTimer);
CCTK_TimerStartI (myGH->recoverParamsTimer);
}
+ if (verbose)
+ printf ("Opening file '%s' for recovery of parameters\n", fname);
+
/* Open file, make sure the file is valid */
ifp = IEEEopen (fname, "r");
if (! IOisValid (ifp)) {
@@ -311,7 +319,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
/* Restore the parameters. */
if (verbose)
printf ("Recovering parameters on processor %d.\n", myproc);
- IOFlexIO_restoreParams (ifp, myproc);
+ IOFlexIO_restoreParams (ifp);
/* Restore global variables */
@@ -319,7 +327,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
if (verbose)
printf ("Recovering main loop index.\n");
index = IOreadAttributeInfo (ifp, "main loop index", &nt_stored, &nels_stored);
-
+
if (index >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) {
IOreadAttribute (ifp, index, &tmpInt);
main_loop_index_stored = (int) tmpInt;
@@ -333,7 +341,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
if (verbose)
printf ("Recovering GH->cctk_iteration.\n");
index = IOreadAttributeInfo (ifp, "GH$iteration", &nt_stored, &nels_stored);
-
+
if (index >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) {
IOreadAttribute (ifp, index, &tmpInt);
cctk_iteration_stored = (int) tmpInt;
@@ -347,7 +355,7 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
if (verbose)
printf ("Recovering GH->cctk_time.\n");
index = IOreadAttributeInfo (ifp, "GH$time", &nt_stored, &nels_stored);
-
+
if (index >= 0 && nt_stored == FLEXIO_REAL && nels_stored == 1) {
IOreadAttribute (ifp, index, &tmpDouble);
cctk_time_stored = (double) tmpDouble;
@@ -359,8 +367,8 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
/* Close the file. */
if (verbose)
- printf ("Closing '%s' after recovery.\n", fname);
- IOclose (ifp);
+ printf ("Closing '%s' after recovery of parameters.\n", fname);
+ CACTUS_IEEEIO_ERROR (IOclose (ifp));
/* stop timer for restoring parameters */
if (print_timing_info)
@@ -416,12 +424,59 @@ int IOFlexIO_RecoverGH (cGH *GH, const char *basename, int called_from)
return (0);
USE_CCTK_PARAMETERS
-
}
-int IOFlexIO_restoreParams (IOFile ifp, int myproc)
+static int IOFlexIO_restoreParams (IOFile ifp)
{
- CCTK_INFO ("Called IOFlexIO_restoreParams()\n");
+ DECLARE_CCTK_PARAMETERS
+ int i;
+
+ for (i = IOnAttributes (ifp) - 1; i >= 0; i--) {
+ int atype, asize;
+ char aname [MAX_ATTRNAME_LEN];
+ char *prefix, *param;
+
+ /* get the name of the next attribute */
+ IOreadIndexedAttributeInfo (ifp, i, aname, &atype, &asize,MAX_ATTRNAME_LEN);
+
+ /* sort out only those attributes which hold a parameter value */
+ prefix = param = NULL;
+ if (atype == FLEXIO_CHAR
+ && Util_SplitString (&prefix, &param, aname, ANAME_DELIMITER) == 0
+ && ! strcmp (prefix, PARAMETER_PREFIX)) {
+ char *name, *impl;
+
+ name = impl = NULL;
+ if (Util_SplitString (&impl, &name, param, "::") == 0) {
+ char *value;
+
+ /* read the parameter's value */
+ value = (char *) malloc (asize + 1);
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, value));
+
+ /* and set it if the implementation is active */
+ if (CCTK_IsImplementationActive (impl)) {
+ if (verbose)
+ printf ("Restoring parameter '%s' to '%s'\n" , param, value);
+ if (ParameterSet (name, CCTK_ImplementationThorn (impl), value))
+ CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
+ "Couldn't set parameter '%s' to '%s'", param, value);
+ }
+
+ free (value);
+ }
+ if (name)
+ free (name);
+ if (impl)
+ free (impl);
+ }
+ if (prefix)
+ free (prefix);
+ if (param)
+ free (param);
+ }
return (0);
+
+ USE_CCTK_PARAMETERS
}