aboutsummaryrefslogtreecommitdiff
path: root/src/DumpGH.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/DumpGH.c')
-rw-r--r--src/DumpGH.c71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/DumpGH.c b/src/DumpGH.c
index 9b66404..471e5c8 100644
--- a/src/DumpGH.c
+++ b/src/DumpGH.c
@@ -51,13 +51,13 @@ static int Checkpoint (const cGH *GH, int called_from);
@routine IOHDF5_InitialDataCheckpoint
@date Fri Aug 21 14:46:28 1998
@author Gerd Lanfermann
- @desc
+ @desc
This routine is registered at CCTK_CPINITIAL.
It checks if initial data should be checkpointed.
- @enddesc
+ @enddesc
@calls Checkpoint
-
+
@var GH
@vdesc Pointer to CCTK grid hierarchy
@vtype const cGH *
@@ -86,13 +86,13 @@ void IOHDF5_InitialDataCheckpoint (const cGH *GH)
@routine IOHDF5_EvolutionCheckpoint
@date Fri Aug 21 14:38:25 1998
@author Gabrielle Allen
- @desc
+ @desc
This routine is registered at CCTK_CHECKPOINT.
It periodically checks if it's time to checkpoint evolution data.
- @enddesc
+ @enddesc
@calls Checkpoint
-
+
@var GH
@vdesc Pointer to CCTK grid hierarchy
@vtype const cGH *
@@ -130,10 +130,10 @@ void IOHDF5_EvolutionCheckpoint (const cGH *GH)
@routine IOHDF5_TerminationCheckpoint
@date Fri Aug 21 14:40:21 1998
@author Gabrielle Allen
- @desc
+ @desc
This routine is registered at CCTK_TERMINATE.
It checks if the last iteration should be checkpointed.
- @enddesc
+ @enddesc
@calls Checkpoint
@@ -149,7 +149,7 @@ void IOHDF5_TerminationCheckpoint (const cGH *GH)
DECLARE_CCTK_PARAMETERS
- myGH = (const ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
if (checkpoint && checkpoint_on_terminate && myGH)
{
if (myGH->last_checkpoint_iteration < GH->cctk_iteration)
@@ -182,12 +182,12 @@ void IOHDF5_TerminationCheckpoint (const cGH *GH)
@routine Checkpoint
@date Fri Aug 21 15:13:13 1998
@author Paul Walker
- @desc
+ @desc
The heart of checkpointing.
Called by the different wrappers, this routine creates
a new checkpoint file and then dumps away using the
dump routines from IOHDF5Util.
- @enddesc
+ @enddesc
@calls IOHDF5Util_DumpGH
@@ -219,11 +219,10 @@ static int Checkpoint (const cGH *GH, int called_from)
#ifdef CCTK_MPI
CCTK_INT tmp;
#endif
- /* FIXME: allocate filenames dynamically */
- char cp_filename[1024], cp_tempname[1024];
- const char *timer_descriptions[3] = {"Time to dump parameters: ",
- "Time to dump datasets: ",
- "Total time to checkpoint:"};
+ char *filename, *tempname;
+ const char *timer_descriptions[] = {"Time to dump parameters: ",
+ "Time to dump datasets: ",
+ "Total time to checkpoint:"};
DECLARE_CCTK_PARAMETERS
@@ -231,8 +230,8 @@ static int Checkpoint (const cGH *GH, int called_from)
file = -1;
myproc = CCTK_MyProc (GH);
- ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO");
- myGH = (ioHDF5GH *) CCTK_GHExtension (GH, "IOHDF5");
+ ioUtilGH = CCTK_GHExtension (GH, "IO");
+ myGH = CCTK_GHExtension (GH, "IOHDF5");
/* check if IOHDF5 was registered as I/O method */
if (myGH == NULL)
@@ -247,30 +246,28 @@ static int Checkpoint (const cGH *GH, int called_from)
CCTK_TimerStartI (myGH->timers[CP_TOTAL_TIMER]);
}
- /* get the checkpoint basename ... */
- IOUtil_PrepareFilename (GH, NULL, cp_filename, called_from,
- myproc / ioUtilGH->ioproc_every,
- ioUtilGH->unchunked);
-
- /* ... and append the extension */
- sprintf (cp_tempname, "%s.tmp.h5", cp_filename);
- sprintf (cp_filename, "%s.h5", cp_filename);
+ /* get the filenames for both the temporary and real checkpoint file */
+ filename = IOUtil_AssembleFilename (GH, NULL, "", ".h5", called_from,
+ myproc / ioUtilGH->ioproc_every,
+ ioUtilGH->unchunked);
+ tempname = IOUtil_AssembleFilename (GH, NULL, ".tmp", ".h5", called_from,
+ myproc / ioUtilGH->ioproc_every,
+ ioUtilGH->unchunked);
/* Now open the file */
if (myproc == ioUtilGH->ioproc)
{
if (CCTK_Equals (verbose, "full"))
{
- CCTK_VInfo (CCTK_THORNSTRING, "Creating checkpoint file '%s'",
- cp_tempname);
+ CCTK_VInfo (CCTK_THORNSTRING, "Creating checkpoint file '%s'", tempname);
}
- file = H5Fcreate (cp_tempname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate (tempname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if (file < 0)
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Can't open checkpoint file '%s'. Checkpointing is skipped.",
- cp_tempname);
+ tempname);
retval = -1;
}
}
@@ -300,7 +297,7 @@ static int Checkpoint (const cGH *GH, int called_from)
{
CCTK_VInfo (CCTK_THORNSTRING, "Closing temporary checkpoint file '%s' "
"and renaming it to '%s'",
- cp_tempname, cp_filename);
+ tempname, filename);
}
if (file >= 0)
@@ -315,13 +312,13 @@ static int Checkpoint (const cGH *GH, int called_from)
#ifdef _WIN32
/* Windows' rename(2) routine isn't POSIX compatible
in that it would unlink an existing file :-( */
- unlink (cp_filename);
+ unlink (filename);
#endif
- if (rename (cp_tempname, cp_filename))
+ if (rename (tempname, filename))
{
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Could not rename temporary checkpoint file '%s' to '%s'",
- cp_tempname, cp_filename);
+ tempname, filename);
retval = -1;
}
else
@@ -334,7 +331,7 @@ static int Checkpoint (const cGH *GH, int called_from)
}
free (myGH->cp_filename_list[myGH->cp_filename_index]);
}
- myGH->cp_filename_list[myGH->cp_filename_index] = strdup (cp_filename);
+ myGH->cp_filename_list[myGH->cp_filename_index] = strdup (filename);
myGH->cp_filename_index = (myGH->cp_filename_index+1) % abs (checkpoint_keep);
}
}
@@ -351,5 +348,9 @@ static int Checkpoint (const cGH *GH, int called_from)
/* save the iteration number of this checkpoint */
myGH->last_checkpoint_iteration = GH->cctk_iteration;
+ /* free allocated resources */
+ free (tempname);
+ free (filename);
+
return (retval);
}