Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

IEEE set halting mode and optimization

$
0
0

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 !


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>