<?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 Resize allocated array (F2003) in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912160#M83649</link>
    <description>In theory, this should work. It will likely incur a large overhead and will almost certainly make a temporary copy of the array in the assignment. It does not matter if the array is derived type.&lt;BR /&gt;</description>
    <pubDate>Fri, 15 Jan 2010 04:17:29 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2010-01-15T04:17:29Z</dc:date>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912159#M83648</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;THIS follows="" up="" on="" a="" thread="" in="" the="" linux=""&gt;&lt;/THIS&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Could someone please clarify re resizing an allocated array.&lt;/P&gt;
&lt;P&gt;For reading data from a file, I often need to allocate an array to store the data before I know how many records are in the file. To save reading through the file first to count the number of records (or reading to a large temp file first), it would be handy if the following was possible withou incurring a large overhead.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;ALLOCATE (array (large_number))  ! large_number &amp;gt;&amp;gt; likely number of records&lt;/P&gt;
&lt;P&gt;n = 0&lt;/P&gt;
&lt;P&gt;DO&lt;/P&gt;
&lt;P&gt;n = n + 1&lt;/P&gt;
&lt;P&gt;READ(...) array(n)&lt;/P&gt;
&lt;P&gt;if ( end of read) EXIT&lt;/P&gt;
&lt;P&gt;END DO&lt;/P&gt;
&lt;P&gt;array = array(:n)  ! hopefully 'array' now has dimension (n) - NB: LHS 'array' smaller than RHS 'array'.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Questions:&lt;/P&gt;
&lt;P&gt;1. Will this work also if 'array' is a derived type?&lt;/P&gt;
&lt;P&gt;2. In the other thread, Steve stated 'To get the automatic reallocation that Tim mentions, you must compile with "-assume realloc_lhs" '. Does this apply for the above case also (/still)?&lt;/P&gt;
&lt;P&gt;3. Does resizing as above incur a large overhead ?&lt;/P&gt;
&lt;P&gt;Not that (3) above matters in most cases for me as it is generally done only once for a particular file - better to have tidy code.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 04:02:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912159#M83648</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-15T04:02:43Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912160#M83649</link>
      <description>In theory, this should work. It will likely incur a large overhead and will almost certainly make a temporary copy of the array in the assignment. It does not matter if the array is derived type.&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Jan 2010 04:17:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912160#M83649</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-01-15T04:17:29Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912161#M83650</link>
      <description>&lt;P&gt;Thanks for the prompt reply.&lt;/P&gt;
&lt;P&gt;Do I need to compile with "-assume realloc_lhs" ?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 04:47:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912161#M83650</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-15T04:47:39Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912162#M83651</link>
      <description>&lt;P&gt;re "-assume realloc_lhs"&lt;/P&gt;
&lt;P&gt;Is this option available in v 11.0.061 ?&lt;/P&gt;
&lt;P&gt;If so, where is it applied (via UI)?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I tried adding it under "Command Line / Additional Options" but just got compiler messages as follows:&lt;/P&gt;
&lt;P style="padding-left: 20pt;"&gt;1&amp;gt;ifort: command line warning #10155: ignoring option '/assume'; argument required&lt;BR /&gt;1&amp;gt;ifort: command line warning #10161: unrecognized source type 'realloc_lhs'; object file assumed&lt;BR /&gt;1&amp;gt;ifort: warning #10146: no action performed for specified object file(s)&lt;/P&gt;
&lt;BR /&gt;
&lt;P&gt;(have to confess my compiler is not up to date - started only updating when need arises)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 09:57:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912162#M83651</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-15T09:57:00Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912163#M83652</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;-assume requires the colon ':' for Windows in place of the linux space ' '.&lt;/P&gt;
&lt;P&gt;If you want to use many f2003 features, you should be updating your compiler frequently.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 13:28:55 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912163#M83652</guid>
      <dc:creator>TimP</dc:creator>
      <dc:date>2010-01-15T13:28:55Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912164#M83653</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Why not code it yourself, and eliminate the possibility of a temporary array&lt;/P&gt;
