<?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 Unusual stack overflow in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775529#M24853</link>
    <description>In this case the z component was declared with "allocatable" and without target(iow not pointer to section of array). Therefore the compiler could directly make the correctdecision about using a temporary or not.&lt;BR /&gt;&lt;BR /&gt;In most other cases where it is unknown at compile time, the compiler writers should be aware that their users (also programmers) are aware of a potential for the need of runtime temporary array allocations... and will avoid coding in a manner that requires a temporary. For these programmers, inserting code (and the associated overhead)to test for overlap and take appropriate code path with/without use of temporary, is preferrable to always generating code using a temp (under questionable circumstances).&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
    <pubDate>Thu, 02 Aug 2012 12:18:14 GMT</pubDate>
    <dc:creator>jimdempseyatthecove</dc:creator>
    <dc:date>2012-08-02T12:18:14Z</dc:date>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775527#M24851</link>
      <description>&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I am using Intel Visual Fortran Compiler XE 12.1.2.278.&lt;BR /&gt;&lt;BR /&gt;When I compile and run the following program, I am getting a stack overflow error.&lt;BR /&gt;I can fix this by making the stack bigger, by using the heap, or changing to a DO loop.&lt;BR /&gt;However, I don't understand why a simple assignment statement would want to use the stack in the first place.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Roman&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;[fortran]
module my_type_mod

   type my_type
      integer,allocatable:: z(:)
   end type my_type

end module my_type_mod
   
!-----------------------------------------------

module sub1_mod

contains

   subroutine sub1( A, B )
   use my_type_mod, only: my_type
   implicit none

   type(my_type),intent(in) :: A
   type(my_type),intent(out):: B

   integer n, i
   
   n = size( A%z )
   allocate( B%z(n) )

   ! The following line causes a stack overflow error.
   B%z = A%z
  
   ! Uncomment the following and comment the previous line
   ! to fix the stack overflow error.
  ! do i = 1, n
  !    B%z(i) = A%z(i)
  ! end do
   
   return
   end subroutine sub1
   
end module sub1_mod

!-----------------------------------------------

program test_stack

use my_type_mod, only: my_type
use sub1_mod, only: sub1

implicit none

type(my_type):: A, B

integer n

n = 1000000

allocate( A%z(n) )
A%z = 1

call sub1( A, B )

write(*,*) sum(B%z)

