<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic In subroutine iMovAlloc, in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157463#M142010</link>
    <description>&lt;P&gt;In subroutine iMovAlloc, dummy "to" is actual argument "a" from caller. The caller's "a" is not being replaced (its member variable "v" is). Thus I think the issue is the intent attribute of iMoveAlloc "to" may need to be "in".&lt;/P&gt;&lt;P&gt;Note, in your alternate call using a%v (and using to=to in iMoveAlloc) then intent(out) is appropriate.&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
    <pubDate>Sat, 14 Dec 2019 13:52:23 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2019-12-14T13:52:23Z</dc:date>
    <item>
      <title>memory leak with move_alloc</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157462#M142009</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;I am using "move_alloc" to transfer the&amp;nbsp;allocation from&amp;nbsp;an intrinsic array to an allocatable member of a DT&amp;nbsp;and&amp;nbsp;I get a memory growth issue (ifort 19 for Mac OS)&lt;BR /&gt;Here is a sample:&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;! compiled with: ifort leak_movealloc.f90 -o leak_movealloc
! (ifort version: 19.0.5 for Mac OS)

PROGRAM leak_movealloc
implicit none

type :: i_t
   integer, allocatable :: v(:,:)
end type i_t

integer, parameter   :: n = 2000, m = 300, RepeateNtimes = 100
type(i_t)            :: a
integer              :: it, Imat0(n,m) = 0
integer, allocatable :: Imat(:,:)

do it = 1, RepeateNtimes

   allocate(Imat, source = Imat0)
!
!- Move allocation from Imat to a%v:
!
   call iMoveAlloc ( from = Imat, to = a )  ! &amp;lt;-- This produces a memory growth
   
  !call move_alloc ( from = Imat, to = a%v ) ! &amp;lt;-- But not this!
   
   write(*,'(a)',advance='no') "hit return to continue" ; read*
   
end do

CONTAINS

   SUBROUTINE iMoveAlloc ( from, to )
   integer  , allocatable, intent(in out) :: from(:,:)
   type(i_t),              intent(   out) :: to

   call move_alloc (from = from, to = to%v)
   
   END SUBROUTINE iMoveAlloc
   
END PROGRAM leak_movealloc&lt;/PRE&gt;

&lt;P&gt;The problem occurs when&amp;nbsp;move_alloc is not called directly but from the&amp;nbsp;subroutine iMoveAlloc&amp;nbsp;(in which the argument "to" has intent "out" though)&lt;/P&gt;
&lt;P&gt;The problem goes away if I deallocate "a%v" before calling&amp;nbsp;iMoveAlloc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone have any idea what the problem is?&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;Riad&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 11:13:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157462#M142009</guid>
      <dc:creator>riad_h_1</dc:creator>
      <dc:date>2019-12-14T11:13:06Z</dc:date>
    </item>
    <item>
      <title>In subroutine iMovAlloc,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157463#M142010</link>
      <description>&lt;P&gt;In subroutine iMovAlloc, dummy "to" is actual argument "a" from caller. The caller's "a" is not being replaced (its member variable "v" is). Thus I think the issue is the intent attribute of iMoveAlloc "to" may need to be "in".&lt;/P&gt;&lt;P&gt;Note, in your alternate call using a%v (and using to=to in iMoveAlloc) then intent(out) is appropriate.&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 13:52:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157463#M142010</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2019-12-14T13:52:23Z</dc:date>
    </item>
    <item>
      <title>Hi Jim and thanks for your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157464#M142011</link>
      <description>&lt;P&gt;Hi Jim and thanks for your answer.&lt;/P&gt;&lt;P&gt;I'm not sure I understand. For a dummy&amp;nbsp;argument with intent(out), components are initialised&amp;nbsp;to its default values (if any,&amp;nbsp;otherwise&amp;nbsp;become undefined)&amp;nbsp;and allocatable members are deallocated on entry to the subroutine. Thus, here, iMovAlloc,&amp;nbsp;deallocates just a%v.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And consider I replace iMoveAlloc by (but of course, that's not what I want to do):&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;   SUBROUTINE copyThenDealloc ( from, to )
   integer  , allocatable, intent(in out) :: from(:,:)
   type(i_t),              intent(   out) :: to

   allocate(to%v, source = from)
   deallocate(from)
   
   END SUBROUTINE copyThenDealloc
&lt;/PRE&gt;

