<?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: are arrays of components of derived type legal in F-95? in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890873#M78221</link>
    <description>Yes to all three, but for the pointer assignment, var has to have the TARGET attribute.&lt;BR /&gt;&lt;BR /&gt;I would recommend not using the (:) in expressions as it can sometimes inhibit optimizations, but I understand if you want to use it to make clear it's an array.&lt;BR /&gt;</description>
    <pubDate>Sat, 17 Nov 2007 06:10:07 GMT</pubDate>
    <dc:creator>Steven_L_Intel1</dc:creator>
    <dc:date>2007-11-17T06:10:07Z</dc:date>
    <item>
      <title>are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890872#M78220</link>
      <description>A few questions re derived types:&lt;BR /&gt;&lt;BR /&gt;1) Is it legal to create arrays using components of derived types, eg,&lt;BR /&gt;arr(:)=var(:)%comp&lt;BR /&gt;assuming arr and comp are of the same type and their dimensions match.&lt;BR /&gt;&lt;BR /&gt;2) Can they be used as targets of pointer association, eg&lt;BR /&gt;p=&amp;gt;var(:)%comp&lt;BR /&gt;&lt;BR /&gt;3) Can they be passed to subroutines expecting array arguments, eg,&lt;BR /&gt;call sub(arr=var(:)%comp)&lt;BR /&gt;&lt;BR /&gt;It appears that both IVF and CVF function correctly in simple cases (eg, see below), but I have a large program where this could be a problem and so wanted to check that these usages (especially 2 and 3) are indeed legal.&lt;BR /&gt;&lt;BR /&gt;thanks in advance,&lt;BR /&gt;dmitri&lt;BR /&gt;&lt;BR /&gt;!***************************&lt;BR /&gt;module m&lt;BR /&gt;implicit none&lt;BR /&gt;type t&lt;BR /&gt; real::r&lt;BR /&gt;endtype t&lt;BR /&gt;contains&lt;BR /&gt;!---&lt;BR /&gt;subroutine test(argR)&lt;BR /&gt;real,intent(in)::argR(:)&lt;BR /&gt;integer::i&lt;BR /&gt;do i=1,size(argR)&lt;BR /&gt; write(*,*)argR(i)&lt;BR /&gt;enddo&lt;BR /&gt;endsubroutine test&lt;BR /&gt;!---&lt;BR /&gt;endmodule m&lt;BR /&gt;!*****************************&lt;BR /&gt;subroutine sample_subroutine()&lt;BR /&gt;use m,only:t,test&lt;BR /&gt;implicit none&lt;BR /&gt;integer,parameter::n=2&lt;BR /&gt;type(t),target::var(n)&lt;BR /&gt;real,pointer::p(:)&lt;BR /&gt;! does 'var(:)%r' constitute a valid array?&lt;BR /&gt;var(:)%r=(/1.0,2.0/) ! is this assignment valid?&lt;BR /&gt;p=&amp;gt;var(:)%r ! is this pointer statement legal?&lt;BR /&gt;call test(argR=var(:)%r) ! is this call legal?&lt;BR /&gt;call test(argR=p)&lt;BR /&gt;endsubroutine sample_subroutine&lt;BR /&gt;!******************************</description>
      <pubDate>Sat, 17 Nov 2007 05:40:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890872#M78220</guid>
      <dc:creator>forall</dc:creator>
      <dc:date>2007-11-17T05:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890873#M78221</link>
      <description>Yes to all three, but for the pointer assignment, var has to have the TARGET attribute.&lt;BR /&gt;&lt;BR /&gt;I would recommend not using the (:) in expressions as it can sometimes inhibit optimizations, but I understand if you want to use it to make clear it's an array.&lt;BR /&gt;</description>
      <pubDate>Sat, 17 Nov 2007 06:10:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890873#M78221</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-11-17T06:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890874#M78222</link>
      <description>&lt;P&gt;Your example is inadequate for testing. To make a better test try&lt;/P&gt;&lt;PRE&gt;type t&lt;BR /&gt;  sequence&lt;BR /&gt; real(8)::r&lt;BR /&gt;integer(4) :: i&lt;BR /&gt;endtype t&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;This way the array of t's is not equivilent to the array of t%r (i.e. the group of r's are not in adjecent memory. And the additional member of t is not a multiple of the size of r.&lt;/P&gt;
