Why a function returns an array is much slower than a subroutine returns an array? (real MWE included)

Although Intel Fortran is your main compiler, I suggest also compiling problematic codes with
gfortran -Wall -Wextra and looking at the results. As @kargl notes, tabs are not valid Fortran, but most compilers can handle them. A bigger problem is

  158 | allocate(iseed(n))
      |                  ^
Warning: 'n' is used uninitialized [-Wuninitialized]

referring to

subroutine setrn(irnin)
! set the seed
integer(kind=i8) :: irnin
integer(kind=i8) :: n
integer(kind=i8), allocatable :: iseed(:)
irn=iand(irnin,mask48)
call savern(irn)
allocate(iseed(n))
iseed=int(irnin)
return
end subroutine setrn
1 Like