From 6b9fd8b33183a0b64531c3369703c914b3072c46 Mon Sep 17 00:00:00 2001 From: dehnert Date: Sun, 26 Jan 2014 12:59:37 +0100 Subject: [PATCH] Added timeout flag so no external tool is needed for aborting a computation. Former-commit-id: ad5a5527cd682b822d39ce5c496cdbbc82648988 --- src/storm.cpp | 8 +++++++- src/utility/ErrorHandling.h | 3 +++ src/utility/StormOptions.cpp | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/storm.cpp b/src/storm.cpp index 207415e31..0038be29c 100644 --- a/src/storm.cpp +++ b/src/storm.cpp @@ -404,9 +404,15 @@ int main(const int argc, const char* argv[]) { return 0; } + // If requested by the user, we install a timeout signal to abort computation. + storm::settings::Settings* s = storm::settings::Settings::getInstance(); + uint_fast64_t timeout = s->getOptionByLongName("timeout").getArgument(0).getValueAsUnsignedInteger(); + if (timeout != 0) { + alarm(timeout); + } + // Now, the settings are received and the specified model is parsed. The actual actions taken depend on whether // the model was provided in explicit or symbolic format. - storm::settings::Settings* s = storm::settings::Settings::getInstance(); if (s->isSet("explicit")) { std::string const chosenTransitionSystemFile = s->getOptionByLongName("explicit").getArgument(0).getValueAsString(); std::string const chosenLabelingFile = s->getOptionByLongName("explicit").getArgument(1).getValueAsString(); diff --git a/src/utility/ErrorHandling.h b/src/utility/ErrorHandling.h index eb06b0afd..e0cbfa2b0 100644 --- a/src/utility/ErrorHandling.h +++ b/src/utility/ErrorHandling.h @@ -139,6 +139,9 @@ void installSignalHandler() { if (sigaction(SIGTERM, &sa, nullptr) == -1) { std::cerr << "FATAL: Installing a signal handler failed." << std::endl; } + if (sigaction(SIGALRM, &sa, nullptr) == -1) { + std::cerr << "FATAL: Installing a signal handler failed." << std::endl; + } #else signal(SIGSEGV, signalHandler); signal(SIGABRT, signalHandler); diff --git a/src/utility/StormOptions.cpp b/src/utility/StormOptions.cpp index 447057093..29f6dccfd 100644 --- a/src/utility/StormOptions.cpp +++ b/src/utility/StormOptions.cpp @@ -34,6 +34,8 @@ bool storm::utility::StormOptions::optionsRegistered = storm::settings::Settings settings->addOption(storm::settings::OptionBuilder("StoRM Main", "fixDeadlocks", "", "If the model contains deadlock states, setting this option will insert self-loops for these states.").build()); + settings->addOption(storm::settings::OptionBuilder("StoRM Main", "timeout", "t", "If specified, computation will abort after the given number of seconds.").addArgument(storm::settings::ArgumentBuilder::createUnsignedIntegerArgument("seconds", "The number of seconds after which to timeout.").setDefaultValueUnsignedInteger(0).build()).build()); + std::vector linearEquationSolver; linearEquationSolver.push_back("gmm++"); linearEquationSolver.push_back("native");