Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

mysterious floating invalid

exactlysameguy
Beginner
461 Views

Hello everybody,

i have the following piece of code, that i cant quite figure out why it crashes: defined in the module :

real(kind=selected_real_kind(12)) function dist(delta_w, delta)
real(kind=selected_real_kind(12)) :: delta_w,delta
real(kind=selected_real_kind(12)) :: res
if (delta.lt.0.0000001) call assertion_fail(273)
res= exp((-0.5)*((delta_w/delta)**2))
if (res.gt.one) call assertion_fail(274)
if (res.lt.zero) call assertion_fail(275)
dist = res
end function dist

one and zero are appropriately defined somewhere else. However the code fails at with floating invalid at 274 and 275, even if i use 1 and 0 respectively.

forrtl: error (65): floating invalid Image PC Routine Line Source
cgehexe.intel-de 0814F1EF scorepmc_mp 275 scoremc.f90

How do i fix this, and why does this error occur in the first place?

  1. delta_w and delta both have values that dont lead to a NaN.
  2. The lines that fail are the lines with the call to assertion_fail(linenumber).
  3. One and zero are of the right types.
  4. exp is the generic intrinsic function.

Cheers and thanks for any help/suggestions

0 Kudos
2 Replies
Steven_L_Intel1
Employee
461 Views
I suggest that you create a small, standalone test case that shows this problem. In the process of doing so, you may figure it out on your own. If not, post the whole thing here and I'm sure we can help. An excerpt is rarely useful.
0 Kudos
mecej4
Honored Contributor III
461 Views
The code that you disclosed is for a function. There are no errors in the function source code, although I see that it contains two lines with assertions that display some paranoia, since exp(-x**2/2) can never be negative or larger than unity for any real x.

You then assure us as to various conditions being properly satisfied for the function call to work correctly, but you do not show the code that calls the function. As a result, you have set your readers up for failure -- failure to help you to go beyond the point that you have reached yourself.

I do not doubt that you received the runtime errors that you reported. Consider, however, that there are a large number of ways of calling the function correctly, and a large number of ways of calling the function incorrectly. Therefore, any runtime errors must have been caused by bugs in the source code that you have not yet shown us. There is a slight chance of compiler bugs being responsible, but that is just speculation and not to be considered until errors in the user code (the part that you have yet to show us) have been ruled out.

Here, for example, is one correct program that incorporates your function:

[fortran]program esguy
implicit none
integer, parameter :: k12 = selected_real_kind(12)

write(*,*) dist(1.0_k12,2.0_k12)

contains
real(kind=k12) function dist(delta_w, delta)
real(kind=k12) :: delta_w,delta
real(kind=k12) :: res
real(kind=k12) :: one = 1, zero = 0
if (delta.lt.0.0000001) call assertion_fail(273)
res= exp((-0.5)*((delta_w/delta)**2))
if (res.gt.one) call assertion_fail(274)
if (res.lt.zero) call assertion_fail(275)
dist = res
end function dist

subroutine assertion_fail(lno)
integer :: lno
write(*,*)' Assertion failed at line ',lno
return
end subroutine assertion_fail

end program esguy[/fortran]
It runs and prints out the correct result.
0 Kudos
Reply