Fortran错误:排列()中的秩不匹配
下面是一个测试Fortran错误:排列()中的秩不匹配,fortran,gfortran,Fortran,Gfortran,下面是一个测试排列固有函数的简单代码: program test_spread implicit none integer, allocatable, dimension(:) :: a integer, allocatable, dimension(:,:) :: b integer, allocatable, dimension(:,:,:) :: c integer, allocatable, dimension(:,:,:) :: d alloca
排列
固有函数的简单代码:
program test_spread
implicit none
integer, allocatable, dimension(:) :: a
integer, allocatable, dimension(:,:) :: b
integer, allocatable, dimension(:,:,:) :: c
integer, allocatable, dimension(:,:,:) :: d
allocate(a(2), b(2,4), c(2,4,2), d(2,4,2))
a(:) = [1, 2]
print*, "a=", a
b(:,:) = spread((a + 1)**2, 2, size(b,2))
print*, "b=", b
c(:,:,:) = spread(b, 3, size(c,3))
print*, "c=", c
d(:,:,:) = spread(spread((a + 1)**2, 2, size(d,2)), 3, size(d,3))
print*, "d=", d
end program
它是用gfortran 8.1.1编译的:
gfortran -g -fcheck=all -Wall -Wtabs -fbacktrace -c test.f90
gfortran -g -fcheck=all -Wall -Wtabs -fbacktrace -o test_spread test.o
我得到以下结果:
a= 1 2
b= 4 9 4 9 4 9 4 9
c= 4 9 4 9 4 9 4 9 4 9 4 9 4 9 4 9
Fortran runtime error: rank mismatch in spread()
Error termination. Backtrace:
#0 0x55b46b14386e in test_spread
at /*****/test_spread/test.f90:20
#1 0x55b46b143966 in main
at /*****/test_spread/test.f90:22
如果删除allocatable
属性,代码将编译并给出正确的结果。我是做错了什么,还是编译器出错了
该代码使用“英特尔Fortran 18”进行编译并给出正确的结果
PS:我在ArchLinux上的Intel(R)Xeon(R)Silver 4114 CPU上使用GCC
$ gfortran --version
GNU Fortran (GCC) 8.1.1 20180531
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2018-06-01史蒂文·G·卡格尔
PR fortran/85816
PR fortran/85975
* libgfortran.h: Remove the GFC_DTYPE_COPY_SETRANK macro.
* intrinsics/reshape_generic.c: Directly assign rank.
* intrinsics/spread_generic.c: Ditto.
...
* m4/spread.m4: Ditto.
请对所有Fortran questions.FWIW使用tag。代码编译并运行时,我使用GFortran 8.0.0进行安装,没有任何问题。我看不出代码有任何错误。您是否在这里指出这是gfortran 8.1.1中的一个编译器错误,并且已经修复或将要修复?现在请详细解释一下,它有点神秘。把三个问题连在一个句子里会让你很难回答。无论如何,是的,是的。3个问题只有2个答案!第三个问题是没有意义的,因为其他两个问题都有答案。