[petsc-users] questions about matrix preallocation

Jed Brown jedbrown at mcs.anl.gov
Thu Nov 24 07:22:28 CST 2011


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

> In any case, I use KSPSetOperators(ksp, A, A, SAME_NONZERO_PATTERN).
>
> 1) If I provide only approximation for number of zeros per row (d_nz
> and o_nz) and I overshoot - will the extra memory still be there or is
> automatically freed?
>

It will still be there, but the data structure is compacted so that the
"holes" are all at the very end of the arrays, so it does not influence
performance at all. Reallocating and copying would cause much higher peak
memory usage, so it's usually not desirable.


>
> 2) Do I need to MatMPIAIJSetPreallocation() after MatZeroEntries(A)?
>

No


> MatZeroEntries man page says:
>
> If the matrix was not preallocated then a default, likely poor
> preallocation will be set in the matrix, so this should be called
> after the preallocation phase.
>
> 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.

PetscErrorCode MatZeroEntries_SeqAIJ(Mat A)
{
  Mat_SeqAIJ     *a = (Mat_SeqAIJ*)A->data;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr =
PetscMemzero(a->a,(a->i[A->rmap->n])*sizeof(PetscScalar));CHKERRQ(ierr);
  a->idiagvalid  = PETSC_FALSE;
  a->ibdiagvalid = PETSC_FALSE;
  PetscFunctionReturn(0);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20111124/9dc321e2/attachment-0001.htm>


More information about the petsc-users mailing list