"where-statement" 使用 ifort 19.0 和 gfortran 9.1 编译器时出现分段错误

Segmentation fault in "where-statement" using ifort 19.0 and gfortran 9.1 compiler

我的代码使用 gfortran 9.1 编译器运行时没有错误,但使用 ifort 19.0 编译器时抛出分段错误。

这是编译器错误还是我使用 "where-statement" 错误?

program where_test
use, intrinsic :: iso_fortran_env, only: dp => REAL64

real(dp), allocatable :: test_array(:,:,:), test_array2(:,:,:)

allocate(test_array(128,128,128), test_array2(128,128,128))

test_array = 5.0_dp    
test_array(64,:,:) = 10.0_dp
test_array2 = 0.0_dp

where(test_array == 10.0_dp) 
    test_array2 = 1.0_dp
elsewhere
    test_array2 = 10.0_dp
end where

write(*,*) minval(test_array), maxval(test_array)
write(*,*) minval(test_array2), maxval(test_array2)

end program where_test

gfortran 9.1 编译器给出了预期的输出:

5.0000000000000000 10.000000000000000

1.0000000000000000 10.000000000000000

The ifort 19.0 yields a segmentation fault in line 12 (beginning of where statement):

您遇到了堆栈溢出。 gfortran默认是把临时数组拷贝放在堆上,而ifort默认是放在栈上,栈是有大小限制的

添加选项 -heap-arrays 它将 运行 就像在 gfortran 中一样。