<?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 Great, thanks again for your in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097866#M126016</link>
    <description>&lt;P&gt;Great, thanks again for your replies!&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2015 20:01:38 GMT</pubDate>
    <dc:creator>Crni_G_</dc:creator>
    <dc:date>2015-12-07T20:01:38Z</dc:date>
    <item>
      <title>workaround for using derived type with allocatable components within OpenMP regions</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097862#M126012</link>
      <description>&lt;P&gt;I'm working on a CFD code, operating on several large 3D arrays.&amp;nbsp; Coming from C background, I was thinking to encapsulate these arrays into a derived type:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type variables
  integer :: nx, ny, nz ! Grid size.
  real, allocatable, dimension(:, :, :) :: p_1 ! Pressure at t = t.
  real, allocatable, dimension(:, :, :) :: p_2 ! Pressure at t = t + dt.
  ! etc.
end type&lt;/PRE&gt;

&lt;P&gt;At the end of each simulation time step, I'm updating arrays to prepare for the next time step:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;type(variables) :: vars
! ...
!$OMP PARALLEL WORKSHARE
  vars%p_1 = vars%p_2
  ! etc.
!$OMP END PARALLEL WORKSHARE
&lt;/PRE&gt;

&lt;P&gt;That was working fine with GNU Fortran (version 4.4.7), however with Intel Fortran (version 13.0.1 20121010) the code will crash within OpenMP region.&amp;nbsp; Looking further into the issue, I learned that using derived types with allocatable components is unsupported with OpenMP, and am looking now into how to overcome the issue.&amp;nbsp; I would still prefer to keep arrays encapsulated into this derived type.&amp;nbsp; I've noticed that the crash is avoided if I create a subroutine for OpenMP region above:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;subroutine update(nx, ny, nz, p_1, p_2)
  integer, intent(in) :: nx, ny, nz
  real, dimension(nx, ny, nz), intent(out) :: p_1
  real, dimension(nx, ny, nz), intent(in) :: p_2

!$OMP PARALLEL WORKSHARE
  p_1 = p_2
!$OMP END PARALLEL WORKSHARE
end subroutine&lt;/PRE&gt;

&lt;P&gt;and if I just pass arrays from derived type into this subroutine:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;  call update(nx, ny, nz, vars%p_1, vars%p_2)&lt;/PRE&gt;

&lt;P&gt;It's somewhat cumbersome approach, still I'm OK with it.&amp;nbsp; But, my question is: is this code now valid, is there any undefined behavior left here?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Dec 2015 22:08:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097862#M126012</guid>
      <dc:creator>Crni_G_</dc:creator>
      <dc:date>2015-12-06T22:08:35Z</dc:date>
    </item>
    <item>
      <title>You might fine the following</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097863#M126013</link>
      <description>&lt;P&gt;You might fine the following to be a bit more efficient:&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;subroutine update(nxyz, p_1, p_2)
&amp;nbsp; integer, intent(in) :: nxyz
&amp;nbsp; real, dimension(*), intent(out) :: p_1
&amp;nbsp; real, dimension(*), intent(in) :: p_2

!$OMP PARALLEL WORKSHARE
&amp;nbsp; p_1(1:nxyz) = p_2(1:nxyz)
!$OMP END PARALLEL WORKSHARE
end subroutine

...

call update(nx*ny*nz, vars%p_1, vars%p_2)&lt;/PRE&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 17:05:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097863#M126013</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2015-12-07T17:05:32Z</dc:date>
    </item>
    <item>
      <title>Thanks for the reply, and for</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097864#M126014</link>
      <description>&lt;P&gt;Thanks for the reply, and for performance hint, but - do you think the approach that I tried to explain in my first message is appropriate for avoiding issues between OpenMP and allocatable components of derived types?&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 17:50:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097864#M126014</guid>
      <dc:creator>Crni_G_</dc:creator>
      <dc:date>2015-12-07T17:50:34Z</dc:date>
    </item>
    <item>
      <title>IMHO, your original post code</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097865#M126015</link>
      <description>&lt;P&gt;IMHO, your original post code should have worked as vars is default shared. I suspect this was a bug.&lt;/P&gt;

&lt;P&gt;My suggested code often produces more efficient code, due to the optimizer not necessarily performing the equivalent of unroll(3). V16 update 1 does still have code efficiency issues of well vectorized ArrayOut = ArrayIn where the two arrays are multi-dimensional. I've seen cases on Xeon Phi (V16 update 1)&lt;/P&gt;

&lt;P&gt;real(8) :: Array(6,6) ! subroutine local array&lt;BR /&gt;
	...&lt;BR /&gt;
	Array = 0.0_8&lt;/P&gt;

&lt;P&gt;producing quite inefficient code. For an allocatable array (known to be contiguous), passing a contiguous multi-dimension slice (or whole), to a dimension(*) array as in #2 can experience significant performance gain for the given operation. If performance is of lessor concern than program elegance then continue to use vars%p_1 = vars%p_2 without the subroutine... and wait for the compiler optimization to catch up.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 19:26:53 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097865#M126015</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2015-12-07T19:26:53Z</dc:date>
    </item>
    <item>
      <title>Great, thanks again for your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097866#M126016</link>
      <description>&lt;P&gt;Great, thanks again for your replies!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 20:01:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/workaround-for-using-derived-type-with-allocatable-components/m-p/1097866#M126016</guid>
      <dc:creator>Crni_G_</dc:creator>
      <dc:date>2015-12-07T20:01:38Z</dc:date>
    </item>
  </channel>
</rss>

