Memory leak caused by derived types (nvfortran)

Consider the following minimal working example:

module lib
    type FG_t
        real,allocatable::g(:)
    contains
        procedure,private::FG_Assign
        generic::assignment(=)=>FG_Assign
    end type
    interface operator(-)
        procedure FG_Sub
    end interface
contains
    elemental subroutine FG_Assign(this,that)
        class(FG_t),intent(inout)::this
        class(FG_t),intent(in)::that
        this%g=that%g
    end
    elemental type(FG_t) function FG_Sub(this,that)
        class(FG_t),intent(in)::this
        real,intent(in)::that
        FG_Sub=FG_t(this%g-that)
    end
end

program prog
    use lib
    type(FG_t)::arr(1000),arr_(SIZE(arr))
    do i=1,SIZE(arr)
        allocate(arr(i)%g(10))
    end do
    do i=1,100000
        arr_=arr-1.
    end do
end

This example was already discussed here.

When running the executable generated from the code with the Nvidia compiler (nvfortran 22.9 on Ubuntu 18.04.2 LTS), memory fills rapidly (which can lead to your PC crashing in the case of a higher number of iterations). Intel VTune Profiler shows that most of the memory is allocated in the line this%g=that%g after FG_Sub is called in the line arr_=arr-1..

The similar problem can be observed with the Intel and NAG compilers. Intel and NAG responded and agreed that it is a bug. Therefore, I would like to report this bug to Nvidia.

Thanks vlad0dalv.

I’ve filled a problem report, TPR #33180, and will have engineering investigate.

-Mat

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.