[petsc-users] MatColoring

Barry Smith bsmith at petsc.dev
Tue May 10 11:35:54 CDT 2022

  This depends to some degree on how you are accessing applying the Jacobian construction process. 

   If you are using SNES or TS then the SNES object handles most of the work of organizing the PETSc objects needed to compute the Jacobian and you can control the choices via the options database. 

   With SNES/TS using a DM you can skip calling SNESSetJacobian() and simply use the option -snes_fd_color to have SNES compute the Jacobian for you. By default, the coloring is obtained from the DM (which is generally the best available coloring), you can have it use a coloring computed directly from the matrix structure with the options -snes_fd_color_use_mat -mat_coloring_type  jp power sl lf ld or greedy (see MatColoringType, MatColoringSetFromOptions) Use  -mat_fd_coloring_view to get information on the computation of the Jacobian from the coloring. Use  -mat_coloring_view to get information on the coloring used. (see MatFDColoringSetFromOptions)

  If you are using SNES/TS but not using a DM you need to compute the nonzero structure of the matrix yourself into J and call SNESSetJacobian(snes,J,J,SNESComputeJacobianDefaultColor,matfdcoloring); you need to create the matfdcoloring object with MatFDColoringCreate() using an iscoloring you obtained with MatColoringCreate() etc.  The same command line arguments as above allow you to control the coloring algorithm used and to view them etc.


> On May 10, 2022, at 11:40 AM, Jorti, Zakariae via petsc-users <petsc-users at mcs.anl.gov> wrote:
> Hi, 
> I am solving a non-linear problem and using a finite difference approximation with coloring to compute the Jacobian matrix.
> There are several coloring algorithms available in PETSc as indicated here:
> https://petsc.org/release/docs/manualpages/Mat/MatColoring.html <https://petsc.org/release/docs/manualpages/Mat/MatColoring.html>
> And I was wondering how to switch from one to another in the Jacobian setup routine and also how to check which coloring algorithm I am currently using.
> Thank you.
> Zakariae Jorti

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220510/bbe70944/attachment.html>

More information about the petsc-users mailing list