Question on matrix preallocation

Tobias Neckel neckel at in.tum.de
Thu May 8 09:07:32 CDT 2008


Hello,

when using petsc (version 2.3.2 on a linux 32bit Intel architecture) to 
set up a serial sparse linear system of equations, I recently noticed 
the well-known allocation performance problem: The matrix setup needs 
more memory than preallocated with a fixed number of column entries for 
all rows.
Thus, I switched to the strategy described in the Users Manual (first 
counting the number of matrix entries for each row individually and then 
  using the nnz parameter in MatCreateSeqAIJ()). But this did not change 
the dynamic allocation behaviour at all.

Therefore, I tried to bring everything down to a (very) small test 
example. I set up a nnz-1D-array of type int and length 4 which holds 
the number of expected non-zero column entries for each row of a matrix 
(in particular 2 columns in row 0). Using this nnz-array, I create a 4x4 
matrix. Afterwards, I set the entry (0,0) of the matrix to a non-zero 
value.
The source code part for this simple test can be found in the attached 
file testMatPreallocation.cpp.

When I run this test (with the additional -info runtime option), the one 
and only matrix entry setting results in an additional memory allocation
(see attached file commandLineOutput.txt)!

This is quite surprising, as I would have expected enough preallocated 
memory for the matrix, which is also visible from the output. Am I 
misusing or missing something necessary to make the preallocation work?

Thanks in advance for any hints,
best regards
Tobias Neckel

-- 
Dipl.-Tech. Math. Tobias Neckel

Institut für Informatik V, TU München
Boltzmannstr. 3, 85748 Garching

Tel.:   089/289-18602
Email:  neckel at in.tum.de
URL:    http://www5.in.tum.de/persons/neckel.html
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: commandLineOutput.txt
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20080508/f84c74ad/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testMatPreallocation.cpp
Type: text/x-c++src
Size: 1693 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20080508/f84c74ad/attachment.cpp>


More information about the petsc-users mailing list