Garbage collection problem
- To: mathgroup at smc.vnet.net
- Subject: [mg51803] Garbage collection problem
- From: D Herring <dherring at at.uiuc.dot.edu>
- Date: Tue, 2 Nov 2004 02:06:06 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
To anyone who can help me,
I've written a small simulator to model the system I'm studying. It
works nicely. Now I'm wrapping that simulator in a set of Do[] loops to
generate maps of its behavior. Unfortunately, long runs quickly fill my
512MB of RAM, even when dumping all my data to files as it is generated.
After a good bit of debugging, I have isolated (at least half of of) the
memory problem to my use of a StoppingTest inside NDSolve.
Example:
(* Setup *)
eq={9.8*(0.99*Cos[qS[t]] + 0.01*Cos[qH[t] + qS[t]]) -
0.01*Sin[qH[t]]*qH'[t]*qS'[t] -
0.01*Sin[qH[t]]*
qH'[t]*(qH'[t] + qS'[t]) + (0.001 + 0.01*Cos[qH[t]])*
qH''[t] + (0.982 + 0.02*Cos[qH[t]])*qS''[t] == 0,
0.1*Cos[qH[t] + qS[t]] + 0.01*Sin[qH[t]]*qS'[t]^2 +
0.001*qH''[t] + (0.001 + 0.01*Cos[qH[t]])*qS''[t] == 0,
qS[0] == 1.71,
qS'[0] == -1.01,
qH[0] == 2.84,
qH'[0] == 1.1};
vars={qS[t], qH[t], qS'[t], qH'[t]};
test=qH[t] >= Pi &&
2*Cos[qH[t]/2]*Cos[qH[t]/2 + qS[t]]*Sin[Pi/180] +
Cos[Pi/180]*(Cos[qS[t]]*Sin[qH[t]] + (1 + Cos[qH[t]])*
Sin[qS[t]]) < -0.01 &&
Cos[qH[t] + qS[t]]*
Derivative[1][qH][t] + (Cos[qS[t]] + Cos[qH[t] + qS[t]])*
Derivative[1][qS][t] < -0.01 || Abs[qH[t]] < Pi/6 ||
Sin[qS[t]] < 1/4;
$HistoryLength=0;
(* end *)
(* example a *)
Do[
soln=NDSolve[eq,vars,{t,0,2}][[1]];
,
{20}];
MemoryInUse[]
(* end *)
(* example b *)
Do[
soln=NDSolve[eq,vars,{t,0,2},StoppingTest->test][[1]];
,
{20}];
MemoryInUse[]
(* end *)
To reproduce this, start a fresh kernel. Execute the setup code, and
then repeatedly run example a or b. When I repeatedly run example a,
MemoryInUse[] quickly converges to a constant value, as expected.
However, each run of example b results in an increase in memory
consumption. Why? How can I fix/avoid this behavior? I stripped out
some other logic, but all I really want are a few numbers from the last
several "soln"s of each run, to observe convergence properties.
FWIW, I'm running on $Version=5.0 for Linux (November 18, 2003)
Thanks,
Daniel