[petsc-users] Mat preallocation in case of variable stencils
Jed Brown
jed at jedbrown.org
Tue Aug 31 10:32:21 CDT 2021
Matteo Semplice <matteo.semplice at uninsubria.it> writes:
> Hi.
>
> We are writing a code for a FD scheme on an irregular domain and thus
> the local stencil is quite variable: we have inner nodes, boundary nodes
> and inactive nodes, each with their own stencil type and offset with
> respect to the grid node. We currently create a matrix with
> DMCreateMatrix on a DMDA and for now have set the option
> MAT_NEW_NONZERO_LOCATIONS to PETSC_TRUE, but its time to render the code
> memory-efficient. The layout created automatically is correct for inner
> nodes, wrong for boundary ones (off-centered stencils) and redundant for
> outer nodes.
>
> After the preprocessing stage (including stencil creation) we'd be in
> position to set the nonzero pattern properly.
>
> Do we need to start from a Mat created by CreateMatrix? Or is it ok to
> call DMCreateMatrix (so that the splitting among CPUs and the block size
> are set by PETSc) and then call a MatSetPreallocation routine?
You can call MatXAIJSetPreallocation after. It'll handle all matrix types so you don't have to shepherd data for all the specific preallocations.
> Also, I've seen in some examples that you call the Seq and the MPI
> preallocation routines in a row. Does this work because
> MatMPIAIJSetPreallocation silently does nothing on a Seq matrix and
> viceversa?
>
> Thanks
>
> Matteo
More information about the petsc-users
mailing list