如何解决如何使用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
。
使错误消失并维护目的的东西
-
使用
lbound
+ubound
虚拟参数:assumed-length
在
assumed-shape
中使用可分配的字符变量作为参数,并使用构造函数。这是我最喜欢的解决方案,因为我可以删除我本来就不需要的module integer function func(arg) character(len=*),intent(in) :: arg end function
。 -
不使用接口
func()
和带有l
的子模块,而是模块module function
的{{1}}部分中的内部功能 -
在虚拟参数中使用
module procedure
和mymod
+contains
assumed-length
在调用
assumed-shape
时也需要使用同样可分配的变量(而不是示例的构造函数表达式,它可能会或可能不会很烦人)
使错误消失的东西但是不是一个选择
- 切换到
allocatable
而不是character(len=:),allocatable,intent(in) :: arg
:func
但随后assumed-size
内在函数将不起作用(是的,这是一个不同的错误,这是可以预期的) - 具有一个
assumed-shape
而不是character(len=l),dimension(*)
的数组(显然,只是检查是否存在任何假定形状的接口模块过程……不是)
没有改变错误的东西
- 仅将
size
添加到虚拟变量声明中,同时保留定义的长度integer
部分(并在调用character
时使用可分配变量作为参数)
随着代码在allocatable
的调整下工作(不再使它成为递延长度的字符,这对我来说很好),我的主要问题与编译器的不同行为有关。
len=l
是否正确编译了该程序,程序是否按预期的方式运行-将其作为func
中的错误-或{{1 }}?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。