Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: create large sparse FEM matrix --> out of memory
Date: Mon, 10 Aug 2009 15:40:36 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 25
Message-ID: <h5pf1k$qit$1@fred.mathworks.com>
References: <h5pbe7$nc2$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1249918836 27229 172.30.248.37 (10 Aug 2009 15:40:36 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 10 Aug 2009 15:40:36 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:562145


"A B" <gitsnedbutzi@hotmail.com> wrote in message <h5pbe7$nc2$1@fred.mathworks.com>...
> Hi,
> 
> I'm writing a FEM application and need to create large sparse matrices.
> 
> Unfortunately I run out of memory pretty soon, so I need to know how to write a more memory efficient code in MATLAB.
> 
> Here's what I do at the moment to create the stiffness matrix:
> 
> I know the number of elements and the size of a single element matrix. I use this information to preallocate the memory for three vectors, storing
> *row index
> *column index
> *value
> 
> Then I calculate the element matrices and start filling up those three vectors with the appropriate information and finally K = sparse(row,col,val) for assembling the global matrix.
> 
> Now I've got a system with 25 000 elements resulting in a length of about 80million entries for each vector. With 1300MB of free memory MATLAB can't even create the vectors and stops with a "out of memory" error.

There is something odd about the description. With a system of 25000 elements and 80e6 non-null entries, that means each of the element has in average 80e6/25e3 = 3200. That doesn't sound right. The average ratio should be about 10 depends on the element type you use, but in no way it could reaches 3200. 

To store " three double vectors of 80e9, you need 80e6*3*8 bytes = 1.9 Gbytes, and the resulting sparse matrix need about 80e6*2*8 = 1.3 Gbytes (i think). The total required memory is 3.2 Gbytes. I'm not surprised it does not fit into you 1.3 Gbytes memory.

The 80e6 non-zeros entries does not sound right to me.

Bruno