I want to run a Mathematica code repeatedly, even after the kernel shuts down when it is out of memory, because I have designed my program to continue appending the data to a file. Currently, I have to restart the kernel manually every 10 minutes. Does anyone have an idea how one can automate this process? Thanks.
2 Answers
If you preselect a range of cells before execution you can continue execution past kernel quit using the option below. Selection and evaluation can be automated and done repeatedly.
SetOptions[$FrontEnd, "ClearEvaluationQueueOnKernelQuit" -> False]
Ref : https://stackoverflow.com/a/13740555/879601
(MemoryConstrained
looks a good solution for your specific problem though.)
-
$\begingroup$ Thanks! SetOptions works great! $\endgroup$ Commented Jul 13, 2013 at 1:07
Here is what rm -rf just mentioned, in the form of an example:
Do[
MemoryConstrained[
a = Range[10^n], 10000];
Print[Total[a]],
{n, 1, 10}
]
Output:
55
5050
500500
500500
500500
500500
500500
500500
500500
500500
By using MemoryConstrained
, you don't get any changes in the list a
after the maximum memory is reached in the above loop, but the loop continues to run.
MemoryConstrained
to abort the computation when the memory exceeds a certain threshold and then restart it... $\endgroup$