[petsc-users] Question about Matrix Free

Matthew Knepley knepley at gmail.com
Sun Jun 24 13:53:20 CDT 2012


On Sun, Jun 24, 2012 at 12:40 PM, behzad baghapour <
behzad.baghapour at gmail.com> wrote:

> Dear developers,
>
> I want to define matrix operation used in SNES as Matrix-Free kernel. Here
> is what I did:
>
>         MatCreateSNESMF( snes, &JMat );
>         MatCreateShell( PETSC_COMM_SELF, nt, nt, nt, nt, (void*)&FC, &JMat
> );
>         MatShellSetOperation( JMat, MATOP_MULT,
> (void(*)())&_petsc_matMultFree );
>
> Where FC is my context which saves the flow field data. In the matrix-Free
> kernel:
>
> void solver::_petsc_matMultFree( Mat J, Vec x, Vec y )
> {
>     MatShellGetContext( J, &FC );
> // perturb the residual ( R -> R(x+eps) )
> // do matrix-vector kernel as: y := Mx = Mass/dt + ( R2 - R1 ) / eps
> }
>

This does not have the right signature (no return type).

   Matt


> But I received the error at first subspace creation in KSP:
>
> [0]PETSC ERROR: MatMult() line 2177 in src/mat/interface/matrix.c
> [0]PETSC ERROR: PCApplyBAorAB() line 610 in src/ksp/pc/interface/precon.c
> [0]PETSC ERROR: GMREScycle() line 156 in src/ksp/ksp/impls/gmres/gmres.c
> [0]PETSC ERROR: KSPSolve_GMRES() line 231 in
> src/ksp/ksp/impls/gmres/gmres.c
> [0]PETSC ERROR: KSPSolve() line 423 in src/ksp/ksp/interface/itfunc.c
> [0]PETSC ERROR: SNES_KSPSolve() line 3396 in src/snes/interface/snes.c
> [0]PETSC ERROR: SNESSolve_LS() line 190 in src/snes/impls/ls/ls.c
> [0]PETSC ERROR: SNESSolve() line 2676 in src/snes/interface/snes.c
> [0]PETSC ERROR: _petsc_NewtonTimeAdvance() line 151 in Newton.cpp
>
> Would you please help me find my mistake ?
>
> Thanks a lot,
> BehZad
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120624/a7ff6e85/attachment.html>


More information about the petsc-users mailing list