I would like to compare array initialization run time for ifort vs gfortran using this compilation lines with gfortran 10.1.0 and ifort 19.1.3.304 on CentOS Linux 7:
ifort array-initialize.f90 -O3 -init=arrays,zero,minus_huge,snan -g -o intel-array.out
gfortran array-initialize.f90 -O3 -finit-local-zero -finit-integer=-2147483647 -finit-real=snan -finit-logical=True -finit-derived -g -o gnu-array.out
array-initialize.f90:
program array_initialize
implicit none
integer :: i, j, limit
real :: my_max
real :: start, finish
my_max = -1.0
limit = 10000
call cpu_time(start)
do j=1, limit
do i=1, limit
my_max = max(my_max, initializer(i, j))
end do
end do
call cpu_time(finish)
print *, my_max
print '("Time = ", f6.3," seconds.")', finish-start
contains
function initializer(i, j)
implicit none
real :: initializer
real :: arr(2)
integer :: i, j
arr(1) = -1.0/(2*i+j+1)
arr(2) = -1.0/(2*j+i+1)
initializer = max(arr(1), arr(2))
end function
end program array_initialize
Run times for this code:
gnu - 0.096 sec
intel - 0.392 sec
When I remove the init flags:
gnu - 0.098 sec
intel - 0.057 sec
When I replace the array with two variables:
gnu - 0.099 sec
intel - 0.065 sec
What happens here? Does gnu not initialize its arrays? Does intel initialize arrays very slow?