<div dir="ltr">Thanks Barry, with <span style="font-family:Menlo;font-size:14px;font-variant-ligatures:no-common-ligatures"> -snes_qn_m 0</span>  it gives exact convergence as 

-snes_type newtonls -snes_linesearch_type basic<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br></div><div dir="ltr">Giang</div></div></div><br></div><br><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">bsmith@petsc.dev</a>> wrote:<br></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;"><div dir="auto" style="overflow-wrap: break-word;"><div><br></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><br></div><div>  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><br></div><div>  You can access my fixes with </div><div><br></div><div>   get fetch</div><div>   git checkout <span style="font-family:Menlo;font-size:14px">barry/2021-05-25/fix-qn-jacobian-setfromoptions/release</span></div><div><br></div><div>  The merge request with the fixes for release is here <a href="https://gitlab.com/petsc/petsc/-/merge_requests/4018" target="_blank">https://gitlab.com/petsc/petsc/-/merge_requests/4018</a></div><div><br></div><div>   I checked it with the runs below. Using first -pc_type lu then the default PC. </div><div><br></div><div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)"><b> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures"> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ ./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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)"><b> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures"> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ ./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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)"><b> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures"> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ ./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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)"><b> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures"> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ ./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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">Number of SNES iterations = 2</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">~/Src/petsc/src/snes/tutorials</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)"><b> (barry/2021-05-25/fix-qn-jacobian-setfromoptions/release *=)</b></span><span style="font-variant-ligatures:no-common-ligatures"> arch-fix-qn-jacobian-setfromoptions</span></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">$ ./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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">  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"><span style="font-variant-ligatures:no-common-ligatures">Number of SNES iterations = 3</span></div><div><br></div><div>  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><br></div><div>  Barry</div><div><br></div><div>   <br><blockquote type="cite"><div>On May 25, 2021, at 12:15 PM, hg <<a href="mailto:hgbk2008@gmail.com" target="_blank">hgbk2008@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hello<div><br></div><div>I would expect the setting below would give the same behaviour like -snes_type newtonls -snes_linesearch_type basic:</div><div><br></div><div>-snes_type qn<br>-snes_qn_type lbfgs<br>-snes_qn_m 1<br>-snes_qn_restart_type periodic<br>-snes_qn_scale_type jacobian<br>-snes_linesearch_type basic<br></div><div><br></div><div>But it's not, below is the convergence log:</div><div>entering BuildRHS<br></div><div>0 SNES Function norm 7.450427214612e+03 <br>entering BuildLHS<br>entering BuildRHS<br>  1 SNES Function norm 7.902262148182e+03 <br>entering BuildRHS<br>  2 SNES Function norm 8.426417730274e+03 <br>    Periodic restart! i_r = 1<br>entering BuildLHS<br>entering BuildRHS<br>  3 SNES Function norm 5.571513092130e+04 <br>entering BuildRHS<br>  4 SNES Function norm 4.019723509872e+05 <br>    Periodic restart! i_r = 1<br>entering BuildLHS<br>entering BuildRHS<br>  5 SNES Function norm 9.259722791615e+05 <br>entering BuildRHS<br>  6 SNES Function norm 3.985884724278e+08 <br>Nonlinear solve did not converge due to DIVERGED_DTOL iterations 6<br></div><div><br></div><div>For -snes_type newtonls -snes_linesearch_type basic:</div><div><br></div><div>entering BuildRHS<br>  0 SNES Function norm 7.450427214612e+03 <br>entering BuildLHS<br>entering BuildRHS<br>  1 SNES Function norm 1.937109245338e+01 <br>entering BuildLHS<br>entering BuildRHS<br>  2 SNES Function norm 8.126736406257e-01 <br>entering BuildLHS<br>entering BuildRHS<br>  3 SNES Function norm 1.143237968970e-03 <br>entering BuildLHS<br>entering BuildRHS<br>  4 SNES Function norm 2.706184329411e-09 <br>Nonlinear solve converged due to CONVERGED_FNORM_RELATIVE iterations 4<br></div><div><br></div><div>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><br></div><div>Thanks<br clear="all"><div><div dir="ltr"><div dir="ltr">Giang</div><div dir="ltr"><br></div></div></div></div></div>
</div></blockquote></div><br></div></div></div></blockquote></div>