https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128722

            Bug ID: 128722
           Summary: Pointer arrays in I/O lists are transferred element by
                    element
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: suvarchal.cheedela at awi dot de
  Target Milestone: ---

Created attachment 66164
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66164&action=edit
program to test io on pointer arrays

gfc_trans_transfer scalarizes every pointer array in an I/O list, so the
library is called once per element.  For asynchronous I/O every element
becomes one queue item.  In an ocean model (FESOM2) whose restart fields
are pointers to allocatable components, a restart took 120 s instead of
4 s.  Also present on trunk (17.0.0 20261113).

$ gfortran -O2 -pthread -fdump-tree-original pointer_io.f90 && ./a.out
array,   synchronous :    0.013 s
pointer, synchronous :    0.113 s
array,   asynchronous:    0.013 s
pointer, asynchronous:    1.850 s

The dump shows _gfortran_transfer_real_write in a loop for "write (10) p"
and a single _gfortran_transfer_array_write for "write (10) a".

--- pointer_io.f90 ---
! Writing pointer arrays: stock gfortran makes one library call per element
! (see the -fdump-tree-original output), and for asynchronous I/O one queue
! item per element.  Prints the time of a plain array and of the same data
! through a pointer, synchronous and asynchronous.
program pointer_io
  implicit none
  integer, parameter :: n = 5000000
  type :: state
     real(8), allocatable :: t(:)
  end type state
  type(state), target :: s
  real(8), pointer :: p(:)
  real(8), allocatable, asynchronous :: a(:)
  integer(8) :: c0, c1, rate
  allocate (s%t(n), a(n))
  call random_number (s%t)
  a = s%t
  p => s%t
  call system_clock (count_rate=rate)
  open (10, file='pointer_io.bin', form='unformatted', status='replace', &
        asynchronous='yes')
  call system_clock (c0); write (10) a; call system_clock (c1)
  print '(a,f8.3,a)', 'array,   synchronous : ', real (c1 - c0) / rate, ' s'
  call system_clock (c0); write (10) p; call system_clock (c1)
  print '(a,f8.3,a)', 'pointer, synchronous : ', real (c1 - c0) / rate, ' s'
  call system_clock (c0); write (10, asynchronous='yes') a; wait (10); call
system_clock (c1)
  print '(a,f8.3,a)', 'array,   asynchronous: ', real (c1 - c0) / rate, ' s'
  call system_clock (c0); write (10, asynchronous='yes') p; wait (10); call
system_clock (c1)
  print '(a,f8.3,a)', 'pointer, asynchronous: ', real (c1 - c0) / rate, ' s'
  close (10, status='delete')
end program pointer_io

Reply via email to