<?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 It is a compiler runtime bug. in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121695#M131886</link>
    <description>&lt;P&gt;It is a compiler runtime bug.&amp;nbsp; You can make it go away for the specific example if you increase things like the block size used for input/output (e.g. set FORT_BLOCKSIZE=256000 before running the program).&lt;/P&gt;

&lt;P&gt;(Reallocation on assignment only applies when assigning to allocatables.&amp;nbsp; There are no allocatables in the program.)&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 10 Jul 2016 20:18:37 GMT</pubDate>
    <dc:creator>IanH</dc:creator>
    <dc:date>2016-07-10T20:18:37Z</dc:date>
    <item>
      <title>writing and reading derived types with pointers</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121683#M131874</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I'm trying to save a write a derived type that contains a pointer to an unformatted file for later reading. &amp;nbsp;Below is a test version. &amp;nbsp;The derived type sol in module dType is separate because I'm patching together various Fortran codes (F95 and F77, etc). &amp;nbsp;The current version of the code "saves" sol1, but it seems to only save the pointer references, not their values, so when sol1 is deallocated, sol2 also becomes unreferenced. &amp;nbsp;I'm sure my hack on the UDTIO is not correct.&lt;/P&gt;

&lt;P&gt;Any help would be appreciated (I'm still trying to figure out UDTIO). &amp;nbsp;Thanks&lt;/P&gt;

&lt;P&gt;-joe&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;   module dType
      implicit none
      type, public :: sol
         integer:: n
         real(8), pointer:: vec(:)
      end type sol
   end module dType   
   
   module dType_io
      use dType
      implicit none
   contains

   subroutine write_sol(dtv, unit, iostat, iomsg)
      class(sol), intent(in) :: dtv
      integer, intent(in)             :: unit
      integer, intent(out)            :: iostat
      character(*), intent(inout)     :: iomsg

      write(unit, iostat=iostat, iomsg=iomsg) dtv%n
      write(unit, iostat=iostat, iomsg=iomsg) size(dtv%vec)
      write(unit, iostat=iostat, iomsg=iomsg) dtv%vec  
   end subroutine write_sol

   subroutine read_sol(dtv, unit, iostat, iomsg)
      class(sol), intent(inout)  :: dtv
      integer, intent(in)                 :: unit
      integer, intent(out)                :: iostat
      character(*), intent(inout)         :: iomsg

      integer allocSize

      ! read is sol type, but allocate pointer space as needed.
      read(unit, iostat=iostat, iomsg=iomsg) dtv%n
      read(unit, iostat=iostat, iomsg=iomsg) allocSize
      allocate( dtv%vec(allocSize) )      
      read(unit, iostat=iostat, iomsg=iomsg) dtv%vec  
   end subroutine read_sol
   end module dType_io
   
   program directAccess
      use dType
      implicit none
      integer, parameter :: dp = kind(0d0)
      type(sol):: sol1, sol2      
      integer solUnit, n, sze
      integer i
      
      sol1%n = 10
      allocate( sol1%vec(sol1%n) )
      sol1%vec = [ (real(i),i=1,sol1%n) ]  
      
      open(newunit=solUnit, file='test.sol', form='unformatted', status='replace', action='write')
      write(solUnit) sol1
      close(solUnit)
      
      open(newunit=solUnit, file='test.sol', form='unformatted', status='old', action='read')
      read(solUnit) sol2
      
      deallocate( sol1%vec ); nullify(sol1%vec) ! this will cause sol2 to lose reference
      
      close(solUnit)      
      stop
   end program directAccess
   
      
      
      
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 22:24:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121683#M131874</guid>
      <dc:creator>j0e</dc:creator>
      <dc:date>2016-07-08T22:24:38Z</dc:date>
    </item>
    <item>
      <title>The code doesn't have the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121684#M131875</link>
      <description>&lt;P&gt;The code doesn't have the necessary declarations of the generic bindings or interfaces that specify that read_sol and write_sol are the procedures implementing defined IO for your type - the code is missing something like&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;INTERFACE READ(UNFORMATTED)
  MODULE PROCEDURE read_sol
END INTERFACE READ(UNFORMATTED)&lt;/PRE&gt;

&lt;P&gt;and similarly for the WRITE(UNFORMATTED) interface.&lt;/P&gt;

&lt;P&gt;The code should not compile without these.&lt;/P&gt;

&lt;P&gt;You want to be using the very latest compiler (and perhaps even a bit later than that) if you are using UDDTIO.&lt;/P&gt;

&lt;P&gt;(Edit to later add... I tried the current beta on the code, and I see it also fails to diagnose the body-text requirement for defined input/output of an object of derived type with pointer components.&lt;/P&gt;

&lt;P&gt;Unrelated to UDDTIO, but I can't help myself - note that DEALLOCATION of a pointer also dissociates it - the nullify after the deallocate is just wearing your keyboard out prematurely.)&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2016 23:13:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121684#M131875</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2016-07-08T23:13:00Z</dc:date>
    </item>
    <item>
      <title>You should also modify your</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121685#M131876</link>
      <description>&lt;P&gt;You should also modify your read and write routines to handle the case where the pointer is NULL.&lt;/P&gt;

&lt;P&gt;e.g. On write, when pointer is null, write 0 for size and do not take size of the array.&lt;BR /&gt;
	On read, when allocSize is 0, nullify the pointer instead of allocating the pointer.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 01:06:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121685#M131876</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-07-09T01:06:52Z</dc:date>
    </item>
    <item>
      <title>Thanks Ian and Jim. As always</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121686#M131877</link>
      <description>&lt;P&gt;&lt;SPAN style="font-size: 13.008px; line-height: 19.512px;"&gt;Thanks Ian and Jim. As always, very helpful!!! I also found Ian's previous post here&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/621651#comment-1864744&amp;nbsp;to" target="_blank"&gt;https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/621651#comment-1864744&amp;nbsp;to&lt;/A&gt; be very useful.&lt;/P&gt;

&lt;P&gt;BTW, I am using the latest Intel compiler and the interface statements solved the problem.&lt;/P&gt;

&lt;P&gt;cheers,&lt;/P&gt;

&lt;P&gt;-joe&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 16:05:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121686#M131877</guid>
      <dc:creator>j0e</dc:creator>
      <dc:date>2016-07-09T16:05:31Z</dc:date>
    </item>
    <item>
      <title>I guess I spoke too soon.  It</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121687#M131878</link>
      <description>&lt;P&gt;I guess I spoke too soon. &amp;nbsp;It appears when the size of the pointer becomes large (&amp;gt; than around 16390 elements), the write works OK, but when the read is executed it produces the IO errors:&lt;/P&gt;

&lt;P&gt;On Write: iostat = &amp;nbsp; &amp;nbsp;0 iomsg = OK&lt;BR /&gt;
	On Read: iostat = &amp;nbsp; 67 iomsg = input statement requires too much data, unit -130, file C:\Users\jvallino\Projec&lt;/P&gt;

&lt;P&gt;The read error occurs when it attempts to:&amp;nbsp;read(unit, iostat=iostat, iomsg=iomsg) dtv%vec(1:allocSize) &amp;nbsp;As far as I can tell, IO limits are not being violated. &amp;nbsp;I'm guessing it is something simple, but I'm currently baffled. &amp;nbsp;Code is below.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;   module dType
      implicit none
      type, public :: sol
         integer:: n
         real(8), dimension(:), pointer:: vec
      end type sol
   end module dType   
   
   module dType_io
      use dType
      implicit none
      interface read(unformatted)
         procedure read_sol
      end interface read(unformatted)
      interface write(unformatted)
         procedure write_sol
      end interface write(unformatted)
      
   contains
   subroutine write_sol(dtv, unit, iostat, iomsg)
      class(sol), intent(in) :: dtv
      integer, intent(in)             :: unit
      integer, intent(out)            :: iostat
      character(*), intent(inout)     :: iomsg

      write(unit, iostat=iostat, iomsg=iomsg) dtv%n
      write(unit, iostat=iostat, iomsg=iomsg) size(dtv%vec)
      write(unit, iostat=iostat, iomsg=iomsg) dtv%vec(1:size(dtv%vec))  
   end subroutine write_sol

   subroutine read_sol(dtv, unit, iostat, iomsg)
      class(sol), intent(inout)  :: dtv
      integer, intent(in)                 :: unit
      integer, intent(out)                :: iostat
      character(*), intent(inout)         :: iomsg

      integer allocSize

      ! read is sol type, but allocate pointer space as needed.
      read(unit, iostat=iostat, iomsg=iomsg) dtv%n
      read(unit, iostat=iostat, iomsg=iomsg) allocSize
      allocate( dtv%vec(allocSize) )      
      read(unit, iostat=iostat, iomsg=iomsg) dtv%vec(1:allocSize)  
   end subroutine read_sol
   end module dType_io
   
   program testUDDTIO
      use dType
      use dType_io
      implicit none
      integer, parameter :: dp = kind(0d0)
      type(sol):: sol1, sol2      
      integer solUnit, n, sze
      character*80 iomsg
      integer i, iostat
      
      sol1%n = 16390
      allocate( sol1%vec(sol1%n) )
      sol1%vec = [ (real(i),i=1,sol1%n) ]  
      iomsg = 'OK'
      open(newunit=solUnit, file='test.sol', form='unformatted', status='replace', action='write')
      write(solUnit, iostat=iostat,  iomsg=iomsg) sol1
      write(*,'(a,i4,2a)') 'On Write: iostat = ', iostat,' iomsg = ',trim(iomsg)
      close(solUnit)
      
      iomsg = 'OK'
      open(newunit=solUnit, file='test.sol', form='unformatted', status='old', action='read')
      read(solUnit, iostat=iostat,  iomsg=iomsg) sol2
      write(*,'(a,i4,2a)') 'On Read: iostat = ', iostat,' iomsg = ',trim(iomsg)

      deallocate( sol1%vec )
      
      close(solUnit)      
      stop
   end program testUDDTIO&lt;/PRE&gt;

&lt;P&gt;The file produced during the write appears to be the correct size. &amp;nbsp;Also, when&amp;nbsp;sol1%n is large enough to cause the read error, only the first 1022 elements are read into dtv%vec.&lt;/P&gt;

&lt;P&gt;Thanks Again!&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 19:41:31 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121687#M131878</guid>
      <dc:creator>j0e</dc:creator>
      <dc:date>2016-07-09T19:41:31Z</dc:date>
    </item>
    <item>
      <title>Hopefully your last code</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121688#M131879</link>
      <description>&lt;P&gt;Hopefully your last code posting will reproduce the error for an Intel software support person. They should be able to investigate the issue with a reproducer. Please provide all the particulars: Compiler version, options used, 32/64-bit build, O/S.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sat, 09 Jul 2016 22:24:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121688#M131879</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-07-09T22:24:28Z</dc:date>
    </item>
    <item>
      <title>You need to allocate sol2</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121689#M131880</link>
      <description>&lt;P&gt;You need to allocate sol2 before the read or have the compiler flag&amp;nbsp;/standard-semantics for it to auto-allocate on read.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 10:24:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121689#M131880</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2016-07-10T10:24:38Z</dc:date>
    </item>
    <item>
      <title>Andrew,</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121690#M131881</link>
      <description>&lt;P&gt;Andrew,&lt;/P&gt;

&lt;P&gt;I believe the auto-allocate only applies to assignment (=) not reads. The option enabling this is realloc_lhs. For READ, the buffer argument is not an LHS entity.&lt;/P&gt;

&lt;P&gt;Jim Dempsey&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 14:03:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121690#M131881</guid>
      <dc:creator>jimdempseyatthecove</dc:creator>
      <dc:date>2016-07-10T14:03:21Z</dc:date>
    </item>
    <item>
      <title>Even if you allocate sol2%vec</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121691#M131882</link>
      <description>&lt;P&gt;Even if you allocate sol2%vec prior to reading (which would defeat the usefulness of UDDTIO it would seem) the problem still occurs when the size exceeds ~16390 elements. &amp;nbsp;I did not try changing compiler options.&lt;/P&gt;

&lt;P&gt;Using ifort 16.0.3.207 (build&amp;nbsp;20160415), x64 compiler&lt;/P&gt;

&lt;P&gt;ifort /debug:full /Od /warn:interfaces /traceback /check:bounds /check:stack /libs:static /threads /dbglibs /Qmkl:parallel derivedTypeWriteRead.f90&lt;/P&gt;

&lt;P&gt;Build and run on Windows 10. &amp;nbsp;&lt;/P&gt;

&lt;P&gt;On a Linux box running version&amp;nbsp;16.0.2 20160204 of ifort, compiled with just "ifort&amp;nbsp;derivedTypeWriteRead.f90" the exact same problem occurs.&lt;/P&gt;

&lt;P&gt;For now, I've dropped trying to use UDDTIO and just went the non object route.&lt;/P&gt;

&lt;P&gt;Thanks for everyone's help!&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 15:21:11 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121691#M131882</guid>
      <dc:creator>j0e</dc:creator>
      <dc:date>2016-07-10T15:21:11Z</dc:date>
    </item>
    <item>
      <title>Your example works with </title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121692#M131883</link>
      <description>&lt;P&gt;Your example works with&amp;nbsp;&lt;SPAN style="font-size: 12px; line-height: 18px;"&gt;/standard-semantics for 18000 which is what I tested.on an x32 build.&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 16:08:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121692#M131883</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2016-07-10T16:08:34Z</dc:date>
    </item>
    <item>
      <title>Actually I take that back, it</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121693#M131884</link>
      <description>&lt;P&gt;Actually I take that back, it only reads the first 1022 elements....&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 16:16:20 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121693#M131884</guid>
      <dc:creator>andrew_4619</dc:creator>
      <dc:date>2016-07-10T16:16:20Z</dc:date>
    </item>
    <item>
      <title>OK, cause I just tried</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121694#M131885</link>
      <description>&lt;P&gt;OK, cause I just tried standard-semantics on both win and linux boxes and it did not work, but thanks for trying&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 16:18:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121694#M131885</guid>
      <dc:creator>j0e</dc:creator>
      <dc:date>2016-07-10T16:18:50Z</dc:date>
    </item>
    <item>
      <title>It is a compiler runtime bug.</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121695#M131886</link>
      <description>&lt;P&gt;It is a compiler runtime bug.&amp;nbsp; You can make it go away for the specific example if you increase things like the block size used for input/output (e.g. set FORT_BLOCKSIZE=256000 before running the program).&lt;/P&gt;

&lt;P&gt;(Reallocation on assignment only applies when assigning to allocatables.&amp;nbsp; There are no allocatables in the program.)&lt;BR /&gt;
	&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 10 Jul 2016 20:18:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121695#M131886</guid>
      <dc:creator>IanH</dc:creator>
      <dc:date>2016-07-10T20:18:37Z</dc:date>
    </item>
    <item>
      <title>Thank Joe, Ian. I escalated</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121696#M131887</link>
      <description>&lt;P&gt;Thank Joe, Ian. I escalated the issues to Development.&lt;/P&gt;

&lt;P&gt;(Internal tracking id: DPD200412514 - not diagnosing body-text requirement for defined input/output of an object of derived type with pointer components)&lt;/P&gt;

&lt;P&gt;(Internal tracking id: DPD200412516 - Run-time iostat=67 reading &amp;gt; ~16390 elements w/UDDTIO)&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 09:40:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121696#M131887</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2016-07-11T09:40:39Z</dc:date>
    </item>
    <item>
      <title>DPD200412514, the missed</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121697#M131888</link>
      <description>&lt;P&gt;DPD200412514, the missed diagnosis, will be fixed in a future major release (not the one later this year).&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jul 2016 14:29:45 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/writing-and-reading-derived-types-with-pointers/m-p/1121697#M131888</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2016-07-11T14:29:45Z</dc:date>
    </item>
  </channel>
</rss>