&lt;P&gt;It is unknown to me as to if the compiler creates a temporary array or if it creates a descriptor with stride when passing var(:)%r as an argument Looking at the dissassembly window would tell you which method was used. Creating an array descriptor with stride would be useful when calling a Fortran subroutine. To get the descriptor passed you would have to declare an interface with the dummy argument declared with (:). For calling a C/C++ you might want the compiler to construct a temporary array as C++ subroutines tend to not examine the Fortran descriptor.&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 17 Nov 2007 16:43:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890874#M78222</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2007-11-17T16:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890875#M78223</link>
      <description>Yes, it seems having more complex (misaligned) derived types triggers a bug when also requiring temp copies for passign arguments.&lt;BR /&gt;&lt;BR /&gt;I tracked down my problem to the following reduced case, which crushes with stack overflow (but doesnt work properly otherwise either). Strangely enough in a more complex code this results in the string becoming blank, rather than causing stack-problems when passing it.&lt;BR /&gt;&lt;BR /&gt;Now I am wondering whether using arrays of components of derived types is a good idea even if it is legal, since it seems to require the creation of temp storage whenever the derived type contains components of different memory lengths (in which case it would be impossible to create a compact descriptor with strides?) - is this a fair statement?&lt;BR /&gt;&lt;BR /&gt;!******************************************************************&lt;BR /&gt;module m&lt;BR /&gt;implicit none&lt;BR /&gt;contains&lt;BR /&gt;!----------------------------------------------------&lt;BR /&gt;subroutine sub1(vname)&lt;BR /&gt;implicit none&lt;BR /&gt;! dummies&lt;BR /&gt;character(*),intent(in)::vname(:)&lt;BR /&gt;call sub2(vname,n=size(vname))&lt;BR /&gt;endsubroutine sub1&lt;BR /&gt;!----------------------------------------------------&lt;BR /&gt;subroutine sub2(item,n)&lt;BR /&gt;implicit none&lt;BR /&gt;integer,intent(in) :: n&lt;BR /&gt;character(*),intent(in) :: item(n) ! this line crashes the code (explicit-shape array)&lt;BR /&gt;!character(*),intent(in) :: item(:) ! this line works&lt;BR /&gt;write(10,'(a)')"'"//item//"'" ! this statement fails&lt;BR /&gt;endsubroutine sub2&lt;BR /&gt;!----------------------------------------------------&lt;BR /&gt;endmodule m&lt;BR /&gt;!*****************************************************************&lt;BR /&gt;subroutine sample_subroutine()&lt;BR /&gt;use m&lt;BR /&gt;implicit none&lt;BR /&gt;type var1_type&lt;BR /&gt; character(10)::name&lt;BR /&gt; real::v ! removing this component makes the code work always (aligned type)&lt;BR /&gt;endtype var1_type&lt;BR /&gt;integer,parameter::n=2&lt;BR /&gt;character(10)::vname(n)&lt;BR /&gt;type(var1_type)::var(n)&lt;BR /&gt;vname=(/"x1","x2"/)&lt;BR /&gt;var(:)%name=vname&lt;BR /&gt;call sub1(vname=vname) ! this works fine&lt;BR /&gt;call sub1(vname=var%name) ! this causes stack-overflow&lt;BR /&gt;endsubroutine sample_subroutine&lt;BR /&gt;!******************************************************************&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Nov 2007 03:07:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890875#M78223</guid>
      <dc:creator>forall</dc:creator>
      <dc:date>2007-11-18T03:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890876#M78224</link>
      <description>I don't understand your comment about strides - a component is always at a fixed offset from the beginning of the structure. That said, I would not be astonished if you always got a copy made when passing a component of an array of derived type.&lt;BR /&gt;&lt;BR /&gt;Please report the bug to Intel Premier Support.&lt;BR /&gt;</description>
      <pubDate>Sun, 18 Nov 2007 04:54:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890876#M78224</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2007-11-18T04:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: are arrays of components of derived type legal in F-95?</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890877#M78225</link>
      <description>&lt;P&gt;Steve,&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt; I don't understand your comment about strides &lt;/P&gt;
&lt;P&gt;The strides may or may not work, depending on how strides are internallyimplemented (number of items or number of bytes)&lt;/P&gt;
&lt;P&gt;Consider&lt;/P&gt;&lt;PRE&gt;type t&lt;BR /&gt;  sequence&lt;BR /&gt; real(8)::r&lt;BR /&gt;integer(4) :: i&lt;BR /&gt;endtype t&lt;BR /&gt;type(t) :: Tarray(100)&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Tarray(1) would start a memory block of&lt;/P&gt;
&lt;P&gt;real(8)&lt;BR /&gt;integer(4)&lt;BR /&gt;real(8)&lt;BR /&gt;integer(4)&lt;BR /&gt;real(8)&lt;BR /&gt;integer(4)&lt;BR /&gt;... 97 more times&lt;/P&gt;
&lt;P&gt;In the above, each element of the array is 12 bytes (with external representation of stride implicitly being 1 element)&lt;/P&gt;
&lt;P&gt;If the internal representation of Stride is in bytes then each 8-byte real would be positioned at 12-byte intervals. Although the 12 byte stride cannot be specified at the source code level, it can very well be specified in the descriptor. Therefore, a descriptor could be constructed for Tarray(:)%r and passed to a subrouting taking real(8) :: r(:) without requiring a copy to/from temp array. &lt;/P&gt;
&lt;P&gt;As an alternate technique, the element size could be specified as being 12 bytes (and stride of 1 element).&lt;/P&gt;
&lt;P&gt;r need not be at the base of the structure since the base address of the 1st r can be used in lieu of the base address of the first t.&lt;/P&gt;
&lt;P&gt;Does this make sense to you?&lt;/P&gt;
&lt;P&gt;Jim Dempsey&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Nov 2007 14:43:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/are-arrays-of-components-of-derived-type-legal-in-F-95/m-p/890877#M78225</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2007-11-18T14:43:25Z</dc:date>
    </item>
  </channel>
</rss>

