[petsc-users] preallocation after DMCreateMatrix?

Smith, Barry F. bsmith at mcs.anl.gov
Fri Nov 24 17:21:42 CST 2017



> On Nov 24, 2017, at 1:21 PM, Matteo Semplice <matteo.semplice at unito.it> wrote:
> 
> Hi.
> 
> The manual for DMCreateMatrix says "Notes: This properly preallocates the number of nonzeros in the sparse matrix so you do not need to do it yourself", so I got the impression that one does not need to call the preallocation routine for the matrix and indeed in most examples listed in the manual page for DMCreateMatrix this is not done or (KSP tutorial ex4) it is called declaring 0 entries per row.
> 
> However, if read in a mesh in a DMPlex ore create a DMDA and then call DMCreateMatrix, the resulting matrix errors out when I call MatSetValues. I have currently followed the suggestion of the error message and call MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE), but I'd like to fix this properly.

  With DMDA for sure it preallocates properly respecting the stencil width and periodicity you define. If it requires additional entries than you are putting in values outside the stencil width. For example if normally you have a stencil width of 1 and set it for the DMDA but you put in matrix entries for a stencil width of 2 at the boundary it will error out.

  Barry

> 
> How should I interpret that note in the manual?
> 
> Thanks,
> 
>     Matteo
> 



More information about the petsc-users mailing list