[petsc-users] Setting/creating Mats for SNES use

Jed Brown jed at jedbrown.org
Mon Nov 2 14:39:09 CST 2015


Justin Chang <jychang48 at gmail.com> writes:

> Hi all,
>
> In my DMPlex program, I have these lines:
>
> Mat A,J;
>
> ...
>
> ierr = DMSetMatType(dm, MATAIJ); CHKERRQ(ierr);
> ierr = DMCreateMatrix(dm, &J); CHKERRQ(ierr);
> A = J;
>
> ierr = DMSNESSetFunctionLocal(dm, ...); CHKERRQ(ierr);
> ierr = DMSNESSetJacobianLocal(dm, ...); CHKERRQ(ierr);
> ierr = SNESSetJacobian(snes, A, J, NULL, NULL); CHKERRQ(ierr);
> ierr = SNESSetFromOptions(snes); CHKERRQ(ierr);
>
> ...
>
> ierr = SNESSolve(snes, NULL, x); CHKERRQ(ierr);
>
> ...
> ierr = MatDestroy(&J); CHKERRQ(ierr);
>
>
> For the line "A = J;", 

This means you have two handles referring to the same object.

> what exactly is the difference, if any, between that and "ierr =
> MatDuplicate(...)" 

This creates a new object.

> or "ierr = MatCopy(...)"? 

The second argument needs to be a valid Mat to call this function.

> Do these different options somehow affect memory usage/performance?

Yes.

> Say I am solving a standard poisson equation using either GAMG and/or
> HYPRE.
>
> Thanks,
> Justin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20151102/a2b9355c/attachment.pgp>


More information about the petsc-users mailing list