does Inspector not like -assume realloc_lhs ?

does Inspector not like -assume realloc_lhs ?

I am using Inspector within a Fortran project and I have noticed that Inspector reports memory leaks for allocatable components of derived type objects which are on the rhs of an assignment at some point during the program execution. If I replace the assignment with a subroutine which does the same work (except of course without relying on ifort's -assume realloc_lhs magic), Inspector does not report those memory leaks.

What am I to conclude? Does Inspector not keep track properly when -assume realloc_lhs is in place, or is realloc_lhs actually causing a memory leak?

6 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Could you please provide you code sample and command line used? I'll try to run it on my side and see what's going on.
To get compiler command line in Visual Studio, go to Project Properties->Configuration properties->Fortran->Command Line.

Also please let me know, what version of Inspector XE do you run? Is it the latest update 2?
Do you build your project with MS or Intel compiler?

Hi - thanks for getting back to me.
I have not had time to reproduce the problem on a small code example - I'll try to do that soon & will post here. For now, I can only reproduce on my full project.
In the meantime, the command I was using to build:

ifort -fpp -assume realloc_lhs -warn all -gen-interfaces -warn notruncated_source -traceback -heap-arrays  -FR -O3  -openmp -openmp-report

The version of ifort is 12.0.3 20110309
The version of Inspector is Intel Inspector XE 2011 Update 1 (build 131372)

I didn't know about the update 2 - I downloaded Inspector just a couple of days ago. If you think it might make a difference, I can try with update 2.

I cannot reproduce this problem on my side, with a simple test case.
I don't know if this is an old bug in compiler, or this is a bugof Inspector XE for specific case.

#inspxe-cl -version
Intel Inspector XE 2011 Update 1 (build 131372) Command Line tool
Copyright (C) 2009-2010 Intel Corporation. All rights reserved.

#source /opt/intel/composerxe-2011.3.174/bin/compilervars.sh intel64

test program:

[fxfortran]MODULE TEST_MOD

   IMPLICIT NONE

   PUBLIC :: MY_TYPE, NEW_MY_TYPE, MY_TYPE_ASSIGNMENT

   PRIVATE

   TYPE MY_TYPE
      PRIVATE
      REAL, DIMENSION(:), POINTER :: ARR => NULL()
      INTEGER, POINTER :: REF_COUNT => NULL()
   CONTAINS
      PROCEDURE :: SET_ARR
      PROCEDURE :: GET_ARR
      FINAL :: DISPOSE
   END TYPE

   INTERFACE ASSIGNMENT (=)
      MODULE PROCEDURE MY_TYPE_ASSIGNMENT
   END INTERFACE

CONTAINS

! Overriding intrinsic assignment

   SUBROUTINE MY_TYPE_ASSIGNMENT( LHS, RHS )
      TYPE(MY_TYPE), INTENT(IN) :: RHS
      TYPE(MY_TYPE), INTENT(OUT) :: LHS
      WRITE(*,*) 'In defined assignment subroutine'
      LHS % ARR => RHS % ARR
      LHS % REF_COUNT => RHS % REF_COUNT
      LHS % REF_COUNT = LHS % REF_COUNT + 1
      WRITE(*,*) 'Reference count is: ', LHS % REF_COUNT
   END SUBROUTINE

! Finalizer
   
   SUBROUTINE DISPOSE( THIS )
      TYPE(MY_TYPE) :: THIS
      Write(*,*) 'In DISPOSE %LOC(THIS) =',%LOC(THIS)
      IF ( ASSOCIATED( THIS % REF_COUNT ) ) THEN
         THIS % REF_COUNT = THIS % REF_COUNT - 1
         WRITE(*,*) 'ref_count = ', THIS % REF_COUNT
         IF ( THIS % REF_COUNT == 0 ) THEN
            WRITE(*,*) 'Finalizing MY_TYPE'
            IF ( ASSOCIATED( THIS % ARR ) ) THEN
               WRITE(*,*) 'Finalizing: ', THIS % ARR
               DEALLOCATE( THIS % ARR )
            END IF
            DEALLOCATE( THIS % REF_COUNT )
         END IF
      END IF 
   END SUBROUTINE

! Constructor

   FUNCTION NEW_MY_TYPE(  ) RESULT( NEW )
      TYPE(MY_TYPE) :: NEW
      ALLOCATE( NEW % REF_COUNT )
      NEW % REF_COUNT = 1
     write (*,*) 'In NEW_MY_TYPE %LOC(NEW) =',%LOC(NEW)
   END FUNCTION

! Accessors

   SUBROUTINE SET_ARR( THIS, ARR )
      CLASS(MY_TYPE) :: THIS
      REAL, DIMENSION(:) :: ARR
      ALLOCATE( THIS % ARR( SIZE( ARR ) ) )
      THIS % ARR(:) = ARR(:)
   END SUBROUTINE

   FUNCTION GET_ARR( THIS ) RESULT( ARR )
      CLASS(MY_TYPE) :: THIS
      REAL, DIMENSION(:), POINTER :: ARR
      ARR => THIS % ARR
   END FUNCTION

END MODULE

SUBROUTINE TEST_SUB

   USE TEST_MOD

   IMPLICIT NONE

   TYPE(MY_TYPE) :: OBJ, OBJ2
   REAL, POINTER :: ARR(:)


   write(*,*) 'Creating new instance'
   OBJ = NEW_MY_TYPE( ) !<---- Function result value is not finalized after assignment
   write(*,*) 'Finished creating new instance'
   CALL OBJ % SET_ARR( [ 1.0, 2.0, 3.0 ] )

   write(*,*) 'New reference begin'
   OBJ2 = OBJ
   write(*,*) 'New reference end'

   ARR => OBJ % GET_ARR()
   WRITE(*,*) ARR

END SUBROUTINE

PROGRAM TEST
   CALL TEST_SUB
END PROGRAM
   
[/fxfortran]

Then build it:
[root@NHM02 problem_report]# ifort -g -check -assume realloc_lhs -warn ref_count.f90

[root@NHM02 problem_report]# inspxe-cl -collect mi3 -- ./a.out
Used suppression file(s): []
Creating new instance
In NEW_MY_TYPE %LOC(NEW) = 140736338714992
In DISPOSE %LOC(THIS) = 140736338714832
In defined assignment subroutine
Reference count is: 2
In DISPOSE %LOC(THIS) = 140736338714992
ref_count = 1
Finished creating new instance
New reference begin
In DISPOSE %LOC(THIS) = 140736338714912
In defined assignment subroutine
Reference count is: 2
New reference end
1.000000 2.000000 3.000000
In DISPOSE %LOC(THIS) = 140736338714832
ref_count = 1
In DISPOSE %LOC(THIS) = 140736338714912
ref_count = 0
Finalizing MY_TYPE
Finalizing: 1.000000 2.000000 3.000000

0 new problem(s) found

Regards, Peter

Thanks for looking into this.

Unfortunately, the work-around is so easy for me that I have not found time to try to come up with a reproducer. It is good to know your test case is handled well though - if/when I get time to look again at this issue, I'll be sure to update this thread.

Yeah, just a reminder - please use latest ifort 12.3 or above,with Inspector XE 2011 Update 1.

It's better that you can provide me a simple test case to reproduce this problem. Thank you.

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen