ifort 11.1 and O2 optimization: wrong results

ifort 11.1 and O2 optimization: wrong results

Dear all,

The code in question:

!##################
! MODULE FOR TYPES
!##################
MODULE mod_types
  IMPLICIT NONE
  PRIVATE

  PUBLIC :: type_glob, type_geom, type_edge

  !-------------
  ! Type node
  !-------------
  TYPE type_node
     REAL :: X = 0.D0
     REAL :: Y = 0.D0
     
  END type type_node

 

  !-------------
  ! Type edge
  !-------------
  TYPE type_edge
     TYPE(type_node) :: node1
     TYPE(type_node) :: node2
     REAL :: Len = 0.D0
     
  END type type_edge

 

  !-------------
  ! Type geom
  !-------------
  TYPE type_geom
     TYPE(type_edge), POINTER, DIMENSION(:) :: tabEdge => NULL()
     
  END type type_geom

 

  !-------------
  ! Type glob
  !-------------
  TYPE type_glob
     INTEGER :: nbBody = 0
     TYPE(type_geom), POINTER, DIMENSION(:) :: geom => NULL()
     
  END type type_glob

END MODULE mod_types

 

!#####################
! MODULE FOR ROUTINES
!#####################
MODULE mod_sub
  USE mod_types , ONLY : type_glob, type_geom, type_edge
  IMPLICIT NONE
  PRIVATE

  PUBLIC :: sub

CONTAINS
  !----------------
  ! Subroutine sub
  !----------------
  SUBROUTINE sub(glob)
    TYPE(type_glob), POINTER :: glob
    
    CALL lire(glob)
    CALL lire2(glob)        ! Good results when commented. Bad results when not commented
    
  END SUBROUTINE sub

 

  !-----------------
  ! Subroutine lire
  !-----------------
  SUBROUTINE lire(glob)
    TYPE(type_glob), POINTER :: glob

    TYPE(type_geom), POINTER :: geom => NULL()
    TYPE(type_edge), POINTER, DIMENSION(:) :: tab => NULL()
    INTEGER :: ibody, N, i

    N = 128

    DO ibody=1, glob%nbBody
       geom => glob%geom(ibody)

       ALLOCATE(geom%tabEdge(N))
       tab => geom%tabEdge
       DO i=1, N
          tab(i)%node1%X = 1.D0
          tab(i)%node1%Y = 2.D0
          tab(i)%node2%X = 3.D0
          tab(i)%node2%Y = 4.D0
          
          tab(i)%Len = SQRT( &
               (tab(i)%node1%X-tab(i)%node2%X)*(tab(i)%node1%X-tab(i)%node2%X) + &
               (tab(i)%node1%Y-tab(i)%node2%Y)*(tab(i)%node1%Y-tab(i)%node2%Y))
          
       END DO
       
       DO i=1, N
          WRITE(*,'(A9,5E20.12)') 'output = ', &
               glob%geom(ibody)%tabEdge(i)%node1%X, &
               glob%geom(ibody)%tabEdge(i)%node1%Y, &
               glob%geom(ibody)%tabEdge(i)%node2%X, &
               glob%geom(ibody)%tabEdge(i)%node2%Y, &
               glob%geom(ibody)%tabEdge(i)%Len
       END DO
    END DO
    

    tab => NULL()
    geom => NULL()

  END SUBROUTINE lire

 

  !------------------
  ! Subroutine lire2
  !------------------
  SUBROUTINE lire2(glob)
    TYPE(type_glob), POINTER :: glob
    
    WRITE(*,*) 'hello'
    
  END SUBROUTINE lire2
 
 
END MODULE mod_sub

 

!#####################
! MAIN PROGRAM
!#####################
PROGRAM main
  USE mod_types , ONLY : type_glob
  USE mod_sub , ONLY : sub
  IMPLICIT NONE
 
  TYPE(type_glob), POINTER :: glob => NULL()
  INTEGER :: i

  ALLOCATE(glob)
  glob%nbBody = 1
  ALLOCATE(glob%geom(glob%nbBody))

  CALL sub(glob)

  DO i=1,glob%nbBody
     DEALLOCATE(glob%geom(i)%tabEdge)
  END DO
  DEALLOCATE(glob%geom)
  DEALLOCATE(glob)

 
END PROGRAM main

 

 

Wrong results (at line 113: output = ) appear when line 76 (CALL lire2(glob)) is not commented. Good results appear when this line is commented. Good result is sqrt(8)=2.8284

Problems appear with ifort 11.1 20100806 and the O2 optimization. No problem with O0 optimization. No problem with ifort 13.1 (even with O2)

It seems that when tab(i)%Len is computed, values for tab(i)%node1%Y and tab(i)%node2%Y are not the ones read just the lines before but the ones given at initialization (here 0.D0)

 

Any idea ?

Thank you.

Best regards,

Pierre

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Use the newer compiler. Bugs get fixed. 14.0 is current.

Steve - Intel Developer Support

Otherwise, if you need to use the 11.1 compiler, try to identify which routine needs to be compiled with lower optimization, (e.g. using a binary search). Compile just this at the highest level that gives correct results. For example, you might try -O1, or -O2 -fp-model precise.

Leave a Comment

Please sign in to add a comment. Not a member? Join today