[petsc-users] How to check NULL pointer in Fortran

Mark Adams mfadams at lbl.gov
Fri Nov 19 06:40:37 CST 2021


You could try this:
integer :: i real :: r i = loc(r) print *, i

On Fri, Nov 19, 2021 at 12:34 AM 袁煕 <yuanxi at advancesoft.jp> wrote:

> Dear PETSc-team,
>
> I am using function PetscSFGetGraph in my program like
> -----------------------
> call PetscSFGetGraph(sf,gnroots,gnleaves,gmine,gremote,ierr)
> -----------------------
>
> In some cases, it works well. But in some cases, I encountered following error
> ------------------
> PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
>
> ------------------
>
> I found it is due to the action of reading gmine, which is a fortran pointer point to an array. It is reasonable because PETSc manual tells me "if returned value is NULL, it means leaves are in contiguous storage". The problem is that I cannot find if gmine is a null pointer.
>
> 1)  I cannot use "if (gmine==PETSC_NULL_INTEGER)" because my intel compiler would return a compile error "A scalar-valued expression is required in this context"
>
> 2)  When using standard style of checking a null pointer in fortran, "associated(gmine)", it returns "T". Even in cases such action of "print *, gmine(1)" would give rise to above Segmentation Violation error.
>
> Is there any means to check the NULL pointer in Fortran in above cases.
>
> Many thanks,
>
> Yuan
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20211119/f227b016/attachment.html>


More information about the petsc-users mailing list