Message Boards Message Boards

No more memory available

Posted 8 years ago

I got a memory-problem on the Pi, yesterday I tried the following code with the trialversion of Mathematica on my desktop-pc and it was fine, so I know it used around 4Gb of memory there. But today the trial ended and I needed to go back to my Raspberry...and if I evaluate the code here (even with almost human settings(res 50)) I got a out of memory error after a few seconds. The memorysplit is already set to 16, so I have ~950Mb free - but it seems to be by far not enough.

Clear[trueImg];
rot[t_] := 8 Pi (0.5 + 0.5 Tanh[6 (t - 0.5)]);
trueImg[t_][x_, y_] := 
 Module[{xt, yt, f}, {xt, yt} = RotationMatrix[rot[t]].{x, y};
  yt = -yt;
  f = 0.5 + 0.5 Tanh[8 Sin[5 xt] Cos[5 yt]];
  (*List@@(ColorData["RedBlueTones"][f])*);
  {f, f, f}]
\[Alpha] = 0.01;
res = 50;
photograph[img_, t_] := 
  Module[{dims, \[Tau]}, 
   Rasterize[
    Image[Table[
      img[t + \[Alpha] (x + 2 y)][x, y], {y, -1, 1, 2/res}, {x, -1, 1,
        2/res}]], ImageSize -> {1920, 1080}]];
Export[NotebookDirectory[] <> "1080-Matthen-ChessRotate.avi", 
 ParallelTable[photograph[trueImg, t], {t, -0.3, 1.5, 0.025}]]

So what can I do now to create this animation on the Raspberry? Is therre any way to solve the mem-problem through cloudcomputing for example? Or is there something in the code that can be changed to save a massive amount of ram?

POSTED BY: Michael Steffen
7 Replies

The Pi has only 950Mb. I simply mark that as 'impossible' for myself and thats it. Playing around with this takes too much time...thanks anyway.

POSTED BY: Michael Steffen
Posted 8 years ago

Do 72 individual pictures and convert those into an avi outside

For[i = 1, i <= 72, i++,
 Export[NotebookDirectory[] <> "1080-Matthen-ChessRotate" <> ToString[i] <> ".jpg",
   photograph[trueImg, -0.3 + 0.025*i]]
 ]

which comes in at about two gigabytes of memory

or do 4 short avi and fuse those into one avi outside

For[i = -0.3, i < 1.5, i = i + 0.45,
 Export[NotebookDirectory[] <> "1080-Matthen-ChessRotate" <> ToString[i] <> ".avi",
   Table[photograph[trueImg, t], {t, i, i + 0.45 - 0.025, 0.025}]]
 ]

Which comes in at just over 1.5 gigabytes of memory

Watch out for little "off by a bit" when adding a sequence of floating point values and comparing against other floating point values. You might consider turning all those into exact rational values which should avoid that problem.

POSTED BY: Bill Simpson

If I want to export frame by frame as pictures, is there a better way than

Export[NotebookDirectory[] <> "1080-Matthen-ChessRotate*.jpg", ...

(which leads to the same memory-problem) or trying to change and evaluate the value t manually by hand every frame?

POSTED BY: Michael Steffen

Why I use 'Parallel' is easy: that is the first I try every anim, cause the Pi is extreme slow here - some animations took hours or days to evaluate and export in higher resolutions - and in view of that, I don't like it, when the cpu-usage only shows 25% all the time, hoping that more cpu-power speeds things up a bit.

You're right in view of saving memory, but in this case it even seems to be too large on one kernel: General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.

Maybe I'll try it with exporting as single pictures tomorrow, I already have had such a .jpg-avi-tool somewhere...hopefully the memory is enough for pictures.....

POSTED BY: Michael Steffen
Posted 8 years ago

If I run your code with the only change being replacing ParallelTable with Table and saving the file on my Win desktop then I find (when I carefully restart the kernel each time)

With table step size .025

In[8]:= MaxMemoryUsed[]

Out[8]= 5544518752

With table step size .05

In[8]:= MaxMemoryUsed[]

Out[8]= 2923990656

With table step size.1

In[8]:= MaxMemoryUsed[]

Out[8]= 1614277072

With table step size .2

In[8]:= MaxMemoryUsed[]

Out[8]= 959420360

Those numbers will likely be somewhat different on the Pi. And you will need to look at the documentation for how memory use is reported when using parallel kernels. But the results will probably be close enough to this that the answer will be the same.

So it appears that you need at least 6 gigabytes free to do this. I suppose what is really needed is for someone to build a Raspberry Pi with 64 gigabytes and supported by Mathematica. I'd sign up for a handful of those.

POSTED BY: Bill Simpson

you should save a sequence of images (every frame 1 file). And then (with a fresh kernel) you might be able to read those back in, and put them together to an AVI, or use other software... Also you could copy the images to your computer and assemble it their using quicktime or ffmpeg or windows moviemaker or .........

POSTED BY: Sander Huisman

Why would you run it in parallel? That will take #numberofkernels times more memory. And you could add $HistoryLength = 1 at the start, so it will only remember the last output.

Perhaps it is better to first save the frames separately, and then using (either Mathematica or another piece of software ffmpeg?) combine them to a movie. In order to make a movie you need all the frames in memory which is generally a lot of MBs.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract