fortran中依赖于编译器的空指针问题

时间:2019-10-01 15:51:18

标签: fortran pgi

我正在尝试编译一个名为NEMO的特定数字代码。我正在使用PGI编译器,并在尝试运行案例时收到以下错误。

-> 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)

diawri.f90文件中的相应代码如下

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

以下是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.

这是qrp定义

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

我在线搜索并找到一些信息,说这是由于有关空指针的fortran 2003标准所致。并且不同的编译器对空指针的处理也不同。据我所知,gfortran主要用于编译此代码,并且看起来运行良好。我想知道如何在不更改编译器的情况下避免错误。

1 个答案:

答案 0 :(得分:0)

看代码,接口histwrite解析为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

伪参数pdata(与实际的qrp关联)是一个假定形状的数组,但不是可分配的。这意味着current Fortran standard第15.5.2.4节的第7段适用:

  
      
  1. 除了对内在查询函数的引用以外,如果哑元参数是非可选的,而实际参数是   是可分配的,则应分配相应的实际参数
  2.   

换句话说,在Fortran中将未分配的qrp传递给histwrite是无效的,因为编译器无法将不存在的数组与现有的数组相关联。

我认为,gfortran在内部仅传递一个空指针,然后使对pdata_2d的调用中的可选参数histw_rnd显示为不存在。但是我怀疑这更多是符合条件的,而不是设计。

您无能为力;这是代码的问题。您可能需要自己修复它,可能是直接使用histw_rnd(绕过histwrite)而不使用其任何可选参数,或者分配了qrp。我认为PGI没有一个神奇的编译器选项可以为您解决。