Coconut
Coconut

Reputation: 184

compiler dependent null pointer problem in fortran

I'm trying to compile one particular numerical code named NEMO. I'm using PGI compiler and get the following error while I'm trying to run a case.

-> report : Performance report : Time spent for XIOS : 4.53964e-05
-> report : Performance report : Time spent in processing events : 0
-> report : Performance report : Ratio : 0%
-> report : Performance report : Time spent for XIOS : 4.54746e-05
-> report : Performance report : Time spent in processing events : 0
-> report : Performance report : Ratio : 0%
0: Null pointer for qrp (/home/user/local/NEMO-4.0/cfgs/MYGYRE/BLD/ppsrc/nemo/diawri.f90: 530)

0: Null pointer for qrp (/home/user/local/NEMO-4.0/cfgs/MYGYRE/BLD/ppsrc/nemo/diawri.f90: 530)

0: Null pointer for qrp (/home/user/local/NEMO-4.0/cfgs/MYGYRE/BLD/ppsrc/nemo/diawri.f90: 530)

0: Null pointer for qrp (/home/user/local/NEMO-4.0/cfgs/MYGYRE/BLD/ppsrc/nemo/diawri.f90: 530)

The corresponding code from the diawri.f90 file is as followed

530          CALL histwrite( nid_T, "sohefldp", it, qrp           , ndim_hT, ndex_hT )   ! heat flux damping

Following is the interface of histwrite

  INTERFACE histwrite
!---------------------------------------------------------------------
!- The "histwrite" routines will give the data to the I/O system.
!- It will trigger the operations to be performed,
!- and the writting to the file if needed
!-
!- We test for the work to be done at this time here so that at a
!- later stage we can call different operation and write subroutine
!- for the REAL and INTEGER interfaces
!-
!- INPUT
!- idf      : The ID of the file on which this variable is to be,
!-            written. The variable should have been defined in
!-            this file before.
!- pvarname : The short name of the variable
!- pitau    : Current timestep
!- pdata    : The variable, I mean the real data !
!- nbindex  : The number of indexes provided. If it is equal to
!-            the size of the full field as provided in histdef
!-            then nothing is done.
!- nindex   : The indices used to expand the variable (pdata)
!-            onto the full field.

This is the qrp definition

   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:) ::   qrp   !: heat flux damping        [w/m2]

I searched online and find some information saying this is due to a fortran 2003 standard about null pointer. And different compilers treat null pointer differently. As I know gfortran is mostly used for compiling this code and seemingly working fine. I would like to know what I can do to avoid the error without changing the compiler.

Upvotes: 1

Views: 376

Answers (1)

jacob
jacob

Reputation: 1630

Looking at the code, the interface histwrite resolves to the following subroutine for your qrp:

SUBROUTINE histwrite_r2d (idf,pvarname,pitau,pdata,nbindex,nindex)
!---------------------------------------------------------------------
  IMPLICIT NONE
!-
  INTEGER,INTENT(IN) :: idf,pitau,nbindex
  INTEGER,DIMENSION(nbindex),INTENT(IN) :: nindex
  REAL,DIMENSION(:,:),INTENT(IN) :: pdata
  CHARACTER(LEN=*),INTENT(IN) :: pvarname
!---------------------------------------------------------------------
  CALL histw_rnd (idf,pvarname,pitau,nbindex,nindex,pdata_2d=pdata)
!---------------------------
END SUBROUTINE histwrite_r2d

The dummy argument pdata (to be associated with the actual qrp) is a assumed-shape array, but not allocatable. This means that the paragraph 7 of section 15.5.2.4 of the current Fortran standard applies:

  1. Except in references to intrinsic inquiry functions, if the dummy argument is nonoptional and the actual argument is allocatable, the corresponding actual argument shall be allocated.

In other words, passing a non-allocated qrp to histwrite is invalid in Fortran, because the compiler can't associate non-existing array with an existing one.

I believe that, internally, gfortran just passes on a null pointer, which then makes the optional argument pdata_2d in call to histw_rnd appear as not present. But I suspect that this is more of a coindidence than a design.

There's little you can do; this is a problem of the code. You would need to fix it yourself, perhaps by using directly histw_rnd (bypassing histwrite) without any of its optional arguments, or by allocating qrp. I don't think there is a magical compiler option for PGI that would just solve it for you.

Upvotes: 1

Related Questions