<?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 Memory consumed by pointers in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741694#M1107</link>
    <description>I am seeking to employ (as targets) dynamically-allocated
(one-dimensional) arrays of a derived data type which itself employs
dynamically-allocated (multi-dimensional) component arrays.
I would then like to create additional independent multi-dimensional
pointers (of identical data type and dimension as the derived data type
component arrays) to point to the component arrays of these targeted
"primary variables". My motivation is to efficiently store large
amounts of data which have one common dimension among them (the one
dimension of the "primary variables" declared with the derived data
type), while the sizes/extents of the other dimensions could vary
greatly, making use of rectangular arrays sized to the largest extents
highly inefficient with memory -- so those would be stored in
dynamically allocated components
of the derived data type "primary variables" (and presumably be
successfully deferenced by the additional independent pointers).
I seek to use pointers to dereference/extract the data contained within
the derived data type for one primary reason: programming simplicity/
code legibiliity. (Because I realize that I am only complicating
things further and consuming some additional -- how much? -- memory by
using these pointers.)&lt;BR /&gt;
&lt;BR /&gt;
I am presuming that using the derived data type for my "primary
variables" will yield me the efficient memory management I seek; I am
concerned about how much additional memory is consumed by the
"additional" pointers. I understand that pointers consume no
memory until associated; but -- once they are associated -- how much
memory do they consume? Do pointers consume additional memory
identical to their targets -- effectively doubling memory consumption
for one array of actual data? Or -- as I hope -- do they only
consume a little bit of additional memory to "map out" the memory of
the associated target? I have come across information about
"fortan array descriptors" which alludes to pointers and seems to imply
that "fortran array descriptors" build a map of the associated target's
memory -- consuming very little memory unto itself -- which is exactly
the explanation I hope to confirm!&lt;BR /&gt;
&lt;BR /&gt;
Questions, comments, assistance all appreciated.&lt;BR /&gt;
&lt;BR /&gt;
EDIT/ADDITION: How much memory "overhead" is involved in array
allocation/declaration? Do "Arrays = Pointers" in Fortran like C? Does
a pointer declaration/allocation use more, less, or same amount of
memory as "typical" array allocation/declaration?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Greg&lt;BR /&gt;
&lt;BR /&gt;</description>
    <pubDate>Wed, 30 Aug 2006 22:21:40 GMT</pubDate>
    <dc:creator>gregory_p_herrick</dc:creator>
    <dc:date>2006-08-30T22:21:40Z</dc:date>
    <item>
      <title>Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741694#M1107</link>
      <description>I am seeking to employ (as targets) dynamically-allocated
(one-dimensional) arrays of a derived data type which itself employs
dynamically-allocated (multi-dimensional) component arrays.
I would then like to create additional independent multi-dimensional
pointers (of identical data type and dimension as the derived data type
component arrays) to point to the component arrays of these targeted
"primary variables". My motivation is to efficiently store large
amounts of data which have one common dimension among them (the one
dimension of the "primary variables" declared with the derived data
type), while the sizes/extents of the other dimensions could vary
greatly, making use of rectangular arrays sized to the largest extents
highly inefficient with memory -- so those would be stored in
dynamically allocated components
of the derived data type "primary variables" (and presumably be
successfully deferenced by the additional independent pointers).
I seek to use pointers to dereference/extract the data contained within
the derived data type for one primary reason: programming simplicity/
code legibiliity. (Because I realize that I am only complicating
things further and consuming some additional -- how much? -- memory by
using these pointers.)&lt;BR /&gt;
&lt;BR /&gt;
I am presuming that using the derived data type for my "primary
variables" will yield me the efficient memory management I seek; I am
concerned about how much additional memory is consumed by the
"additional" pointers. I understand that pointers consume no
memory until associated; but -- once they are associated -- how much
memory do they consume? Do pointers consume additional memory
identical to their targets -- effectively doubling memory consumption
for one array of actual data? Or -- as I hope -- do they only
consume a little bit of additional memory to "map out" the memory of
the associated target? I have come across information about
"fortan array descriptors" which alludes to pointers and seems to imply
that "fortran array descriptors" build a map of the associated target's
memory -- consuming very little memory unto itself -- which is exactly
the explanation I hope to confirm!&lt;BR /&gt;
&lt;BR /&gt;
Questions, comments, assistance all appreciated.&lt;BR /&gt;
&lt;BR /&gt;
EDIT/ADDITION: How much memory "overhead" is involved in array
allocation/declaration? Do "Arrays = Pointers" in Fortran like C? Does
a pointer declaration/allocation use more, less, or same amount of
memory as "typical" array allocation/declaration?&lt;BR /&gt;
&lt;BR /&gt;
Thanks!&lt;BR /&gt;
Greg&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 30 Aug 2006 22:21:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741694#M1107</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-08-30T22:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741695#M1108</link>
      <description>Pointers in Fortran are not quite like pointers in C. For pointers to arrays, the pointer itself is that "descriptor" you read about - some additional storage that records the bounds of the array - but this is typically a few dozen bytes at most per pointer. The array data itself is no different in size than if you had declared it as a non-pointer array. For pointers to scalar objects, then it's just an address just like C.&lt;BR /&gt;&lt;BR /&gt;Let me suggest that rather than use POINTER that you use ALLOCATABLE components in your derived types. These have subtle performance advantages in some cases and some nice semantics when you assign one structure to another.&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Aug 2006 03:43:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741695#M1108</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-08-31T03:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741696#M1109</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;IMG src="https://community.intel.com/file/6745" /&gt; &lt;STRONG&gt;MADsblionel:&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Let me suggest that rather than use
