[petsc-users] KSP has an extra iteration when use shell matrix

Yi Hu y.hu at mpie.de
Tue Jan 30 14:19:18 CST 2024


Hello Barry,

Thanks for your reply. The monitor options are fine. I actually meant my 
modification of snes tutorial ex1f.F90 does not work and has some 
unexpected behavior. I basically wanted to test if I can use a shell 
matrix as my jacobian (code is here 
https://github.com/hyharry/small_petsc_test/blob/master/test_shell_jac/ex1f.F90). 
After compile my modified version and run with these monitor options, it 
gives me the following,

  ( in rhs )
  ( leave rhs )
   0 SNES Function norm 6.041522986797e+00
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 6.041522986797e+00
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 5.065392549852e-16
   Linear solve converged due to CONVERGED_RTOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
   1 SNES Function norm 3.512662245652e+00
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 3.512662245652e+00
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 6.230314124713e-16
   Linear solve converged due to CONVERGED_RTOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   2 SNES Function norm 8.969285922373e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 8.969285922373e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 0.000000000000e+00
   Linear solve converged due to CONVERGED_ATOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   3 SNES Function norm 4.863816734540e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 4.863816734540e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 0.000000000000e+00
   Linear solve converged due to CONVERGED_ATOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   4 SNES Function norm 3.512070785520e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 3.512070785520e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 0.000000000000e+00
   Linear solve converged due to CONVERGED_ATOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   5 SNES Function norm 2.769700293115e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 2.769700293115e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 1.104778916974e-16
   Linear solve converged due to CONVERGED_RTOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   6 SNES Function norm 2.055345318150e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 2.055345318150e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 0.000000000000e+00
   Linear solve converged due to CONVERGED_ATOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   7 SNES Function norm 1.267482220786e-01
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 1.267482220786e-01
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 1.498679601680e-17
   Linear solve converged due to CONVERGED_RTOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
   8 SNES Function norm 3.468150619264e-02
  ++++++++++++ in jac shell +++++++++++
     0 KSP Residual norm 3.468150619264e-02
  === start mymult ===
  === done mymult ===
     1 KSP Residual norm 5.944160522951e-18
   Linear solve converged due to CONVERGED_RTOL iterations 1
  === start mymult ===
  === done mymult ===
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  ( in rhs )
  ( leave rhs )
  === start mymult ===
  === done mymult ===
Nonlinear solve did not converge due to DIVERGED_LINE_SEARCH iterations 8
Number of SNES iterations =     8

After each "Linear solve converged due to CONVERGED_ATOL iterations", 
the code starts to do mymult again. So I thought it did an extra 
(unwanted) KSP iteration. I would like to ask if this extra iteration 
could be disabled, or maybe I am wrong about it.

Best regards,

Yi

On 1/30/24 18:35, Barry Smith wrote:
>
>   How do I see a difference? What does "hence ruin my previous 
> converged KSP result" mean? A different answer at the end of the KSP 
> solve?
>
> $ ./joe > joe.basic
>
> ~/Src/petsc/src/ksp/ksp/tutorials*(barry/2023-09-15/fix-log-pcmpi=)*arch-fix-log-pcmpi
>
> $ ./joe -ksp_monitor -ksp_converged_reason -snes_monitor > joe.monitor
>
> ~/Src/petsc/src/ksp/ksp/tutorials*(barry/2023-09-15/fix-log-pcmpi=)*arch-fix-log-pcmpi
>
> $ diff joe.basic joe.monitor
>
> 0a1,36
>
> >   0 SNES Function norm 6.041522986797e+00
>
> >    0 KSP Residual norm 6.041522986797e+00
>
> >    1 KSP Residual norm 5.065392549852e-16
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   1 SNES Function norm 3.512662245652e+00
>
> >    0 KSP Residual norm 3.512662245652e+00
>
> >    1 KSP Residual norm 6.230314124713e-16
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   2 SNES Function norm 8.969285922373e-01
>
> >    0 KSP Residual norm 8.969285922373e-01
>
> >    1 KSP Residual norm 0.000000000000e+00
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   3 SNES Function norm 4.863816734540e-01
>
> >    0 KSP Residual norm 4.863816734540e-01
>
> >    1 KSP Residual norm 0.000000000000e+00
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   4 SNES Function norm 3.512070785520e-01
>
> >    0 KSP Residual norm 3.512070785520e-01
>
> >    1 KSP Residual norm 0.000000000000e+00
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   5 SNES Function norm 2.769700293115e-01
>
> >    0 KSP Residual norm 2.769700293115e-01
>
> >    1 KSP Residual norm 1.104778916974e-16
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   6 SNES Function norm 2.055345318150e-01
>
> >    0 KSP Residual norm 2.055345318150e-01
>
> >    1 KSP Residual norm 1.535110861002e-17
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   7 SNES Function norm 1.267482220786e-01
>
> >    0 KSP Residual norm 1.267482220786e-01
>
> >    1 KSP Residual norm 1.498679601680e-17
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
> >   8 SNES Function norm 3.468150619264e-02
>
> >    0 KSP Residual norm 3.468150619264e-02
>
> >    1 KSP Residual norm 5.944160522951e-18
>
> >  Linear solve converged due to CONVERGED_RTOL_NORMAL iterations 1
>
>
>
>
>> On Jan 30, 2024, at 11:19 AM, Yi Hu <y.hu at mpie.de> wrote:
>>
>> Dear PETSc team,
>> I am still trying to sort out my previous 
>> threadhttps://lists.mcs.anl.gov/pipermail/petsc-users/2024-January/050079.htmlusing 
>> a minimal working example. However, I encountered another problem. 
>> Basically I combined the basic usage of SNES solver and shell matrix 
>> and tried to make it work. The jacobian of my snes is replaced by a 
>> customized MATOP_MULT. The minimal example code can be viewed 
>> herehttps://github.com/hyharry/small_petsc_test/blob/master/test_shell_jac/ex1f.F90
>> When running with -ksp_monitor -ksp_converged_reason, it shows an 
>> extra mymult step, and hence ruin my previous converged KSP result. 
>> Implement a customized converged call-back also does not help. I am 
>> wondering how to skip this extra ksp iteration. Could anyone help me 
>> on this?
>> Thanks for your help.
>> Best wishes,
>> Yi
>>
>>
>> ------------------------------------------------------------------------
>> -------------------------------------------------
>> Stay up to date and follow us on LinkedIn, Twitter and YouTube.
>>
>> Max-Planck-Institut für Eisenforschung GmbH
>> Max-Planck-Straße 1
>> D-40237 Düsseldorf
>>
>> Handelsregister B 2533
>> Amtsgericht Düsseldorf
>>
>> Geschäftsführung
>> Prof. Dr. Gerhard Dehm
>> Prof. Dr. Jörg Neugebauer
>> Prof. Dr. Dierk Raabe
>> Dr. Kai de Weldige
>>
>> Ust.-Id.-Nr.: DE 11 93 58 514
>> Steuernummer: 105 5891 1000
>>
>>
>> Please consider that invitations and e-mails of our institute are
>> only valid if they end with …@mpie.de.
>> If you are not sure of the validity please contact rco at mpie.de
>>
>> Bitte beachten Sie, dass Einladungen zu Veranstaltungen und E-Mails
>> aus unserem Haus nur mit der Endung …@mpie.de gültig sind.
>> In Zweifelsfällen wenden Sie sich bitte an rco at mpie.de
>> -------------------------------------------------
>

-------------------------------------------------
Stay up to date and follow us on LinkedIn, Twitter and YouTube.

Max-Planck-Institut für Eisenforschung GmbH
Max-Planck-Straße 1
D-40237 Düsseldorf
 
Handelsregister B 2533 
Amtsgericht Düsseldorf
 
Geschäftsführung
Prof. Dr. Gerhard Dehm
Prof. Dr. Jörg Neugebauer
Prof. Dr. Dierk Raabe
Dr. Kai de Weldige
 
Ust.-Id.-Nr.: DE 11 93 58 514 
Steuernummer: 105 5891 1000


Please consider that invitations and e-mails of our institute are 
only valid if they end with …@mpie.de. 
If you are not sure of the validity please contact rco at mpie.de

Bitte beachten Sie, dass Einladungen zu Veranstaltungen und E-Mails
aus unserem Haus nur mit der Endung …@mpie.de gültig sind. 
In Zweifelsfällen wenden Sie sich bitte an rco at mpie.de
-------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240130/e0496212/attachment-0001.html>


More information about the petsc-users mailing list