在定义我自己的TYPE时,ifort和gfortran的结果不同

时间:2013-04-24 21:28:49

标签: fortran gfortran intel-fortran

我是Fortran的新手,但是一旦我了解了模块和类型,我一般会发现我可以使用C或Matlab完成大部分工作。但是,我对结果的这种差异感到困惑,这取决于我是使用gfortran(gcc版本4.6.2)还是ifort(13.0.2)。 Gfortran给了我期望的结果,但ifort给了我3个空行!有什么想法吗?

module define_structures
implicit none
private

public modelling_params

    type modelling_params
        real, dimension(:), allocatable :: freqs
        real, dimension(:), allocatable :: offsets      
        complex, dimension(:), allocatable :: data
    end type modelling_params   
end module define_structures

program main

use define_structures
    implicit none

    type (modelling_params) :: S

    S%data = [(1,1) ,(2,3), (3,1)]
    S%freqs = [1, 3, 7]
    S%offsets = [100, 200, 300]
    print *,S%data
    print *,S%freqs
    print *,S%offsets


end program main

这是使用gfortran

编译的输出
(  1.0000000    ,  1.0000000    ) (  2.0000000    ,  3.0000000    ) (  3.0000000    ,  1.0000000    )
1.0000000       3.0000000       7.0000000    
100.00000       200.00000       300.00000   

使用ifort,我只得到3个空行,虽然编译得很好!!

提前致谢。

1 个答案:

答案 0 :(得分:2)

ifort命令行选项传递给编译器时,支持在-assume realloc_lhs中分配时重新分配可分配变量。如果在第一次分配后立即插入以下内容:

print *, allocated(S%data)

您会看到F,这意味着在分配时不会分配可分配字段。代码按预期使用-assume realloc_lhs