我听说使用假定/显式形状数组比可分配数组更有效。但是,如果我将一个已分配的数组传递给一个需要显式形状数组的子程序,我会恢复性能吗?
E.g。考虑以下两个玩具示例。两者都同样有效率
示例1:
program myprog
implicit none
integer, parameter :: n = 1 000 000
real, allocatable :: x(:)
allocate(x(n))
call mysub(x,n)
contains
subroutine mysub(x,n)
integer, intent(in) :: n
real, intent(inout) :: x(n)
! Work with x
end subroutine
end program
示例2:
program myprog
implicit none
integer, parameter :: n = 1 000 000
real :: x(n)
call mysub(x,n)
contains
subroutine mysub(x,n)
integer, intent(in) :: n
real, intent(inout) :: x(n)
! Work with x
end subroutine
end program