diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Output.c | 60 |
1 files changed, 56 insertions, 4 deletions
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); + } +} |