&lt;P&gt;No leak is produced.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Riad&lt;/P&gt;</description>
      <pubDate>Sat, 14 Dec 2019 14:48:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157464#M142011</guid>
      <dc:creator>riad_h_1</dc:creator>
      <dc:date>2019-12-14T14:48:52Z</dc:date>
    </item>
    <item>
      <title>In #3</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157465#M142012</link>
      <description>&lt;P&gt;In #3&lt;/P&gt;&lt;P&gt;The UDT variable &lt;EM&gt;to&lt;/EM&gt; is declared with intent(out)&lt;BR /&gt;the variable &lt;EM&gt;to&amp;nbsp;&lt;/EM&gt;is not being redefined, rather a member variable (v) within it is being allocated then initialized.&lt;BR /&gt;In a general sense, UDT variable &lt;EM&gt;to&lt;/EM&gt; could contain additional member variables, would you intend for these to be destroyed and redefined with default values (should you have a i_t&amp;nbsp;initializer)?&lt;/P&gt;&lt;P&gt;The observation that the code works is by no means an assurance that the code is correct (and won't fail under different circumstances).&lt;/P&gt;&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 13:56:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157465#M142012</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2019-12-16T13:56:30Z</dc:date>
    </item>
    <item>
      <title>yes in my real code, the DT</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157466#M142013</link>
      <description>&lt;P&gt;yes in my real code, the DT contains additional members (with default values).&amp;nbsp;And yes, in that case, they&amp;nbsp;are also (re)initialised in iMoveAlloc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seemed to me by using "out" I didn't have to worry about destroying the members of "to" and&amp;nbsp;that they would be automatically destroyed on entry (deallocated for allocatable members, initialised to default values for others).&lt;/P&gt;&lt;P&gt;Declaring "to" with intent(inout), requires more work. With my second routine (copyThenDealloc), for example, I should first&amp;nbsp;test if to%v is allocated (and if so,&amp;nbsp;deallocate it), etc.&lt;/P&gt;&lt;P&gt;Riad&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 15:08:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157466#M142013</guid>
      <dc:creator>riad_h_1</dc:creator>
      <dc:date>2019-12-16T15:08:30Z</dc:date>
    </item>
    <item>
      <title>Hi riad h., these kinds of</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157467#M142014</link>
      <description>&lt;P&gt;Hi riad h., these kinds of memory-leaks have troubled me for a long time with ifort, even though your issue is new since version 18 (linux version). As a workaround, I got used to writing finalizers, e.g. as follows&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;type :: i_t
    integer, allocatable :: v(:,:)
contains
    final :: i_t_final
end type i_t

! [...]

subroutine i_t_final(this)
    type(i_t), intent(inout) :: this
    if (allocated(this%v)) deallocate(this%v)
end subroutine&lt;/PRE&gt;

&lt;P&gt;These finalizers can eventually be removed once the issues are fixed by Intel.&lt;/P&gt;
&lt;P&gt;Kind regards&lt;BR /&gt;Ferdinand&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 15:54:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157467#M142014</guid>
      <dc:creator>Ferdinand_T_</dc:creator>
      <dc:date>2019-12-16T15:54:00Z</dc:date>
    </item>
    <item>
      <title>Hi Ferdinand,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157468#M142015</link>
      <description>&lt;P&gt;Hi Ferdinand,&lt;/P&gt;&lt;P&gt;Oh yes, that works!&lt;/P&gt;&lt;P&gt;In general, I use finalizers&amp;nbsp;only for DT&amp;nbsp;containing pointers,&amp;nbsp;I wouldn't have thought it would be necessary for allocatable components.&lt;/P&gt;&lt;P&gt;Many thanks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Riad.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 16:18:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157468#M142015</guid>
      <dc:creator>riad_h_1</dc:creator>
      <dc:date>2019-12-16T16:18:01Z</dc:date>
    </item>
    <item>
      <title>Quote:riad h. wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157469#M142016</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;riad h. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..&amp;nbsp;I am using "move_alloc" to transfer the&amp;nbsp;allocation from&amp;nbsp;an intrinsic array to an allocatable member of a DT&amp;nbsp;and&amp;nbsp;I get a memory growth issue (ifort 19 for Mac OS) ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@riad h.,&lt;/P&gt;&lt;P&gt;My impression is Intel Fortran team can notice the issue with your example as well as a further simplified one using Intel's own tools in Parallel Studio such as Intel Inspector.&amp;nbsp; The issue can also be confirmed with a private memory analyzer I use.&amp;nbsp; Note the same simple code when analyzed based on compilation output from another processor e.g., gfortran does NOT show a leak, so I'm inclined to believe this is an issue with Intel Fortran compiler.&amp;nbsp; I believe your code is conforming.&lt;/P&gt;&lt;P&gt;If you are able to, you should consider submitting a support request at Intel OSC center:&amp;nbsp;https://supporttickets.intel.com/servicecenter?lang=en-US&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;   type :: t
      integer, allocatable :: i
   end type
   integer, allocatable :: n
   type(t) :: foo
   n = 42
   call my_move_alloc( n, foo )
   print *, "foo%i = ", foo%i, "; expected is 42"
contains
   subroutine my_move_alloc( from, to )
      integer, allocatable, intent(inout) :: from
      type(t), intent(out)                :: to
      call move_alloc( from, to%i )
   end subroutine
end
&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="leak.PNG"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/10603i637AC9A71A84968B/image-size/large?v=v2&amp;amp;px=999&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="leak.PNG" alt="leak.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Dec 2019 17:07:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157469#M142016</guid>
      <dc:creator>FortranFan</dc:creator>
      <dc:date>2019-12-17T17:07:44Z</dc:date>
    </item>
    <item>
      <title>@FortranFan,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157470#M142017</link>
      <description>&lt;P&gt;@FortranFan,&lt;/P&gt;&lt;P&gt;I'll take your advice and&amp;nbsp;Thanks&amp;nbsp;for your example and comment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 14:12:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157470#M142017</guid>
      <dc:creator>riad_h_1</dc:creator>
      <dc:date>2019-12-18T14:12:31Z</dc:date>
    </item>
    <item>
      <title>Thank you for your report -</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157471#M142018</link>
      <description>&lt;P&gt;Thank you for your report - this case has been escalated to compiler engineering.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 23:53:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/memory-leak-with-move-alloc/m-p/1157471#M142018</guid>
      <dc:creator>Devorah_H_Intel</dc:creator>
      <dc:date>2019-12-20T23:53:32Z</dc:date>
    </item>
  </channel>
</rss>