stop
end program test_stack
[/fortran]</description>
      <pubDate>Wed, 01 Aug 2012 21:58:48 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775527#M24851</guid>
      <dc:creator>Roman1</dc:creator>
      <dc:date>2012-08-01T21:58:48Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775528#M24852</link>
      <description>I believe this is on our "to do" list. The compiler does not recognize that whole allocatable array components are contiguous and don't overlap, so it creates a temporary copy of the right side of the assignment. I will nudge the developers again about this.</description>
      <pubDate>Wed, 01 Aug 2012 22:39:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775528#M24852</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-08-01T22:39:59Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775529#M24853</link>
      <description>In this case the z component was declared with "allocatable" and without target(iow not pointer to section of array). Therefore the compiler could directly make the correctdecision about using a temporary or not.&lt;BR /&gt;&lt;BR /&gt;In most other cases where it is unknown at compile time, the compiler writers should be aware that their users (also programmers) are aware of a potential for the need of runtime temporary array allocations... and will avoid coding in a manner that requires a temporary. For these programmers, inserting code (and the associated overhead)to test for overlap and take appropriate code path with/without use of temporary, is preferrable to always generating code using a temp (under questionable circumstances).&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Thu, 02 Aug 2012 12:18:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775529#M24853</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2012-08-02T12:18:14Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775530#M24854</link>
      <description>&lt;DIV id="tiny_quote"&gt;
                &lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=99850" class="basic" href="https://community.intel.com/en-us/profile/99850/"&gt;jimdempseyatthecove&lt;/A&gt;&lt;/DIV&gt;
                &lt;DIV style="background-color: #e5e5e5; padding: 5px; border: 1px; border-style: inset; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;In most other cases where it is unknown at compile time, the compiler writers should be aware that their users (also programmers) are aware of a potential for the need of runtime temporary array allocations... and will avoid coding in a manner that requires a temporary. For these programmers, inserting code (and the associated overhead)to test for overlap and take appropriate code path with/without use of temporary, is preferrable to always generating code using a temp (under questionable circumstances).&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;The compiler failing to take into account overlap where overlap was at all possible (and legal) would be a pretty serious bug. In my book, this would render the compiler all but unusable for any code with POINTERs.&lt;BR /&gt;&lt;BR /&gt;Based on questions seen on this forum and similar, there is a signficant proportion of Fortran programmers who wouldn't be aware of the potential for overlap with variables with the pointer/target attribute and the consequences of that in terms of the requirement for temporaries. I suspect that of the remainder, there would be a very significant proportion that wish for the compiler to do the right thing before it tries to do the fast thing.&lt;BR /&gt;&lt;BR /&gt;Programmers that are worried about performance/stack space consumption etc, (perhaps when they observe problems during a run, such as in this post) can trivially code around any compiler generated temporaries, whether they are necessary or not.&lt;BR /&gt;</description>
      <pubDate>Thu, 02 Aug 2012 23:11:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775530#M24854</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-08-02T23:11:05Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775531#M24855</link>
      <description>The Intel compiler assumes there is overlap unless it can prove there isn't. Over the years we've needed to refine and add tests to detect more cases where we know there is no overlap, such as this one. The developers know about it.&lt;BR /&gt;&lt;BR /&gt;/heap-arrays is a workaround, but if performance is important, avoiding the temp entirely is preferable.</description>
      <pubDate>Fri, 03 Aug 2012 13:41:24 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775531#M24855</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-08-03T13:41:24Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775532#M24856</link>
      <description>IanH,&lt;BR /&gt;&lt;BR /&gt;The compiler can test for overlap, in the cited example the two arguments were known by the compiler to be ALLOCATABLE and thus could not have overlaped. I think the compiler goofed the check for allocatable due to the z array being a component of a user defined type. Though the programmer's use of A%z and B%z could concievably be a reference to thethe same object z=z of the same allocated array should be harmless (though costly in unnecessary CPU cycles).&lt;BR /&gt;&lt;BR /&gt;In the situations where the compiler cannot assure non-overlap, then the compiler has two choices&lt;BR /&gt;a) Always use temporary (not preferred by me)&lt;BR /&gt;b) Insert code to determine b.1) overlaps, b.2) non-overlapping, b.3) unknown.&lt;BR /&gt;In the case of b.1 or b.3 use the temp, in the case of b.2 no temp.&lt;BR /&gt;&lt;BR /&gt;Note, the compiler writer can choose the degree to which the non-overlap test works (failure results in b.3 unknown).&lt;BR /&gt;&lt;BR /&gt;The most simple of test can be&lt;BR /&gt;&lt;BR /&gt; if(Stride.A == 1)&lt;BR /&gt; if(Stride.B == 1)&lt;BR /&gt; if(loc(A(lbound)) .lt. loc(B(lbound)))&lt;BR /&gt; if(loc(A(ubound)) .lt. loc(B(lbound)))&lt;BR /&gt; return non-overlap&lt;BR /&gt; else&lt;BR /&gt; return overlap&lt;BR /&gt; endif&lt;BR /&gt;endif&lt;BR /&gt; if(loc(B(lbound)) .lt. loc(A(lbound)))&lt;BR /&gt; if(loc(B(ubound)) .lt. loc(A(lbound)))&lt;BR /&gt; return non-overlap&lt;BR /&gt; else&lt;BR /&gt; return overlap&lt;BR /&gt; endif&lt;BR /&gt;endif&lt;BR /&gt; // here if A==B&lt;BR /&gt;decide if to remove unnecessary code&lt;BR /&gt; endif&lt;BR /&gt; endif&lt;BR /&gt;return unknown&lt;BR /&gt;&lt;BR /&gt;The above test could be donewith less than30 instructions.&lt;BR /&gt;&lt;BR /&gt;Please consider adding a compiler option to indicate if you want the test overhead (to avoid copy overhead) or no test overhead (generate copy code when compiler cannot make the determination).&lt;BR /&gt;&lt;BR /&gt;I suspect that there is some benchmark program that always requires a temporary and in this case performance is increased by not having the test. (default could then be no runtime test for overlap).&lt;BR /&gt;&lt;BR /&gt;What is the compiler writer's opinion of if the cache designer decided the test for data in cache is extra work so we won't make this test? Well creating an unnecessary temporary can cause 10's, 100's, 1000's, ... of unnecessary cache misses, flushes, and not to mention the occasional Stack Overflow.&lt;BR /&gt;&lt;BR /&gt;Jim Dempsey</description>
      <pubDate>Fri, 03 Aug 2012 15:52:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775532#M24856</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2012-08-03T15:52:40Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775533#M24857</link>
      <description>Ok. I thought you were advocating for a c) the compiler writers should assume that things with the POINTER/TARGET attribute will never overlap (don't bother testing and don't bother with a temporary) because Fortran programmers are smart.&lt;BR /&gt;&lt;BR /&gt;(I initially read your response as saying that "these (smart) programmers" should be "inserting code", not the compiler - I follow your point now.)</description>
      <pubDate>Fri, 03 Aug 2012 23:04:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775533#M24857</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2012-08-03T23:04:39Z</dc:date>
    </item>
    <item>
      <title>Unusual stack overflow</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775534#M24858</link>
      <description>It turns out that this problem occurs only when dummy arguments are involved. We have fixed that for a future release (not the one coming up.)</description>
      <pubDate>Thu, 23 Aug 2012 21:19:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Unusual-stack-overflow/m-p/775534#M24858</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2012-08-23T21:19:00Z</dc:date>
    </item>
  </channel>
</rss>

