aboutsummaryrefslogtreecommitdiff
path: root/src/DumpGH.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/DumpGH.c')
-rw-r--r--src/DumpGH.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/DumpGH.c b/src/DumpGH.c
index 3b75071..21d1af0 100644
--- a/src/DumpGH.c
+++ b/src/DumpGH.c
@@ -324,8 +324,6 @@ static int Checkpoint (const cGH *GH, int called_from)
flexioGH *myGH;
const ioGH *ioUtilGH;
char *filename, *tempname, *fullname;
- static char **cp_filenames = NULL;
- static int cp_fileindex = 0;
const char *timer_descriptions[] = {"Time to dump parameters: ",
"Time to dump datasets: ",
"Total time to checkpoint:"};
@@ -334,12 +332,6 @@ static int Checkpoint (const cGH *GH, int called_from)
retval = 0;
- /* allocate the ring buffer for checkpoint filenames */
- if (! cp_filenames)
- {
- cp_filenames = calloc (abs (checkpoint_keep), sizeof (char *));
- }
-
/* start the total timer */
myGH = CCTK_GHExtension (GH, "IOFlexIO");
if (myGH->print_timing_info)
@@ -522,16 +514,31 @@ static int Checkpoint (const cGH *GH, int called_from)
/* delete the oldest dumpfile if checkpoint_keep_all isn't set
and put the new filename into the ring buffer */
- if (cp_filenames[cp_fileindex])
+ if (checkpoint_keep > 0)
{
- if (checkpoint_keep > 0)
+ if (myGH->cp_filenames[myGH->cp_fileindex])
+ {
+ remove (myGH->cp_filenames[myGH->cp_fileindex]);
+ free (myGH->cp_filenames[myGH->cp_fileindex]);
+ myGH->cp_filenames[myGH->cp_fileindex] = NULL;
+ }
+
+ myGH->cp_filenames[myGH->cp_fileindex] = strdup (filename);
+ myGH->cp_fileindex = (myGH->cp_fileindex+1) % checkpoint_keep;
+ if (myGH->checkpoint_keep != checkpoint_keep)
{
- remove (cp_filenames[cp_fileindex]);
+ char **cp_filenames = calloc (checkpoint_keep, sizeof (char *));
+ int min = myGH->checkpoint_keep < checkpoint_keep ?
+ myGH->checkpoint_keep : checkpoint_keep;
+ while (min-- > 0)
+ {
+ cp_filenames[min] = myGH->cp_filenames[min];
+ }
+ free (myGH->cp_filenames);
+ myGH->cp_filenames = cp_filenames;
+ myGH->checkpoint_keep = checkpoint_keep;
}
- free (cp_filenames[cp_fileindex]);
}
- cp_filenames[cp_fileindex] = strdup (filename);
- cp_fileindex = (cp_fileindex + 1) % abs (checkpoint_keep);
/* stop total checkpoint timer and print timing info */
if (myGH->print_timing_info)