diff options
author | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2002-11-08 12:41:54 +0000 |
---|---|---|
committer | tradke <tradke@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2002-11-08 12:41:54 +0000 |
commit | b5dc0457b3e7036e4644e6b81a1a134b213c196b (patch) | |
tree | 36ac30309eff472d47330395c1ce6b6966277021 | |
parent | 7825d91799b2d0b71ba9ce017855153aae8ea212 (diff) |
Added another termination condition integer parameter cactus::max_runtime
and extended the keyword parameter cactus::terminate to select this condition.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@3027 17b73243-c579-4c4c-a9d2-2d5706c11dac
-rw-r--r-- | src/main/CactusDefaultEvolve.c | 111 | ||||
-rw-r--r-- | src/param.ccl | 23 |
2 files changed, 98 insertions, 36 deletions
diff --git a/src/main/CactusDefaultEvolve.c b/src/main/CactusDefaultEvolve.c index 80da3884..b7414d72 100644 --- a/src/main/CactusDefaultEvolve.c +++ b/src/main/CactusDefaultEvolve.c @@ -22,6 +22,13 @@ #include "cctk_Misc.h" #include "cctk_IO.h" +#ifdef HAVE_TIME_GETTIMEOFDAY +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif +#include <unistd.h> +#endif + static const char *rcsid="$Header$"; CCTK_FILEVERSION(main_CactusDefaultEvolve_c); @@ -59,7 +66,7 @@ static int cactus_terminate_global = 0; ********************* Local Routine Prototypes ********************* ********************************************************************/ -static int DoneMainLoop (cGH *GH, CCTK_REAL cctk_time, int iteration); +static int DoneMainLoop (const cGH *GH, CCTK_REAL cctk_time, int iteration); static void StepGH (cGH *GH); /******************************************************************** @@ -84,8 +91,9 @@ int CactusDefaultEvolve (tFleshConfig *config); DoneMainLoop StepGH @history - @hdate Fri May 12 2000 @hauthor Thomas Radke - @hdesc Moved evolution loop termination check into DoneMainLoop() + @hdate Fri May 12 2000 + @hauthor Thomas Radke + @hdesc Moved evolution loop termination check into DoneMainLoop() @endhistory @var config @@ -209,14 +217,19 @@ int CactusDefaultEvolve (tFleshConfig *config) Check the termination conditions for the evolution loop @enddesc @calls CCTK_TerminationReached + @history + @hdate Thu 6 Nov 2002 + @hauthor Thomas Radke + @hdesc Added max_runtime condition test + @endhistory @var GH @vdesc pointer to CCTK grid hierarchy - @vtype cGH * + @vtype const cGH * @vio in @endvar - @var time - @vdesc current physical time + @var simulation_time + @vdesc current physical simulation time @vtype CCTK_REAL @vio in @endvar @@ -231,41 +244,81 @@ int CactusDefaultEvolve (tFleshConfig *config) true (1) or false (0) for done/not done with main loop @endreturndesc @@*/ -static int DoneMainLoop (cGH *GH, CCTK_REAL time, int iteration) +static int DoneMainLoop (const cGH *GH, CCTK_REAL simulation_time,int iteration) { + int max_iteration_reached, max_simulation_time_reached, max_runtime_reached; int retval; +#ifdef HAVE_TIME_GETTIMEOFDAY + struct timeval runtime; + static struct timeval starttime = {0, 0}; +#endif DECLARE_CCTK_PARAMETERS +#ifdef HAVE_TIME_GETTIMEOFDAY + /* on the first time through, get the start time */ + if (starttime.tv_sec == 0 && starttime.tv_usec == 0) + { + gettimeofday (&starttime, NULL); + } +#endif + retval = terminate_next || CCTK_TerminationReached (GH); - if (! retval) + if (! retval && ! CCTK_Equals (terminate, "never")) { - if (CCTK_Equals (terminate, "never")) + max_iteration_reached = iteration >= cctk_itlast; + + if (cctk_initial_time < cctk_final_time) { - retval = 0; + max_simulation_time_reached = simulation_time >= cctk_final_time; } - else if (CCTK_Equals (terminate, "iteration")) + else { - retval = iteration >= cctk_itlast; + max_simulation_time_reached = simulation_time <= cctk_final_time; } - else + + max_runtime_reached = 0; +#ifdef HAVE_TIME_GETTIMEOFDAY + if (max_runtime > 0) { - if (cctk_initial_time < cctk_final_time) - { - retval = time >= cctk_final_time; - } - else - { - retval = time <= cctk_final_time; - } - if (CCTK_Equals (terminate, "either")) - { - retval |= iteration >= cctk_itlast; - } - else if (CCTK_Equals (terminate, "both")) - { - retval &= iteration >= cctk_itlast; - } + /* get the elapsed runtime in minutes and compare with max_runtime */ + gettimeofday (&runtime, NULL); + runtime.tv_sec -= starttime.tv_sec; + runtime.tv_sec /= 60; + max_runtime_reached = runtime.tv_sec >= max_runtime; + } +#endif + + if (CCTK_Equals (terminate, "iteration")) + { + retval = max_iteration_reached; + } + else if (CCTK_Equals (terminate, "time")) + { + retval = max_simulation_time_reached; + } + else if (CCTK_Equals (terminate, "runtime")) + { + retval = max_runtime_reached; + } + else if (CCTK_Equals (terminate, "any")) + { + retval = max_iteration_reached || max_simulation_time_reached || + max_runtime_reached; + } + else if (CCTK_Equals (terminate, "all")) + { + retval = max_iteration_reached && max_simulation_time_reached && + max_runtime_reached; + } + /* the following two conditions are deprecated in BETA14 */ + else if (CCTK_Equals (terminate, "either")) + { + retval = max_iteration_reached || max_simulation_time_reached; + } + else /* if (CCTK_Equals (terminate, "both")) */ + { + retval = max_iteration_reached && max_simulation_time_reached; } } diff --git a/src/param.ccl b/src/param.ccl index 4c8659af..2cf8af2c 100644 --- a/src/param.ccl +++ b/src/param.ccl @@ -68,24 +68,33 @@ BOOLEAN terminate_next "Terminate on next iteration?" STEERABLE=ALWAYS KEYWORD terminate "Condition on which to terminate evolution loop" STEERABLE=ALWAYS { - "never" :: "Never terminate" + "never" :: "Never terminate" "iteration" :: "Take termination condition from iteration number" - "time" :: "Take termination condition from coordinate time" - "either" :: "Take termination condition from either iteration number or coordinate time" - "both" :: "Take termination condition from both iteration number and coordinate time" + "time" :: "Take termination condition from coordinate time" + "runtime" :: "Take termination condition from elapsed runtime" + "any" :: "Take termination condition from any of iteration number, coordinate time, or elapsed runtime" + "all" :: "Take termination condition from all of iteration number, coordinate time, and elapsed runtime" + "either" :: "Take termination condition from either iteration number or coordinate time (DEPRECATED IN BETA14)" + "both" :: "Take termination condition from both iteration number and coordinate time (DEPRECATED IN BETA14)" } "iteration" REAL cctk_initial_time "Initial time for evolution" { - : :: "Anything" + : :: "Anything" } 0.0 REAL cctk_final_time "Final time for evolution" STEERABLE=ALWAYS { - : :: "Anything" + : :: "Anything" } -1.0 INT cctk_itlast "Final iteration number" STEERABLE = ALWAYS { -: :: "Any integer" + : :: "Any integer" } 10 + +INT max_runtime "Terminate evolution loop after a certain elapsed runtime (in minutes)" STEERABLE = ALWAYS +{ + 0: :: "Zero disables maximum runtime condition" + 1:* :: "Run evolution loop for so many minutes, then terminate" +} 0 |