<?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 linked list memory usage in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747405#M4961</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;
&lt;P&gt;I am trying to figure out the memory usage of a linked list in fortran 90. I use the following simple test code. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;program test_sub&lt;BR /&gt; implicit none&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; type:: mytype&lt;BR /&gt; integer :: ij(2)&lt;BR /&gt; type(mytype), pointer :: next&lt;BR /&gt; end type mytype&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; integer :: k, n&lt;BR /&gt; type(mytype), pointer :: head, tail, item&lt;BR /&gt;&lt;BR /&gt; n=1e7 ---&amp;gt;length of the list&lt;BR /&gt; mem =0&lt;BR /&gt; nullify(head, tail)&lt;BR /&gt; do k=1,n&lt;BR /&gt; nullify(item)&lt;BR /&gt; allocate(item)&lt;BR /&gt; item%ij=1&lt;BR /&gt; mem=mem+sizeof(item)&lt;BR /&gt; if (k==1) then&lt;BR /&gt; head=&amp;gt;item&lt;BR /&gt; tail=&amp;gt;item&lt;BR /&gt; else&lt;BR /&gt; tail%next=&amp;gt;item&lt;BR /&gt; tail=&amp;gt;item&lt;BR /&gt; end if&lt;BR /&gt; end do&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; print*, sizeof(head) -&amp;gt; This gives 16&lt;BR /&gt; print*, sizeof(head%next) -&amp;gt;This gives 16&lt;BR /&gt; print*, sizeof(head%ij)-&amp;gt;This gives8&lt;BR /&gt; print*, real(mem)/1024/1024 -&amp;gt; This gives 152.5879mb&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; stop&lt;BR /&gt;end program test_sub&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Using the sizeof function I expect 16 byte per node and ~150mb memory usage in total. However when I check the usage through the system using 'top' command, I see 300mb. If I increase thelength of the list to 1e8, memory usage is 3gb while I expect it to be1.5gb. Am I doing something stupid in this code? Or my calculations are wrong? I am using intel compiler version 9.1 on a linux 64 bit machine. I forgot to add: I compiled the code without any flags. &lt;/P&gt;
&lt;P&gt;Thank you for your help&lt;/P&gt;
&lt;P&gt;Onur Bakir&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 03 Mar 2008 20:44:09 GMT</pubDate>
    <dc:creator>onurb</dc:creator>
    <dc:date>2008-03-03T20:44:09Z</dc:date>
    <item>
      <title>linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747405#M4961</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;
&lt;P&gt;I am trying to figure out the memory usage of a linked list in fortran 90. I use the following simple test code. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;program test_sub&lt;BR /&gt; implicit none&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; type:: mytype&lt;BR /&gt; integer :: ij(2)&lt;BR /&gt; type(mytype), pointer :: next&lt;BR /&gt; end type mytype&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; integer :: k, n&lt;BR /&gt; type(mytype), pointer :: head, tail, item&lt;BR /&gt;&lt;BR /&gt; n=1e7 ---&amp;gt;length of the list&lt;BR /&gt; mem =0&lt;BR /&gt; nullify(head, tail)&lt;BR /&gt; do k=1,n&lt;BR /&gt; nullify(item)&lt;BR /&gt; allocate(item)&lt;BR /&gt; item%ij=1&lt;BR /&gt; mem=mem+sizeof(item)&lt;BR /&gt; if (k==1) then&lt;BR /&gt; head=&amp;gt;item&lt;BR /&gt; tail=&amp;gt;item&lt;BR /&gt; else&lt;BR /&gt; tail%next=&amp;gt;item&lt;BR /&gt; tail=&amp;gt;item&lt;BR /&gt; end if&lt;BR /&gt; end do&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt; print*, sizeof(head) -&amp;gt; This gives 16&lt;BR /&gt; print*, sizeof(head%next) -&amp;gt;This gives 16&lt;BR /&gt; print*, sizeof(head%ij)-&amp;gt;This gives8&lt;BR /&gt; print*, real(mem)/1024/1024 -&amp;gt; This gives 152.5879mb&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; stop&lt;BR /&gt;end program test_sub&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Using the sizeof function I expect 16 byte per node and ~150mb memory usage in total. However when I check the usage through the system using 'top' command, I see 300mb. If I increase thelength of the list to 1e8, memory usage is 3gb while I expect it to be1.5gb. Am I doing something stupid in this code? Or my calculations are wrong? I am using intel compiler version 9.1 on a linux 64 bit machine. I forgot to add: I compiled the code without any flags. &lt;/P&gt;
&lt;P&gt;Thank you for your help&lt;/P&gt;
&lt;P&gt;Onur Bakir&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Mar 2008 20:44:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747405#M4961</guid>
      <dc:creator>onurb</dc:creator>
      <dc:date>2008-03-03T20:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747406#M4962</link>
      <description>&lt;P&gt;Can it be explained like this: There is an overhead when using derived-types (there is right?) something like an array descriptor. If Iallocate a continuousarray of derived types (defining thenodes of the linked list), I have only one of these array descriptors. But when using a linked-list structure I allocate each node seperately,then theoverhead is repeated for each node. As far as I observed the there is an almost constant scale between expected and actual memory usage. If this is true linked-list would be a very unfortunate choice for large data sets right? Oh boy I am doomed. Can anybody help me out here?&lt;/P&gt;
