From: bangerth Date: Fri, 10 Dec 2010 13:17:55 +0000 (+0000) Subject: Install a thread that terminates the program after a time determined X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78932cf65ff3bf335efaf077788bba204d63d4d1;p=dealii-svn.git Install a thread that terminates the program after a time determined by the WALLTIME environment variable. This kills the program in the case of deadlocks, rather than letting it hang forever. This is necessary since the time limit we specify with 'ulimit' only affects CPU time, not actual wall time. git-svn-id: https://svn.dealii.org/trunk@22958 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/tests.h b/tests/tests.h index cd307d1c1e..b1a4198ba0 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -21,8 +21,11 @@ #include #include #include +#include #include #include +#include +#include // implicitly use the deal.II namespace everywhere, without us having to say // so in each and every testcase @@ -91,8 +94,6 @@ namespace internal } -DEAL_II_NAMESPACE_CLOSE - // A structure and a variable that are used to set grainsizes for parallel // mode smaller than they would otherwise be. this is used to test that the // parallel algorithms in lac/ work alright. @@ -113,6 +114,61 @@ set_grain_sizes; +// spawn a thread that terminates the program after a certain time +// given by the environment variable WALLTIME. this makes sure we +// don't let jobs that deadlock on some mutex hang around +// forever. note that this is orthogonal to using "ulimit" in +// Makefile.rules, which only affects CPU time and consequently works +// on infinite loops but not deadlocks +#ifdef DEAL_II_USE_MT + +struct DeadlockKiller +{ + private: + static void nuke_it () + { + char * env = std::getenv("WALLTIME"); + + if (env != 0) + { + std::istringstream conv (env); + int delay; + conv >> delay; + if (conv) + { + sleep (delay); + std::cerr << "Time's up: Killing job because it overran its allowed walltime" + << std::endl; + std::abort (); + } + else + { + std::cerr << "Invalid value for WALLTIME environment variable." + << std::endl; + std::abort (); + } + } + else + // environment variable is + // not set, so assume + // infinite wait time and + // simply quite this thread + ; + } + + public: + DeadlockKiller () + { + dealii::Threads::new_thread (&nuke_it); + } +}; +DeadlockKiller deadlock_killer; + +#endif + +DEAL_II_NAMESPACE_CLOSE + + // append the directory name with an output file name that indicates // the number of MPI processes std::string output_file_for_mpi (const std::string &directory)