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/DumpGH.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/DumpGH.c')
-rw-r--r-- | src/DumpGH.c | 413 |
1 files changed, 219 insertions, 194 deletions
diff --git a/src/DumpGH.c b/src/DumpGH.c index bfd8b77..e411532 100644 --- a/src/DumpGH.c +++ b/src/DumpGH.c @@ -3,11 +3,12 @@ @date Wed Jun 10 14:13:35 1998 @author Paul Walker @desc - DumpGH dumps an entire grid hierarchy (except for 1D arrays) to a - checkpoint file. This file also contains the different wrappers for - IOFlexIODumpGH: in case of initial data, termination or regular checkpointing + Checkpoint routines scheduled at CCTK_CPINITIAL, CCTK_CHECKPOINT, + and CCTK_TERMINATE. + They check the IO checkpointing parameters and - if it's time + to do so - call the routine which finally creates a checkpoint. @enddesc - @version $Id$ + @version $Id$ @@*/ @@ -30,30 +31,65 @@ static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_DumpGH_c) -/* prototypes of routines defined in this source file */ -void IOFlexIO_ConditionallyDumpGH (cGH *GH); -void IOFlexIO_TerminationDumpGH (cGH *GH); -void IOFlexIO_InitialDataDumpGH (cGH *GH); -void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof); -void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile iof); +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +void IOFlexIO_InitialDataCheckpoint (cGH *GH); +void IOFlexIO_EvolutionCheckpoint (cGH *GH); +void IOFlexIO_TerminationCheckpoint (cGH *GH); +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int Checkpoint (const cGH *GH, int called_from); /*@@ - @routine IOFlexIO_ConditionallyDumpGH - @date Fri Aug 21 14:38:25 1998 - @author Gabrielle Allen + @routine IOFlexIO_InitialDataCheckpoint + @date Fri Aug 21 14:46:28 1998 + @author Gerd Lanfermann @desc - registered as CCTK_CHECKPOINT, checks if it's time for - checkpointing, sets the checkpoint type and calls DumpGH + This routine is registered at CCTK_CPINITIAL. + It checks if initial data should be checkpointed. @enddesc - @calls IOFlexIO_DumpGH - @history - - @endhistory + @calls Checkpoint + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar @@*/ +void IOFlexIO_InitialDataCheckpoint (cGH *GH) +{ + DECLARE_CCTK_PARAMETERS + -void IOFlexIO_ConditionallyDumpGH (cGH *GH) + if (checkpoint && checkpoint_ID) + { + Checkpoint (GH, CP_INITIAL_DATA); + } +} + + + /*@@ + @routine IOFlexIO_EvolutionCheckpoint + @date Fri Aug 21 14:38:25 1998 + @author Gabrielle Allen + @desc + This routine is registered at CCTK_CHECKPOINT. + It periodically checks if it's time to checkpoint evolution data. + @enddesc + + @calls Checkpoint + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar +@@*/ +void IOFlexIO_EvolutionCheckpoint (cGH *GH) { DECLARE_CCTK_PARAMETERS @@ -68,7 +104,7 @@ void IOFlexIO_ConditionallyDumpGH (cGH *GH) CCTK_VInfo (CCTK_THORNSTRING, "Dumping periodic checkpoint file at " "iteration %d", GH->cctk_iteration); } - IOFlexIO_DumpGH (GH, CP_EVOLUTION_DATA); + Checkpoint (GH, CP_EVOLUTION_DATA); /* reset the 'checkpoint_next' parameter */ if (checkpoint_next) @@ -76,87 +112,34 @@ void IOFlexIO_ConditionallyDumpGH (cGH *GH) CCTK_ParameterSet ("checkpoint_next", CCTK_THORNSTRING, "no"); } } - } /*@@ - @routine IOFlexIO_TerminationDumpGH + @routine IOFlexIO_TerminationCheckpoint @date Fri Aug 21 14:40:21 1998 @author Gabrielle Allen @desc - This routine is registered as CCTK_TERMINATE - and does a checkpoint if the parameter - 'IO::checkpoint_on_terminate' was set. + This routine is registered at CCTK_TERMINATE. + It checks if the last iteration should be checkpointed. @enddesc - @calls IOFlexIO_DumpGH + + @calls Checkpoint + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @@*/ -void IOFlexIO_TerminationDumpGH (cGH *GH) +void IOFlexIO_TerminationCheckpoint (cGH *GH) { DECLARE_CCTK_PARAMETERS if (checkpoint && checkpoint_on_terminate) { - IOFlexIO_DumpGH (GH, CP_EVOLUTION_DATA); - } -} - - - /*@@ - @routine IOFlexIO_InitialDataDumpGH - @date Fri Aug 21 14:46:28 1998 - @author Gerd Lanfermann - @desc - This routine dumps the initial data of the GHs, registered - as CCTK_CPINITIAL; sets cp_type to CP_INITIAL_DATA and calls - DumpGH; BoxInBox needs special treatment since for now. - @enddesc - @calls IOFlexIO_DumpGH - @history - - @endhistory - -@@*/ - -void IOFlexIO_InitialDataDumpGH (cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - - -/*** FIXME ***/ -#if 0 - cGH *helperGH; - static int maxlev = 0; - int l; - -#ifdef THORN_BOXINBOX - /* This will go once we reorganize the CINitial calling structure! */ - /* or have a function to deregister a rfr routine */ - /* BoxinBox does its own: get maxlevel (once!) and do dumpGH for all GH*/ - /* when this is called by the highest box */ - if (Contains("boxinbox","yes")) { - if (maxlev==0) while (GHbyLevel(0,maxlev+1,0)) maxlev++; - if (maxlev==0) return; - - if (GH->level==maxlev) - for (l=0;l<=maxlev;l++) { - printf("Dumping BoxinBox level %d of %d \n",l,maxlev); - IOFlexIO_DumpGH(GHbyLevel(0,l,0), CP_INITIAL_DATA); - } - return; - } -#endif -#endif - - if (checkpoint && checkpoint_ID) - { - IOFlexIO_DumpGH (GH, CP_INITIAL_DATA); + Checkpoint (GH, CP_EVOLUTION_DATA); } } @@ -166,13 +149,11 @@ void IOFlexIO_InitialDataDumpGH (cGH *GH) @date Thu Jan 20 2000 @author Thomas Radke @desc - Gets the parameters of all active implementations as a single string - and writes it as an attribute into a group of an already opened HDF5 file. + Gets the parameters of all active implementations and writes them + as a single string attribute into a group GLOBAL_PARAMETERS. @enddesc - @calledby IOFlexIO_Write3D, IOFlexIO_DumpGH - @history + @calls IOUtil_GetAllParameters - @endhistory @var GH @vdesc Pointer to CCTK grid hierarchy @vtype const cGH * @@ -184,22 +165,23 @@ void IOFlexIO_InitialDataDumpGH (cGH *GH) @vtype int @vio in @endvar - @var iof + @var file @vdesc the IEEEIO file where to dump the parameters to @vtype IOFile @vio in @endvar @@*/ -void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof) +void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile file) { char *parameters; parameters = IOUtil_GetAllParameters (GH, all); - if (parameters) { - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, GLOBAL_PARAMETERS, FLEXIO_CHAR, - strlen (parameters) + 1, parameters)); + if (parameters) + { + FLEXIO_ERROR (IOwriteAttribute (file, GLOBAL_PARAMETERS, FLEXIO_CHAR, + strlen (parameters) + 1, parameters)); free (parameters); } } @@ -210,119 +192,149 @@ void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof) @date Thu Jan 20 2000 @author Thomas Radke @desc - Dumps the important variables from the grid hierarchy, PUGH, and IO - into a group of an already opened IEEEIO file. + Dumps the important variables from the grid hierarchy, PUGH, + and IO into a group of an already opened IEEEIO file. @enddesc - @calledby IOFlexIO_Write3D, IOFlexIO_DumpGH - @history - @endhistory @var GH @vdesc Pointer to CCTK grid hierarchy @vtype const cGH * @vio in @endvar - @var iof + @var file @vdesc the IEEEIO file where to dump the GH extensions to @vtype IOFile @vio in @endvar @@*/ -void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile iof) +void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile file) { - CCTK_INT4 i_temp; - CCTK_REAL d_temp; + CCTK_INT4 itmp; + CCTK_REAL dtmp; const char *version; ioGH *ioUtilGH; - /* Get the handle for IOUtil extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - i_temp = CCTK_MainLoopIndex (); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "main loop index", FLEXIO_INT4, - 1, &i_temp)); + /* get the handle for IOUtil extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + + itmp = CCTK_MainLoopIndex (); + FLEXIO_ERROR (IOwriteAttribute (file, "main loop index",FLEXIO_INT4,1,&itmp)); - i_temp = GH->cctk_iteration; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$iteration", FLEXIO_INT4, - 1, &i_temp)); + itmp = GH->cctk_iteration; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$iteration", FLEXIO_INT4, 1, &itmp)); - i_temp = ioUtilGH->ioproc_every; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$ioproc_every", FLEXIO_INT4, - 1, &i_temp)); + itmp = ioUtilGH->ioproc_every; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$ioproc_every",FLEXIO_INT4,1,&itmp)); - i_temp = CCTK_nProcs (GH); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$nprocs", FLEXIO_INT4, - 1, &i_temp)); + itmp = CCTK_nProcs (GH); + FLEXIO_ERROR (IOwriteAttribute (file, "GH$nprocs", FLEXIO_INT4, 1, &itmp)); - d_temp = GH->cctk_time; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$time", FLEXIO_REAL, - 1, &d_temp)); + dtmp = GH->cctk_time; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$time", FLEXIO_REAL, 1, &dtmp)); version = CCTK_FullVersion (); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "Cactus version", FLEXIO_CHAR, - strlen (version) + 1, (const void *) version)); + FLEXIO_ERROR (IOwriteAttribute (file, "Cactus version", FLEXIO_CHAR, + strlen (version) + 1, version)); } +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ /*@@ - @routine IOFlexIO_DumpGH + @routine Checkpoint @date Fri Aug 21 15:13:13 1998 @author Paul Walker @desc - The heart of checkpointing. Called by the different wrappers, this - routines get the appropriate filename by IOUtil_PrepareFilename() and - then dumps away using the dump routines from IO ... + The heart of checkpointing. + Called by the different wrappers, this routine creates + a new checkpoint file and then dumps away all grid variables. @enddesc - @calledby IOFlexIO_ConditionallyDumpGH, IOFlexIO_TerminationDumpGH, - IOFlexIO_InitialDataDumpGH + + @calls IOUtil_PrepareFilename + IOUtil_PrintTimings + IOFlexIOi_DumpParameters + IOFlexIOi_DumpGHExtensions + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + @var called_from + @vdesc flag indicating where this routine was called from + (either CHECKPOINT_ID, CHECKPOINT, or filereader) + @vtype int + @vio in + @endvar + @history - @hdate Oct 4 1998 @hauthor Gabrielle Allen - @hdesc Removed code which checked and reset unchunked, assume that this - is done when the variable is first set. - @hdate Nov 4 1998 @hauthor Gabrielle Allen - @hdesc Do a forced synchronization before checkpointing - @hdate Apr 16 1999 @hauthor Thomas Radke - @hdesc Removed forced sync before checkpointing (just do a normal sync) - Introduced a ring buffer for keeping last <checkpoint_keep> files + @hdate Oct 4 1998 + @hauthor Gabrielle Allen + @hdesc Removed code which checked and reset unchunked, assume that this + is done when the variable is first set. + @hdate Nov 4 1998 + @hauthor Gabrielle Allen + @hdesc Do a forced synchronization before checkpointing + @hdate Apr 16 1999 + @hauthor Thomas Radke + @hdesc Removed forced sync before checkpointing (just do a normal sync) + Introduced a ring buffer for keeping last <checkpoint_keep> files @endhistory + @returntype int + @returndesc + the accumulated return code from @seeroutine IOHDF5Util_DumpVar + (should be 0 for success, or negative if some error occured), or + -1 if checkpoint file could not be created + @endreturndesc @@*/ - -void IOFlexIO_DumpGH (const cGH *GH, int called_from) +static int Checkpoint (const cGH *GH, int called_from) { - DECLARE_CCTK_PARAMETERS - char dumpfname [1024], tmpfname [1024]; - IOFile iof; - int first_vindex, vindex, gindex; + char filename [1024], tmpfilename [1024]; + IOFile file; + int myproc, first_vindex, vindex, gindex, maxdim, retval; int timelevel, last_timelevel; cGroup gdata; int *old_downsample; int old_out_single; ioGH *ioUtilGH; flexioGH *myGH; - static char **dumpfnames = NULL; /* dump filename ring buffer */ - static int findex = 0; /* index into ring buffer */ + static char **cp_filenames = NULL; + static int cp_fileindex = 0; /*** FIXME: can CCTK_SyncGroup() have a 'const cGH *' parameter ?? ***/ union { const cGH *const_ptr; cGH *non_const_ptr; } GH_fake_const; + const char *timer_descriptions [3] = {"Time to dump parameters: ", + "Time to dump datasets: ", + "Total time to checkpoint:"}; + DECLARE_CCTK_PARAMETERS + retval = 0; GH_fake_const.const_ptr = GH; - /* Get the handles for IOUtil and IOFlexIO extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; + /* get the handles for IOUtil and IOFlexIO extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); - /* allocate the ring buffer for filenames */ - if (! dumpfnames) - dumpfnames = (char **) calloc (checkpoint_keep, sizeof (char *)); + myproc = CCTK_MyProc (GH); + maxdim = CCTK_MaxDim (); + + /* allocate the ring buffer for checkpoint filenames */ + if (! cp_filenames) + { + cp_filenames = (char **) calloc (checkpoint_keep, sizeof (char *)); + } /* disable downsampling after saving original downsampling params */ - old_downsample = (int *) malloc (CCTK_MaxDim () * sizeof (int)); - for (vindex = 0; vindex < CCTK_MaxDim (); vindex++) { + old_downsample = (int *) malloc (maxdim * sizeof (int)); + for (vindex = 0; vindex < maxdim; vindex++) + { old_downsample [vindex] = ioUtilGH->downsample [vindex]; ioUtilGH->downsample [vindex] = 1; } @@ -333,38 +345,38 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) /* start the total timer */ if (myGH->print_timing_info) + { CCTK_TimerStartI (myGH->timers[2]); - - /* sync all active groups */ - for (vindex = 0; vindex < CCTK_NumGroups (); vindex++) - if (CCTK_IsImplementationActive (CCTK_ImpFromVarI ( - CCTK_FirstVarIndexI (vindex)))) - CCTK_SyncGroupI (GH_fake_const.non_const_ptr, vindex); + } /* get the base filename ... */ - IOUtil_PrepareFilename (GH, NULL, dumpfname, called_from, - CCTK_MyProc (GH) / ioUtilGH->ioproc_every, - ioUtilGH->unchunked); + IOUtil_PrepareFilename (GH, NULL, filename, called_from, + myproc / ioUtilGH->ioproc_every, ioUtilGH->unchunked); /* ... and append the extension */ - sprintf (tmpfname, "%s.tmp.ieee", dumpfname); - sprintf (dumpfname, "%s.ieee", dumpfname); + sprintf (tmpfilename, "%s.tmp.ieee", filename); + sprintf (filename, "%s.ieee", filename); /* Now open the file */ - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) { + if (myproc == ioUtilGH->ioproc) + { if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "Creating file '%s'", tmpfname); - iof = IEEEopen (tmpfname, "w"); - if (! IOisValid (iof)) { + { + CCTK_VInfo (CCTK_THORNSTRING, "Creating file '%s'", tmpfilename); + } + file = IEEEopen (tmpfilename, "w"); + if (! IOisValid (file)) + { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Can't open checkpoint file '%s'. Checkpointing is skipped", - tmpfname); - return; + tmpfilename); + return (-1); } - } else - iof = (IOFile) NULL; - - /* Great; Now start dumping away! */ + } + else + { + file = (IOFile) NULL; + } /* start timer for dumping parameters */ if (myGH->print_timing_info) @@ -373,12 +385,15 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) CCTK_TimerStartI (myGH->timers[0]); } - /* first the parameters ... */ - if (iof) { + /* first dump the parameters ... */ + if (file) + { if (verbose) + { CCTK_INFO ("Dumping Params ..."); - IOFlexIOi_DumpParameters (GH, 1, iof); - IOFlexIOi_DumpGHExtensions (GH, iof); + } + IOFlexIOi_DumpParameters (GH, 1, file); + IOFlexIOi_DumpGHExtensions (GH, file); } /* stop parameter timer and start timer for dumping datasets */ @@ -413,64 +428,74 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) for (vindex = first_vindex; vindex < first_vindex + gdata.numvars; vindex++) { if (verbose) + { CCTK_VInfo (CCTK_THORNSTRING, " %s", CCTK_VarName (vindex)); + } for (timelevel = 0; timelevel < last_timelevel; timelevel++) { - IOFlexIO_DumpVar (GH, vindex, timelevel, iof); + retval += IOFlexIO_DumpVar (GH, vindex, timelevel, file); } } /* end of loop over all variables */ } /* end of loop over all groups */ /* stop timer for dumping datasets */ if (myGH->print_timing_info) + { CCTK_TimerStopI (myGH->timers[1]); + } - CACTUS_IEEEIO_ERROR (IOclose (iof)); + /* close the temporary checkpoint file */ + FLEXIO_ERROR (IOclose (file)); - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) { + if (myproc == ioUtilGH->ioproc) + { if (verbose) + { CCTK_VInfo (CCTK_THORNSTRING, "Closing and renaming checkpoint file " - "into '%s'", dumpfname); + "into '%s'", filename); + } #ifdef _WIN32 /* Windows' rename(2) routine isn't POSIX compatible in that it would unlink an existing file */ - unlink (dumpfname); + unlink (filename); #endif - if (rename (tmpfname, dumpfname)) + if (rename (tmpfilename, filename)) + { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not rename temporary checkpoint file %s to %s", - tmpfname, dumpfname); + tmpfilename, filename); + } } /* delete the oldest dumpfile if checkpoint_keep_all isn't set and put the new filename into the ring buffer */ - if (dumpfnames [findex]) { + if (cp_filenames [cp_fileindex]) + { if (! checkpoint_keep_all) - remove (dumpfnames [findex]); - free (dumpfnames [findex]); + { + remove (cp_filenames [cp_fileindex]); + } + free (cp_filenames [cp_fileindex]); } - dumpfnames [findex] = strdup (dumpfname); - findex = (findex + 1) % checkpoint_keep; + cp_filenames [cp_fileindex] = strdup (filename); + cp_fileindex = (cp_fileindex + 1) % checkpoint_keep; /* restore output precision flag */ ioUtilGH->out_single = old_out_single; /* restore original downsampling params */ - memcpy (ioUtilGH->downsample, old_downsample, CCTK_MaxDim () * sizeof (int)); + memcpy (ioUtilGH->downsample, old_downsample, maxdim * sizeof (int)); free (old_downsample); /* stop total checkpoint timer and print timing info */ if (myGH->print_timing_info) { - const char *timer_descriptions [3] = {"Time to dump parameters: ", - "Time to dump datasets: ", - "Total time to checkpoint:"}; - - CCTK_TimerStopI (myGH->timers[2]); IOUtil_PrintTimings ("Timing information for checkpointing in IOFlexIO:", 3, myGH->timers, timer_descriptions); } + + return (retval); } |