<div dir="ltr"><div>Is there a quick way for me to find out which version of PETSc KSPConvergedDefaultCreate() was introduced with? <br></div><div>I'll likely need to conditionally pragma-out these calls for back compatibility.</div><div><br></div><div>Thanks,</div><div><br></div><div>Daniel<br></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, Jan 21, 2025 at 1:16 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><div><br></div> Yes, that can be passed in also with KSPSetConvergenceTest()<div><br id="m_-5206572987229389071lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Jan 21, 2025, at 4:25 AM, Daniel Stone <<a href="mailto:daniel.stone@opengosim.com" target="_blank">daniel.stone@opengosim.com</a>> wrote:</div><br><div><div dir="ltr"><div>That works wonderfully, thanks! Should be paired with <br></div><div><br></div><div> call KSPConvergedDefaultDestroy(ctx,ierr)</div><div><br></div><div>I think.</div><div><br></div><div>Best Regards,</div><div><br></div><div>Daniel<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 20, 2025 at 3:20 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">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"><br>
David,<br>
<br>
KSPConvergedDefault() now takes a non-NULL context that must be provided. I have attached a modified version of ex5f.F90 that demonstrates how it is constructured before being passed to KSPSetConvergenceTest(). <br>
<br>
Barry<br>
<br>
<br>
> On Jan 20, 2025, at 8:54 AM, Daniel Stone <<a href="mailto:daniel.stone@opengosim.com" target="_blank">daniel.stone@opengosim.com</a>> wrote:<br>
> <br>
> Hello PETSc Community,<br>
> <br>
> I think I've found a bug -<br>
> <br>
> Go to $PETSC_DIR/src/ksp/ksp/tutorials/<br>
> <br>
> open ex5f.F90, and add the following line in MyKSPConverged(), say around line 336:<br>
> <br>
> call KSPConvergedDefault(ksp,n,rnorm,flag,dummy,ierr)<br>
> <br>
> It should make sense why someone would want to do this - within a definition of custom convergence behaviour, get the default convergence flags, and, based on certain conditions, overwrite it.<br>
> <br>
> Now, building and running the exercise, making sure to include the flag to use the custom convergence:<br>
> <br>
> boston@boston-SYS-540A-TR:~/DATA_DRIVE/PETSC_DIRS/petsc_3.22/src/ksp/ksp/tutorials$ ./ex2f -my_ksp_convergence<br>
> [0]PETSC ERROR: ------------------------------------------------------------------------<br>
> [0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range[...]<br>
> <br>
> From my debugging, the issue is at line 1520 of iterativ.c:<br>
> <br>
> KSPConvergedDefaultCtx *cctx = (KSPConvergedDefaultCtx *)ctx;<br>
> <br>
> Because a dummy is used for the context object, this cast fails (my debugger says "cannot access memory..." for cctx). Then the crash happens when trying to access members of cctx:<br>
> <br>
> if (cctx->convmaxits && n >= ksp->max_it) {<br>
> <br>
> <br>
> I'm not sure how to fix it. Crucially, we must note that that this did work in older versions of PETSc - I can repeat this test in 3.19.1, for example, and it works fine - a debugger shows the cast succeeding and producing some<br>
> defaulted version of the ctx object, the subsequent crash does not happen, etc.<br>
> <br>
> Does anybody have any advice for working around this for the time being? A piece of software I work with uses a custom ksp convergence test in the manner described above, and is only functional with older versions of petsc because of this.<br>
> Like in ex2f, I have no need of the ctx object, and just as in ex2f, I use 0 instead.<br>
> <br>
> Things I'll try next: defining a proper ctx object (I use 0, like in ex2f), or looking for some PETSC_NULL_CTX definition somewhere.<br>
> <br>
> Many Thanks,<br>
> <br>
> Daniel<br>
> <br>
> <br>
> <br>
<br>
</blockquote></div>
</div></blockquote></div><br></div></div></blockquote></div>