how to get the best solution

Barry Smith bsmith at mcs.anl.gov
Wed May 3 14:22:24 CDT 2006


   Etienne,

     One thing to note, most PETSc KSP methods by default use the norm of
the PRECONDITIONED residual (as opposed to the true b - Ax residual). So
just picking the solution with the best "residual" may not be what you want.
See the manual pages for KSPSetNormType() and KSPSetPreconditionerSide().
Also, GMRES for example, only computes an "estimate" of the residual, which
often gets wrong for very ill-conditioned problems.

   To try to answer your question: You can use KSPSetMonitor() to provide your
function that checks the current norm against the best so far. If it is better then
the best so far it copies over the solution into a buffer. You can put the "best
so far" and buffer inside a C struct that you pass into KSPSetMonitor.

   Sadly, this may still not be a good solution. GMRES, for example, does not
actually COMPUTE the solution at each iteration; it only computes it at restarts 
and when KSPSolve() ends. You need to call KSPBuildSolution() to get the 
current solution that you put into the buffer. Alternatively you could call
the solver twice, locating the lowest norm in the first run and then collecting the
solution from that location in the second run. Again not a great solution.

   My recommendation for very ill-conditioned problems with no good preconditioner/solver;
use a direct method if at all possible. Sparse direct methods can now solve upwards
of a million unknowns. Yes it is slow and uses LOTS of memory but usually it works.

   Barry


On Wed, 3 May 2006, DevTeam wrote:

> Hi all,
> I'm a newbie with PetSc so sorry if it is a well known question (I've seen nothing in the  mailing archive).
>
> I have a linear system wich is qui ill conditionned. So whatever solver and preconditionner I use convergence is a bit chaotic
> and it use to quit the solver when the maximum number of iteration has been reached with the last residual.
>
> Last residual that is never the best residual found during the whole convergence path. Is there a way to get this best solution from PetSc ?
>
> Thanks,
> Etienne Perchat
>




More information about the petsc-users mailing list