diff options
-rw-r--r-- | interface.ccl | 6 | ||||
-rw-r--r-- | param.ccl | 8 | ||||
-rw-r--r-- | schedule.ccl | 6 | ||||
-rw-r--r-- | src/Output.c | 60 |
4 files changed, 76 insertions, 4 deletions
diff --git a/interface.ccl b/interface.ccl index 64d47a4..274ab89 100644 --- a/interface.ccl +++ b/interface.ccl @@ -2,3 +2,9 @@ # $Header$ implements: timerreport + + + +CCTK_INT FUNCTION IO_TruncateOutputFiles (CCTK_POINTER_TO_CONST IN cctkGH) + +REQUIRES FUNCTION IO_TruncateOutputFiles @@ -15,6 +15,12 @@ INT out_at "Output timer information at a given iteration" STEERABLE=ALWAYS 0:* :: "At this iteration" } -1 +STRING out_filename "File name for timer reports" STEERABLE=ALWAYS +{ + "^$" :: "empty filename: print to stdout" + "^.+$" :: "otherwise: print to that file" +} "" + BOOLEAN before_checkpoint "Before a checkpoint" STEERABLE=ALWAYS { } "no" @@ -25,4 +31,6 @@ BOOLEAN next "On next iteration" STEERABLE=ALWAYS shares: IO +USES STRING out_dir + USES INT checkpoint_every diff --git a/schedule.ccl b/schedule.ccl index fee2fd7..e10d99b 100644 --- a/schedule.ccl +++ b/schedule.ccl @@ -8,6 +8,12 @@ SCHEDULE TimerReport_Output AS zzz_TimerReport_Output AT CCTK_ANALYSIS OPTIONS: global } "Print the timer report" +SCHEDULE TimerReport_Output AS zzz_TimerReport_Output AT CCTK_TERMINATE BEFORE Driver_Terminate +{ + LANG: C + OPTIONS: global +} "Print the timer report" + SCHEDULE TimerReport_Checkpoint AS zzz_TimerReport_Checkpoint AT CCTK_CHECKPOINT { LANG: C diff --git a/src/Output.c b/src/Output.c index d1d9241..39fe709 100644 --- a/src/Output.c +++ b/src/Output.c @@ -8,12 +8,15 @@ @version $Header$ @@*/ +#include <stdio.h> #include <stdlib.h> #include "cctk.h" #include "cctk_Parameters.h" #include "cctk_Arguments.h" +#include "util_String.h" + #include "cctk_Schedule.h" static const char *rcsid = "$Header$"; @@ -28,6 +31,8 @@ CCTK_FILEVERSION(CactusUtils_TimerReport_Output_c); ********************* Local Routine Prototypes ********************* ********************************************************************/ +static void PrintTimes (CCTK_ARGUMENTS); + /******************************************************************** ********************* Scheduled Routine Prototypes *************** ********************************************************************/ @@ -68,7 +73,7 @@ void TimerReport_Output(CCTK_ARGUMENTS) CCTK_VInfo(CCTK_THORNSTRING, "Timer Report at iteration %d time %g", cctk_iteration, (double)cctk_time); - CCTK_SchedulePrintTimes(NULL); + PrintTimes(CCTK_PASS_CTOC); if (next) { @@ -94,12 +99,12 @@ void TimerReport_Checkpoint(CCTK_ARGUMENTS) if (before_checkpoint && (checkpoint_every && cctk_iteration%checkpoint_every == 0)) { - + CCTK_VInfo(CCTK_THORNSTRING, "Timer Report before checkpointing at iteration %d, time %g", cctk_iteration, (double)cctk_time); - CCTK_SchedulePrintTimes(NULL); - + PrintTimes(CCTK_PASS_CTOC); + } } @@ -107,3 +112,50 @@ void TimerReport_Checkpoint(CCTK_ARGUMENTS) ******************** Internal Routines ************************ ********************************************************************/ +static void PrintTimes (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int myproc; + FILE *file; + char *filename; + const int filename_length = 10000; + const char *flags; + static int first_time = 1; + + if (CCTK_EQUALS (out_filename, "")) + { + /* Print to stdout. */ + CCTK_SchedulePrintTimes(NULL); + } + else + { + /* Print to a file. */ + myproc = CCTK_MyProc(cctkGH); + filename = malloc(filename_length); + Util_snprintf(filename, filename_length, + "%s/%s.%04d.txt", out_dir, out_filename, myproc); + + /* truncate or append */ + flags = first_time && IO_TruncateOutputFiles(cctkGH) ? "w" : "a"; + first_time = 0; + + file = fopen(filename, flags); + if (file) + { + /* Print the schedule to the file */ + fprintf(file, "Timer Report at iteration %d time %g:\n\n", + cctk_iteration, (double) cctk_time); + CCTK_SchedulePrintTimesToFile(NULL, file); + fprintf(file, "\n********************************************************************************\n"); + fclose(file); + } + else + { + CCTK_VWarn(1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Could not open timer report output file \"%s\"", filename); + } + free(filename); + } +} |