diff options
author | swhite <swhite@e5a5a894-0e4f-0410-be11-d22c8b0a171a> | 2006-04-26 14:49:06 +0000 |
---|---|---|
committer | swhite <swhite@e5a5a894-0e4f-0410-be11-d22c8b0a171a> | 2006-04-26 14:49:06 +0000 |
commit | d69c71d3983cee0cfd3793734a5c9fa8b1391b21 (patch) | |
tree | a00610f272508fd476741c884b9b2ccc16f210f0 /src | |
parent | 30eb89d539b87ded1d82298c43f205b5a3b4837e (diff) |
Christian's TriggerTerminationManual, renamed and expanded
git-svn-id: http://svn.aei.mpg.de/numrel/AEIThorns/ManualTermination/trunk@2 e5a5a894-0e4f-0410-be11-d22c8b0a171a
Diffstat (limited to 'src')
-rw-r--r-- | src/ManualTermination.c | 140 | ||||
-rw-r--r-- | src/ManualTermination.h | 8 | ||||
-rw-r--r-- | src/ManualTerminationFile.c | 48 | ||||
-rw-r--r-- | src/make.code.defn | 8 |
4 files changed, 204 insertions, 0 deletions
diff --git a/src/ManualTermination.c b/src/ManualTermination.c new file mode 100644 index 0000000..0dce2fe --- /dev/null +++ b/src/ManualTermination.c @@ -0,0 +1,140 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +#include "cctk.h" +#include "cctk_Arguments.h" +#include "cctk_Parameters.h" +#include "cctk_Termination.h" +#include "cctk_Timers.h" +#include "ManualTermination.h" + +enum{ BUFLEN = 128 }; + +/* On first call, pass parameter terminate_filename. + If it is null will construct file name in /tmp based on PBS_JOBID. + Subsequent calls ignore the argument, and return a static buffer. +*/ +const char * MT_get_terminate_filename( CCTK_STRING terminate_filename ) +{ + static char buf[BUFLEN]; + + if( strlen( buf ) != 0 ) + return buf; + + if( strlen( terminate_filename ) == 0 ) + { + const char * pbs_jobid = getenv("PBS_JOBID"); + snprintf( buf, BUFLEN, "/tmp/cactus_terminate.%s", pbs_jobid ); + } + else + { + snprintf( buf, BUFLEN, "%s", terminate_filename ); + } + return buf; +} + +int ManualTermination_StartTimer (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int retval = 0; + int ierr; + int TimerIndex; + + /* only one processor needs to query the elapsed runtime */ + if (CCTK_MyProc (cctkGH) != 0) + { + return (0); + } + /* Create timer */ + TimerIndex = CCTK_TimerCreate("WatchWalltime"); + /* Start timer */ + ierr = CCTK_TimerStart("WatchWalltime"); + + *watchminutes = output_remtime_every_minutes*1.0e0; + + CCTK_VInfo (CCTK_THORNSTRING, "Started Timer"); + CCTK_VInfo (CCTK_THORNSTRING, "Reminding you every %d " + "minutes about remaining walltime.", + output_remtime_every_minutes); + + if( termination_from_file ) + { + FILE *termfile = fopen( MT_get_terminate_filename(termination_file), "w" ); + if( termfile != NULL ) + { + fprintf( termfile, "%d", 0 ); + fclose( termfile ); + } + else + { + CCTK_VWarn (CCTK_WARN_ABORT, __LINE__, __FILE__, "ManualTermination", + "Could not open termination file '%s'. Error: %d", + MT_get_terminate_filename(NULL), strerror(errno)); + } + } + return (retval); +} + +int ManualTermination_ResetMinutes (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + *watchminutes = output_remtime_every_minutes*1.0e0; + + return 0; +} + +int ManualTermination_CheckWalltime (CCTK_ARGUMENTS) +{ + DECLARE_CCTK_ARGUMENTS; + DECLARE_CCTK_PARAMETERS; + + int retval,ierr; + cTimerData *info; + const cTimerVal *walltime; + CCTK_REAL time; + + /* only one processor needs to query the elapsed runtime */ + if (CCTK_MyProc (cctkGH) != 0) + { + return (0); + } + + info = CCTK_TimerCreateData(); + ierr = CCTK_Timer("WatchWalltime",info); + + /* stop timer */ + ierr = CCTK_TimerStop("WatchWalltime"); + /* get walltime */ + walltime = CCTK_GetClockValue("gettimeofday",info); + time = CCTK_TimerClockSeconds(walltime); + CCTK_TimerDestroyData(info); + /* Start timer */ + ierr = CCTK_TimerStart("WatchWalltime"); + + if ( (time/60.0e0 > *watchminutes) && *watchminutes != 0) + { + *watchminutes = (*watchminutes)+output_remtime_every_minutes*1.0e0; + CCTK_INFO ("***********************************************************"); + CCTK_VInfo (CCTK_THORNSTRING, "Remaining wallclock time for your job " + "is %1.2f minutes. :-)", (max_walltime*60.0-time/60.0)); + CCTK_INFO ("***********************************************************"); + } + + if (time/60.0e0 >= (max_walltime*60.0e0 - on_remaining_walltime*1.0e0)) + { + CCTK_VInfo (CCTK_THORNSTRING, "Remaining wallclock time for your job " + "is %1.2f minutes. Triggering termination ...", + (max_walltime*60.0-time/60.0)); + CCTK_TerminateNext (cctkGH); + } + + retval = 0; + + return (retval); +} diff --git a/src/ManualTermination.h b/src/ManualTermination.h new file mode 100644 index 0000000..bca3f3c --- /dev/null +++ b/src/ManualTermination.h @@ -0,0 +1,8 @@ +#ifndef MANUALTERMINATION_H +#define MANUALTERMINATION_H + +#include "cctk.h" + +const char * MT_get_terminate_filename( CCTK_STRING ); + +#endif diff --git a/src/ManualTerminationFile.c b/src/ManualTerminationFile.c new file mode 100644 index 0000000..342ac3f --- /dev/null +++ b/src/ManualTerminationFile.c @@ -0,0 +1,48 @@ +#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 "ManualTermination.h" + + +int ManualTerminationFile (CCTK_ARGUMENTS) +{ + int retval = 0, terminate; + FILE *terminationfile; + + DECLARE_CCTK_PARAMETERS; + + /* only one processor needs to query the elapsed runtime */ + if (CCTK_MyProc (cctkGH) != 0) + { + return (0); + } + + if ( ((cctkGH->cctk_iteration-1) % check_file_every*1.0e0) != 0) + { + return(0); + } + + terminationfile = fopen(MT_get_terminate_filename(NULL),"r"); + + if(terminationfile!=NULL) + { + terminate=0; + fscanf(terminationfile,"%d",&terminate); + fclose(terminationfile); + + if (terminate==1) + { + CCTK_VInfo (CCTK_THORNSTRING, "OH MY GOD! Found termination signal " + "in termination file! TERMINATION NOW!!!!"); + CCTK_TerminateNext (cctkGH); + } + } + + return (retval); +} diff --git a/src/make.code.defn b/src/make.code.defn new file mode 100644 index 0000000..bf7f9e4 --- /dev/null +++ b/src/make.code.defn @@ -0,0 +1,8 @@ +# Main make.code.defn file for thorn ManualTermination +# $Header$ + +# Source files in this directory +SRCS = ManualTermination.c ManualTerminationFile.c + +# Subdirectories containing source files +SUBDIRS = |