On Mon, May 7, 2012 at 2:15 PM, <span dir="ltr"><<a href="mailto:coco@dmi.unict.it" target="_blank">coco@dmi.unict.it</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear all,<br>
<br>
I am trying to use a matrix-free method to solve a linear system with Petsc. In particular, I noticed that if I solve the same linear system with the same KSP solver, the same preconditioner, and the same options, I obtain different convergence results if I solve the system with the full- or free-matrix method. Is that plausible?<br>
</blockquote><div><br></div><div>Always always always use -ksp_view to see what you are actually doing. The default for actual matrices is ILU(0), since we can</div><div>calculate it. The default for Shell matrices is nothing, since we have no matrix to calculate from. Thus, the inferior convergence.</div>
<div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here is a piece of code:<br>
<br>
//Method #1:<br>
ierr=MatCreate(PETSC_COMM_<u></u>WORLD,&M); CHKERRQ(ierr);<br>
ierr=MatSetType(M, MATMPIAIJ); CHKERRQ(ierr);<br>
ierr=MatSetSizes(M,PETSC_<u></u>DECIDE,PETSC_DECIDE,N,M); CHKERRQ(ierr);<br>
[...filling the matrix...]<br>
ierr = KSPCreate(PETSC_COMM_WORLD,&<u></u>ksp);CHKERRQ(ierr);<br>
ierr = KSPSetOperators(ksp,M,M,<u></u>DIFFERENT_NONZERO_PATTERN);<u></u>CHKERRQ(ierr);<br>
ierr = KSPSetTolerances(ksp,1.e-12,<u></u>PETSC_DEFAULT,PETSC_DEFAULT,<u></u>PETSC_DEFAULT);CHKERRQ(ierr);<br>
ierr = KSPSolve(ksp,RHS,U);CHKERRQ(<u></u>ierr);<br>
<br>
//Method #2:<br>
extern PetscErrorCode UserMult(Mat,Vec,Vec);<br>
ierr=MatCreateShell(PETSC_<u></u>COMM_WORLD,N,M,n,M,ctx,&M1); CHKERRQ(ierr);<br>
ierr=MatShellSetOperation(M,<u></u>MATOP_MULT,(void(*)(void)) UserMult); CHKERRQ(ierr);<br>
ierr=MatAssemblyBegin(M,MAT_<u></u>FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
ierr=MatAssemblyEnd(M,MAT_<u></u>FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
ierr = KSPCreate(PETSC_COMM_WORLD,&<u></u>ksp1);CHKERRQ(ierr);<br>
ierr = KSPSetOperators(ksp1,M1,M1,<u></u>DIFFERENT_NONZERO_PATTERN);<u></u>CHKERRQ(ierr);<br>
ierr = KSPSetTolerances(ksp1,1.e-12,<u></u>PETSC_DEFAULT,PETSC_DEFAULT,<u></u>PETSC_DEFAULT);CHKERRQ(ierr);<br>
ierr = KSPSolve(ksp1,RHS,U1);CHKERRQ(<u></u>ierr);<br>
<br>
In particular, the method #1 converges in 15 iterations, while the method #2 in more than 1000.<br>
<br>
Thank you in advance.<br>
Armando<br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>