开发者

SystemCache and MemoryInUse - can anyone explain this behavior?

This question is inspired by the question on memory leaks in Mathematica due to internal caching of results of intermediate computations. All these things are undocumented but are important for anyone who runs memory-intensive computations.

When trying to understand the logic of the internal caching mechanism I found something interesting. Consider the following:

$HistoryLength = 0;
(*dummy command for loading of the Root package*)
Root[# &, 1];
d = 13;
f[z_, i_] := Sum[(2 Mod[Floor[(i - 1)/2^k], 2] - 1) z^(d - k), {k, 0, d}];
(memLog = Flatten[
     Table[Root[f[z, i], j]; {SessionTime[], MemoryInUse[]/1024.^2}, {j, 1, 
       d}, {i, 1, 2^d}], 1];) // Timing
pl1 = ListLinePlot[memLog, 
  FrameLabel -> {"SessionTime, sec", "MemoryInUse, Mb"}, PlotRange -> All, 
  Frame -> True, Axes -> False]
pl2 = ListLinePlot[memLog[[All, 2]], 
  FrameLabel -> {"Point", "MemoryInUse, Mb"}, PlotRange -> All, Frame -> True,
   Axes -> False]

In fresh kernel session the output on my machine (Mathematica 7.0.1 for Windows) is always as follows:

SystemCache and MemoryInUse - can anyone explain this behavior?

Can a开发者_Python百科nyone explain why there is a break of the curve near the point number 8400?


The point at which the change in slope occurs is no. 8192. This equals 2^13, which is the upper bound of the fastest of your Table indices, i. When mma arrives at this point it has calculated all possible f[z, i] values. Since this call is independent of j, the next value of j (2) will generate the same range (f[z, 1], ..., f[z, 8192]) again. I assume this is where internal caching kicks in and fewer additional memory is needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