[Bug fortran/52053] SUM intrinsic is wrong for very large arrays
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Jan 30 15:44:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52053
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-01-30 14:48:09 UTC ---
(In reply to comment #0)
> REAL(KIND=4) :: a(20,1000,1000)
If you want to reduce problems due to the accumulation of rounds, you should
increase the precision. Try kind=8, 10 or 16 (in this case "8" is enough).
Note: Not all kind values are available on all systems. And depending on the
algorithm and the required precision, even kind=16 might be not precise enough.
In that case, one should find a better algorithm - for instance using integers.
Note, additionally, that the result also depends on the optimization level:
$ gfortran -O0 test.f90 && ./a.out
16777216.0
20000000.0
$ gfortran -Ofast test.f90 && ./a.out
20000000.0
20000000.0
And for a different compiler:
$ ifort -O0 test.f90 && ./a.out
1.6777216E+07
2.0000000E+07
$ ifort -O3 test.f90 && ./a.out
2.0000000E+07
2.0000000E+07
More information about the Gcc-bugs
mailing list