&lt;P&gt;Onur&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2008 20:23:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747406#M4962</guid>
      <dc:creator>onurb</dc:creator>
      <dc:date>2008-03-04T20:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747407#M4963</link>
      <description>There is no overhead using derived types. Array descriptors do take more space, but you don't have any in this program. Pointers to non-array types are just addresses.&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 14:20:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747407#M4963</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-03-05T14:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747408#M4964</link>
      <description>Did a quick test on the program and printed the addresses of the items.&lt;BR /&gt;The difference between 2 allocation is in this case 32 byte (so an overhead of 16 bytes), resulting in the observations of Onur. Changing the size of the type results in other overhead values.&lt;BR /&gt;(Used Intel 10.1 on a 64-bit system)&lt;BR /&gt;&lt;BR /&gt;Albert&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Mar 2008 15:36:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747408#M4964</guid>
      <dc:creator>albert</dc:creator>
      <dc:date>2008-03-05T15:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747409#M4965</link>
      <description>what option are you using (or not using) for -align &lt;KEYWORD&gt; ?&lt;BR /&gt;&lt;BR /&gt;ron&lt;BR /&gt;&lt;/KEYWORD&gt;</description>
      <pubDate>Wed, 05 Mar 2008 23:09:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747409#M4965</guid>
      <dc:creator>Ron_Green</dc:creator>
      <dc:date>2008-03-05T23:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747410#M4966</link>
      <description>&lt;P&gt;I don't use any options. Just plain:&lt;/P&gt;
&lt;P&gt;ifort filename.f90&lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2008 03:44:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747410#M4966</guid>
      <dc:creator>onurb</dc:creator>
      <dc:date>2008-03-06T03:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747411#M4967</link>
      <description>The difference in addresses between two allocations does not imply that the size of the allocation increased. Allocations automatically align, though I am not sure what the boundary is.&lt;BR /&gt;&lt;BR /&gt;An easy way to check this is to declare an array of the structures and look at the size of the array divided by the number of elements. Remember that padding will be added by default to natural boundaries unless you say SEQUENCE in the type.&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Mar 2008 13:50:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747411#M4967</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-03-06T13:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747412#M4968</link>
      <description>I agree about the amount of memory allocated. But for the total memory used by the process is increased by the allocated memory and the "padding" (so in total with the number of bytes between 2 calls). That is correct ?&lt;BR /&gt;&lt;BR /&gt;Albert&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Mar 2008 15:34:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747412#M4968</guid>
      <dc:creator>albert</dc:creator>
      <dc:date>2008-03-06T15:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747413#M4969</link>
      <description>I check the allocation through the system, and that space is allocated (or padded but not usable, whatever you call it). I cannot use sequence in this type because the type statement includes a recursive pointer in itself. Compiler returns a warning that the structure is misaligned.</description>
      <pubDate>Thu, 06 Mar 2008 15:35:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747413#M4969</guid>
      <dc:creator>onurb</dc:creator>
      <dc:date>2008-03-06T15:35:14Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747414#M4970</link>
      <description>&lt;P&gt;I think I was too optimistic about the size of the pointers. I have learned that another compiler is using around 16 bytes for a pointer to a scalar structure not 8, they told me that fortran pointers are not just memory addresses (I did not know that before). &lt;/P&gt;
&lt;P&gt;Also, I forgot to add one more observation: IfIchange the length of the integers %ij from 1-4, memory usage does not change at all (it increases after 4).This structure is taking up 32 bytes of memory-space, with padding or no padding. Therefore it is extremely inefficient if the structure contains very small amount of data. &lt;/P&gt;</description>
      <pubDate>Thu, 06 Mar 2008 18:43:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747414#M4970</guid>
      <dc:creator>onurb</dc:creator>
      <dc:date>2008-03-06T18:43:16Z</dc:date>
    </item>
    <item>
      <title>Re: linked list memory usage</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747415#M4971</link>
      <description>What another compiler does is not necessarily relevant to Intel Fortran. For non-array types, Intel Fortran represents a pointer as an address only. &lt;BR /&gt;&lt;BR /&gt;In my test, each allocation is of size 16 (on x64), but there is extra space that the memory allocator uses to record information about the allocation so that it can properly deallocate the space.&lt;BR /&gt;&lt;BR /&gt;If you are doing lots of allocations of small objects, this is going to add up. I'd suggest instead that you add a layer of your own memory manager that allocates, say, 4096 instances of "item" at a time and then doles them out as needed.&lt;BR /&gt;</description>
      <pubDate>Thu, 06 Mar 2008 22:42:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/linked-list-memory-usage/m-p/747415#M4971</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2008-03-06T22:42:31Z</dc:date>
    </item>
  </channel>
</rss>

