<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> Excellant, thanks for letting us know.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On May 25, 2021, at 5:30 PM, hg <<a href="mailto:hgbk2008@gmail.com" class="">hgbk2008@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks Barry, with <span style="font-family:Menlo;font-size:14px;font-variant-ligatures:no-common-ligatures" class=""> -snes_qn_m 0</span> it gives exact convergence as
-snes_type newtonls -snes_linesearch_type basic<br clear="all" class=""><div class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><br class=""></div><div dir="ltr" class="">Giang</div></div></div><br class=""></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 25, 2021 at 10:51 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;" class=""><div dir="auto" style="overflow-wrap: break-word;" class=""><div class=""><br class=""></div> Yes, with your options I would expect the first SNES iteration of QN to produce the same result as the first iteration of SNES Newton ls. <div class=""><br class=""></div><div class=""> I have fixed an error that crept (well actually I put it there) in where KSPSetFromOptions() was not being called with the QN and Jacobian option, hence only the default PC (ilu) was being used so if you changed the PC it only affected Newton not QN. I also made it possible to run with a history of length 0 so that with the Jacobian option it should exactly match Newton for all iterations. </div><div class=""><br class=""></div><div class=""> You can access my fixes with </div><div class=""><br class=""></div><div class=""> get fetch</div><div class=""> git checkout <span style="font-family:Menlo;font-size:14px" class="">barry/2021-05-25/fix-qn-jacobian-setfromoptions/release</span></div><div class=""><br class=""></div><div class=""> The merge request with the fixes for release is here <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4018" target="_blank" class="">https://gitlab.com/petsc/petsc/-/merge_requests/4018</a></div><div class=""><br class=""></div><div class=""> I checked it with the runs below. Using first -pc_type lu then the default PC. </div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)" class=""><b class=""> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">$ ./ex19 -pc_type lu -snes_monitor -snes_type qn -snes_qn_type lbfgs -snes_qn_m 0 -snes_qn_restart_type periodic -snes_qn_scale_type jacobian -snes_linesearch_type basic </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 0 SNES Function norm 2.391552133017e-01 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 1 SNES Function norm 6.819684624592e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 2 SNES Function norm 4.203401869625e-12 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)" class=""><b class=""> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">$ ./ex19 -pc_type lu -snes_monitor -snes_linesearch_type basic</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 0 SNES Function norm 2.391552133017e-01 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 1 SNES Function norm 6.819684624592e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 2 SNES Function norm 4.203401869625e-12 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)" class=""><b class=""> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">$ ./ex19 -snes_monitor -snes_linesearch_type basic</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 0 SNES Function norm 2.391552133017e-01 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 1 SNES Function norm 6.839858507066e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 2 SNES Function norm 8.558777232425e-11 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)" class=""><b class=""> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">$ ./ex19 -snes_monitor -snes_type qn -snes_qn_type lbfgs -snes_qn_m 0 -snes_qn_restart_type periodic -snes_qn_scale_type jacobian -snes_linesearch_type basic </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 0 SNES Function norm 2.391552133017e-01 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 1 SNES Function norm 6.839858507066e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 2 SNES Function norm 8.558777232425e-11 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)" class=""><b class=""> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">$ ./ex19 -snes_monitor -snes_type qn -snes_qn_type lbfgs -snes_qn_m 1 -snes_qn_restart_type periodic -snes_qn_scale_type jacobian -snes_linesearch_type basic </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">lid velocity = 0.0625, prandtl # = 1., grashof # = 1.</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 0 SNES Function norm 2.391552133017e-01 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 1 SNES Function norm 6.839858507066e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 2 SNES Function norm 1.977614824765e-05 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 3 SNES Function norm 1.286952209377e-10 </span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">Number of SNES iterations = 3</span></div><div class=""><br class=""></div><div class=""> If you still have trouble with the branch you can run with -ksp_monitor -snes_linesearch_monitor -info -snes_view to see what may be different with your runs with Newton and with QN. </div><div class=""><br class=""></div><div class=""> Barry</div><div class=""><br class=""></div><div class=""> <br class=""><blockquote type="cite" class=""><div class="">On May 25, 2021, at 12:15 PM, hg <<a href="mailto:hgbk2008@gmail.com" target="_blank" class="">hgbk2008@gmail.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Hello<div class=""><br class=""></div><div class="">I would expect the setting below would give the same behaviour like -snes_type newtonls -snes_linesearch_type basic:</div><div class=""><br class=""></div><div class="">-snes_type qn<br class="">-snes_qn_type lbfgs<br class="">-snes_qn_m 1<br class="">-snes_qn_restart_type periodic<br class="">-snes_qn_scale_type jacobian<br class="">-snes_linesearch_type basic<br class=""></div><div class=""><br class=""></div><div class="">But it's not, below is the convergence log:</div><div class="">entering BuildRHS<br class=""></div><div class="">0 SNES Function norm 7.450427214612e+03 <br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 1 SNES Function norm 7.902262148182e+03 <br class="">entering BuildRHS<br class=""> 2 SNES Function norm 8.426417730274e+03 <br class=""> Periodic restart! i_r = 1<br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 3 SNES Function norm 5.571513092130e+04 <br class="">entering BuildRHS<br class=""> 4 SNES Function norm 4.019723509872e+05 <br class=""> Periodic restart! i_r = 1<br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 5 SNES Function norm 9.259722791615e+05 <br class="">entering BuildRHS<br class=""> 6 SNES Function norm 3.985884724278e+08 <br class="">Nonlinear solve did not converge due to DIVERGED_DTOL iterations 6<br class=""></div><div class=""><br class=""></div><div class="">For -snes_type newtonls -snes_linesearch_type basic:</div><div class=""><br class=""></div><div class="">entering BuildRHS<br class=""> 0 SNES Function norm 7.450427214612e+03 <br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 1 SNES Function norm 1.937109245338e+01 <br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 2 SNES Function norm 8.126736406257e-01 <br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 3 SNES Function norm 1.143237968970e-03 <br class="">entering BuildLHS<br class="">entering BuildRHS<br class=""> 4 SNES Function norm 2.706184329411e-09 <br class="">Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 4<br class=""></div><div class=""><br class=""></div><div class="">Would it be the parameters not the same? My idea is first starting with a good configuration of lbfgs then increase the restart (m) to see how the convergence going (and save time).</div><div class=""><br class=""></div><div class="">Thanks<br clear="all" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class="">Giang</div><div dir="ltr" class=""><br class=""></div></div></div></div></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div>
</div></blockquote></div><br class=""></body></html>