Re: Garbage collection problem
- To: mathgroup at smc.vnet.net
- Subject: [mg51852] Re: Garbage collection problem
- From: sean_incali at yahoo.com (sean kim)
- Date: Wed, 3 Nov 2004 01:26:03 -0500 (EST)
- References: <cm7d0u$lho$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
flank the routine in Module[] and keep things local.
In[13]:=
(* Setup *)
run[do_]:=Do[
Module[{},
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; ],
{do}]
(* end *)
In[20]:=
run[2000];
MemoryInUse[]
Out[21]=
2944448
In[24]:=
run[2];
MemoryInUse[]
Out[25]=
2944448
D Herring <dherring at at.uiuc.dot.edu> wrote in message news:<cm7d0u$lho$1 at smc.vnet.net>...
> 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