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

袁煕 yuanxi at advancesoft.jp
Thu Nov 18 23:34:03 CST 2021


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/3241b0a3/attachment.html>


More information about the petsc-users mailing list