[petsc-users] Question about Matrix Free

behzad baghapour behzad.baghapour at gmail.com
Sun Jun 24 13:40:28 CDT 2012


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
}

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120624/2ead6a41/attachment.html>


More information about the petsc-users mailing list