Question on matrix preallocation

Matthew Knepley knepley at gmail.com
Thu May 8 09:43:19 CDT 2008


You are assembling before inserting values. This wipes out the preallocation
information since assembly shrinks the matrix to an optimal size.

  Matt

On Thu, May 8, 2008 at 9:07 AM, Tobias Neckel <neckel at in.tum.de> wrote:
> 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
>
>  14:33:53 debug    petsc::PETScLibTest::testMatPreallocation()
> start PETSc mat preallocation test
>  [0] PetscCommDuplicate(): Duplicating a communicator 1140850688 -2080374784
> max tags = 2147483647
>  [0] MatAssemblyEnd_SeqAIJ(): Matrix size: 4 X 4; storage space: 10
> unneeded,0 used
>  [0] MatAssemblyEnd_SeqAIJ(): Number of mallocs during MatSetValues() is 0
>  [0] MatAssemblyEnd_SeqAIJ(): Maximum nonzeros in any row is 0
>  [0] Mat_CheckInode(): Found 1 nodes of 4. Limit used: 5. Using Inode
> routines
>  [0] MatAssemblyEnd_SeqAIJ(): Matrix size: 4 X 4; storage space: 14
> unneeded,1 used
>  [0] MatAssemblyEnd_SeqAIJ(): Number of mallocs during MatSetValues() is 1
>  [0] MatAssemblyEnd_SeqAIJ(): Maximum nonzeros in any row is 1
>  [0] Mat_CheckInode(): Found 2 nodes of 4. Limit used: 5. Using Inode
> routines
>   14:33:53 debug    petsc::PETScLibTest::testMatPreallocation()
> stop PETSc mat preallocation test
>
>
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which
their experiments lead.
-- Norbert Wiener




More information about the petsc-users mailing list