aboutsummaryrefslogtreecommitdiff
path: root/src/walltime.c
diff options
context:
space:
mode:
authorschnetter <schnetter@ec5ace1c-6809-4267-9cad-ed2f0ecfe59c>2010-01-11 22:25:14 +0000
committerschnetter <schnetter@ec5ace1c-6809-4267-9cad-ed2f0ecfe59c>2010-01-11 22:25:14 +0000
commit571f4fec08bba4af5be3734ca515926325b729a7 (patch)
treefc725ac891e187cff24ad99f297ba0d899e285ce /src/walltime.c
parent6b4b7c39e9fb4d3763472b064edadb779ba408be (diff)
Add new thorn TerminationTrigger.
This thorn watches the elapsed walltime. If only n minutes are left before the some limit set by the user, it triggers termination of the simulation. Termination is also triggered if a special file with a special content exists. git-svn-id: http://svn.cactuscode.org/arrangements/CactusUtils/TerminationTrigger/trunk@2 ec5ace1c-6809-4267-9cad-ed2f0ecfe59c
Diffstat (limited to 'src/walltime.c')
-rw-r--r--src/walltime.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/walltime.c b/src/walltime.c
new file mode 100644
index 0000000..85209ed
--- /dev/null
+++ b/src/walltime.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "cctk.h"
+#include "cctk_Arguments.h"
+#include "cctk_Parameters.h"
+#include "cctk_Termination.h"
+#include "cctk_Timers.h"
+
+
+
+void TerminationTrigger_StartTimer (CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ /* only one processor needs to query the elapsed runtime */
+ if (CCTK_MyProc (cctkGH) != 0)
+ {
+ return;
+ }
+
+ *watchminutes = output_remtime_every_minutes;
+
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Reminding you every %g minutes about remaining walltime",
+ (double) output_remtime_every_minutes);
+}
+
+
+
+void TerminationTrigger_ResetMinutes (CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ /* only one processor needs to query the elapsed runtime */
+ if (CCTK_MyProc (cctkGH) != 0)
+ {
+ return;
+ }
+
+ *watchminutes = output_remtime_every_minutes;
+}
+
+
+
+void TerminationTrigger_CheckWalltime (CCTK_ARGUMENTS)
+{
+ DECLARE_CCTK_ARGUMENTS;
+ DECLARE_CCTK_PARAMETERS;
+
+ CCTK_REAL time;
+
+ /* only one processor needs to query the elapsed runtime */
+ if (CCTK_MyProc (cctkGH) != 0)
+ {
+ return;
+ }
+
+ /* get walltime in seconds */
+ time = CCTK_RunTime();
+
+ if ((time/60.0 > *watchminutes) && *watchminutes != 0) {
+ *watchminutes += output_remtime_every_minutes;
+ CCTK_INFO ("***********************************************************");
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Remaining wallclock time for your job is %g minutes",
+ (double) (max_walltime*60.0 - time/60.0));
+ CCTK_INFO ("***********************************************************");
+ }
+
+ if (time/60.0 >= (max_walltime*60.0 - on_remaining_walltime)) {
+ CCTK_VInfo (CCTK_THORNSTRING,
+ "Remaining wallclock time for your job is %g minutes. "
+ "Triggering termination...",
+ (double) (max_walltime*60.0 - time/60.0));
+ CCTK_TerminateNext (cctkGH);
+ }
+}