Dear newsgroup,

I encountered some problems with vector-valued functions in F90/F95.

Here, is a simple demo-program:

program quick

implicit none

integer, parameter :: dp=8

real(dp), dimension(:), pointer :: u,v,r

real :: tt0,tt1

integer :: i,n

n=1000000

allocate(u(n),v(n),r(n))

u=2; v=2

call cpu_time(tt0)

do i=1,1000

r=feval(u,v)

end do

call cpu_time(tt1)

print *, tt1-tt0

call cpu_time(tt0)

do i=1,1000

call seval(u,v,r)

end do

call cpu_time(tt1)

print *, tt1-tt0

deallocate(u,v,r)

contains

function feval(u,v) result(r)

real(dp), dimension(:), intent(in) :: u,v

real(dp), dimension(size(u)) :: r

r=u*v

end function feval

subroutine seval(u,v,r)

real(dp), dimension(:), intent(in) :: u,v

real(dp), dimension(:), intent(out) :: r

r=u*v

end subroutine seval

end program quick

I compiled it both with Ifort (9.1) and G95 (0.91) and see, that

functions are much slower. My question is why? Nothing needs to be

allocated on-the-fly. Shouldn't the code perform similar in both cases?

Here are the timing:

G95

function: 19.70523

subroutine: 5.620352

Ifort

function: 9.824615

subroutine: 5.768361

Many thanks in advance,