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

Bug in intrinsic function sum() compiled with -fp-model precise

$
0
0

I'm running the latest ifort 2017.1 and found this unwanted behavior. It's illustrated by a short program and the result after two different compilations.

> cat test_sum.f
      PROGRAM TEST_SUM
      INTEGER(8),PARAMETER :: N = 1024 * 1024 * 1024
      INTEGER(8) :: SEED(1) = (/12345678/)
      REAL(4) :: A(N)
      REAL(8) :: B(N)

!     Fill the array A with random numbers in the range [0 - 1].
      CALL RANDOM_SEED(PUT=SEED)
      CALL RANDOM_NUMBER( A )

!     Copy the values to the double precision array B.
      B(:) = A(:)

!     Expected sum = N * 0.5 = 536870912 = 5.3687091E+08
!     The sum may differ a bit due to the random numbers drawn.
      PRINT *, 'Sum(A):', REAL(SUM(A))
      PRINT *, 'Sum(B):', REAL(SUM(B))

      END PROGRAM TEST_SUM
>
> ifort -i8 test_sum.f
> a.out
 Sum(A):  5.3684355E+08
 Sum(B):  5.3687296E+08
>
> ifort -i8 -fp-model precise test_sum.f
> a.out
 Sum(A):  1.6777216E+07
 Sum(B):  5.3687296E+08

So the real*8 array was summed up correctly, but not the real*4 array when compiled with the -fp-model precise option. The result was the same if the arrays A and B were allocated arrays.

Thread Topic: 

Bug Report

Viewing all articles
Browse latest Browse all 2583

Trending Articles



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