如何使用ifort将假定形状的显式长度字符数组用作伪参数?

问题描述

最近,当我从gfortran(gcc 9.3)切换到ifort(intel 19.2)(从本地计算机更改为群集)时,我偶然发现了以下问题。

简化为MWE表示将假定形状(:)字符数组传递给模块子例程。这是代码

module mymod
  implicit none

  interface
    module integer function func(arg,l)
      integer :: l
      character(len=l),dimension(:),intent(in) :: arg
    end function
  end interface

end module


submodule (mymod) submod
  implicit none

  contains

    module procedure func
      implicit none
      func = size(arg)
    end procedure

end submodule


program myprog
  use mymod
  implicit none
  write(*,*) func(["xy","ab","ij"],2)
end program

这是ifort引发的错误:

myprog.f90: catastrophic error: **Internal compiler error: segmentation violation signal raised** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for myprog.f90 (code 1)

我的函数的初衷显然有所不同,但稍微复杂一点,但是概念是相同的,因为它要求size()(或{{1 }}和arg

使错误消失并维护目的的东西

  1. 使用lbound + ubound虚拟参数:

    assumed-length

    assumed-shape中使用可分配的字符变量作为参数,并使用构造函数。这是我最喜欢的解决方案,因为我可以删除我本来就不需要的module integer function func(arg) character(len=*),intent(in) :: arg end function

  2. 不使用接口func()和带有l的子模块,而是模块module function的{​​{1}}部分中的内部功能

  3. 在虚拟参数中使用module proceduremymod + contains

    assumed-length

    在调用assumed-shape时也需要使用同样可分配的变量(而不是示例的构造函数表达式,它可能会或可能不会很烦人)

使错误消失的东西但是不是一个选择

  1. 切换到allocatable而不是character(len=:),allocatable,intent(in) :: arg
    func 但随后assumed-size内在函数将不起作用(是的,这是一个不同的错误,这是可以预期的)
  2. 具有一个assumed-shape而不是character(len=l),dimension(*)的数组(显然,只是检查是否存在任何假定形状的接口模块过程……不是)

没有改变错误的东西

  1. 仅将size添加到虚拟变量声明中,同时保留定义的长度integer部分(并在调用character时使用可分配变量作为参数)

随着代码在allocatable的调整下工作(不再使它成为递延长度的字符,这对我来说很好),我的主要问题与编译器的不同行为有关。

len=l是否正确编译了该程序,程序是否按预期的方式运行-将其作为func中的错误-或{{1 }}?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...