Why is Mathematica Stopping My Long Calculation?


January 30 2016 in Mathematica, Programming | Tags: | Author: Christopher Rackauckas

You set it all up, you know it’s going to take a few days, and you run it. You check it a few hours later, it’s all good! The next morning… there are no cells computing still?

Mathematica’s documentation isn’t that helpful for what just happened. If you were using a function like FullSimplify, there are time limits on it. However, it will give you an error/warning if it hits the time limit, so if you ended up with a blank screen with no calculations, that’s not it.

This happened to me. I found out that the hidden culprit (for me) was Mathematica’s history tracking. The fix is simple, add the following code to the top of your file:

$HistoryLength = 10;

What’s happening is that Mathematica saves its entire command history by default. This is for your convenience to be able to call % to get the previous command. However, if you are churning computations for days on end, the default $HistoryLength = infinite starts to build up quickly, and even on a machine with 128Gb of RAM I ran out. When this happens, Mathematica has a silent error (no warnings, etc.), stops the computation, and skips to the next cell to compute (so if you have a long computational step and are trying to find out why you are getting the wrong answers, this could be the cause).

So as you can see, a quick fix is to change the history length. When I found this out, I set it to zero since I don’t tend to use it. But 10 is safe and bounded. It took me awhile to find the fix, since when I frantically Googled “Why is Mathematica stopping my calculation?” I got no hits. Hope this helps.

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.