Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Another Out of Memory Problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91322] Re: Another Out of Memory Problem
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 15 Aug 2008 06:54:35 -0400 (EDT)
  • References: <g8137j$19$1@smc.vnet.net> <48A42D4D.7060504@gmail.com>

On Thu, Aug 14, 2008 at 6:58 PM, Kevin J. McCann  wrote:
> Jean-Marc,
>
> Thanks for the detailed analysis. I am not sure what I will do about it. I
> guess I can rationalize the coefficients.
>
> Kevin

Unfortunately, I am afraid that it might be not that simple or
straightforward depending on the "complexity" or "size" of the
rational numbers generated.

For instance, using different approximations/rationalizations to
2.718281828, Mathematica reaches 2 GB of memory in less than 20 s,
about 42 s, and never when fed with 1633527/600941, 15062/5541, and
193/71, respectively, as coefficients of x.

So you may have to monitor the behavior of Integrate and fine tune
accordingly the second parameter of Rationalize to find the best
comprise among memory consumption, performances, and accuracy of the
result.


IIn[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-12]

Out[1]= E^(I*z*Cos[x])*Cos[(1633527*x)/600941]

In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30,
  "More than 2 GB required"] // Timing

Out[2]= {19.8789, "More than 2 GB required"}

In[3]:= MaxMemoryUsed[]/2.^30 GB

Out[3]= 2.02337 GB

In[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-7]

Out[1]= E^(I*z*Cos[x])*Cos[(15062*x)/5541]

In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30,
  "More than 2 GB required"] // Timing

Out[2]= {42.521, "More than 2 GB required"}

In[3]:= MaxMemoryUsed[]/2.^30 GB

Out[3]= 2.01026 GB

In[1]:= f = Rationalize[Cos[2.718281828*x]*Exp[I*z*Cos[x]], 10^-4]

Out[1]= E^(I*z*Cos[x])*Cos[(193*x)/71]

In[2]:= MemoryConstrained[Integrate[f, {x, -Pi, Pi}], 2 2^30,
  "More than 2 GB required"] // Timing

Out[2]= $Aborted (* After one hour -- elapsed time *)

In[3]:= MaxMemoryUsed[]/2.^30 GB

Out[3]= 0.41452 GB


Best regards,
- Jean-Marc


> Jean-Marc Gulliet wrote:
>
> On Thu, Aug 14, 2008 at 3:08 PM, Kevin J. McCann wrote:
>
>
>
> Thanks, Jean-Marc. I still find it strange that it runs out of memory and so
> fast. The error message comes up within less than 1 second.
>
>
> [... Cross-posted on MathGroup ...]
>
> Kevin,
>
> I have just tried to do the integration with approximate coefficient
> on my system (64-bit Intel Core 2 Duo 4 GB RAM Mac OS X Leopard 1.5.4
> Mathematica 6.0.3).
>
> . On this 64-bit platform, the kernel does not crash: the expression
> returns unevaluated after about four minutes elapsed-time (or about
> two minutes cpu-time)
>
> . However, the computation takes up to about 2.2 GB of memory, which
> is fine on a 64-bit system but is too much on a standard 32-bit
> platform
>
> . Also, I have observed thanks to the command Top (UNIX/Mac OS X shell
> command) that the memory consumption varies/oscillates quickly from
> nearly nothing (few dozens of MB) to one or two GB in a fraction of
> second
>
> . OTOH, with exact coeffiecients, the integration consumes about 200
> MB of memory (steady increase from the beginning to the end, no wild
> variations, as far as I can tell), though the process is seven time
> slower
>
> So it seems that the algorithm goes wild when used with approximate
> numbers, for reasons I am clueless about.
>
> (* Timing and memory consumption with *floating-point* coefficients *)
>
> In[1]:= Integrate[Cos[2.5*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing
>
> Out[1]=
>                      I z Cos[x]
> {112.795, Integrate[E           Cos[2.5 x], {x, -Pi, Pi}]}
>
> In[2]:= MaxMemoryUsed[]/2.^30 GB
>
> Out[2]= 2.19748 GB
>
> In[3]:= $Version
>
> Out[3]= "6.0 for Mac OS X x86 (64-bit) (May 21, 2008)"
>
> (* Timing and memory consumption with *exact* coefficients *)
>
> In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}] // Timing
>
> Out[1]=
>                      I z Cos[x]     5 x
> {705.092, Integrate[E           Cos[---], {x, -Pi, Pi}]}
>                                      2
>
> In[2]:= MaxMemoryUsed[]/2.^30 GB
>
> Out[2]= 0.191426 GB
>
> In[3]:= $Version
>
> Out[3]= "6.0 for Mac OS X x86 (64-bit) (May 21, 2008)"
>
> Best regards,
> -- Jean-Marc
>
>
>
> Kevin
>
> Jean-Marc Gulliet wrote:
>
>
> Kevin J. McCann wrote:
>
>
>
> I can do the following:
>
> Integrate[Cos[2*x]*
>      Exp[I*z*Cos[x]],
>    {x, -Pi, Pi}]
>
>
> which produces a Bessel function answer; however if I change the
> argument in the cosine to 2.5 as in:
>
> Integrate[Cos[2.5*x]*
>      Exp[I*z*Cos[x]],
>    {x, -Pi, Pi}]
>
> I almost immediately get this:
>
> No more memory available.
> Mathematica kernel has shut down.
> Try quitting other applications and then retry.
>
> Any ideas why? I am running XP with 2Gb of memory.
>
>
> When using symbolic function (i.e. Integrate rather than NIntegrate, Solve
> rather than NSolve, etc.) it is always a good idea to feed the function with
> *exact* (infinite precision) numbers, thus 5/2 rather 2.5 in your case.
> (Mathematica does not find any closed form for your integrand. Note that it
> take a while to compute but memory consumption is under control.)
>
> In[1]:= Integrate[Cos[5/2*x]*Exp[I*z*Cos[x]], {x, -Pi, Pi}]
>
> Out[1]=
>
>           I z Cos[x]     5 x
> Integrate[E           Cos[---], {x, -Pi, Pi}]
>                           2


  • Prev by Date: Re: NDSolve precision and velocity problem
  • Next by Date: Re: ODE in mathematica. what is wrong?
  • Previous by thread: Re: Another Out of Memory Problem
  • Next by thread: Re: Another Out of Memory Problem