I am using Mathematica to generate 3D graphics frame for a video. The process goes as follows:
- Loop over a counter
i
- Use
Import
to load in data fromdata.$i.hdf5
intodata
- Apply some expression to
data
, then useInterpolation
on it - Make a
ParametricPlot3D
of the surface withPlotPoints -> 50
and store it inoutgfx
- Export result to
outgfx.png
withImageSize -> {2048, 2048}
- Use
The problem is that MathKernel keeps crashing every 3-5 frames with no reason given. I tried putting the entire body of the loop in a Block
and store all variables locally, hoping that the garbage collector would be better behaved, but this did not help. My current solution is to manually babysit Mathematica and manually change the loop limits and re-run the code every time I hear a beep.
I figured that way to sidestep this issue is to launch a new kernel for each iteration, do the processing, then shut down the kernel before looping. If the new kernel crashes, since the loop itself runs in a different kernel, it can keep going.
Is there a way to do this in the frontend?
$HistoryLength=0
which will probably help in decreasing the memory consumption. For running in extra kernels you could have a look at the parallel functionality. If you use that with only one parallel kernel and doCloseKernels
once in a while that probably is the most convenient interface to do what you want. For your application using more than one kernel in parallel would probably also make sense. It would certainly also be possible to start a kernel with lower level functionality... $\endgroup$ – Albert Retey May 19 '15 at 9:20