diff --git a/docs/conjure-help.html b/docs/conjure-help.html
index 51b247958..c57234302 100644
--- a/docs/conjure-help.html
+++ b/docs/conjure-help.html
@@ -134,6 +134,9 @@
| --seed=INT | Random number generator seed. |
| --limit-models=INT | Maximum number of models to generate. |
| --use-existing-models=FILE | File names of Essence' models generated beforehand. If given, Conjure skips the modelling phase and uses the existing models for solving. The models should be inside the output directory (See -o). |
+runsolver: |
+ | --runsolver-cpu-time-limit=INT | Use runsolver to limit total CPU time (in seconds) |
+ | --runsolver-memory-limit=INT | Use runsolver to limit total memory usage (in megabytes). This is the total memory usage: both RAM and swap space. |
Options for other tools: |
| --savilerow-options=ITEM | Options passed to Savile Row. |
| --solver-options=ITEM | Options passed to the backend solver. |
diff --git a/docs/conjure-help.txt b/docs/conjure-help.txt
index 729e539ec..5c70d8f56 100644
--- a/docs/conjure-help.txt
+++ b/docs/conjure-help.txt
@@ -261,6 +261,10 @@
If given, Conjure skips the modelling phase and uses the existing models
for solving.
The models should be inside the output directory (See -o).
+ runsolver:
+ --runsolver-cpu-time-limit=INT Use runsolver to limit total CPU time (in seconds)
+ --runsolver-memory-limit=INT Use runsolver to limit total memory usage (in megabytes).
+ This is the total memory usage: both RAM and swap space.
Options for other tools:
--savilerow-options=ITEM Options passed to Savile Row.
--solver-options=ITEM Options passed to the backend solver.
diff --git a/src/Conjure/UI.hs b/src/Conjure/UI.hs
index ac90e8c27..119cd93aa 100644
--- a/src/Conjure/UI.hs
+++ b/src/Conjure/UI.hs
@@ -99,6 +99,8 @@ data UI
, responses :: String
, responsesRepresentation :: String
, solutionsInOneFile :: Bool
+ , runsolverCPUTimeLimit :: Maybe Int
+ , runsolverMemoryLimit :: Maybe Int
-- flags related to logging
, logLevel :: LogLevel
, verboseTrail :: Bool
@@ -739,6 +741,19 @@ ui = modes
&= explicit
&= help "Place all solutions in a single file instead of generating a separate file per solution.\n\
\Off by default."
+ , runsolverCPUTimeLimit
+ = def
+ &= name "runsolver-cpu-time-limit"
+ &= groupname "runsolver"
+ &= explicit
+ &= help "Use runsolver to limit total CPU time (in seconds)"
+ , runsolverMemoryLimit
+ = def
+ &= name "runsolver-memory-limit"
+ &= groupname "runsolver"
+ &= explicit
+ &= help "Use runsolver to limit total memory usage (in megabytes). \n\
+ \This is the total memory usage: both RAM and swap space."
, logLevel
= def
&= name "log-level"
diff --git a/src/Conjure/UI/MainHelper.hs b/src/Conjure/UI/MainHelper.hs
index 022942a6e..b1c35c19c 100644
--- a/src/Conjure/UI/MainHelper.hs
+++ b/src/Conjure/UI/MainHelper.hs
@@ -803,7 +803,12 @@ savileRowNoParam ui@Solve{..} (modelPath, eprimeModel) = sh $ errExit False $ do
let handler = liftIO . srStdoutHandler
(outBase, modelPath, "", ui)
tr (1::Int)
- (stdoutSR, solutions) <- partitionEithers <$> runHandle savilerowScriptName srArgs handler
+ let runsolverArgs = maybe [] (\ limit -> ["-C", show limit]) runsolverCPUTimeLimit ++
+ maybe [] (\ limit -> ["-V", show limit]) runsolverMemoryLimit
+ (stdoutSR, solutions) <- partitionEithers <$>
+ if null runsolverArgs
+ then runHandle savilerowScriptName srArgs handler
+ else runHandle "runsolver" (map stringToText runsolverArgs ++ [stringToText savilerowScriptName] ++ srArgs) handler
srCleanUp outBase ui (stringToText $ unlines stdoutSR) solutions
savileRowNoParam _ _ = bug "savileRowNoParam"
@@ -844,7 +849,13 @@ savileRowWithParams ui@Solve{..} (modelPath, eprimeModel) (paramPath, essencePar
let handler = liftIO . srStdoutHandler
(outBase, modelPath, paramPath, ui)
tr (1::Int)
- (stdoutSR, solutions) <- partitionEithers <$> runHandle savilerowScriptName srArgs handler
+ let runsolverArgs = maybe [] (\ limit -> ["-C", show limit]) runsolverCPUTimeLimit ++
+ maybe [] (\ limit -> ["-V", show limit]) runsolverMemoryLimit
+ (stdoutSR, solutions) <- partitionEithers <$>
+ if null runsolverArgs
+ then runHandle savilerowScriptName srArgs handler
+ else runHandle "runsolver" (map stringToText runsolverArgs ++ [stringToText savilerowScriptName] ++ srArgs) handler
+
srCleanUp outBase ui (stringToText $ unlines stdoutSR) solutions
savileRowWithParams _ _ _ = bug "savileRowWithParams"