<?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 ifort's default (-auto in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162367#M143453</link>
    <description>&lt;P&gt;ifort's default (-auto-scalars) is that local arrays are statically allocated (unless you made the procedure RECURSIVE or used -auto or some other option that implies -auto.) It's actually sub1 where I might expect a stack overflow, but the compiler probably realized that you never used the array and eliminated it.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Nov 2018 15:04:00 GMT</pubDate>
    <dc:creator>Steve_Lionel</dc:creator>
    <dc:date>2018-11-21T15:04:00Z</dc:date>
    <item>
      <title>Code generation flags and automatic array confusion</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162366#M143452</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attempting to understand stack overflows brought about by large statically-sized local arrays using ifort on linux.&amp;nbsp;I hoped to produce a stack overflow error by reducing the stack size to 1000kb using "ulimit -s 1000" and then running a&amp;nbsp;test program included below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, I compiled this program with gfortran using a variety of options and was given an output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;In sub1: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1200000&lt;BR /&gt;Segmentation fault (core dumped)&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This makes sense to me. The compiler does not know the size of the array in sub1, so it allocates it to the heap.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However,&amp;nbsp;compiling with ifort using three different flags:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ifort -qopenmp test.f90&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;ifort -recursive test.f90&amp;nbsp;&lt;/P&gt;&lt;P&gt;ifort -auto&amp;nbsp; -heap-arrays 1500 test.f90&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All three executables produce the output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;In sub1: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1200000&lt;BR /&gt;&amp;nbsp;In sub2: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1200000&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, my question is, why is the second subroutine not producing a stack overflow?&amp;nbsp; I've tried using ifort 16.0.8 and 14.0.4 with similar results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would think that since the compiler knows the size of array p in sub2, it should put it on the stack, given the chosen options at compile time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class="brush:fortran; class-name:dark;"&gt;program test                                                                                                                                                                                                
  implicit none                                                                                                                                                                                             
                                                                                                                                                                                                            
  integer :: a                                                                                                                                                                                              
                                                                                                                                                                                                            
  a = 300000                                                                                                                                                                                                
                                                                                                                                                                                                            
  call sub1(a)                                                                                                                                                                                              
  call sub2(a)                                                                                                                                                                                              
end program                                                                                                                                                                                                 
                                                                                                                                                                                                            
subroutine sub1(a)                                                                                                                                                                                          
  implicit none                                                                                                                                                                                             
                                                                                                                                                                                                            
  integer,intent(in) :: a                                                                                                                                                                                   
  integer,dimension(a) :: q                                                                                                                                                                                 
                                                                                                                                                                                         
  print*, "In sub1:", sizeof(q)                                                                                                                                                                             
  q = 0                                                                                                                                                                                                     
                                                                                                                                                                                                            
end subroutine sub1                                                                                                                                                                                         
                                                                                                                                                                                                            
subroutine sub2(a)                                                                                                                                                                                          
  implicit none                                                                                                                                                                                             
                                                                                                                                                                                                            
  integer,intent(in) :: a                                                                                                                                                                                   
  integer,dimension(300000) :: p                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                            
  print*, "In sub2:", sizeof(p)                                                                                                                                                                             
  p = 0                                                                                                                                                                                                     
                                                                                                                                                                                                            
end subroutine sub2    &lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Nov 2018 15:43:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162366#M143452</guid>
      <dc:creator>Nathan</dc:creator>
      <dc:date>2018-11-20T15:43:52Z</dc:date>
    </item>
    <item>
      <title>ifort's default (-auto</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162367#M143453</link>
      <description>&lt;P&gt;ifort's default (-auto-scalars) is that local arrays are statically allocated (unless you made the procedure RECURSIVE or used -auto or some other option that implies -auto.) It's actually sub1 where I might expect a stack overflow, but the compiler probably realized that you never used the array and eliminated it.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 15:04:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162367#M143453</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2018-11-21T15:04:00Z</dc:date>
    </item>
    <item>
      <title> Indeed the compiler seems to</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162368#M143454</link>
      <description>&lt;P&gt;&amp;nbsp;Indeed the compiler seems to have foregone creating the array. Adding some random numbers and sums to the mix brought about the stack overflows I was expecting.&amp;nbsp; Thank you for your response.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Nov 2018 17:46:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Code-generation-flags-and-automatic-array-confusion/m-p/1162368#M143454</guid>
      <dc:creator>Nathan</dc:creator>
      <dc:date>2018-11-21T17:46:37Z</dc:date>
    </item>
  </channel>
</rss>

