<?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: array referencing in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984180#M26762</link>
    <description>Only a little bit of the last subroutine was chopped (light a fire under their butts, Steve.)  Here it is: &lt;BR /&gt;&lt;PRE&gt;&lt;FONT size="+0"&gt; 
subroutine serialize(block, x) 
   use block_mod 
   implicit none 
   type(block_type) block(:) 
   real, target :: x(:) 
 
! Empty subroutine 
end subroutine serialize 
! Last line of separate.f90 
&lt;/FONT&gt;&lt;/PRE&gt; &lt;BR /&gt;So, perhaps rather surprisingly, you didn't miss much.  The idea of my program is that when, in Fortran, you pass an array element as an actual argument to a subroutine with an implicit interface that is invisible to the compiler, a reference to the array element pretty much has to be passed in order for sequence association to work like it has since 1960 or earlier.  In the called subroutine, if the array element actual argument is explicitly dimensioned as an array dummy argument, the callee is actually looking at an array consisting of all the elements of the original array from the actual argument element to the end.  It can, in the callee, be declared of any rank, and of course it can be a TARGET, so you can point a POINTER at it in the callee.  On return, the standard considers it processor-dependent as to whether the POINTER you pointed at it has defined association status or not -- I'm not sure whether anybody at Compaq has even thought about whether this should be the case for their 'processor'.  Thus I played a few tricks to keep the compiler in the dark about what I am doing (via separate compilation) and included the serialize subroutine that forces the compiler to reload all elements of the two arrays from memory because for all it knows they may have been changed by it (although, as you can see, the subroutine does nothing, but the comiler doesn't know that!) &lt;BR /&gt; &lt;BR /&gt;I can't compose an example specific to your case because I don't know what the mapping between the two arrays has to be: for example the first dimension of a2 could be split into two dimensions in a3, or the second could be, or something even more complex could be in the offing. &lt;BR /&gt; &lt;BR /&gt;Well, a student is begging me for help and since she's better looking than you I have to sign off now...</description>
    <pubDate>Tue, 19 Feb 2002 11:59:03 GMT</pubDate>
    <dc:creator>Intel_C_Intel</dc:creator>
    <dc:date>2002-02-19T11:59:03Z</dc:date>
    <item>
      <title>Re: array referencing</title>
      <link>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984178#M26760</link>
      <description>I think the only way (I wish I was wrong) to obtain a run-time equivalence is using Cray pointers. It's relatively easy for 3-d and 1-d arrays: &lt;PRE&gt; 
REAL, ALLOCATABLE:: a3(:,:,:) 
REAL:: a1(*); POINTER(pa1, a1) 
... 
ALLOCATE(a3(i,j,k)) 
pa1=LOC(a3) 
&lt;/PRE&gt; &lt;BR /&gt;However, your exact sample for 3-d and 2-d arrays is still tougher to realize;  &lt;BR /&gt;if the leading dimension of both is known at compile-time, you might write: &lt;CODE&gt;&lt;BR /&gt;REAL:: a2(5000,*); POINTER(pa2, a2)&lt;/CODE&gt;&lt;BR /&gt;. Otherwise... I don't know.  &lt;BR /&gt; &lt;BR /&gt;Perhaps the cleanest way is to simply use 2-d array and to access it using varying second index when you need to "emulate" 3-d, i.e (a2(i, iStride*j+k)) where &lt;BR /&gt;iStride=SIZE(a3,2). &lt;BR /&gt; &lt;BR /&gt;Jugoslav</description>
      <pubDate>Mon, 18 Feb 2002 20:26:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984178#M26760</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2002-02-18T20:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: array referencing</title>
      <link>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984179#M26761</link>
      <description>&lt;PRE&gt;&lt;FONT size="+0"&gt; &lt;BR /&gt;! Shows how possibly standard-conforming code can point to &lt;BR /&gt;! a rank-1 array with a rank-2 pointer. &lt;BR /&gt;! Also has potentially dangerous code segment not in &lt;BR /&gt;! original posting. &lt;BR /&gt;! Posted to thread "Sparse matrix subblocks" &lt;BR /&gt;! 2001-09-10 12:52:12 PST &lt;BR /&gt; &lt;BR /&gt;! main.f90 -- Contains the compiler-visible part of the code. &lt;BR /&gt; &lt;BR /&gt;module block_mod &lt;BR /&gt;   implicit none &lt;BR /&gt;   type block_type &lt;BR /&gt;      real, pointer :: array(:,:) &lt;BR /&gt;   end type block_type &lt;BR /&gt;end module block_mod &lt;BR /&gt; &lt;BR /&gt;module special_interfaces &lt;BR /&gt;   use block_mod &lt;BR /&gt;   implicit none &lt;BR /&gt;   interface &lt;BR /&gt;      subroutine set_pointer(q) &lt;BR /&gt;         implicit none &lt;BR /&gt; &lt;BR /&gt;         real, pointer :: q(:,:) &lt;BR /&gt;      end subroutine set_pointer &lt;BR /&gt; &lt;BR /&gt;      subroutine serialize(block, x) &lt;BR /&gt;         use block_mod &lt;BR /&gt;         implicit none &lt;BR /&gt;         type(block_type) block(:) &lt;BR /&gt;         real, target :: x(:) &lt;BR /&gt; &lt;BR /&gt;      end subroutine serialize &lt;BR /&gt;   end interface &lt;BR /&gt; &lt;BR /&gt;   external get_pointer &lt;BR /&gt;end module special_interfaces &lt;BR /&gt; &lt;BR /&gt;program main &lt;BR /&gt;   use block_mod &lt;BR /&gt;   use special_interfaces &lt;BR /&gt;   implicit none &lt;BR /&gt;   type(block_type), allocatable :: block(:) &lt;BR /&gt;   real, allocatable, target :: array(:) &lt;BR /&gt;   integer N &lt;BR /&gt;   integer i, j, k &lt;BR /&gt;   character(80) fmt &lt;BR /&gt;   logical, allocatable :: test(:) &lt;BR /&gt;   real x1, x2 &lt;BR /&gt;   real, pointer :: p &lt;BR /&gt; &lt;BR /&gt;   N = 2 &lt;BR /&gt;   write(fmt,'(a,i0,a,i0,a,i0,a)') '(',N,'L3,2x,',N,'F6.1,2X',N,'F6.1)' &lt;BR /&gt;   allocate(array(N**3)) &lt;BR /&gt;   allocate(block(N)) &lt;BR /&gt;   allocate(test(N)) &lt;BR /&gt;   do k = 1, N &lt;BR /&gt;      call get_pointer(array((k-1)*N**2+1), N) &lt;BR /&gt;      call set_pointer(block(k)%array) &lt;BR /&gt;   end do &lt;BR /&gt;   array = (/(i,i=1,size(array))/) &lt;BR /&gt;   call serialize(block, array) &lt;BR /&gt;   do k = 1, N &lt;BR /&gt;      write(*,'(a,i1,a,i0,a,i0,a)') repeat(' ',(3*N-5)/2)//'Assoc'// &amp;amp; &lt;BR /&gt;         repeat(' ',9*N/2-4)//'Block(',k,')'//repeat(' ',6*N-8)// &amp;amp; &lt;BR /&gt;         'Array(',(k-1)*N**2+1,':',k*N**2,')' &lt;BR /&gt;      do i = 1, N &lt;BR /&gt;!         write(*,fmt) (associated(block(k)%array(i,j), &amp;amp; &lt;BR /&gt;!            array((k-1)*N**2+i+N*(j-1))), j = 1, N), &amp;amp; &lt;BR /&gt;!            (block(k)%array(i,j), j = 1, N), &amp;amp; &lt;BR /&gt;!            (array((k-1)*N**2+i+N*(j-1)), j = 1, N) &lt;BR /&gt;         do j = 1, N &lt;BR /&gt;            p =&amp;gt; block(k)%array(i,j) &lt;BR /&gt;            test(j) = associated(p, array((k-1)*N**2+i+N*(j-1))) &lt;BR /&gt;         end do &lt;BR /&gt;         write(*,fmt) (test(j), j = 1, N), &amp;amp; &lt;BR /&gt;            (block(k)%array(i,j), j = 1, N), &amp;amp; &lt;BR /&gt;            (array((k-1)*N**2+i+N*(j-1)), j = 1, N) &lt;BR /&gt;      end do &lt;BR /&gt;      write(*,'()') &lt;BR /&gt;   end do &lt;BR /&gt;   write(fmt,'(a,i0,a)') '(a,',N**3,'(f0.1:1x))' &lt;BR /&gt;   write(*,fmt) 'array = ', array &lt;BR /&gt;   array(7) = -1 &lt;BR /&gt;   x1 = array(7) &lt;BR /&gt;   x2 = block(2)%array(1,2) &lt;BR /&gt;   array = 42 &lt;BR /&gt;   write(*,'(/a,f0.1,a,f0.1/)') 'x1 = ', x1, '; x2 = ', x2 &lt;BR /&gt;   write(*,fmt) 'array = ', array &lt;BR /&gt;end program main &lt;BR /&gt;! Last line of main.f90 &lt;BR /&gt; &lt;BR /&gt;! separate.f90 -- Contains subroutines to map pointers &lt;BR /&gt;! to different ranks.  Compile separately so the compiler &lt;BR /&gt;! has to generate its most general interfacing code. &lt;BR /&gt; &lt;BR /&gt;module separate_temp &lt;BR /&gt;   implicit none &lt;BR /&gt;   save &lt;BR /&gt;   real, pointer :: p(:,:) &lt;BR /&gt;end module separate_temp &lt;BR /&gt; &lt;BR /&gt;subroutine get_pointer(x,n) &lt;BR /&gt;   use separate_temp &lt;BR /&gt;   implicit none &lt;BR /&gt;   integer, intent(in) :: n &lt;BR /&gt;   real, target :: x(n,n) &lt;BR /&gt; &lt;BR /&gt;   p=&amp;gt;x &lt;BR /&gt;end subroutine get_pointer &lt;BR /&gt; &lt;BR /&gt;subroutine set_pointer(q) &lt;BR /&gt;   use separate_temp &lt;BR /&gt; 
  implicit none &lt;BR /&gt; &lt;BR /&gt;   real, pointer :: q(:,:) &lt;BR /&gt;   q=&amp;gt;p &lt;BR /&gt;end subroutine set_pointer &lt;BR /&gt; &lt;BR /&gt;subroutine serialize(block, x) &lt;BR /&gt;   use block_mod &lt;BR /&gt;   impli&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Feb 2002 04:15:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984179#M26761</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2002-02-19T04:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: array referencing</title>
      <link>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984180#M26762</link>
      <description>Only a little bit of the last subroutine was chopped (light a fire under their butts, Steve.)  Here it is: &lt;BR /&gt;&lt;PRE&gt;&lt;FONT size="+0"&gt; 
subroutine serialize(block, x) 
   use block_mod 
   implicit none 
   type(block_type) block(:) 
   real, target :: x(:) 
 
! Empty subroutine 
end subroutine serialize 
! Last line of separate.f90 
&lt;/FONT&gt;&lt;/PRE&gt; &lt;BR /&gt;So, perhaps rather surprisingly, you didn't miss much.  The idea of my program is that when, in Fortran, you pass an array element as an actual argument to a subroutine with an implicit interface that is invisible to the compiler, a reference to the array element pretty much has to be passed in order for sequence association to work like it has since 1960 or earlier.  In the called subroutine, if the array element actual argument is explicitly dimensioned as an array dummy argument, the callee is actually looking at an array consisting of all the elements of the original array from the actual argument element to the end.  It can, in the callee, be declared of any rank, and of course it can be a TARGET, so you can point a POINTER at it in the callee.  On return, the standard considers it processor-dependent as to whether the POINTER you pointed at it has defined association status or not -- I'm not sure whether anybody at Compaq has even thought about whether this should be the case for their 'processor'.  Thus I played a few tricks to keep the compiler in the dark about what I am doing (via separate compilation) and included the serialize subroutine that forces the compiler to reload all elements of the two arrays from memory because for all it knows they may have been changed by it (although, as you can see, the subroutine does nothing, but the comiler doesn't know that!) &lt;BR /&gt; &lt;BR /&gt;I can't compose an example specific to your case because I don't know what the mapping between the two arrays has to be: for example the first dimension of a2 could be split into two dimensions in a3, or the second could be, or something even more complex could be in the offing. &lt;BR /&gt; &lt;BR /&gt;Well, a student is begging me for help and since she's better looking than you I have to sign off now...</description>
      <pubDate>Tue, 19 Feb 2002 11:59:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Re-array-referencing/m-p/984180#M26762</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2002-02-19T11:59:03Z</dc:date>
    </item>
  </channel>
</rss>

