<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div>  Matt,<div class=""><br class=""></div><div class="">    This does not solve Pierre's problem because when the user calls XXSetFromOptions() later in the run, for example, to change some options for later computations the SetFromOptions on the inner objects do not get called; since the XXSetFromOptions__YYY() does not transverse through them by construction, hence one needs to add code like I have done to make sure that future calls to XXSetFromOptions__YYY()  do transverse them once they have been created.</div><div class=""><br class=""></div><div class="">Barry</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2022, at 12:14 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">On Wed, Jul 13, 2022 at 11:02 AM Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>> wrote:<br class=""></div><div class="gmail_quote"><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 class=""><br class=""></div>  Some of the ugliness of SetFromOptions in some of the nested solvers :-(<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="">* thread #1, queue = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)" class="">'com.apple.main-thread'</span><span style="font-variant-ligatures:no-common-ligatures" class="">, stop reason = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)" class="">breakpoint 1.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="">  * frame #0: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x00000001132795f0</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`KSPSetFromOptions(ksp=0x00007f899f149a70) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">itcl.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">324</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">19</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="">    frame #1: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x0000000112eddda4</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`PCSetUp_FieldSplit(pc=0x00007f899f08d870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">fieldsplit.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">1087</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">32</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="">    frame #2: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x0000000112dfb874</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`PCSetUp(pc=0x00007f899f08d870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">precon.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">991</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">5</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="">    frame #3: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x0000000113285834</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`KSPSetUp(ksp=0x00007f899e95f670) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">401</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">3</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="">    frame #4: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x000000011328b5e9</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`KSPSolve_Private(ksp=0x00007f899e95f670, b=0x00007f899f0dec70, x=0x00007f899f0ce870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">835</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">3</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="">    frame #5: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x000000011328aa66</span><span style="font-variant-ligatures:no-common-ligatures" class=""> libpetsc.3.017.3.dylib`KSPSolve(ksp=0x00007f899e95f670, b=0x00007f899f0dec70, x=0x00007f899f0ce870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">1066</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">3</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="">    frame #6: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x000000010e7c94e8</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ex1111`main(argc=12, args=0x00007ff7b1739328) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)" class="">ex1111.c</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">33</span><span style="font-variant-ligatures:no-common-ligatures" class="">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">3</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="">    frame #7: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)" class="">0x000000011703751e</span><span style="font-variant-ligatures:no-common-ligatures" class=""> dyld`start + 462</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=""><br class=""></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="">The SetFromOptions doesn't always traverse all the sub-methods suitably calling SetFromOptions on them because they may not have been created by the time that</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="">the SetFromOptions is first called. In this case, the PCSetUp_FieldSplit() creates the sub solvers and calls the options database on them after the initial call to PCSetFromOptions_FieldSplit() </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=""><br class=""></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="">I've attached a patch that should fix this particular issue. </span></div></div></div><div style="overflow-wrap: break-word;" class=""><div class=""><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class="">I ran it with your test code, and it seemed to resolve the issue and ran the test suite, and it did not break anything.</div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class=""><br class=""></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class="">A redesigned/implemented PETSc would need some thought on how to improve the SetFromOptions model to prevent this kind of difficulty.</div></div></div></blockquote><div class=""><br class=""></div><div class="">My solution, which is used elsewhere in PETSc, would be for all PetscObjects to have a setfromoptions flag. If it creates a subobject and its own</div><div class="">flag is set, it calls SetFromOptions on it.</div><div class=""><br class=""></div><div class="">  Thanks,</div><div class=""><br class=""></div><div class="">     Matt</div><div 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 class=""><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo" class="">Barry</div><div class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2022, at 8:40 AM, Pierre Jolivet <<a href="mailto:pierre@joliv.et" target="_blank" class="">pierre@joliv.et</a>> wrote:</div><br class=""><div class=""><div class="">Hello,<br class="">A user(*) wants to switch back and forth with the option -fieldsplit_1_ksp_reuse_preconditioner, but it’s generating results that I don’t understand.<br class="">In the following example I solve three successive linear systems.<br class="">If I run<br class="">$ ./ex1111 -pc_type fieldsplit -fieldsplit_pc_type lu -log_view -info -options_view -switch false<br class="">-fieldsplit_1_ksp_reuse_preconditioner is always false, and I properly get:<br class="">1) convergence in a single iteration every time <br class="">2) [0] PCSetUp(): Setting up PC with same nonzero pattern for the last solve<br class="">3) MatLUFactorNum         3 in -log_view<br class=""><br class="">Now, if I run<br class="">$ ./ex1111 -pc_type fieldsplit -fieldsplit_pc_type lu -log_view -info -options_view -switch true<br class="">-fieldsplit_1_ksp_reuse_preconditioner is set to true for the second solve and switched back to false for the last solve.<br class="">I (wrongfully, IMHO?) get:<br class="">1) convergence in 2 iterations for the last solve (instead of 1?)<br class="">2) [0] PCSetUp(): Leaving PC with identical preconditioner since reuse preconditioner is set (which should not be set for the last solve?)<br class="">3) MatLUFactorNum         1 (instead of 2?)<br class="">4) #PETSc Option Table entries:<br class="">-fieldsplit_1_ksp_reuse_preconditioner false (though from -info, cf. point #2 just above, this option value is true?)<br class=""><br class="">Does it make sense or do you agree that something is off?<br class=""><br class="">Thanks,<br class="">Pierre<br class=""><br class=""><span id="gmail-m_-13273819428253308cid:26734774-5894-4752-8BB9-731BC6BEA23F" class=""><ex1111.c></span><br class=""><br class="">(*) <a href="https://community.freefem.org/t/supply-petsc-numbering-for-shared-memory-block-matrix/486/18" target="_blank" class="">https://community.freefem.org/t/supply-petsc-numbering-for-shared-memory-block-matrix/486/18</a></div></div></blockquote></div><br class=""></div></div></blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</div></blockquote></div><br class=""></div></body></html>