&lt;PRE&gt;[bash]ALLOCATE (ReadInArray (large_number))      ! large_number &amp;gt;&amp;gt; likely number of records
n = 0
DO
  n = n + 1
  READ(...) ReadInArray(n)
  if ( end of read) EXIT
END DO
n=n-1
if(n == 0) goto NoData
ALLOCATE(array(n))
array = ReadInArray(:n)
DEALLOCATE(ReadInArray)
[/bash]&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 15:55:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912164#M83653</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-01-15T15:55:29Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912165#M83654</link>
      <description>&lt;P&gt;Thanks Jim&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;That is how I have always done it.&lt;/P&gt;
&lt;P&gt;Currently writing a new (relatively small) program &amp;amp; though it would look tidier code the "new" way.&lt;/P&gt;
&lt;P&gt;Do not see that the temp array situation is much different either way - the old way there is a small overlap where two arrays are required.&lt;/P&gt;
&lt;P&gt;I just tried it with Tim's correction (':' instead of ' ') &amp;amp; the resize works perfectly.&lt;/P&gt;
&lt;P&gt;(knew there was a reason to stick the the Windows forum!)&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2010 22:11:02 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912165#M83654</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-15T22:11:02Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912166#M83655</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Hmm - worked for a small test case (array size 5000 reduced to 41), but seems to crash when I try it with a 'production' size array; ie. 600,000 down to c.120,000 :(.&lt;/P&gt;
&lt;P&gt;In real use I would do it 47 times, all 600,000 max, with reduced size varying from c. 100,000 to 500,000.&lt;/P&gt;
&lt;P&gt;Is this a heap (stack?) issue or similar?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2010 02:29:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912166#M83655</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-18T02:29:56Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912167#M83656</link>
      <description>&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Answering my own question - yes.&lt;/P&gt;
&lt;P&gt;I just set HEAP &amp;amp; STACK reserve sizes to 16,000,000.&lt;/P&gt;
&lt;P&gt;Perhaps when I get time, I will test which one is needed - and how big is needed.&lt;/P&gt;
&lt;P&gt;For now, it just works.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2010 03:00:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912167#M83656</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-18T03:00:38Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912168#M83657</link>
      <description>&lt;P&gt;Continuing the monologue !&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Answering my own question - yes.&lt;/P&gt;
&lt;P&gt;I just set HEAP &amp;amp; STACK reserve sizes to 16,000,000.&lt;/P&gt;
&lt;P&gt;Perhaps when I get time, I will test which one is needed - and how big is needed.&lt;/P&gt;
&lt;P&gt;For now, it just works.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;As noted, it works, but I now find, only in Debug mode. In Release mode, it crashes still, even after raising Heap &amp;amp; Stack reserve to 33,554,432.&lt;/P&gt;
&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2010 08:53:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912168#M83657</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-18T08:53:33Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912169#M83658</link>
      <description>Set "Heap Arrays" to 0 under Fortran &amp;gt; Optimization. You are getting temporary arrays created and copied.</description>
      <pubDate>Mon, 18 Jan 2010 16:32:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912169#M83658</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2010-01-18T16:32:38Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912170#M83659</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;Do not see that the temp array situation is much different either way - the old way there is a small overlap where two arrays are required.&lt;/P&gt;
&lt;P&gt;In the sample code presented you overallocate temp array(s) read into the temporary array(s), then allocate target array, copy temp to target, deallocate temp (2 allocations and one copy)&lt;/P&gt;
&lt;P&gt;In the (broken) auto-reallocate lhs, you over allocate target array, use auto-reallocate lhs which creates a temp, copies to temp, then deallocates lhs, then allocates lhs, then copies temp to lhs then deallocates temp. (potentially 3 allocations and 2 copies).&lt;/P&gt;
&lt;P&gt;All this hoop jumping to "tidy" the code. In addition to unnecessary overhead it tends to fragment the heap.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jan 2010 20:49:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912170#M83659</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-01-18T20:49:36Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912171#M83660</link>
      <description>&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="border: 1px inset; padding: 5px; background-color: #e5e5e5; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;
