[petsc-users] preallocation after DMCreateMatrix?

Matteo Semplice matteo.semplice at unito.it
Fri Nov 24 15:21:55 CST 2017


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.

How should I interpret that note in the manual?

Thanks,

     Matteo



More information about the petsc-users mailing list