IEEE set halting mode and optimization

IEEE set halting mode and optimization

Dear all,

I found that some optimizations override IEEE instructions when using ifort 13.1.0:

program test
   !
   use, intrinsic :: ieee_exceptions
   implicit none
   !
   integer, parameter :: RKIND = 16
   !
   real(RKIND) :: a, b, c
   logical     :: ieee_flag_is_raised
   !
   a = 1.0_RKIND
   b = 0.0_RKIND
   !
   ! Division by zero allowed
   !
   call ieee_set_halting_mode(IEEE_DIVIDE_BY_ZERO, .false.)
   c = a / b
   ieee_flag_is_raised = .false.
   call ieee_get_flag(IEEE_DIVIDE_BY_ZERO, ieee_flag_is_raised)
   print *, c, ieee_flag_is_raised
   !
   ! Division by zero forbidden
   !
   call ieee_set_halting_mode(IEEE_DIVIDE_BY_ZERO, .true.)
   c = a / b
   call ieee_get_flag(IEEE_DIVIDE_BY_ZERO, ieee_flag_is_raised)
   print *, c, ieee_flag_is_raised
   !
   stop 'End of test.'
   !
end program test

This code does not works properly when using -O2:

{bis01216}: ~/tmp> ifort -O2 test.f90
{bis01216}: ~/tmp> a.out
                                   Infinity T
                                   Infinity T
End of test.

But if I disable optimizations it is OK:

{bis01216}: ~/tmp> ifort -O0 test.f90
{bis01216}: ~/tmp> a.out
                                   Infinity T
forrtl: error (73): floating divide by zero
Image              PC                Routine            Line        Source             
a.out              000000000046DA9F  Unknown               Unknown  Unknown
a.out              0000000000402C7B  Unknown               Unknown  Unknown
a.out              0000000000402B2C  Unknown               Unknown  Unknown
libc.so.6          0000003475E1ECDD  Unknown               Unknown  Unknown
a.out              0000000000402A29  Unknown               Unknown  Unknown
Abandon (core dumped)

Thank you for your support !

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Yes if you check docs you should see requirements to set -fp precise for full ieee support.

Thank you Tim, but using -fp-model precise or source does not change anything.

It works when I use -fpe0.

With optimization the compiler can see the values are constants and does the operation at compile-time and it doesn't see your request to change the halting mode. If you READ the values instead, you'll get this:

1 0
                                   Infinity T
forrtl: error (73): floating divide by zero
Image              PC        Routine            Line        Source
t.exe              01136CD8  Unknown               Unknown  Unknown
t.exe              010E1137  _MAIN__                    26  t.f90

 

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today