Hello<br><br>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:<br>
<pre>PetscErrorCode PETSCMAT_DLLEXPORT MatMFFDSetFunction(Mat mat,PetscErrorCode (*func)(void*,Vec,Vec),void *funcctx)<br></pre><br>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. <br>
<br>I&#39;m doing this in Fortran, so I really don&#39;t know what argument &quot;void *&quot; should correspond to?<br><br>Currently my code looks like this:<br><br>! Setup Matrix-Free dRdw matrix<br>call MatCreateMFFD(sumb_comm_world,nDimW,nDimW,&amp;<br>
       PETSC_DETERMINE,PETSC_DETERMINE,dRdw,ierr)<br> <br>call MatMFFDSetFunction(dRdw,FormFunction2,ctx,ierr)<br>call MatAssemblyBegin(dRdw,MAT_FINAL_ASSEMBLY,ierr)<br>call MatAssemblyEnd(dRdw,MAT_FINAL_ASSEMBLY,ierr)<br>
<br>The function prototype for FormFunction2 is:<br><br>subroutine FormFunction2(mfmat,wVec,rVec,ierr)<br>  Mat     mfmat<br>  Vec     wVec, rVec<br>  PetscInt ierr<br>end subroutine FormFunction2<br><br>When I try to use this in a KSP linear solve I get the following tracsback:<br>
<br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>
[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/petsc-as/documentation/troubleshooting.html#Signal[0]PETSC">http://www.mcs.anl.gov/petsc/petsc-as/documentation/troubleshooting.html#Signal[0]PETSC</a> ERROR: or try <a href="http://valgrind.org">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>
[0]PETSC ERROR: likely location of problem given in stack below<br>[0]PETSC ERROR: ---------------------  Stack Frames ------------------------------------<br>[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,<br>
[0]PETSC ERROR:       INSTEAD the line number of the start of the function<br>[0]PETSC ERROR:       is given.<br>[0]PETSC ERROR: [0] MatMult line 1877 src/mat/interface/matrix.c<br>[0]PETSC ERROR: [0] PCApplyBAorAB line 540 src/ksp/pc/interface/precon.c<br>
[0]PETSC ERROR: [0] GMREScycle line 132 src/ksp/ksp/impls/gmres/gmres.c<br>[0]PETSC ERROR: [0] KSPSolve_GMRES line 227 src/ksp/ksp/impls/gmres/gmres.c<br><br>If I use KSPPREONLY it works fine.<br><br>Thank you,<br><br>Gaetan<br>