<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>   This is a bug <a href="https://gitlab.com/petsc/petsc/-/merge_requests/5424" class="">https://gitlab.com/petsc/petsc/-/merge_requests/5424</a> repeated calls to XXXSetFromOptions() with changed options should always propagate down to all the sub solvers regardless of how much a pain it may be to do, otherwise it provides a terrible user experience.<div class=""><br class=""></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=""><meta charset="UTF-8" class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 18px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" 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-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div style="overflow-wrap: break-word;" class=""><div class=""><br class=""></div> <span class="Apple-converted-space"> </span>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 class="Apple-converted-space"> </span></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 class="Apple-converted-space"> </span></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=""> <span class="Apple-converted-space"> </span>* frame #0:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`KSPSetFromOptions(ksp=0x00007f899f149a70) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #1:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`PCSetUp_FieldSplit(pc=0x00007f899f08d870) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #2:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`PCSetUp(pc=0x00007f899f08d870) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #3:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`KSPSetUp(ksp=0x00007f899e95f670) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #4:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`KSPSolve_Private(ksp=0x00007f899e95f670, b=0x00007f899f0dec70, x=0x00007f899f0ce870) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #5:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>libpetsc.3.017.3.dylib`KSPSolve(ksp=0x00007f899e95f670, b=0x00007f899f0dec70, x=0x00007f899f0ce870) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #6:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>ex1111`main(argc=12, args=0x00007ff7b1739328) at<span class="Apple-converted-space"> </span></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="">   <span class="Apple-converted-space"> </span>frame #7:<span class="Apple-converted-space"> </span></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=""><span class="Apple-converted-space"> </span>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-width: 1px; border-left-style: solid; border-left-color: 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<span class="Apple-converted-space"> </span><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="">(*)<span class="Apple-converted-space"> </span><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>--<span class="Apple-converted-space"> </span><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></div></div></div></div></div></div></div></div></div></blockquote></div><br class=""></div></body></html>