[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on matrix preallocation
- To: petsc-users@xxxxxxxxxxx
- Subject: Re: Question on matrix preallocation
- From: "Matthew Knepley" <knepley@xxxxxxxxx>
- Date: Thu, 8 May 2008 09:43:19 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=ePRdPPv/SwFaheNAxWiiQGLgHWRCnhAC0z6vBOuFK6Y=; b=Min5+kDQkvy6qCrY+TaxEYBylf41k8qAJadRmdD9H4q0PEafNFs4+PBk4Rav/8OKp/ibiXnenUjrwaPqg/bpa1W3rWJtBlrhAQabtIzE9/vsY+ZkrFPRKNM/WhBovPjNtwF83anb8VdMe8mvIDQjc5s/hrh3N0X2evuUFTUIcxY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JfD1Qd4uGcAoUdWRtp+s2+VD3KXnN/hrLkyCbm/bPFwEpAIl0vlX2XRHGiJ9PyXOrrBggGZCLVkElF/fdZjN7VffyfqI2ztuScHWyiAbCl8/RhbYKvTJG51u9SbDFPyk6l2Vo5Y5IfHVDR7Ar8dI5dTJGplFPChiH1BUx5PmV+0=
- In-reply-to: <48230924.7040600@in.tum.de>
- References: <48230924.7040600@in.tum.de>
- Reply-to: petsc-users@xxxxxxxxxxx
- Sender: owner-petsc-users@xxxxxxxxxxx
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@xxxxxxxxx> 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@xxxxxxxxx
> 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