Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
2  
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... –  rm -rf Jul 12 '13 at 18:15

2 Answers 2

up vote 3 down vote accepted

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 : http://stackoverflow.com/a/13740555/879601

(MemoryConstrained looks a good solution for your specific problem though.)

share|improve this answer
    
Thanks! SetOptions works great! –  math-student Jul 13 '13 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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