help-octave
[Top][All Lists]

## Re: same mem problem

 From: John W. Eaton Subject: Re: same mem problem Date: Tue, 8 Feb 2000 22:19:19 -0600 (CST)

```On  0-Feb-, Erich Schneider <address@hidden> wrote:

| Try this code and watch the memory usage:
|
| clear;
| f5hs3=rand(570,720)*5000;
| f5ls3=rand(570,720)*5000+1;
| C=-636.73*(f5hs3-f5ls3)./f5ls3-0.079098*f5hs3+332.15;
| clear f5ls3;
| [m,n]=size(f5hs3);
| C_temp1=C(2:2:m,2:2:n);
| clear C;
| C_temp=C_temp1(:);
| clear C_temp1;
| average=mean(C_temp(find(f5hs3(2:2:m,2:2:n)<3400)))
| clear C_temp;
|
| You could even subdivide the calculation for C into something like:
|
| c1 = f5hs3-f5ls3;
| c2 = -636.73.*c1./f5ls3;
| clear c1;
| C = c2+332.15-0.079098.*f5hs3;
| clear c2;
|
| I'm using 2.0.13, too, but couldn't reproduce your error when running
| your script repeatedly. It seems to me that for the calculation of C
| octave is storing 2 additional temporary matrices.

If you mean the calculation of

C=-636.73*(f5hs3-f5ls3)./f5ls3-0.079098*f5hs3+332.15;

then I think the best Octave can do is

t1 = (f5hs3-f5ls3)
t2 = -636.73*t1
t1 = t2 ./ f5ls3
t2 = 0.079098*f5hs3
t3 = t1 - t2
t1 = t3 + 332.15;
C = t1 # just some reference counting magic; elements are not acutally copied

so yes, it takes some temporary storage.  Octave doesn't try to
optimize this operation into one loop.  If you can do that, please
submit a patch!  AFAIK, it would not be trivial...

| I saw the following behaviour of octave 2.0.13 and .14:
|
| a=ones(8000000,1);
| a=ones(8000000,1);
| memory exhausted bla ...
| b=ones(4000000,1);
| c=ones(4000000,1);
|
| If memory is exhausted then why can I execute the steps for b and c?

The `memory exhausted' message means
that there wasn't enough memory available to satisfy the request, not
that there is no more memory available.  So it is not surprising that
the allocation for `b' succeeded after you tried to allocate two
8000000x1 matrices (two, because Octave doesn't delete the contents of
the left-hand side of the assignment until the right-hand side has
been evaluated; this is a feature, not a bug).  It's hard to say why
the allocation for `c' also succeeded without knowing more about what
might have been happening on your system at the time.  Perhaps some
memory was freed by some other process and that allowed your
allocation to succeed?

jwe

-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------

```