MathGroup Archive 2008

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

Search the Archive

Re: help with "no more memory" at mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91051] Re: help with "no more memory" at mathematica
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 4 Aug 2008 03:26:43 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g73u1c$nhd$1@smc.vnet.net>

lopmart wrote:

> we have the next code in mathematica 6, when we use n = 200  we get
> the next error
> 
> 
> h = Import["h.dat"]; v = Import["v.dat"];
> n = 200
> 
> 
>  MSE2 =
>   Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] -
>         h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] +
>    Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] +
>    Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}];
> 
>  s1 = Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i,
>      1, (n*n) - 1}];
> 
> s3 = SparseArray[
>    Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i,
>      1, (n*n) - 1}]];
> ar = ArrayRules[s3];
> Export["matrix1.txt", ar];
> 
> b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]]]];

*Erroneous Code Above*: Either you do not want a table or Table is 
missing a counter. So you must choose between,

   b = SparseArray[Table[Simplify[-1*D[s1, a[1, 1]]], {Some_Counter} ]]

or

   b = SparseArray[Simplify[-1*D[s1, a[1, 1]]]]


> b2 = ArrayRules[b];["B.txt", b2];

??? What ["B.txt", b2] is supposed to do? As written it is a nonsense. 
Perhaps you had in mind Export["B.txt", b2]?

> No more memory available.
> Mathematica kernel has shut down.
> Try quitting other applications and then retry.
> 
> How to solve?

So, what do you try to compute?

Could you post an example (or give a description) of h.dat and v.dat?

The tests I have done (with own interpretation -- assumptions about -- 
the code you posted) shows that the matrices matrix1.txt and B.txt are 
dense (the files contain rules, but since there is a rule for each 
matrix entry, we can hardly claim that the matrices are sparse). Does 
this matches your own results?

Module[{h, v, MSE2, s1, s3, sr, b2, a},
  For[n = 10, n <= 400, n *= 2, Print["n: ", n, ", CPU: ",
    Timing[
      h = RandomReal[{0, n}, {n, n}];
      v = RandomReal[{0, n}, {n, n}];
      MSE2 =
       Sum[(a[i - 1, j] - v[[i, j]] a[i, j])^2 + (a[i, j - 1] -
             h[[i, j]] a[i, j])^2, {i, 2, n}, {j, 2, n}] +
        Sum[(a[1, j - 1] - h[[1, j]] a[1, j])^2, {j, 2, n}] +
        Sum[(a[i - 1, 1] - v[[i, 1]] a[i, 1])^2, {i, 2, n}];
      s1 =
       Table[Simplify[D[MSE2, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i,
         1, (n*n) - 1}];
      s3 =
       SparseArray[
        Table[Simplify[D[s1, a[Floor[i/n] + 1, Mod[i, n] + 1]]], {i,
          1, (n*n) - 1}]];
      ar = ArrayRules[s3];
      Export["matrix1_n" <> ToString[n] <> ".txt", ar];
      b = SparseArray[Simplify[-1*D[s1, a[1, 1]]]];
      b2 = ArrayRules[b];
      Export["B_n" <> ToString[n] <> ".txt", b2];][[1]],
    " s, Max mem used: ", MaxMemoryUsed[]/2^20 // Round,
    " MB, Mem in use: ", MemoryInUse[]/2^20 // Round, " MB"]]]

n: 10, CPU: 0.309607 s, Max mem used: 18 MB, Mem in use: 18 MB

n: 20, CPU: 3.2838 s, Max mem used: 21 MB, Mem in use: 20 MB

n: 40, CPU: 45.3366 s, Max mem used: 42 MB, Mem in use: 23 MB

n: 80, CPU: 574.157 s, Max mem used: 345 MB, Mem in use: 37 MB

[... I stopped the evaluation here ...]

Regards,
-- Jean-Marc


  • Prev by Date: Re: Sending Objects from Java - Mathematica
  • Next by Date: Re: Manipulate with specified step size
  • Previous by thread: Re: help with "no more memory" at mathematica
  • Next by thread: Missing Posts