# Help with adding a new routine to the MATMFFD module

Barry Smith bsmith at mcs.anl.gov
Thu Jan 8 17:51:42 CST 2009

```   You are doing everything right; there must be a glitch along the way.

First run in the debugger and put a breakpoint in
MatMFFDRegisterAll() make sure the code gets there.
Then step through while it does the dynamic registration of the new
method and make sure everything
looks reasonable along the way.

Barry

On Jan 8, 2009, at 5:42 PM, Rafael Santos Coelho wrote:

> Hello everyone,
>
> I've implemented a new routine for computing the differencing
> parameter "h" used with the finite-difference based matrix-free
> Jacobian by the MATMFFD module. This new approach, which I labeled
> "avg", can be found in the article entitled "Jacobian-free Newton-
> Krylov methods: a survey of approaches and applications", authored
> by D. A. Knoll and D. E. Keyes. It has the following formula:
>
> h = b * {[S / (n * || a ||)] + 1}
>
> 	• "b" is the square root of the machine round-off (10^-6 for 64-bit
> double precision);
> 	• "n" is the problem dimension (number of unknowns);
> 	• "a" is the vector in the Jacobian-vector product that is being
> approximated (J(U)a);
> 	• "S" = sum[i = 1, n] |Ui| is the sum of the absolute values of the
> solution vector entries.
> Well, the programming part is all done and correct, but I'm
> experiecing difficulties to (statically) incorporate the routine in
> the PETSc API. I've done everything that I could, but whenever I try
> to test my code by running an example with the -mat_mffd_type avg
> command-line option, I get this error message:
>
> {PETSC_DIR}/petsc-2.3.3-p15/src/snes/examples/tutorials\$ mpirun -np
> 2 ./ex5 -snes_mf -mat_mffd_type avg
> [1]PETSC ERROR: --------------------- Error Message
> ------------------------------------
> [1]PETSC ERROR: Unknown type. Check for miss-spelling or missing
> external package needed for type!
> [1]PETSC ERROR: Unknown MatMFFD type avg given!
> [1]PETSC ERROR:
> ------------------------------------------------------------------------
> [1]PETSC ERROR: Petsc Release Version 2.3.3, Patch 15, Tue Sep 23
> 10:02:49 CDT 2008 HG revision:
> 31306062cd1a6f6a2496fccb4878f485c9b91760
> [1]PETSC ERROR: See docs/changes/index.html for recent updates.
> [1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
> [1]PETSC ERROR: See docs/index.html for manual pages.
> [1]PETSC ERROR:
> ------------------------------------------------------------------------
> [1]PETSC ERROR: ./ex5 on a linux-gnu named hepburn by rafael Thu
> Jan  8 19:52:36 2009
> [1]PETSC ERROR: Libraries linked from /home/rafael/ufes/petsc-2.3.3-
> p15/lib/linux-gnu-c-debug
> [1]PETSC ERROR: Configure run at Sun Nov 23 02:11:51 2008
> [1]PETSC ERROR: Configure options --with-cc=mpicc --with-cxx=mpicxx
> --with-fc=0 --download-c-blas-lapack=1 --with-shared=0
> [1]PETSC ERROR:
> ------------------------------------------------------------------------
> [1]PETSC ERROR: MatMFFDSetType() line 107 in src/mat/impls/mffd/mffd.c
> [1]PETSC ERROR: MatMFFDSetFromOptions() line 493 in src/mat/impls/
> mffd/mffd.c
> [1]PETSC ERROR: SNESSetUp() line 1194 in src/snes/interface/snes.c
> [1]PETSC ERROR: SNESSolve() line 1855 in src/snes/interface/snes.c
> [1]PETSC ERROR: main() line 209 in src/snes/examples/tutorials/ex5.c
> [hepburn:22928] MPI_ABORT invoked on rank 1 in communicator
> MPI_COMM_WORLD with errorcode 86
> [0]PETSC ERROR: --------------------- Error Message
> ------------------------------------
> [0]PETSC ERROR: Unknown type. Check for miss-spelling or missing
> external package needed for type!
> [0]PETSC ERROR: Unknown MatMFFD type avg given!
> [0]PETSC ERROR:
> ------------------------------------------------------------------------
>
> So, here's what I did:
>
> 	• Put the source code (avg.c) in the {PETSC_DIR}/src/mat/impls/
> mffd/ directory (when writing the avg.c, I basically followed the
> same code structure in the wp.c file);
> 	• Added "avg.c" and "avg.o" to {PETSC_DIR}/src/mat/impls/mffd/
> makefile;
> 	• Added the macro "#define MATMFFD_AVG "avg"" to the petscmat.h file;
> 	• Called MatMFFDRegisterDynamic(MATMFFD_AVG, path,
> "MatMFFDCreate_AVG", MatMFFDCreate_AVG) inside the
> MatMFFDRegisterAll routine in the mfregis.c file.
> What step am I missing here? Why is this not working? Thanks in
> advance!
>
> Rafael
>

```

More information about the petsc-users mailing list