<div class="gmail_quote">On Thu, Mar 17, 2011 at 05:16, Gu Shiyuan <span dir="ltr"><<a href="mailto:gshy2014@gmail.com">gshy2014@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div> I want to solve a linear eq. Kx=b where K is changed at each time step and the preconditioner is a shell function and doesn't change. After I change K, do I need to explicitly call KSP/PCSetOperator again to reset the matrix inside the KSP solver? </div>
<div>Does KSP hold copies of the matrices or just pointers to the matrices? </div><div>i.e., </div><div><br></div><div>PCSetOperator(pc,K,K,SAME_PRECONDITIONER);</div></blockquote><div><br></div><div>It is "PCSetOperators". SAME_PRECONDITIONER means that the PC will not be updated for the new matrix.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div> ..............///other setup</div><div>KSPSolve(..);</div>
<div>...........////change K;</div><div>/////////Is PCSetOperator(......) needed here?</div></blockquote><div><br></div><div>You should be calling KSPSetOperators() to inform the KSP that the operator has changed. Rebuilding the preconditioner is a separate matter which you control using the MatStructure flag.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><br></div><div>And what about if I want to change the preconditioner? do I need to destroy the PC/KSP object and re-create and setup everything?</div>
</blockquote><div><br></div><div>No, when you pass in SAME_NONZERO_PATTERN, numeric factorization is performed again using the same data structures. With DIFFERENT_NONZERO_PATTERN, some internal structures are reallocated. For many preconditioners, there is very little performance difference between these.</div>
<div><br></div><div>If you want to change the type of the preconditioner, just call PCSetType(). This will free things like ILU factors and then switch to the new PCType.</div></div>