Assume a module with the following definitions:
(a)  real, allocatable, dimension(:) :: array
or
(b)  real, dimension(500) :: array

Both arrays are contiguous as one cannot allocate strides
  allocate(array(1:1000:2)) ! invalid
Thus: Only pointers or dummy arguments can have strides.

If one accesses the array in a loop, this can slow down the calculation
considerably.

Test case:

module a
  implicit none
  real, dimension(500) :: array
!  real, allocatable, dimension(:) :: array
contains
  subroutine test(x,n)
    integer :: n, i
    real :: x(n)
!    allocate(array(1:500))
    do i = 1, n
      x(i) = array(i)
    end do
  end subroutine test
end module a
end

>From the dump difference:

-              (*x)[(int8) i + -1] = array[(int8) i + -1];
+              (*x)[(int8) i + -1] = (*(real4[0:] *) array.data)[(int8) i *
array.dim[0].stride + array.offset];

Full example, see:
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/8fac8fcf6e93fba7/
("Program slowdown when calling function with dynamic arrays" by Paul Hilscher)


-- 
           Summary: gfortran treads known-to-be-contiguous array as having
                    strides
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33753

Reply via email to