[petsc-users] PETSc MatMFFDSetFunction Function
Gaetan Kenway
kenway at utias.utoronto.ca
Wed Feb 9 17:43:59 CST 2011
Hello
I was wondering what the user supplied function is supposed to look like for
setting the function in MatMFFDSetFunction. I am trying to use a Matrix-Free
Matrix for a linear Krylov Solver. The website says:
PetscErrorCode PETSCMAT_DLLEXPORT MatMFFDSetFunction(Mat
mat,PetscErrorCode (*func)(void*,Vec,Vec),void *funcctx)
This indicates the function should have the calling sequence: (void
*,Vec,Vec). Since there are zero examples of actually using this function,
what exactly is the sequence? I gather that the second and third arguments
are Vec x and Vec y where x is the input and y is the output, but what is
the void * supposed to be.
I'm doing this in Fortran, so I really don't know what argument "void *"
should correspond to?
Currently my code looks like this:
! Setup Matrix-Free dRdw matrix
call MatCreateMFFD(sumb_comm_world,nDimW,nDimW,&
PETSC_DETERMINE,PETSC_DETERMINE,dRdw,ierr)
call MatMFFDSetFunction(dRdw,FormFunction2,ctx,ierr)
call MatAssemblyBegin(dRdw,MAT_FINAL_ASSEMBLY,ierr)
call MatAssemblyEnd(dRdw,MAT_FINAL_ASSEMBLY,ierr)
The function prototype for FormFunction2 is:
subroutine FormFunction2(mfmat,wVec,rVec,ierr)
Mat mfmat
Vec wVec, rVec
PetscInt ierr
end subroutine FormFunction2
When I try to use this in a KSP linear solve I get the following tracsback:
[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation,
probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see
http://www.mcs.anl.gov/petsc/petsc-as/documentation/troubleshooting.html#Signal[0]PETSCERROR:
or try
http://valgrind.org on GNU/linux and Apple Mac OS X to find memory
corruption errors
[0]PETSC ERROR: likely location of problem given in stack below
[0]PETSC ERROR: --------------------- Stack Frames
------------------------------------
[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,
[0]PETSC ERROR: INSTEAD the line number of the start of the function
[0]PETSC ERROR: is given.
[0]PETSC ERROR: [0] MatMult line 1877 src/mat/interface/matrix.c
[0]PETSC ERROR: [0] PCApplyBAorAB line 540 src/ksp/pc/interface/precon.c
[0]PETSC ERROR: [0] GMREScycle line 132 src/ksp/ksp/impls/gmres/gmres.c
[0]PETSC ERROR: [0] KSPSolve_GMRES line 227 src/ksp/ksp/impls/gmres/gmres.c
If I use KSPPREONLY it works fine.
Thank you,
Gaetan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110209/72ed653f/attachment.htm>
More information about the petsc-users
mailing list