[petsc-users] Reusing ML preconditioner

Barry Smith bsmith at mcs.anl.gov
Wed Jun 29 22:01:56 CDT 2011


  John,

   The MatCreateSeqAIJWithArrays() uses the memory (arrays) that you provide so you cannot free those arrays or muck with them until you are finished with the solve.

   What happens if you ALWAYS copy with MatDuplicate() the MatCreate*WithArrays() matrix immediately after you create it and use that matrix as I describe below in the setoperators? Does it start behaving like 
the 1) MatSetValues()  or does it still behave "badly"?

    Barry

On Jun 29, 2011, at 9:54 PM, John Fettig wrote:

> On Wed, Jun 29, 2011 at 10:38 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>>   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.
> 
> I have two equivalent ways of building the matrix: 1) MatSetValues,
> (standard route) 2) MatCreate*WithArrays.  Both routines produce
> identical matrices and identical solutions.  However, if I run with
> version 1), the preconditioner is pretty good for many solves.  If I
> run with version 2), the preconditioner only works well for a couple
> of solves.
> 
>>    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 tried this and it works ok for a couple of solves (a couple of
> nonlinear iterations), but on the next timestep it takes a lot more
> iterations than what I referenced above as version 1).  The total
> KSPSolve time in version 1) strongly indicates to me that it is indeed
> using the old preconditioner.
> 
> Thanks,
> John



More information about the petsc-users mailing list