标签: nag-fortran

函数返回具有相同参数的不同答案

我正在从MATLAB过渡到Fortran,遇到了各种奇怪的行为,这些行为是我从未期望过的.这是让我困惑的一个:

Program pruebanormal

double precision :: g01eaf, x, y

character :: T*1

integer :: Iffail

Iffail = 0

T = 'L'

x = 0.0

y = g01eaf('L',0.0,Iffail)

write(*,*) 'y = ',y

end program pruebanormal
Run Code Online (Sandbox Code Playgroud)

我有这个相当简单的程序,我试图在标准N(0,1)变量的x = 0处找到pdf(应该是0.5).g01eaf()是NAG库函数,它为我做这个.我正在使用gfortran进行编译.

保留程序的其余部分,取决于我如何编写参数g01eaf(),我得到不同的答案:

a) g01eaf(T,x,Iffail)

b) g01eaf(T,0.0,Iffail)

c) g01eaf(T,x,0)
Run Code Online (Sandbox Code Playgroud)

现在,在MATLAB下,我会得到相同的(正确的)答案:y = 0.500000.但是,在Fortran下,我得到:

a) y = 0.500000

b) y = 1.000000

c) Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0xB766C163
#1  0xB766C800
#2  0xB77763FF …
Run Code Online (Sandbox Code Playgroud)

matlab fortran arguments nag-fortran

2
推荐指数
1
解决办法
180
查看次数

空数组的边界检查——各种编译器的行为

更新20210914:Absoft 支持确认下面描述的af95/行为是无意的,并且确实是一个错误。af90Absoft 开发人员将努力解决这个问题。其他编译器在这方面的行为是正确的。感谢@Vladimir F 的回答、评论和建议。


我的印象是 Fortran 对于大小为 0 的数组很酷。但是,在 Absoft Pro 21.0 中,我遇到了涉及此类数组的(奇怪的)错误。相比之下,gfortranifortnagforpgfortransunf95g95都对同一段代码感到满意。

下面是一个最小的工作示例。

! testempty.f90

!!!!!! A module that offends AF90/AF95 !!!!!!!!!!!!!!!!!!!!!!!!
module empty_mod

implicit none
private
public :: foo

contains

subroutine foo(n)
implicit none
integer, intent(in) :: n
integer :: a(0)
integer :: b(n - 1)
call bar(a)  ! AF90/AF95 is happy with this line.
call bar(b)  ! AF90/AF95 is …
Run Code Online (Sandbox Code Playgroud)

fortran gfortran intel-fortran pgi-visual-fortran nag-fortran

2
推荐指数
1
解决办法
88
查看次数