<div dir="ltr"><div dir="ltr">On Wed, Jul 13, 2022 at 1:53 PM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br></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;"><div><br></div>  Matt,<div><br></div><div>    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></blockquote><div><br></div><div>Yes, that makes sense.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </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>Barry</div><div><br><div><br><blockquote type="cite"><div>On Jul 13, 2022, at 12:14 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div dir="ltr">On Wed, Jul 13, 2022 at 11:02 AM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> wrote:<br></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><div><br></div>  Some of the ugliness of SetFromOptions in some of the nested solvers :-(<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">* thread #1, queue = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">'com.apple.main-thread'</span><span style="font-variant-ligatures:no-common-ligatures">, stop reason = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">breakpoint 1.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">  * frame #0: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x00000001132795f0</span><span style="font-variant-ligatures:no-common-ligatures"> libpetsc.3.017.3.dylib`KSPSetFromOptions(ksp=0x00007f899f149a70) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">itcl.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">324</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">19</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">    frame #1: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x0000000112eddda4</span><span style="font-variant-ligatures:no-common-ligatures"> libpetsc.3.017.3.dylib`PCSetUp_FieldSplit(pc=0x00007f899f08d870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">fieldsplit.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">1087</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">32</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">    frame #2: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x0000000112dfb874</span><span style="font-variant-ligatures:no-common-ligatures"> libpetsc.3.017.3.dylib`PCSetUp(pc=0x00007f899f08d870) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">precon.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">991</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">5</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">    frame #3: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x0000000113285834</span><span style="font-variant-ligatures:no-common-ligatures"> libpetsc.3.017.3.dylib`KSPSetUp(ksp=0x00007f899e95f670) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">401</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">3</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">    frame #4: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x000000011328b5e9</span><span style="font-variant-ligatures:no-common-ligatures"> 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)">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">835</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">3</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">    frame #5: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x000000011328aa66</span><span style="font-variant-ligatures:no-common-ligatures"> 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)">itfunc.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">1066</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">3</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">    frame #6: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x000000010e7c94e8</span><span style="font-variant-ligatures:no-common-ligatures"> ex1111`main(argc=12, args=0x00007ff7b1739328) at </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(46,174,187)">ex1111.c</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">33</span><span style="font-variant-ligatures:no-common-ligatures">:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">3</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">    frame #7: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">0x000000011703751e</span><span style="font-variant-ligatures:no-common-ligatures"> dyld`start + 462</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"><br></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">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"><span style="font-variant-ligatures:no-common-ligatures">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"><span style="font-variant-ligatures:no-common-ligatures"><br></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">I've attached a patch that should fix this particular issue. </span></div></div></div><div><div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo">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"><br></div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo">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><br></div><div>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>flag is set, it calls SetFromOptions on it.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div><div style="margin:0px;font-stretch:normal;font-size:14px;line-height:normal;font-family:Menlo">Barry</div><div><blockquote type="cite"><div>On Jul 13, 2022, at 8:40 AM, Pierre Jolivet <<a href="mailto:pierre@joliv.et" target="_blank">pierre@joliv.et</a>> wrote:</div><br><div><div>Hello,<br>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>In the following example I solve three successive linear systems.<br>If I run<br>$ ./ex1111 -pc_type fieldsplit -fieldsplit_pc_type lu -log_view -info -options_view -switch false<br>-fieldsplit_1_ksp_reuse_preconditioner is always false, and I properly get:<br>1) convergence in a single iteration every time <br>2) [0] PCSetUp(): Setting up PC with same nonzero pattern for the last solve<br>3) MatLUFactorNum         3 in -log_view<br><br>Now, if I run<br>$ ./ex1111 -pc_type fieldsplit -fieldsplit_pc_type lu -log_view -info -options_view -switch true<br>-fieldsplit_1_ksp_reuse_preconditioner is set to true for the second solve and switched back to false for the last solve.<br>I (wrongfully, IMHO?) get:<br>1) convergence in 2 iterations for the last solve (instead of 1?)<br>2) [0] PCSetUp(): Leaving PC with identical preconditioner since reuse preconditioner is set (which should not be set for the last solve?)<br>3) MatLUFactorNum         1 (instead of 2?)<br>4) #PETSc Option Table entries:<br>-fieldsplit_1_ksp_reuse_preconditioner false (though from -info, cf. point #2 just above, this option value is true?)<br><br>Does it make sense or do you agree that something is off?<br><br>Thanks,<br>Pierre<br><br><span id="gmail-m_6575749065243279429gmail-m_-13273819428253308cid:26734774-5894-4752-8BB9-731BC6BEA23F"><ex1111.c></span><br><br>(*) <a href="https://community.freefem.org/t/supply-petsc-numbering-for-shared-memory-block-matrix/486/18" target="_blank">https://community.freefem.org/t/supply-petsc-numbering-for-shared-memory-block-matrix/486/18</a></div></div></blockquote></div><br></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</div></blockquote></div><br></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>