POINTER that you use ALLOCATABLE components in your derived types.
These have subtle performance advantages in some cases and some nice
semantics when you assign one structure to another.&lt;BR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;
&lt;BR /&gt;
My plan was to use "allocatable" components within the derived data
type type-description, and then use "pointer" independent variables to
point to those "allocated" components of the derived data type
variable. [While "primary variables" would be "allocatable" and of
"type (derived_type)" ]&lt;BR /&gt;
&lt;BR /&gt;
Are we saying/thinking the same thing?&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much for your help,&lt;BR /&gt;
Greg&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Aug 2006 04:14:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741696#M1109</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-08-31T04:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741697#M1110</link>
      <description>Yes, that should work.&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Aug 2006 05:02:54 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741697#M1110</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-08-31T05:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741698#M1111</link>
      <description>Note that if you use ALLOCATABLE components, the entire derived type variable must have the TARGET attribuite to allow you to pointer-assign to a component. If you make them POINTERs, then you don't. Perhaps for your purpose POINTER will be fine.&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Aug 2006 21:21:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741698#M1111</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-08-31T21:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741699#M1112</link>
      <description>Thank you for your tips. I am implementing them now in my (large) code... then will come the fun of debugging!&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Sep 2006 07:08:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741699#M1112</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-09-01T07:08:26Z</dc:date>
    </item>
    <item>
      <title>Another question on the subject of "memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741700#M1113</link>
      <description>From Steve's comment above: "For pointers to scalar objects, then it's just an address just like C."&lt;BR /&gt;&lt;BR /&gt;How may bytes does a scalar address consume?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;For the simple fortran code below:&lt;BR /&gt;&lt;BR /&gt;INTEGER :: I&lt;BR /&gt;INTEGER, POINTER :: I_PTR&lt;BR /&gt;&lt;BR /&gt;I_PTR=&amp;gt;I&lt;BR /&gt;&lt;BR /&gt;I understand that /I/ will consume however many bytes I set for "integers" in my compilation; how many "overhead" bytes will /I_PTR/ consume?&lt;BR /&gt;&lt;BR /&gt;I ask this simple example specifically because it does *not* involve arrays -- where (I think I understand how) the "fortran array descriptors" facilitate the consumption of very little "overhead" memory in mapping large arrays.&lt;BR /&gt;&lt;BR /&gt;Again, my concern is that /I/ and /I_PTR/ will consume "double" the required to memory to store what is actually a single integer datum.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance,&lt;BR /&gt;Greg&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Sep 2006 22:58:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741700#M1113</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-09-06T22:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Another question on the subject of "memory consumed by poin</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741701#M1114</link>
      <description>An address is four bytes on a 32-bit system, 8 bytes on a 64-bit platform. The size of the variable itself does not matter.&lt;BR /&gt;</description>
      <pubDate>Wed, 06 Sep 2006 23:14:18 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741701#M1114</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-09-06T23:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741702#M1115</link>
      <description>If the derived data structure has a pointer array with the deferred shape, the memory size of a pointer pointing to such derived data can be much more than you expected.  &lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;Type :: test1&lt;BR /&gt;Integer var1&lt;BR /&gt;integer, dimension(:), pointer :: ptr&lt;BR /&gt;End type &lt;BR /&gt;&lt;BR /&gt;Type (test1), pointer :: test_ptr1&lt;BR /&gt;&lt;BR /&gt;You may use sizeof(test_ptr1) to see the size of this pointer, and compare the one without the pointer array. For my 64-bit machine, the size of pointer test_ptr1 is 80 bytes. comparing to 4 bytes if it is&lt;BR /&gt;&lt;BR /&gt;
