4

everyone,

I'm trying to do some calculations and plot the results, but it seems that these are too heavy for Maxima. When I try to calculate N1 and N2 the program crashes when parameter j is too high or when I try to plot them, the program displays the following error message: "Heap exhausted, game over." What should I do? I've seen some people saying to try to compile Maxima with ccl, but I don't know how to do it or if it will work.

I usually receive error messages like:

Message from maxima's stderr stream: Heap exhausted during garbage collection: 0 bytes available, 16     requested. 
Gen  Boxed Unboxed   LgBox LgUnbox  Pin       Alloc     Waste        Trig      WP GCs Mem-age 
 0       0       0       0       0    0           0         0    20971520       0   0  0,0000 
 1       0       0       0       0    0           0         0    20971520       0   0  0,0000 
 2       0       0       0       0    0           0         0    20971520       0   0  0,0000 
 3   16417       2       0       0   43  1075328496    707088   293986768   16419   1  0,8032 
 4   13432      21       0    1141   70   955593760    838624     2000000   14594   0  0,2673 
 5       0       0       0       0    0           0         0     2000000       0   0  0,0000 
 6     741     184      34      28    0    63259792   1424240     2000000     987   0  0,0000 
 7       0       0       0       0    0           0         0     2000000       0   0  0,0000 
           Total bytes allocated    =    2094182048 
           Dynamic-space-size bytes =    2097152000 
GC control variables: 
   *GC-INHIBIT* = true 
   *GC-PENDING* = true 
   *STOP-FOR-GC-PENDING* = false 
fatal error encountered in SBCL pid 13884(tid 0000000001236360): 
Heap exhausted, game over. 

Here goes the code:

enter code here

a: 80$;
b: 6*a$;
h1: 80$;
t: 2$;
j: 5$;
carga: 250$;
sig: -carga/2$;

n: 2*q*%pi/b$;
m: i*%pi/a$;
i: 2*p-1$;
i1: 2*p1-1$;
/*i1: p1$;*/

Φ: a/b$;
τ: cosh(x) - (x/sinh(x))$;
σ: sinh(x) - (x/cosh(x))$;
Ψ: sinh(x)/τ$;
Χ: cosh(x)/σ$;

