diff options
author | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-04-17 18:01:50 +0000 |
---|---|---|
committer | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-04-17 18:01:50 +0000 |
commit | e7b5e1e51708eca4912aed95860f06a8b5a522f1 (patch) | |
tree | f6062873e2e0cf56b3e64fe6889fb7c9338b3fad /src/RecoverGH.c | |
parent | f7f7a801866271138a1888a493ae0c50ca372b52 (diff) |
Tidying up the code to make it consistent with the structure in IOHDF5.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@230 ebee0441-1374-4afa-a3b5-247f3ba15b9a
Diffstat (limited to 'src/RecoverGH.c')
-rw-r--r-- | src/RecoverGH.c | 269 |
1 files changed, 115 insertions, 154 deletions
diff --git a/src/RecoverGH.c b/src/RecoverGH.c index 5a1932e..53befd0 100644 --- a/src/RecoverGH.c +++ b/src/RecoverGH.c @@ -3,24 +3,15 @@ @date Fri Jun 19 09:14:22 1998 @author Tom Goodale @desc - Contains the routines to do the internal checkpoint recovery. - - 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. + Routines to recover variables from a given IEEEIO data or + checkpoint file. @enddesc - @history - @hauthor Gabrielle Allen @hdate 19 Oct 1998 - @hdesc Changed names ready for thorn_IO - @endhistory - @version $Id$ + @version $Id$ @@*/ -#include <ctype.h> #include <stdio.h> +#include <string.h> #include <stdlib.h> #include "cctk.h" @@ -30,29 +21,30 @@ #include "ioFlexGH.h" /* the rcs ID and its dummy function to use it */ - static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_RecoverGH_c) - +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ /* maximum length of an attribute name */ #define MAX_ATTRNAME_LEN 256 -/* prototypes of routines defined in this source file */ -int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from); +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ int IOFlexIO_RecoverParameters (void); -static int IOFlexIOi_RecoverParameters (fileinfo_t *file); -static int IOFlexIOi_RecoverGHextensions (cGH *GH, - fileinfo_t *file); -static int IOFlexIOi_OpenFile (cGH *GH, - const char *basefilename, - int called_from, - fileinfo_t *file); -/* this one comes from RestoreFile.c */ -int IOFlexIOi_RecoverVariables (cGH *GH, - fileinfo_t *file); + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int RecoverParameters (fileinfo_t *file); +static int RecoverGHextensions (cGH *GH, fileinfo_t *file); +static int OpenFile (cGH *GH, const char *basefilename, int called_from, + fileinfo_t *file); /*@@ @@ -61,15 +53,19 @@ int IOFlexIOi_RecoverVariables (cGH *GH, @author Tom Goodale @desc Recovers a GH from an IEEEIO file. - This routine is registered with IOUtil - as IOFlexIO's recovery routine. + This routine is registered with IOUtil as IOFlexIO's recovery + routine. @enddesc - @calledby IOUtil_RecoverFromFile - @history - @endhistory + + @calls OpenFile + RecoverParameters + RecoverGHextensions + IOFlexIOi_RecoverVariables + IOUtil_PrintTimings + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @var basefilename @@ -84,31 +80,22 @@ int IOFlexIOi_RecoverVariables (cGH *GH, @vtype int @vio in @endvar + @returntype int @returndesc >0 = success -1 = recovery failed @endreturndesc - - @history - @hauthor Gabrielle Allen - @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) - @hauthor Gabrielle Allen @hdate Oct 17 1998 - @hdesc Added input of (some) GH structure variables - @endhistory - @@*/ - int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) { - DECLARE_CCTK_PARAMETERS int result; flexioGH *myGH; static fileinfo_t file; /* this is static because info is passed from CP_RECOVERY_PARAMETERS to CP_RECOVERY_DATA */ + const char *timer_description = "Time to recover:"; + DECLARE_CCTK_PARAMETERS + /* to make the compiler happy */ myGH = NULL; @@ -117,7 +104,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* start the total timer */ if (GH) { - myGH = (flexioGH *) GH->extensions[CCTK_GHExtensionHandle ("IOFlexIO")]; + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); if (myGH->print_timing_info) { CCTK_TimerStartI (myGH->timers[3]); @@ -130,7 +117,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) called_from == FILEREADER_DATA || (GH && (GH->cctk_levfac[0] > 1 || GH->cctk_convlevel > 0))) { - if (IOFlexIOi_OpenFile (GH, basefilename, called_from, &file) < 0) + if (OpenFile (GH, basefilename, called_from, &file) < 0) { return (-1); } @@ -149,7 +136,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* Recover parameters (and return) */ if (called_from == CP_RECOVER_PARAMETERS) { - return (IOFlexIOi_RecoverParameters (&file)); + return (RecoverParameters (&file)); } /* Recover GH extensions */ @@ -159,7 +146,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) { CCTK_INFO ("Recovering GH extensions"); } - result = IOFlexIOi_RecoverGHextensions (GH, &file); + result = RecoverGHextensions (GH, &file); } if (! result) @@ -189,7 +176,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) CCTK_VInfo (CCTK_THORNSTRING, "Closing data file '%s'", file.filename); } } - CACTUS_IEEEIO_ERROR (IOclose (file.fid)); + FLEXIO_ERROR (IOclose (file.fid)); if (called_from == CP_RECOVER_DATA && recover_and_remove) { @@ -209,9 +196,6 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* stop total recovery timer and print timing info */ if (called_from == CP_RECOVER_DATA && myGH->print_timing_info) { - const char *timer_description = "Time to recover:"; - - CCTK_TimerStopI (myGH->timers[3]); IOUtil_PrintTimings ("Timing information for recovery in IOFlexIO:", 1, &myGH->timers[3], &timer_description); @@ -250,10 +234,16 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) not even a GH, because this doesn't exist yet at the time it is being called. @enddesc - @calledby flesh's scheduler - @history - @endhistory + @calls IOUtil_RecoverParameters + + @returntype int + @returndesc + return code of @seeroutine IOUtil_RecoverParameters, ie. + positive for successful parameter recovery, or<BR> + 0 if recovery wasn't requested, or<BR> + negative if parameter recovery failed + @endreturndesc @@*/ int IOFlexIO_RecoverParameters (void) { @@ -261,34 +251,21 @@ int IOFlexIO_RecoverParameters (void) } -/**************************** local routines ******************************/ - -static int IOFlexIOi_OpenFile (cGH *GH, - const char *basefilename, - int called_from, - fileinfo_t *file) +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int OpenFile (cGH *GH, const char *basefilename, int called_from, + fileinfo_t *file) { - DECLARE_CCTK_PARAMETERS - int retval; - int vindex; - int nprocs, myproc; - Long nels_stored; - int nt_stored; - CCTK_INT4 tmpInt; + int i, myproc, nprocs, type, retval; + Long dim; #ifdef CCTK_MPI MPI_Comm comm; CCTK_INT4 info[4]; #endif + DECLARE_CCTK_PARAMETERS -#ifdef CCTK_MPI - /* Get the communicator for broadcasting the info structure */ - /* NOTE: When recovering parameters thorn PUGH is not yet initialized - so that we have to use MPI_COMM_WORLD in this case */ - comm = CCTK_GHExtensionHandle ("PUGH") < 0 ? - MPI_COMM_WORLD : PUGH_pGH (GH)->PUGH_COMM_WORLD; -#endif - /* identify myself */ nprocs = CCTK_nProcs (GH); myproc = CCTK_MyProc (GH); @@ -311,7 +288,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, if (myproc == 0) { - if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Opening file '%s'", file->filename); @@ -319,11 +295,8 @@ static int IOFlexIOi_OpenFile (cGH *GH, /* Open file, make sure the file is valid */ file->fid = IEEEopen (file->filename, "r"); - if (IOisValid (file->fid)) - { - file->is_IEEEIO_file = 1; - } - else + file->is_IEEEIO_file = IOisValid (file->fid); + if (! file->is_IEEEIO_file) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No valid IEEEIO file '%s' found", file->filename); @@ -345,19 +318,16 @@ static int IOFlexIOi_OpenFile (cGH *GH, } } - /* Okay, we have the complete filename. Let's read the file now. */ + /* okay, we have the complete filename. Let's read the file now. */ if (myproc == 0 && file->is_IEEEIO_file) { - file->is_IEEEIO_file = 0; - /* Determine how the data was written by reading the GH extensions */ - vindex = IOreadAttributeInfo (file->fid, "GH$ioproc_every", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* determine how the data was written by reading the GH extensions */ + i = IOreadAttributeInfo (file->fid, "GH$ioproc_every", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->ioproc_every = tmpInt; + IOreadAttribute (file->fid, i, &file->ioproc_every); } else { @@ -366,13 +336,11 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->ioproc_every = nprocs; } - /* Read nprocs used to write data */ - vindex = IOreadAttributeInfo (file->fid, "GH$nprocs", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* read nprocs used to write data */ + i = IOreadAttributeInfo (file->fid, "GH$nprocs", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->nprocs = tmpInt; + IOreadAttribute (file->fid, i, &file->nprocs); } else { @@ -381,14 +349,12 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->nprocs = 1; } - /* Determine whether data is chunked or unchunked + /* determine whether data is chunked or unchunked We could derive this from the filename itself but just to be sure ... */ - vindex = IOreadAttributeInfo (file->fid, "unchunked", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + i = IOreadAttributeInfo (file->fid, "unchunked", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->unchunked = tmpInt; + IOreadAttribute (file->fid, i, &file->unchunked); } else { @@ -397,28 +363,21 @@ static int IOFlexIOi_OpenFile (cGH *GH, "and continuing", file->unchunked ? "true" : "false"); } - /* Determine whether data was written using the old timelevel naming + /* determine whether data was written using the old timelevel naming scheme. New files contain a Cactus version string attribute... */ - vindex = IOreadAttributeInfo (file->fid, "Cactus version", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_CHAR) - { - /* for now we don't actually need the Cactus version info */ - file->has_version = 1; - } - else + i = IOreadAttributeInfo (file->fid, "Cactus version", &type, &dim); + file->has_version = i >= 0 && type == FLEXIO_CHAR; + if (! file->has_version) { CCTK_WARN (4, "Unable to restore 'Cactus version' attribute. " "Assuming data was written using the the old timelevel " "naming scheme and continuing"); - file->has_version = 0; } /* If we recover from multiple files the number of * writing processors must match the number of reading * processors, and the total number of processors must match. */ - if ((file->ioproc_every == nprocs && nprocs > 1) || file->unchunked) { if (verbose) @@ -457,6 +416,12 @@ static int IOFlexIOi_OpenFile (cGH *GH, } #ifdef CCTK_MPI + /* Get the communicator for broadcasting the info structure */ + /* NOTE: When recovering parameters thorn PUGH is not yet initialized + so that we have to use MPI_COMM_WORLD in this case */ + comm = CCTK_GHExtensionHandle ("PUGH") < 0 ? + MPI_COMM_WORLD : PUGH_pGH (GH)->PUGH_COMM_WORLD; + /* Broadcast the file information to all processors */ info[0] = file->is_IEEEIO_file; info[1] = file->unchunked; @@ -471,7 +436,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, if (file->is_IEEEIO_file) { - /* Determine the IO processors for each node and the corresponding checkpoint file */ file->ioproc = myproc - (myproc % file->ioproc_every); @@ -482,7 +446,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, /* Open chunked files on other IO processors */ if (myproc == file->ioproc && myproc != 0) { - if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Opening chunked file '%s' on " @@ -498,17 +461,19 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->is_IEEEIO_file = 0; } } + #ifdef CCTK_MPI /* Finally check whether all files have valid recovery files */ info[0] = file->is_IEEEIO_file; - CACTUS_MPI_ERROR (MPI_Allreduce (&info[0], &info[1], 1, - PUGH_MPI_INT4, MPI_LAND, comm)); + CACTUS_MPI_ERROR (MPI_Allreduce (&info[0], &info[1], 1, PUGH_MPI_INT4, + MPI_LAND, comm)); file->is_IEEEIO_file = info[1]; #endif } /* Return 0 for success otherwise negative */ retval = (file->is_IEEEIO_file ? 0 : -1); + return (retval); } @@ -518,25 +483,24 @@ static int IOFlexIOi_OpenFile (cGH *GH, Broadcasting the GH extensions is found faster than sending it in a loop from each IO processor to all the non IOs (don't have subcommunicators yet) */ -static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) +static int RecoverGHextensions (cGH *GH, fileinfo_t *file) { - Long nels_stored; - int vindex, nt_stored; + Long dim; + int i, type; CCTK_REAL realBuffer; CCTK_INT4 int4Buffer[2]; + if (CCTK_MyProc (GH) == 0) { - /* rewind to the first dataset where the GH extensions are attached to */ - CACTUS_IEEEIO_ERROR (IOseek (file->fid, 0)); + FLEXIO_ERROR (IOseek (file->fid, 0)); - /* Get the iteration number. */ - vindex = IOreadAttributeInfo (file->fid, "GH$iteration", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* get the iteration number */ + i = IOreadAttributeInfo (file->fid, "GH$iteration", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &int4Buffer[0]); + IOreadAttribute (file->fid, i, &int4Buffer[0]); } else { @@ -544,12 +508,11 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) int4Buffer[0] = 0; } - /* Get the main loop index. */ - vindex = IOreadAttributeInfo (file->fid, "main loop index", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* get the main loop index */ + i = IOreadAttributeInfo (file->fid, "main loop index", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &int4Buffer[1]); + IOreadAttribute (file->fid, i, &int4Buffer[1]); } else { @@ -557,12 +520,11 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) int4Buffer[1] = 0; } - /* Get cctk_time. */ - vindex = IOreadAttributeInfo (file->fid, "GH$time", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_REAL && nels_stored == 1) + /* get cctk_time */ + i = IOreadAttributeInfo (file->fid, "GH$time", &type, &dim); + if (i >= 0 && type == FLEXIO_REAL && dim == 1) { - IOreadAttribute (file->fid, vindex, &realBuffer); + IOreadAttribute (file->fid, i, &realBuffer); } else { @@ -577,8 +539,7 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) because PUGH_COMM_WORLD is not yet set up at parameter recovery time. We also assume that PUGH_MPI_INT4 is a compile-time defined datatype. */ CACTUS_MPI_ERROR (MPI_Bcast (int4Buffer, 2, PUGH_MPI_INT4, 0,MPI_COMM_WORLD)); - CACTUS_MPI_ERROR (MPI_Bcast (&realBuffer, 1, PUGH_MPI_REAL, 0, - MPI_COMM_WORLD)); + CACTUS_MPI_ERROR (MPI_Bcast (&realBuffer, 1, PUGH_MPI_REAL,0,MPI_COMM_WORLD)); #endif GH->cctk_time = realBuffer; @@ -594,22 +555,21 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) Broadcasting the complete parameter string is found faster than sending it in a loop from each IO processor to all the non IOs (don't have subcommunicators yet) */ -static int IOFlexIOi_RecoverParameters (fileinfo_t *file) +static int RecoverParameters (fileinfo_t *file) { - DECLARE_CCTK_PARAMETERS - int retval; - int vindex, atype; + int i, myproc, atype, retval; Long asize; char *parameters; CCTK_INT4 parameterSize; - cGH *GH = NULL; /* There's no cGH set up yet so we pass - a NULL pointer to CCTK_MyProc() */ + DECLARE_CCTK_PARAMETERS + /* To make the compiler happy */ parameterSize = -1; parameters = NULL; - if (CCTK_MyProc (GH) == 0) + myproc = CCTK_MyProc (NULL); + if (myproc == 0) { if (verbose) { @@ -618,12 +578,12 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) } /* Get the parameters attribute. */ - vindex = IOreadAttributeInfo (file->fid, GLOBAL_PARAMETERS, &atype, &asize); - if (vindex >= 0 && atype == FLEXIO_CHAR && asize > 0) + i = IOreadAttributeInfo (file->fid, GLOBAL_PARAMETERS, &atype, &asize); + if (i >= 0 && atype == FLEXIO_CHAR && asize > 0) { parameterSize = (CCTK_INT4) asize; parameters = (char *) malloc (parameterSize); - IOreadAttribute (file->fid, vindex, parameters); + IOreadAttribute (file->fid, i, parameters); } else { @@ -644,7 +604,7 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) if (parameterSize > 0) { #ifdef CCTK_MPI - if (CCTK_MyProc (GH) != 0) + if (myproc) { parameters = (char *) malloc (parameterSize + 1); } @@ -658,7 +618,8 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) free (parameters); } - /* Return positive value for success otherwise negative */ + /* return positive value for success otherwise negative */ retval = (parameterSize > 0 ? 1 : -1); - return retval; + + return (retval); } |