[petsc-users] questions about matrix preallocation

Dominik Szczerba dominik at itis.ethz.ch
Thu Nov 24 07:33:51 CST 2011


>> A was preallocated during creation, but unless I call
>> MatMPIAIJSetPreallocation after MatZeroEntries, I get a lot of unneded
>> mallocs.
>
> That should not happen. Perhaps the type was not set in your original
> preallocation, but this function does not change allocation.

I create A only once as:

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?

Thanks
Dominik


More information about the petsc-users mailing list