3
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ There's no way to automate this because a fresh kernel won't know what it did in the past. Why do you want to let things get to the point where the kernel crashes? Instead, you can try to use MemoryConstrained to abort the computation when the memory exceeds a certain threshold and then restart it... $\endgroup$ – rm -rf Jul 12 '13 at 18:15
8
$\begingroup$

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.)

$\endgroup$
  • $\begingroup$ Thanks! SetOptions works great! $\endgroup$ – math-student Jul 13 '13 at 1:07
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.