aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2005-06-10 11:57:51 +0000
committertradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2005-06-10 11:57:51 +0000
commitcd0851b03d3adebdd32ea4c95cde4f9f0489130c (patch)
tree8ae07124aa367862cfc3540450ff0b58f66d4239
parentabcb8cf9052052e7e2dbde2a9f27cc2dd8802112 (diff)
Added necessary logic to implement IO::checkpoint_keep as steerable parameter.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@336 ebee0441-1374-4afa-a3b5-247f3ba15b9a
-rw-r--r--src/DumpGH.c35
-rw-r--r--src/Startup.c4
-rw-r--r--src/ioFlexGH.h5
3 files changed, 30 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)
diff --git a/src/Startup.c b/src/Startup.c
index 9861f3e..7443f41 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -252,6 +252,10 @@ static void *SetupGH (tFleshConfig *config, int conv_level, cGH *GH)
myGH->out_last = malloc (numvars * sizeof (int));
myGH->out2D_last = malloc (numvars * sizeof (int));
+ myGH->cp_fileindex = 0;
+ myGH->checkpoint_keep = abs (checkpoint_keep);
+ myGH->cp_filenames = calloc (myGH->checkpoint_keep, sizeof (char *));
+
myGH->out_vars = strdup ("");
myGH->out_every_default = out_every - 1;
myGH->out2D_vars = strdup ("");
diff --git a/src/ioFlexGH.h b/src/ioFlexGH.h
index a772233..99cd945 100644
--- a/src/ioFlexGH.h
+++ b/src/ioFlexGH.h
@@ -141,6 +141,11 @@ typedef struct IOFlexIOGH
/* 2D slices */
int **sp2xyz;
+ /* ring buffer for list of successfully created cp files */
+ int checkpoint_keep;
+ int cp_fileindex;
+ char **cp_filenames;
+
/* iteration number of the last checkpoint */
int last_checkpoint_iteration;