[petsc-users] questions about matrix preallocation

Jed Brown jedbrown at mcs.anl.gov
Thu Nov 24 07:36:59 CST 2011


On Thu, Nov 24, 2011 at 07:33, Dominik Szczerba <dominik at itis.ethz.ch>wrote:

> MatCreateMPIAIJ(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, NTOT,
> NTOT, 500, PETSC_NULL, 500, PETSC_NULL, &A);
>
> (with 500 a big overshoot)
>
> then I do in a loop:
>
> 1. ierr = MatMPIAIJSetPreallocation(A, 500, PETSC_NULL, 500,
> PETSC_NULL); CHKERRQ(ierr);
> 2. ierr = MatZeroEntries(A); CHKERRQ(ierr);
>
> Line 1. does not matter the first time in the loop, info.mallocs is
> always 0, but if it is commented out, info.mallocs is non-zero the
> second time loop is executed.
> So I am confused, is the preallocation in MatCreateMPIAIJ not
> sufficient? Does it need to be refreshed?
>

You must be changing the number of nonzeros in each iteration of the loop.

I suggest assembling all possible entries (even the ones that happen to be
zero) in the first assembly. Then there will be space and you can reuse the
data structure.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111124/9b80bc0e/attachment.htm>


More information about the petsc-users mailing list