[petsc-users] Sparse Matrix preallocation and performance

Matthew Knepley knepley at gmail.com
Thu Apr 7 08:15:40 CDT 2011


On Thu, Apr 7, 2011 at 8:04 AM, Bartłomiej W <bartlomiej.wach at yahoo.pl>wrote:

> Hello,
>
> Wheather I use
>
>   ierr = MatCreate(PETSC_COMM_WORLD,&L);CHKERRQ(ierr);
>   ierr = MatSetSizes(L,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);
>              MatSeqAIJSetPreallocation(L,PETSC_NULL,nnz);
>   ierr = MatSetFromOptions(L);CHKERRQ(ierr);
>

Move SetPreallocation() after SetFromOptions(). Here is what happens:

  SetFromOptions() will give the matrix a type, since it does not have one
already

  Since the matrix had no type before SetPreallocation(), the call was
ignored

     Matt


> or
>
>
>   ierr =
> MatCreateSeqAIJ(PETSC_COMM_WORLD,n,n,PETSC_DEFAULT,nnz,&L);CHKERRQ(ierr);
>   ierr = MatSetFromOptions(L);CHKERRQ(ierr);
>
> Gives me
>
>    Number of mallocs during MatSetValues() is  X
>
> On matrix assembly, where X is positive
> Is this indicating the preallocation or should it be zero and I'm missing
> something?
>
> Moreover, using MatCreateSeqAIJ lowers the performance of MatSetValues
>
> Is my code improper?
>
> Regards
> Bartłomiej Wach
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110407/88df624a/attachment-0001.htm>


More information about the petsc-users mailing list