链接已复制
7 回复数
Hi jhjensen
You may want to try the intrinsic IEEE_EXCEPTIONS module and monitor the exceptions flag. (Below is a very terse snippet.) This will not "generate traceback" per say; but gives you more control.
Yet another possibility, if you are using Visual Studio, is to enable Debug--> Exception --> Win32 exceptions.
Abhi
-------
Program Test_TrapFloatingPoint
Use IEEE_EXCEPTIONS
Implicit None
Real(8) :: x, y, z
Logical :: Exception(5)
Call Random_Seed()
Call Random_number(x)
Write(*,*) "Give a real number"
Read *, y
z = x/y
! Exception = [IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO,
! IEEE_INVALID, IEEE_UNDERFLOW, IEEE_INEXACT]
Call IEEE_GET_FLAG(IEEE_ALL, Exception)
if (ANY(Exception)) then
Write(*,*)
Write(*,*) "IEEE exception flags are:-"
Write(*,*)
Write(*,*) "IEEE_OVERFLOW:", Exception(1)
Write(*,*) "IEEE_DIVIDE_BY_ZERO:", Exception(2)
Write(*,*) "IEEE_INVALID:", Exception(3)
Write(*,*) "IEEE_UNDERFLOW:", Exception(4)
Write(*,*) "IEEE_INEXACT:", Exception(5)
else
Write(*,*) "Operation completed successfully."
endif
End Program Test_TrapFloatingPoint
You may want to try the intrinsic IEEE_EXCEPTIONS module and monitor the exceptions flag. (Below is a very terse snippet.) This will not "generate traceback" per say; but gives you more control.
Yet another possibility, if you are using Visual Studio, is to enable Debug--> Exception --> Win32 exceptions.
Abhi
-------
Program Test_TrapFloatingPoint
Use IEEE_EXCEPTIONS
Implicit None
Real(8) :: x, y, z
Logical :: Exception(5)
Call Random_Seed()
Call Random_number(x)
Write(*,*) "Give a real number"
Read *, y
z = x/y
! Exception = [IEEE_OVERFLOW, IEEE_DIVIDE_BY_ZERO,
! IEEE_INVALID, IEEE_UNDERFLOW, IEEE_INEXACT]
Call IEEE_GET_FLAG(IEEE_ALL, Exception)
if (ANY(Exception)) then
Write(*,*)
Write(*,*) "IEEE exception flags are:-"
Write(*,*)
Write(*,*) "IEEE_OVERFLOW:", Exception(1)
Write(*,*) "IEEE_DIVIDE_BY_ZERO:", Exception(2)
Write(*,*) "IEEE_INVALID:", Exception(3)
Write(*,*) "IEEE_UNDERFLOW:", Exception(4)
Write(*,*) "IEEE_INEXACT:", Exception(5)
else
Write(*,*) "Operation completed successfully."
endif
End Program Test_TrapFloatingPoint
PROGRAM TESTOVERFLOW
real r
integer i,n
write(*,*) 'Hello world'
read(*,*) i
r=1.
n=45
do i=1,n
r=r*10.
end do
write(*,*) 'r= ',r
read(*,*) i
END
compile and link:
ifort /c /MW /traceback /check:all /warn:nodeclarations /Qzero /fpe0 testoverflow.for
link /subsystem:windows testoverflow
Running will produce overflow error but no traceback line numbers
Regards
JHJ
real r
integer i,n
write(*,*) 'Hello world'
read(*,*) i
r=1.
n=45
do i=1,n
r=r*10.
end do
write(*,*) 'r= ',r
read(*,*) i
END
compile and link:
ifort /c /MW /traceback /check:all /warn:nodeclarations /Qzero /fpe0 testoverflow.for
link /subsystem:windows testoverflow
Running will produce overflow error but no traceback line numbers
Regards
JHJ
Interesting. Your use of /subsystem:windows and /MW made me wonder if the traceback was being disabled by that but I can see the same effect with a console application. I'll ask the developers about this. Issue ID is DPD200157968.
I note that compiling with /arch:ia32 allows the traceback to work.
I note that compiling with /arch:ia32 allows the traceback to work.
