ieee_get_flag behavior varies for externally linked procedures?

ieee_get_flag behavior varies for externally linked procedures?

Hello all, 

I have noticed a wierd behavior when using ieee_get_flag.

As an example consider the following.

Compiling the following as a whole (from a single .f90 file, without any compilation options), gives a False for the ieee_invalid flag for 0/0 [ attached file test2.f90 ]:

module my_subs
implicit none
subroutine NaNsub(r1)
real,intent(out) :: r1
r1 = 0./0.
end subroutine NaNsub
end module my_subs
program test2
use ieee_exceptions
use my_subs
implicit none
logical :: NaN_found
real :: r1
call NaNsub(r1)
call ieee_get_flag(ieee_invalid,NaN_found)
print *, NaN_found
end program test2

However, if I put the module in a seperate file [test3.f90 + NaNsub.f90] compile it and link it to the main code the answer flag becomes true (no compilation options). So I think that something strange happens. Could you please check if you can reproduce this ? Could this behavior be related to the default optimizations used? I'm using v13.1.2 running in Ubuntu 13.01. 

Many Thanks,


Descargar test2.f90336 bytes
Descargar test3.f90192 bytes
Descargar nansub.f9078 bytes
publicaciones de 7 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Steve Lionel (Intel)

You need to compile with -fp-model strict when using the IEEE modules or trying things such as 0./0..  Does this help?

Imagen de Steve Lionel (Intel)

I would also recommend using IEEE_VALUE(0.,IEEE_SIGNALING_NAN) rather than rolling your own NaN.


Hello Steve,

Thank you very much for your answer. 
Indeed using -fp-model strict (or removing the optimizations say -check all) gives the desired answer. But still, does this explain the same code having a different behavior based on whether:

1. I compile the module and main both included in the same .txt file : test2.f90

        ifort test2.f90
        -> gives False 

2. I compile the module first (or just the subroutine - nansub.f90) and link it to the the main (test3.f90)

         ifort -c nansub.f90
         ifort test3.f90 nansub.o
         -> gives True

So the same code has produces a different based on whether the linking is implied or not. Should this happen ? Shouldn't I obtain the same result independently on how the executable is produced (when using default compilation options)? 

Thank you!


Imagen de Steve Lionel (Intel)

No - when you have the caller and callee together, the optimizer can inline the call and it may do additional optimizations that interfere with your assumptions about IEEE behavior. With the separate compilation it can't do that (unless you also use -ipo).


Thank you Steve!

-ipo produces false in both cases

So would you suggest -ipo as a recommended practise when linking seperately ?

Imagen de Steve Lionel (Intel)

-ipo is an optimization option. If your program is correct, it should not change the behavior. In your case, it was the missing -fp-model that caused the problem. You are encouraged to use -ipo to improve performance of applications, as long as you understand that it will increase build time and resource usage.


Inicie sesión para dejar un comentario.