[petsc-users] Bug report: using a custom ksp convergence function
Barry Smith
bsmith at petsc.dev
Mon Jan 20 09:19:51 CST 2025
David,
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().
Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ex5f.F90
Type: application/octet-stream
Size: 16786 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250120/f41ca062/attachment-0001.obj>
-------------- next part --------------
> On Jan 20, 2025, at 8:54?AM, Daniel Stone <daniel.stone at opengosim.com> wrote:
>
> Hello PETSc Community,
>
> I think I've found a bug -
>
> Go to $PETSC_DIR/src/ksp/ksp/tutorials/
>
> open ex5f.F90, and add the following line in MyKSPConverged(), say around line 336:
>
> call KSPConvergedDefault(ksp,n,rnorm,flag,dummy,ierr)
>
> 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.
>
> Now, building and running the exercise, making sure to include the flag to use the custom convergence:
>
> boston at boston-SYS-540A-TR:~/DATA_DRIVE/PETSC_DIRS/petsc_3.22/src/ksp/ksp/tutorials$ ./ex2f -my_ksp_convergence
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range[...]
>
> From my debugging, the issue is at line 1520 of iterativ.c:
>
> KSPConvergedDefaultCtx *cctx = (KSPConvergedDefaultCtx *)ctx;
>
> 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:
>
> if (cctx->convmaxits && n >= ksp->max_it) {
>
>
> 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
> defaulted version of the ctx object, the subsequent crash does not happen, etc.
>
> 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.
> Like in ex2f, I have no need of the ctx object, and just as in ex2f, I use 0 instead.
>
> 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.
>
> Many Thanks,
>
> Daniel
>
>
>
More information about the petsc-users
mailing list