DomBernard
Programmer
I've extracted from a larger code the following code where the DO loop is the cause of a bug:
PROGRAM MODIF_GEOM3D
IMPLICIT NONE
INTEGER :: NX,NY,NZ,I
REAL(KIND=4) :: IVF1,IVF2
! REAL(KIND=8) :: IVF1,IVF2
! INTEGER :: IVF1,IVF2
NX = 400**3
DO I=1,NX
IVF2 = IVF1
IVF1 = I
IF(IVF1==IVF2) THEN
WRITE(6,*) I,IVF1,IVF2
STOP
ENDIF
ENDDO
WRITE(6,*) 'IVF1 = ',IVF1
END PROGRAM MODIF_GEOM3D
After compiling with gfortran on 3 different computers I've obtained the following:
[uxmalrog_DB/Geom/src] bernard% gfortran Simple_Test.FOR
[uxmalrog_DB/Geom/src] bernard% ./a.out
16777217 16777216. 16777216.
If IVF1 and IVF2 are declared as REAL 8 or INTEGER the result is now:
[uxmalrog_DB/Geom/src] bernard% gfortran Simple_Test.FOR
[uxmalrog_DB/Geom/src] bernard% ./a.out
IVF1 = 64000000.000000000
This is of course the logical one.
Any explanation?
PROGRAM MODIF_GEOM3D
IMPLICIT NONE
INTEGER :: NX,NY,NZ,I
REAL(KIND=4) :: IVF1,IVF2
! REAL(KIND=8) :: IVF1,IVF2
! INTEGER :: IVF1,IVF2
NX = 400**3
DO I=1,NX
IVF2 = IVF1
IVF1 = I
IF(IVF1==IVF2) THEN
WRITE(6,*) I,IVF1,IVF2
STOP
ENDIF
ENDDO
WRITE(6,*) 'IVF1 = ',IVF1
END PROGRAM MODIF_GEOM3D
After compiling with gfortran on 3 different computers I've obtained the following:
[uxmalrog_DB/Geom/src] bernard% gfortran Simple_Test.FOR
[uxmalrog_DB/Geom/src] bernard% ./a.out
16777217 16777216. 16777216.
If IVF1 and IVF2 are declared as REAL 8 or INTEGER the result is now:
[uxmalrog_DB/Geom/src] bernard% gfortran Simple_Test.FOR
[uxmalrog_DB/Geom/src] bernard% ./a.out
IVF1 = 64000000.000000000
This is of course the logical one.
Any explanation?