由于我懒得不在英特尔开设账户而不是评论stackexchange,我决定把它放在这里。无论如何,在学习fortran时,我发现自己写了这段F03代码:
module log_module
implicit none
public :: assignment(=), operator(+), operator(-), &
operator(*), operator(==), operator(/=)
private :: logical_to_integer, integer_to_logical, &
log_plus_log, log_minus, log_times_log, &
log_equals_log, log_nequals_log
interface assignment(=)
module procedure logical_to_integer, &
integer_to_logical
end interface
interface operator(+)
module procedure log_plus_log
end interface
interface operator(-)
module procedure log_minus
end interface
interface operator(*)
module procedure log_times_log
end interface
interface operator(==)
module procedure log_equals_log
end interface
interface operator(/=)
module procedure log_nequals_log
end interface
contains
elemental function log_equals_log(x, y) result(log_result)
logical, intent(in) :: x, y
logical :: log_result
log_result = x .eqv. y
end function log_equals_log
elemental function log_nequals_log(x, y) result(log_result)
logical, intent(in) :: x, y
logical :: log_result
log_result = x .neqv. y
end function log_nequals_log
function log_plus_log(x, y) result(log_result)
logical, intent(in) :: x, y
logical :: log_result
log_result = x .or. y
end function log_plus_log
function log_minus(x) result(log_result)
logical, intent(in) :: x
logical :: log_result
log_result = .not. x
end function log_minus
function log_times_log(x, y) result(log_result)
logical, intent(in) :: x, y
logical :: log_result
log_result = x .and. y
end function log_times_log
subroutine logical_to_integer(i, log_exp)
integer, intent(out) :: i
logical, intent(in) :: log_exp
if(log_exp) then
i = 1
else
i = 0
end if
end subroutine logical_to_integer
subroutine integer_to_logical(logic, inte)
integer, intent(in) :: inte
logical, intent(out) :: logic
if(inte == 0) then
logic = .false.
else
logic = .true.
end if
end subroutine integer_to_logical
end module log_module
program test
use log_module
implicit none
integer :: i, j
logical :: k
logical, dimension(:), allocatable :: a, b
a = [.true., .true.]
b = [.false., .true.]
print *, a
i = .false.
print *, i
j = (5 < 7) .and. (sin(0.3) < 1.0)
print *, j
k = 3*5 - 5*3
if(.not.k) print *, "Conversion to logical is correct"
print *
print *, .false. + .true.
print *, .true. * .true.
print *, (2.2>5.5) + (2.2<5.5) ! + has higher precedence than < or >
print *, 2.2>5.5 .or. 2.2<5.5 ! see my point?
print *
print *, [.true., .false.] == [.true., .false.]
if(all(a == b)) then
print *, "something's wrong"
else if(any(a /= b)) then
print *, "Array non-equality check"
end if
end program test
所以,我使用ifort编译了它,并得到了&#34;错误的东西&#34;消息,然后我编译它 使用gfortran,它按预期运行。尝试时似乎有些东西坏了 将逻辑数组分配给可分配的逻辑数组变量(此处为a和b)。
目前,我正在使用ifort 15的试用版。将来,我计划为我的数值模拟代码购买学生(每个许可证200美元)的套餐。有些人可能会问,&#34;为什么不继续使用gfortran?&#34;好吧,我喜欢fortran 2003的功能,而语言的一些重要方面还没有在gfortran中实现:(。
评论?建议?投诉?
答案 0 :(得分:3)
嗯,它不是ifort
...你正在使用一个相对已知的功能(2003,我认为)通过为可分配的数组分配左侧来分配左侧:
a = [.true., .true.]
b = [.false., .true.]
对于内在分配,默认情况下会为ifort
停用此功能。在编译期间使用-assume realloc-lhs
,可以激活此功能,并且您的代码将按预期编译和运行。