[petsc-users] Reusing ML preconditioner

Barry Smith bsmith at mcs.anl.gov
Wed Jun 29 21:38:34 CDT 2011


On Jun 29, 2011, at 10:50 AM, John Fettig wrote:

> I'm trying to reuse a ML preconditioner but it's not working
> correctly.  The A matrix is changing (even being destroyed), so here's
> what I do:
> 
> 1) The first time I'm setting up the KSP, I duplicate the A matrix
> with MatDuplicate and pass it to the KSP:
>   MatDuplicate(Amat,MAT_COPY_VALUES,&Pmat);
>   KSPSetOperators( ksp, Amat, Pmat, SAME_PRECONDITIONER );
> 
> 2) I call KSPSolve, then Amat gets destroyed.  The KSP persists.

> 
> 3) The next time through, I follow the instructions on the manpage for
> KSPSetOperators and do the following, note that Amat is a totally
> different matrix:
> 
>              Mat tmp_A, tmp_P;
>              MatStructure tmp_flag;
> 
>              KSPGetOperators(ksp,&tmp_A,&tmp_P,&tmp_flag);
>              PetscObjectReference((PetscObject)(tmp_P));
>              KSPSetOperators( ksp, new_Amat, tmp_P, SAME_PRECONDITIONER );
> 
> However it doesn't work.  The iteration count is too high (I verified
> through a slower method that the preconditioner is still good for
> new_Amat).  What am I doing wrong?

   What do you mean a slower method? How can you verify that it is still a good preconditioner without actually running the old preconditioner on the new matrix.

    BTW: You don't need that complicated stuff above. Just do 

    KSPSetOperators( ksp, Amat, Amat, SAME_PRECONDITIONER );
    KSPSolve().
    change Amat, or destroy it and make a new one
    KSPSetOperators( ksp, Amat, Amat, SAME_PRECONDITIONER );
    KSPSolve().

    It will solve the new linear system using the old preconditioner built during the first KSPSolve(). There is no reason to pass in the old version of Amat you copied to Pmat

    I suspect that the linear system changes more than you think and that the old preconditioner simply isn't good enough for the new system.

   Barry


> 
> Thanks,
> John



More information about the petsc-users mailing list