Since hand-coding routines for Jacobian and Hessian matrix evaluation can be error prone, SNES provides easy-to-use support for checking these matrices against finite difference versions. In the simplest form of comparison, users can employ the option -snes_type test to compare the matrices at several points. Although not exhaustive, this test will generally catch obvious problems. One can compare the elements of the two matrices by using the option -snes_test_display , which causes the two matrices to be printed to the screen.
Another means for verifying the correctness of a code for Jacobian or Hessian computation is running the problem with either the finite difference or matrix-free variant, -snes_fd or -snes_mf. see Section Finite Difference Jacobian Approximations or Section Matrix-Free Methods ). If a problem converges well with these matrix approximations but not with a user-provided routine, the problem probably lies with the hand-coded matrix.