aboutsummaryrefslogtreecommitdiff
path: root/src/Output.c
diff options
context:
space:
mode:
authorschnetter <schnetter@d0051148-8e13-4bef-be1d-f6c572c85f9f>2007-08-25 02:32:12 +0000
committerschnetter <schnetter@d0051148-8e13-4bef-be1d-f6c572c85f9f>2007-08-25 02:32:12 +0000
commit865d76b2f07aa64ea4dd6972ef7490661bd88948 (patch)
treec9f44bef09491881607e75f4213f4aa93cb3d8f7 /src/Output.c
parent4c0e8f0a50204854feb57e46f4d1c7ea77c08a5b (diff)
Output timer reports to a file instead of to stdout
Add a parameter to the thorn CactusUtils/TimerReport to output the timer reports to files instead of to stdout. The reports are often many lines long, and they use more than 80 characters per line, cluttering stdout. Additionally, having them in files allows looking at timer reports from all processors without collecting all processors' stdout. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/TimerReport/trunk@19 d0051148-8e13-4bef-be1d-f6c572c85f9f
Diffstat (limited to 'src/Output.c')
-rw-r--r--src/Output.c60
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);
+ }
+}