<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On 13 Jul 2022, at 6:01 PM, Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> Some of the ugliness of SetFromOptions in some of the nested solvers :-(</div></div></blockquote><div><br class=""></div><div>Right, I figured it out slightly after sending the mail by pulling the sub KSP and explicitly calling KSPSetFromOptions on it, which also works.</div><div>I’ve provided a fix to my user by telling them to pull the sub KSP, so if you are not satisfied by your patch, rest assured that they can live with this “undocumented feature” for the time being.</div><div><br class=""></div><div>Thanks,</div><div>Pierre</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><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: #2fb41d" 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: #b42419" 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: #9fa01c" 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: #2eaebb" class="">itcl.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">324</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">fieldsplit.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">1087</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">precon.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">991</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">itfunc.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">401</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">itfunc.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">835</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">itfunc.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">1066</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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: #2eaebb" class="">ex1111.c</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" class="">33</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9fa01c" 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: #9fa01c" 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><span id="cid:BAAF9DF1-D4EF-448C-AEC7-9FC20B627C4F"><fix-fieldsplit-recall-setfromoptions.patch></span><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" 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 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="">Barry</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=""><br class=""></div><div style="margin: 0px; font-stretch: normal; font-size: 14px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Jul 13, 2022, at 8:40 AM, Pierre Jolivet <<a href="mailto:pierre@joliv.et" class="">pierre@joliv.et</a>> wrote:</div><br class="Apple-interchange-newline"><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="cid: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" 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></div></blockquote></div><br class=""></body></html>