Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Out of Memory
Date: Fri, 3 Apr 2009 18:22:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 57
Message-ID: <gr5k49$akq$1@fred.mathworks.com>
References: <gr5ega$t7f$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1238782921 10906 172.30.248.35 (3 Apr 2009 18:22:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 3 Apr 2009 18:22:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1786892
Xref: news.mathworks.com comp.soft-sys.matlab:530131


"Derek O'Connor" <derekroconnor@eircom.net> wrote in message <gr5ega$t7f$1@fred.mathworks.com>...
> Can anyone explain the following behavior on a 16GB machine. Notice that the memory error occurs in two different places : `plus' and 'mtimes'.
> 
> >> clear all;
> 
> >> n = 2.5*10^4;
> 
> % --- GBytes = 8*n^2/10^9;
> 
> % --- Memory needed for each nxn matrix = 5GB;
> 
> >> C = rand(n,n);  D = rand(n,n);
> 
> % ---  WTM records total memory in use 12.6GB.  2.6 (OS + ?) +(5+5) matrices: checks
> 
> >> whos
>   Name          Size                    Bytes  Class     Attributes
> 
>   C         25000x25000            5000000000  double              
>   D         25000x25000            5000000000  double              
>   n             1x1                         8  double              
> 
> >> memory
> Maximum possible array:               3498 MB (3.667e+009 bytes) *
> Memory available for all arrays:      3498 MB (3.667e+009 bytes) *
> Memory used by MATLAB:                9929 MB (1.041e+010 bytes)
> Physical Memory (RAM):               16381 MB (1.718e+010 bytes)
> 
> 
> >> C = 2*C;
> ??? Error using ==> mtimes
> Out of memory. Type HELP MEMORY for your options
> 
> >> C = C+C;
> ??? Error using ==> plus
> Out of memory. Type HELP MEMORY for your options.
> 
> for i = 1:n, for j = 1:n, C(i,j) = 2*C(i,j);end;end;  % --- works ok ---
> >> % --- Interrupted at keyboard after 5mins ---
> 
> >>for i = 1:n, for j = 1:n, C(i,j) = C(i,j)+C(i,j);end;end;  % --- works ok ---
> >> % --- Interrupted at keyboard after 5mins ---
> 
> >> ver
> -------------------------------------------------------------------------------------
> MATLAB Version 7.6.0.324 (R2008a)
> MATLAB License Number: 
> Operating System: Microsoft Windows Vista Version 6.0 (Build 6001: Service Pack 1)
> Java VM Version: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
> -------------------------------------------------------------------------------------
> 
> Derek O'Connor

Well, even if you would not compute those operations you are near the limit of your phisical ram just with matrix storage ... and that's not the best for ram performance. Second, there are large possibilities that you don't need all that amount of data, because those that really need don't have these problems =))) 
Whatever, in the C= operations(C) istruction you need a copy of C, so your extimated memory usage would be 15 gb at least, and crumbs waste memory too...  
Third, if you really want to work with all those data try to load only some data in memory and keep the whole matrix in a file, 
and last, you really need a double random number? Try to recast to something less expensive.