[petsc-users] Segfaults when calling some PETSc functions in Fortran with variables initialized to PETSC_NULL_XX

Robert Hager rhager at pppl.gov
Sun Jul 20 09:32:25 CDT 2025


Hello,

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:

solver%rhs2_mat = PETSC_NULL_MAT

[...]

*call* MatDuplicate(solver%Amat,MAT_DO_NOT_COPY_VALUES,solver%rhs2_mat,ierr)

--> Segfault


solver%ksp      = PETSC_NULL_KSP

[...]

*call* KSPCreate(solver%comm,solver%ksp,ierr)

--> Segfault


When I comment out the assignments to PETSC_NULL_XX in the above examples,
the code works just fine.

Is this the intended behavior or a bug that you might have fixed by now?

Best,

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250720/96e3abef/attachment-0001.html>


More information about the petsc-users mailing list