aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--interface.ccl6
-rw-r--r--param.ccl8
-rw-r--r--schedule.ccl6
-rw-r--r--src/Output.c60
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
diff --git a/param.ccl b/param.ccl
index 015b6a6..3a31f7d 100644
--- a/param.ccl
+++ b/param.ccl
@@ -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);
+ }
+}