Type :: test1&lt;BR /&gt;
Integer var1&lt;BR /&gt;
End type &lt;BR /&gt;&lt;BR /&gt;Therefore, it is quite expensive to have an array of pointer in a derived data structure in FORTRAN 90. It seems that C does not have such problem. &lt;BR /&gt;&lt;BR /&gt;Junhui&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 04:10:49 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741702#M1115</guid>
      <dc:creator>jhliu</dc:creator>
      <dc:date>2006-09-07T04:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741703#M1116</link>
      <description>Actually, no, the pointer to the derived type object is the same size. I agree that the pointer to allocatable or pointer arrays inside the derived type is larger, but I had already said that.&lt;BR /&gt;&lt;BR /&gt;C "does not have such problem" because C pointers are not Fortran pointers. C does not have the concept of arrays and array bounds and dimensions. All it has is simple address pointers and syntax for indexing into them. You cannot ask the shape of an array in C, for example. Fortran pointers for arrays keep much more information because arrays are a fundamental construct in Fortran whereas they are an afterthought in C.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 05:01:15 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741703#M1116</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-09-07T05:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741704#M1117</link>
      <description>I guess I should have written up a simple example to show my intentions:&lt;BR /&gt;======================&lt;BR /&gt;program junk&lt;BR /&gt;type :: type_variable&lt;BR /&gt;real*8,allocatable :: x(:,:,:)&lt;BR /&gt;end type type_variable&lt;BR /&gt;&lt;BR /&gt;type(type_variable),allocatable,target :: var_data(:)&lt;BR /&gt;real*8,pointer :: x(:,:,:)&lt;BR /&gt;&lt;BR /&gt;integer :: i&lt;BR /&gt;&lt;BR /&gt;do i=...&lt;BR /&gt; x=&amp;gt;var_data(i)%x !using pointer 'x' for coding &lt;BR /&gt; !simplicity/legibility when accessing&lt;BR /&gt; !'var_data(i)%x'&lt;BR /&gt; ::::&lt;BR /&gt; :::&lt;BR /&gt;enddo&lt;BR /&gt;end&lt;BR /&gt;=======================&lt;BR /&gt;I apologize for not writing up this simple example in my first post; I think this simple example should be 1000x clearer than my initial post's two paragraphs of prose.&lt;BR /&gt;&lt;BR /&gt;Note that I am *not* using pointers *within* my derived data type.&lt;BR /&gt;I *am* using pointers to point to *allocatable* arrays within said target derived data type.&lt;BR /&gt;&lt;BR /&gt;I am seeking coding simplicity/legibility/brevity by use of the pointer; I am using the derived data type (allocatable -- with allocatable components) for "efficient" allocation of memory.&lt;BR /&gt;&lt;BR /&gt;Will I achieve my goal of "efficient" memory management using a scheme such as I typed above?&lt;BR /&gt;&lt;BR /&gt;Or will pointer x consume nearly as much (additional) memory as the target var_data(i)%x?&lt;BR /&gt;&lt;BR /&gt;Thank you for your responses and guidance; your help is greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;Greg&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 21:33:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741704#M1117</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-09-07T21:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741705#M1118</link>
      <description>The appearance of an allocatable component (x) in the derived type type_variable means thaty for each element of array var_data, there will be a descriptr ofr component x. The size of that descriptor will be 24 + (12*rank) bytes, or in this case, 60 bytes. It would be the same if component x was a pointer rather than an allocatable.&lt;BR /&gt;&lt;BR /&gt;Pointer x will also be 60 bytes since it is an array pointer of rank 3, not a scalar.&lt;BR /&gt;&lt;BR /&gt;I can't comment on how efficient this is without knowing the typical size of the array components. You're not saving any memory by using the pointer variable x though the code will be more legible, I agree.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 21:41:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741705#M1118</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-09-07T21:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741706#M1119</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;IMG src="https://community.intel.com/file/6745" /&gt; &lt;STRONG&gt;MADsblionel:&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;The appearance of an allocatable component (x) in the derived type type_variable means thaty for each element of array var_data, there will be a descriptr ofr component x. The size of that descriptor will be 24 + (12*rank) bytes, or in this case, 60 bytes. It would be the same if component x was a pointer rather than an allocatable.&lt;BR /&gt;&lt;BR /&gt;Pointer x will also be 60 bytes since it is an array pointer of rank 3, not a scalar.&lt;BR /&gt;&lt;BR /&gt;I can't comment on how efficient this is without knowing the typical size of the array components. You're not saving any memory by using the pointer variable x though the code will be more legible, I agree.&lt;BR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;I understand that the memory consumed by the array descriptors will be identical (and counted twice: once for component x, once for pointer x). But -- aside from the two identical array descriptors -- no other memory will be "double bookkept", correct? The 3-dimensions of x are usually sized ~50:50:50. So I am hoping I can have brief, legible code accessing the x data with only 60 bytes (array descriptor) "excess" memory consumed. The 50:50:50 x data should consume 1MB unto itself - - and not twice that (one for component, one for pointer), correct?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 22:00:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741706#M1119</guid>
      <dc:creator>gregory_p_herrick</dc:creator>
      <dc:date>2006-09-07T22:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Memory consumed by pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741707#M1120</link>
      <description>Correct. The data itself is not duplicated.&lt;BR /&gt;</description>
      <pubDate>Thu, 07 Sep 2006 22:30:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Memory-consumed-by-pointers/m-p/741707#M1120</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2006-09-07T22:30:59Z</dc:date>
    </item>
  </channel>
</rss>

