I have a 1-dimensional work array
real(8), allocatable :: work(:)
which is passed to a subroutine that operates on a 2-dimensional array
pure subroutine f(work, dim1, dim2)
real(8), intent(out) :: work(dim1, dim2)
integer, intent(in) :: dim1, dim2
...
What is the difference in the following ways of passing the array?
call f(work, dim1, dim2)
call f(work(1), dim1, dim2)
Are they the same in that they just pass the pointer to the first array element or is there some extra overhead with either call? Are there more elegant ways in modern Fortran of passing an array whose shape needs to change, without passing the dimensions explicitly, but without taking a performance hit?
I know the above looks like old Fortran but I've found it faster than declaring a two-dimensional array in the parent subroutine and passing an array section, work(:dim1,:dim2)
, to f
.