&lt;P&gt;&amp;gt;&amp;gt;Do not see that the temp array situation is much different either way - the old way there is a small overlap where two arrays are required.&lt;/P&gt;
&lt;P&gt;In the sample code presented you overallocate temp array(s) read into the temporary array(s), then allocate target array, copy temp to target, deallocate temp (2 allocations and one copy)&lt;/P&gt;
&lt;P&gt;In the (broken) auto-reallocate lhs, you over allocate target array, use auto-reallocate lhs which creates a temp, copies to temp, then deallocates lhs, then allocates lhs, then copies temp to lhs then deallocates temp. (potentially 3 allocations and 2 copies).&lt;/P&gt;
&lt;P&gt;All this hoop jumping to "tidy" the code. In addition to unnecessary overhead it tends to fragment the heap.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;/I&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Steve, thanks, setting "Heap Arrays" to 0 did the trick. Works!&lt;/P&gt;
&lt;P&gt;Jim, much appreciate your comments &amp;amp; assistance. Yes the 'old' way may involve less copying (esp). I will accept your comments re the heap fragmentation - that is beyond my expertise.&lt;/P&gt;
&lt;P&gt;It is not critical for this particular application (I think ...!). It is a small program to consolidate &amp;amp; manipulate data for input to a simulation program. Though it involves a large amount of data (total ~8m records read in, combined with other data from serval sources, then output reformated), the computational effort is relatively minor.  Total runtime is only ~3mins for the 8m+ records (~2GB output file).&lt;/P&gt;
&lt;P&gt;Partly it was a matter of experimenting / gaining experience with f2003 constructs, and partly to make the code 'tidier', given that it was not a 'time critical' situation.&lt;/P&gt;
&lt;P&gt;With the modification that Steve suggested it is now working fine (Debug &amp;amp; Release modes). Given your comments I guess I will avoid it in more critical applications.&lt;/P&gt;
&lt;P&gt;My only 'concern' is your comment re heap fragmentation. Does that last only within the current application (not an issue, because the program works well), or is this a more permanent impact; ie. remains fragmented after the analysis has completed &amp;amp; hence will impact following programs until the PC has been re-booted&lt;/P&gt;
&lt;P&gt;Sorry, showing my ignorance of what exactly heap fragmentation is. I assumed the heap is there only as long as the application is running &amp;amp; heap fragmentation hence has no 'permanent' effect.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2010 01:03:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912171#M83660</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-19T01:03:23Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912172#M83661</link>
      <description>&lt;P&gt;&amp;gt;&amp;gt;My only 'concern' is your comment re heap fragmentation. Does that last only within the current application (not an issue, because the program works well), or is this a more permanent impact; ie. remains fragmented after the analysis has completed &amp;amp; hence will impact following programs until the PC has been re-booted&lt;/P&gt;
&lt;P&gt;Yes it is only within the current application. Fragmentation is a concern usually when you have a large number of allocations and deallocations going on within a program. But sometimes this will occure with a few very large allocations.&lt;/P&gt;
&lt;P&gt;From the description of your program this should not be a problem.&lt;/P&gt;
&lt;P&gt;Another side effect of auto-allocate lhs is you do not get an opportunity to programmatically work through a low memory condition. IOW you crash instead of dying gracefully or attempting to recover by returning other memory that you have held on to for performance reasons.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2010 20:55:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912172#M83661</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2010-01-19T20:55:43Z</dc:date>
    </item>
    <item>
      <title>Resize allocated array (F2003)</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912173#M83662</link>
      <description>Thanks for the clarification Jim.</description>
      <pubDate>Wed, 20 Jan 2010 00:23:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Resize-allocated-array-F2003/m-p/912173#M83662</guid>
      <dc:creator>davidspurr</dc:creator>
      <dc:date>2010-01-20T00:23:03Z</dc:date>
    </item>
  </channel>
</rss>

