Interrupting Mathematica in mid calculation

Main Question or Discussion Point

Hi all,

I've left Mathematica running on a set of calculations that I thought should take about 5 hours, and after 5 days I need to stop it. Is there any way I can actually extract useful information about what it's been doing? I know that I can enter a "subsession" via the panel that comes up when I enter alt +, but I'm not sure what I can actually do in this dialog.

In particular, I asked it to evaluate about 1900 integrals, depending on three parameters, and tabulate the results; is there any way I can see how far along it is, and write any of the results to a file?

In the subsession you can issue a Stack[] or Stack[somepattern] and see what is sitting in the evaluation stack. Doing that should not damage the calculation in progress, unless something goes wrong and the whole session crashes. Unfortunately, the result of Stack is often very large and doesn't seem to contain what I'm hoping for when I really really need it.

Roughly, in a subsession you are sitting there with all the current state, can display things that have values, can even do calculations, etc. I suggest not changing the value of any variables, but just gently peeking at things.

IF you had been carefully building up a list of results and storing that in a global variable then you can look at the value of that variable or use Stack[] to look at some calculations in progress and see the accumulated results, but if you were just constructing a large Table of results and expecting the final value of that to be what you wanted then I would give up hope.

where n is the n'th integral you are working on and yourmsg is optionally something helpful to keep you informed, you get the idea, will paste a little message in the lower left corner of your notebook display so you can try to tell if it is hung and where. Google
Mathematica SetNotebookStatusLine
to find examples of using this.

Do some primitive file appends during your calculation, open a file, write a "{" and then close the file. At the completion of each integral open the file, append a single expression followed by a comma to the file and then close the file. If you have to kill it then the file should not be damaged, you can manually replace the final "," with "}" outside of Mathematica and then the whole file will be a single expression that can be read back in for inspection.

You can also do more complicated things where you roughly put a time limit on a particular calculation and bail out if it takes too long. That will let you get all the reasonable results and you can try to decide what to do about the rest, but this is more advanced and you need to do some poking around to learn the technique.