[petsc-users] snes setjacobian with csr sparse matrix

Adolfo Rodriguez adantra at gmail.com
Tue Jul 21 11:37:44 CDT 2020


Thanks! That worked.

On Mon, Jul 20, 2020 at 11:10 AM Barry Smith <bsmith at petsc.dev> wrote:

>
>    If you are running sequentially you likely want the first routine, in
> parallel the third routine.
>
> MatCreateSeqAIJWithArrays()
> PETSC_EXTERN PetscErrorCode MatSeqAIJSetPreallocationCSR(Mat,const
> PetscInt [],const PetscInt [],const PetscScalar []);
> PETSC_EXTERN PetscErrorCode MatMPIAIJSetPreallocationCSR(Mat,const
> PetscInt[],const PetscInt[],const PetscScalar[]);
>
>
> PETSC_EXTERN PetscErrorCode
> MatSeqBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const
> PetscInt[],const PetscScalar[]);
> PETSC_EXTERN PetscErrorCode
> MatMPIBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const
> PetscInt[],const PetscScalar[]);
> PETSC_EXTERN PetscErrorCode
> MatSeqSBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const
> PetscInt[],const PetscScalar[]);
> PETSC_EXTERN PetscErrorCode
> MatMPISBAIJSetPreallocationCSR(Mat,PetscInt,const PetscInt[],const
> PetscInt[],const PetscScalar[]);
>
>
>
> > On Jul 20, 2020, at 7:38 AM, Adolfo Rodriguez <adantra at gmail.com> wrote:
> >
> > 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.
> >
> > 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200721/dbebec67/attachment.html>


More information about the petsc-users mailing list