<?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: How is array memory allocated? Stack Overflow! in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841972#M59941</link>
    <description>It looks like you're trying to do dynamic allocation of arrays x and y. Try declaring x and y as ALLOCATABLE and then use the ALLOCATE statement with n as the dimension size.&lt;BR /&gt;&lt;BR /&gt;Mike</description>
    <pubDate>Thu, 08 Aug 2002 20:01:58 GMT</pubDate>
    <dc:creator>durisinm</dc:creator>
    <dc:date>2002-08-08T20:01:58Z</dc:date>
    <item>
      <title>How is array memory allocated? Stack Overflow!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841971#M59940</link>
      <description>How does Visual Fortran allocate memory for arrays? I'm trying to picture what's going on inside the computer to cause a stack overflow. We're having a debate here centered around the simple test program below. What's the difference between the calling argument being allocated in the calling routine and sent in and the local variables?&lt;BR /&gt;&lt;BR /&gt;We seem to have fixed our problem by changing the local variables from using the dimension passed in to using a constant. What is the compiler doing different?&lt;BR /&gt;&lt;BR /&gt;We'd like to let the calling routine take care of the dimension.&lt;BR /&gt;&lt;BR /&gt;subroutine foo(x, n)&lt;BR /&gt;   parameter (max=20)&lt;BR /&gt;c *** y &amp;amp; z are local variables ***&lt;BR /&gt;   dimension x(n), y(n), z(max)&lt;BR /&gt;&lt;BR /&gt;I'm using Visual Fortran v6.6a on W2K with 1Gb of RAM. I tried /stack:4000000 with no luck.&lt;BR /&gt;&lt;BR /&gt;The real program we're debugging is a java client with a Corba server calling a C++/Fortran DLL via JNI which is making debugging a real pain.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Aug 2002 07:33:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841971#M59940</guid>
      <dc:creator>dwreich</dc:creator>
      <dc:date>2002-08-08T07:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: How is array memory allocated? Stack Overflow!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841972#M59941</link>
      <description>It looks like you're trying to do dynamic allocation of arrays x and y. Try declaring x and y as ALLOCATABLE and then use the ALLOCATE statement with n as the dimension size.&lt;BR /&gt;&lt;BR /&gt;Mike</description>
      <pubDate>Thu, 08 Aug 2002 20:01:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841972#M59941</guid>
      <dc:creator>durisinm</dc:creator>
      <dc:date>2002-08-08T20:01:58Z</dc:date>
    </item>
    <item>
      <title>Re: How is array memory allocated? Stack Overflow!</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841973#M59942</link>
      <description>In your example, y and z are, as you say, local variables.  z isn't relevant to the discussion, but y has its bounds determined at run-time by the dummy argument n.  This makes it an "automatic array" and CVF allocates these on the stack when the routine is entered.  Windows has a fixed stack size, allocated by the linker, defaulting to 1MB.&lt;BR /&gt;&lt;BR /&gt;As Mike suggests, a better alternative is to declare y as ALLOCATABLE.  For example:&lt;BR /&gt;&lt;BR /&gt;subroutine foo(x, n)&lt;BR /&gt;parameter (max=20)&lt;BR /&gt;c *** y &amp;amp; z are local variables ***&lt;BR /&gt;dimension x(n), z(max)&lt;BR /&gt;real, allocatable :: y(:)&lt;BR /&gt;...&lt;BR /&gt;allocate(y(n))&lt;BR /&gt;&lt;BR /&gt;This will cause the allocation to be on the "heap", not subject to the stack limitation.  y will be automatically deallocated when foo returns, or you can deallocate it explicitly.&lt;BR /&gt;&lt;BR /&gt;Steve&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Aug 2002 20:37:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/How-is-array-memory-allocated-Stack-Overflow/m-p/841973#M59942</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2002-08-08T20:37:11Z</dc:date>
    </item>
  </channel>
</rss>

