diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file.c | 109 | ||||
-rw-r--r-- | src/make.code.defn | 7 | ||||
-rw-r--r-- | src/walltime.c | 81 |
3 files changed, 197 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c new file mode 100644 index 0000000..ec111ef --- /dev/null +++ b/src/file.c @@ -0,0 +1,109 @@ +#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" +#include "util_String.h" + + + +enum { BUFLEN = 10000 }; + + + +static +const char * get_termination_file (void) +{ + DECLARE_CCTK_PARAMETERS; + + static char filename[BUFLEN]; + + if (strlen (termination_file) == 0) + { + const char * pbs_jobid = getenv ("MANUAL_TERMINATION_JOB_ID"); + if (pbs_jobid == NULL) + pbs_jobid = getenv ("PBS_JOBID"); + + if (pbs_jobid == NULL) + CCTK_VWarn (CCTK_WARN_ABORT, __LINE__, __FILE__, "ManualTermination", + "Could not find environment variable " + "'MANUAL_TERMINATION_JOB_ID' or 'PBS_JOBID'"); + else + Util_snprintf (filename, BUFLEN, "/tmp/cactus_terminate.%s", pbs_jobid); + } + else + { + if (termination_file[0] == '/') + { + /* file name begins with a slash, do not use IO::out_dir */ + Util_snprintf (filename, BUFLEN, "%s", termination_file); + } + else + { + /* add IO::out_dir to filename */ + Util_snprintf (filename, BUFLEN, + "%s/%s", out_dir, termination_file); + } + } + return filename; +} + + + +void TerminationTrigger_CreateFile (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + FILE *file; + + /* only one processor needs to create the file */ + if (CCTK_MyProc (cctkGH) != 0) + { + return; + } + + file = fopen (get_termination_file(), "w"); + fclose (file); +} + + + +void TerminationTrigger_CheckFile (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + FILE *file; + int terminate; + + /* only one processor needs to check the file */ + if (CCTK_MyProc (cctkGH) != 0) + { + return; + } + + if (cctk_iteration % check_file_every != 0) + { + return; + } + + file = fopen (get_termination_file(), "r"); + + if (file != NULL) { + terminate = 0; + fscanf (file, "%d", &terminate); + fclose (file); + + if (terminate == 1) { + CCTK_INFO ("Found termination signal in termination file. " + "Triggering termination..."); + + CCTK_TerminateNext (cctkGH); + } + } +} diff --git a/src/make.code.defn b/src/make.code.defn new file mode 100644 index 0000000..044fea0 --- /dev/null +++ b/src/make.code.defn @@ -0,0 +1,7 @@ +# Main make.code.defn file for thorn TerminationTrigger + +# Source files in this directory +SRCS = walltime.c file.c + +# Subdirectories containing source files +SUBDIRS = 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); + } +} |