<div dir="ltr"><div dir="ltr">On Mon, Jul 21, 2025 at 7:49 AM Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Robert, [I don't see this message to PETSc users in my email so cc'ing manually]<div><br></div><div>This is odd, something is messed up. </div><div>These NULL things are certainly 0 and the initial value of these objects is not defined by the compiler, and they could be 0 in some cases.</div></div></blockquote><div><br></div><div>Hi Robert,</div><div><br></div><div>I am not the Fortran expert, but I believe that passing PETSC_NULL_XXX to a creation routine is not correct. Here is my logic.</div><div><br></div><div>In the wrapper, PETSC_NULL_XXX is converted to a NULL pointer (_not_ a pointer whose value is NULL). Thus KSPCreate would try to set a NULL pointer and you get the SEGV. I think it may have worked before because this was not automated, so these routines did not check for PETSC_NULL_XXX since it is not a case handled by the C function.</div><div><br></div><div>Could you try without initializing? Barry would have to tell you what they should be initialized to.</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 dir="ltr"><div>Others are more up on the new Fortran stuff, but I would do a clean build of PETSc (rm -fr arch...), and turn debugging on. </div><div>You will get a stack trace and it might find something and give a useful error message, or "fix" the problem mysteriously.</div><div><br></div><div>You could put a print statement in before these are initialized to see what *was* in it that you are clobbering.</div><div><br></div><div>Mark</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 20, 2025 at 10:33 AM Robert Hager <<a href="mailto:rhager@pppl.gov" target="_blank">rhager@pppl.gov</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 dir="ltr">FYI<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <strong class="gmail_sendername" dir="auto">Robert Hager</strong> <span dir="auto"><<a href="mailto:rhager@pppl.gov" target="_blank">rhager@pppl.gov</a>></span><br>Date: Sun, Jul 20, 2025 at 10:32 AM<br>Subject: Segfaults when calling some PETSc functions in Fortran with variables initialized to PETSC_NULL_XX<br>To:  <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>><br></div><br><br><div dir="ltr">Hello,<div><br></div><div>I am in the process of updating my code to use PETSc versions >=3.22. (I am using v3.22.3 compiled with GCC on Perlmutter-CPU at NERSC for debugging at this time.) After updating all the Fortran function calls that have changed from v3.21 to v3.22 I am now getting segfaults in some PETSc routines. In the two instances I was able to identify, the problem seems to be calling the PETSc function with a PETSc variable that has been initialized to PETSC_NULL_XX:</div><div><span style="color:rgba(0,0,0,0.85);font-family:Menlo;font-size:12px"><br></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><span style="color:rgba(0,0,0,0.85);font-family:Menlo;font-size:12px">solver%rhs</span><span style="font-family:Menlo;font-size:12px;color:rgb(28,0,207)">2</span><span style="color:rgba(0,0,0,0.85);font-family:Menlo;font-size:12px">_mat = PETSC_NULL_MAT</span></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)">[...]</p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)"><span style="color:rgb(155,35,147)"><b>call</b></span> MatDuplicate(solver%Amat,MAT_DO_NOT_COPY_VALUES,solver%rhs<span style="color:rgb(28,0,207)">2</span>_mat,ierr)</p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)">--> Segfault</p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)"><br></p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)">solver%ksp<span>      </span>= PETSC_NULL_KSP</p></div><div><p style="margin:0px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)">[...]</p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)"><span style="color:rgb(155,35,147)"><b>call</b></span> KSPCreate(solver%comm,solver%ksp,ierr)</p></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgba(0,0,0,0.85)">--> Segfault</p></div></blockquote><div><font face="Menlo"><span style="color:rgba(0,0,0,0.85);font-size:12px"><br></span></font></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif">When I comment out the assignments to PETSC_NULL_XX in the above examples, the code works just fine.</font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif">Is this the intended behavior or a bug that you might have fixed by now?</font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif">Best,</font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif"><br></font></span></div><div><span style="color:rgba(0,0,0,0.85);font-size:12px"><font face="arial, sans-serif">Robert</font></span></div></div>
</div></div>
</blockquote></div>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><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="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Ylz6mzmFkBJe1SAiy6sraNQ79TbZP3WWJtJY0kJSoeydhbohH8fH8uPd-f_ig_mjlKa2S7MME6rnPWQlLV-_$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>