<?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 Re: stack overflow problem in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528515#M168337</link>
    <description>&lt;P&gt;gfortran uses the equivalent of Intel's -heap-arrays option by default.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 15:12:25 GMT</pubDate>
    <dc:creator>Steve_Lionel</dc:creator>
    <dc:date>2023-09-28T15:12:25Z</dc:date>
    <item>
      <title>stack overflow problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528356#M168330</link>
      <description>&lt;P&gt;Hello, I found a strange problem when I use Intel Fortran&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000&lt;/LI-CODE&gt;&lt;P&gt;The minimal work source code is as the below,&lt;/P&gt;&lt;LI-CODE lang="fortran"&gt;subroutine foo(adim1,bdim1,adim2,bdim2,a,b,abdist)
    implicit none
    integer,parameter::nmax=1000
    integer ,intent(in):: adim1,bdim1,adim2,bdim2
    double precision ,intent(in)::a(adim1,adim2),b(bdim1,bdim2)
    double precision ,intent(out)::abdist(adim2,bdim2)
    double precision :: c(nmax,nmax)   !OK
    !double precision :: c(adim2,bdim2)     !NG
    print*,"adim1,bdim1,adim2,bdim2:",adim1,bdim1,adim2,bdim2
    
    c=0.0
    abdist=0.0

    return
end subroutine
      
      

      
program main
    implicit none
    integer,parameter::nmax=1000,ndim=2
    integer na,nb      
    double precision a(ndim,nmax),b(ndim,nmax)
    integer i
    
    double precision abdist_(nmax,nmax)
    double precision ,allocatable :: abdist(:,:)
    print*,'test:'
    !OK case   
    na = 500 ;  nb = 250    !(1)
    ! NG case
    na = 500 ;  nb = 300    !(2)
    do i=1,na
      a(:,i) = i*1.0
    end do      
    do i=1,nb
      b(:,i) = i*1.0
    end do      
      
    !reshape abdist according to the current size
    abdist = RESHAPE(abdist_,(/na,nb/))
    
    call foo(ndim,ndim,na,nb,a&amp;nbsp;,b,abdist)      
    print*,"final abdist:",abdist(na,nb)
      
    stop
end 

&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the subroutine foo, if I declare array c&amp;nbsp;&lt;/P&gt;&lt;P&gt;double precision :: c(adim2,bdim2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, in my test main program,&lt;/P&gt;&lt;P&gt;when I let na=500;nb=250, it is OK.&lt;/P&gt;&lt;P&gt;But when I let na=500;nb=300, it gave me error.&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;forrtl: severe (170): Program Exception - stack overflow&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But if I declare c in subroutine foo as&amp;nbsp;&lt;/P&gt;&lt;P&gt;double precision :: c(nmax,nmax)&amp;nbsp; !nmax=1000&lt;/P&gt;&lt;P&gt;it will also be OK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I compile the above code using command&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;ifort test.f90 -check -traceback  -o test.exe&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;gfortran has no such problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me to solve this problem. Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 00:41:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528356#M168330</guid>
      <dc:creator>mybiandou</dc:creator>
      <dc:date>2023-09-28T00:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: stack overflow problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528428#M168334</link>
      <description>&lt;P&gt;You are exceeding the stack size. There are compiler options to change the stack size and also the heaparrays option to make certain things be created on heap rather than stack. it gets a bit complicated and is effort! As a principal it is usually better to make larger arrays allocatable and allocate them and they are then always on the heap.&amp;nbsp; &amp;nbsp;See if that fixes the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 10:47:06 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528428#M168334</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2023-09-28T10:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: stack overflow problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528515#M168337</link>
      <description>&lt;P&gt;gfortran uses the equivalent of Intel's -heap-arrays option by default.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 15:12:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528515#M168337</guid>
      <dc:creator>Steve_Lionel</dc:creator>
      <dc:date>2023-09-28T15:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: stack overflow problem</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528672#M168353</link>
      <description>&lt;P&gt;Thanks for your answers,&amp;nbsp;&lt;SPAN&gt;andrew_461 and&amp;nbsp;Steve_Lionel.&lt;BR /&gt;Following your help, I use -heap-arrays option and get it run ok.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ifort test.f90 -heap-arrays  -check -traceback  -o test.exe&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 23:36:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/stack-overflow-problem/m-p/1528672#M168353</guid>
      <dc:creator>mybiandou</dc:creator>
      <dc:date>2023-09-28T23:36:29Z</dc:date>
    </item>
  </channel>
</rss>

