http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60543
Dominique d'Humieres <dominiq at lps dot ens.fr> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2014-03-16 Summary|Random number problems with |[4.8/4.9 Regression] |REAL64 precision at |Function with side effect |different optimization |removed by the optimizer. |levels | Ever confirmed|0 |1 --- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> --- Confirmed, although this has nothing to do with REAL64 precision nor with random number. The problem comes from the fact that one call to random() is optimized away. On trunk (4.9) the code is optimized as with following changes: @@ -45,7 +45,7 @@ USE globalParameters USE generalFunctions IMPLICIT NONE -REAL(DP):: magnitude +REAL(DP):: magnitude, tmp REAL(DP):: mass REAL(DP):: angle1, angle2 REAL(DP):: upsilon0_local, gasConstant, T @@ -71,11 +71,12 @@ DO i=1,2000 DO magnitude = 5e0_DP*random() ! WRITE(*,*) magnitude, EXP(-magnitude**2) - IF ( random() <= EXP(-magnitude**2) ) EXIT + tmp = random() + IF ( tmp <= EXP(-magnitude**2) ) EXIT END DO ! WRITE(*,*) - angle1=random()*twopi + angle1=tmp*twopi angle2=ACOS(2e0_DP*random()-1e0_DP) ; angle2=angle2-pi/2e0_DP upsilon0_local=SQRT(2e0_DP * gasConstant * T) For the moment I don't really understand what is happening with 4.8, i.e., infinite loop. AFAIU the dumps it looks optimized as @@ -69,9 +69,10 @@ T=293.15e0_DP DO i=1,2000 DO - magnitude = 5e0_DP*random() + tmp = random() + magnitude = 5e0_DP*tmp ! WRITE(*,*) magnitude, EXP(-magnitude**2) - IF ( random() <= EXP(-magnitude**2) ) EXIT + IF ( tmp <= EXP(-magnitude**2) ) EXIT END DO ! WRITE(*,*) But the executable does not hang when compiled with 4.7.4 or trunk.