Λ0: 1/(((i/2)^2+Φ^2*q^2)^2)$;
Λ1: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ0, p, 1, j)$;
Λ2: sum(((q1^3*subst([x=(q1*%pi*Φ)],Χ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ1, q1, 1, j)$;
Λ3: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ2, p, 1, j)$;
Λ4: sum(((q1^3*subst([x=(q1*%pi*Φ)],Χ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ3, q1, 1, j)$;
Λ5: sum((((i/2)^3*subst([x=(i*%pi/(2*Φ))],Ψ))/(((i/2)^2+Φ^2*q1^2)^2))*Λ4, p, 1, j)$;

Ζ0: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ0, q, 1, j)$;
Ζ2: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ2, q, 1, j)$;
Ζ4: sum(((q^3*subst([x=(q*%pi*Φ)],Χ))/(((i1/2)^2+Φ^2*q^2)^2))*Λ4, q, 1, j)$;

E: 200000$;
ν: 0.3$;
λ: (ν*E)/((1+ν)*(1-2*ν))$;
μ: E/(2*(1+ν))$;

a0: float(1/(b/2)*integrate(0, y, -(b/2), -h1/2)+1/b*integrate(sig, y, -h1/2,     h1/2)+1/(b/2)*integrate(0, y, h1/2, (b/2)))$;
aq: float(1/(b/2)*integrate(0*cos(q*y*%pi/(b/2)), y, -(b/2), - h1/2)+1/(b/2)*integrate(sig*cos(q*y*%pi/(b/2)), y, -h1/2, h1/2)+1/(b/2)*integrate(0*cos(q*y*%pi/(b/2)),   y, h1/2, (b/2)))$;
aq1: float(1/(b/2)*integrate(0*cos(q1*y*%pi/(b/2)), y, -(b/2), - h1/2)+1/(b/2)*integrate(sig*cos(q1*y*%pi/(b/2)), y, -h1/2,   h1/2)+1/(b/2)*integrate(0*cos(q1*y*%pi/(b/2)), y, h1/2, (b/2)))$;

Bq:  aq/((λ+μ)*subst([x=q*%pi*Φ],σ))+((16*Φ^4*q^2*(-1)^q)/((λ+μ)*%pi^2*sub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+μ)*sum(βp*((1+((m*b*cosh(m*b/2))/(2*sinh(m*b/2))))*cosh(m*y)-m*y*sinh(m*y))*sin(m*x),p,1,j);

wxplot3d(N1, [x,-a/2,a/2], [y,-b/2,b/2])$;

wxplot3d(N2, [x,-a/2,a/2], [y,-b/2,b/2])$;
Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • 2
    You are hitting the SBCL heap size limit, which in this case appears to be 2GB. Assuming your machine has more memory than this, you can increase the heap size limit substantially, which may get you through. To to this when running SBCL you use `--dynamic-space-size `: I have no idea how you persuade Maxima to do that however (which is why this is a comment not an answer). –  Feb 23 '20 at 14:28
  • Sorry for the question, but how do I use it? – Mateus Nogueira Feb 23 '20 at 22:27
  • My advice is to try to narrow down which operation is causing trouble. How far do you get before running out of memory? Can you figure out which is the last operation which is completed successfully? It may be possible to work around the problem by allocating more memory, however, the problem may be related to factoring very large expressions or something like that, for which allocating more memory might just mean it runs longer before failing. You might wish to post a message on the Maxima mailing list. See: https://sourceforge.net/projects/maxima/lists/maxima-discuss – Robert Dodier Feb 25 '20 at 00:28

3 Answers3

4

This is not a complete answer, since I don't know how this should work with wxMaxima: I would suggest that you ask the developers. However it's too long for a comment and I think might be useful to people, and it does answer the question of how you solve the heap-size limit for Maxima itself when using SBCL, at least when run on Linux or some other platform with a command-line.

As a note, I suspect that the underlying problem is not the heap size, but that the calculation is blowing up in some horrible way: the best fix is probably to understand what's blowing up and fix that. See Robert Dodier's answer, which is probably going to be a lot more helpful. However, if heap size is the problem, this is how you deal with it for Maxima.

The trick is that you can tell SBCL what the heap limit should be by passing it the --dynamic-space-size <MB> argument, and you can pas arguments through the maxima wrapper to do this.

Here is a transcript of Maxima, being run on Linux, with SBCL as a back end (this is a version built from source: the packaged version will I assume be the same):

$ maxima
Maxima 5.43.2 http://maxima.sourceforge.net
using Lisp SBCL 2.0.0
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (sb-ext:dynamic-space-size)

1073741824

So, on this system the defaule heap limit is 1GB (this is SBCL's default limit on the platform).

Now we can pass the -X <lisp options> aka --lisp-options=<lisp options> option to the maxima wrapper to pass the appropriate option through to sbcl:

$ maxima -X '--dynamic-space-size 2000'
Lisp options: (--dynamic-space-size 2000)
Maxima 5.43.2 http://maxima.sourceforge.net
using Lisp SBCL 2.0.0
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (sb-ext:dynamic-space-size)

2097152000

As you can see this has doubled the heap size.


If someone knows the answer for wxMaxima then please do add an edit to this answer: I can't experiment it because all my Linux VMs are headless.

1

Also not a complete answer here, but some more notes and pointers which I hope will help.

To make the problem easier for Maxima to digest, use only exact numbers (integers and ratios), and avoid float and numer. (Plotting functions will apply float and numer automatically.) I changed 0.3 to 3/10 and cut out the calls to float.

Also, try setting j to a smaller number (I tried j equal to 1) to try to work all the way through the problem before increasing it to 5 again.

Also, replace all sum and integrate with 'sum and 'integrate (i.e. noun expressions instead of verb expressions). Take a look at the summands and integrands to see if they look right. You can evaluate the sums and/or integrals or both via ev(expr, sum) or ev(expr, integrate) or ev(expr, nouns) to evaluate 'sum, 'integrate, or all noun expressions, respectively.

With j equal to 1, I get the following expression for N1:

(2500000*((-(13*cosh(%pi/6)
               *((8503056*cosh(%pi/6)^2*sinh(3*%pi)^2)
                /(9765625*%pi^4
                         *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
                         *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
                +(52488*cosh(%pi/6)*sinh(3*%pi))
                 /(15625*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                        *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
                +324/25))
         /(120000*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                 *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))))
         +(13*sinh(3*%pi)
             *((2754990144*cosh(%pi/6)^3*sinh(3*%pi)^2)
              /(244140625*%pi^4
                         *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^3
                         *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
              +(17006112*cosh(%pi/6)^2*sinh(3*%pi))
               /(390625*%pi^2
                       *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
                       *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
              +(104976*cosh(%pi/6))
               /(625*(sinh(%pi/6)-%pi/(6*cosh(%pi/6))))))
          /(22680000*%pi^2*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
         +13/(35000*%pi^2*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))))
        *sin((%pi*(2*p-1)*x)/80)
        *((%pi*(2*p-1)*y*sinh((%pi*(2*p-1)*y)/80))/80
         +(1-(3*%pi*(2*p-1)*cosh(3*%pi*(2*p-1)))
             /sinh(3*%pi*(2*p-1)))
          *cosh((%pi*(2*p-1)*y)/80)))
 /13
 +(2500000*((-(13*cosh(%pi/6)
                 *((344373768*cosh(%pi/6)^2*sinh(3*%pi)^3)
                  /(244140625*%pi^4
                             *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                              ^2
                             *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))
                              ^3)
                  +(2125764*cosh(%pi/6)*sinh(3*%pi)^2)
                   /(390625*%pi^2
                           *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                           *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
                  +(13122*sinh(3*%pi))
                   /(625*(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))))
           /(1620000*%pi^3*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2))
           +(13*sinh(3*%pi)
               *((8503056*cosh(%pi/6)^2*sinh(3*%pi)^2)
                /(9765625*%pi^4
                         *(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))^2
                         *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi))^2)
                +(52488*cosh(%pi/6)*sinh(3*%pi))
                 /(15625*%pi^2*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                        *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
                +324/25))
            /(3780000*%pi^3*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))
                     *(cosh(3*%pi)-(3*%pi)/sinh(3*%pi)))
           -13/(20000*%pi*(sinh(%pi/6)-%pi/(6*cosh(%pi/6)))))
          *(((%pi*sinh(%pi/6))/(6*cosh(%pi/6))+1)
           *sinh((%pi*x)/240)
           -(%pi*x*cosh((%pi*x)/240))/240)*cos((%pi*y)/240))
  /13-(25*x)/48$

Now in order to plot that, it should be a function of x and y only. However listofvars reports that it contains x, y, and p. Hmm. I see that βp has a summation over p1 but it contains Ζ0, which contains Λ0, which contains p. Is the summation over p1 supposed to be over p? Is the summand supposed to contain p1 instead of p?

Likewise it appears that N2, after evaluating the sums and integrals with j equal to 1, contains p.

Maybe you need to rework the formulas somewhat? I don't know what the correct form might be.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
0

In addition to the answer of user5920214:

wxMaxima manual, in section 3.13, deals with the heap size limit problem:

3.13 My sbcl-based maxima runs out of memory

One way to provide maxima (and thus sbcl) with command line parameters is the additional parameters field of wxMaxima’s configuration dialogue.

Vickel
  • 7,879
  • 6
  • 35
  • 56