[petsc-users] snes setjacobian with csr sparse matrix

Jed Brown jed at jedbrown.org
Mon Jul 20 08:28:06 CDT 2020


Adolfo Rodriguez <adantra at gmail.com> writes:

> I am trying to use PETSc to solve a non-linear problem. The problem I am
> facing is that I already have the Jacobian matrix formed in CSR format. Now
> I am trying to define a function FormJacobian which takes this preexisting
> matrix and writes it in PETSc format. For a small problem, I can use
> MatSetValue, looping over all non-zero elements one at a time. However,
> this turns out too slow for larger problems.

Best to call MatSetValues once per row.  If the matrix is preallocated, it should not be slow.  Check

https://www.mcs.anl.gov/petsc/documentation/faq.html#efficient-assembly

> In my current implementation, I am using MatCreateSeqAIJ which works great.
> However, this approach does not seem to work to set the Jacobian.
>
> Any suggestions?
>
> Regards,
>
> Adolfo


More information about the petsc-users mailing list