-1

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?

nadavhalahmi
  • 101
  • 6

1 Answers1

0

OOPS.

I disabled vectorization using -no-vec on ifort and -fno-tree-vectorize on gfortran, and now the run times are same and about 0.39 sec (just like the original intel time).

nadavhalahmi
  • 101
  • 6
  • 2
    What is the point of this exercise? Using options to initialize variables is not a part of the Fortran standard. A compiler can do anything it wants, so compare behavior between any two compilers is pointless. – steve May 19 '21 at 16:05
  • @steve I have a legacy code which can be compiled with ifort and gfortran. When I compare both performances, I can tell how to optimize each one of them individually. I can tell, where what could have performed better, and help it get there. – nadavhalahmi May 20 '21 at 08:00
  • 1
    Don't know about intel, but all of those -finit-* options for gfortran can effect performance. If you're worried about performance with your legacy code, then use a profiler to find hot spots. Artificial benchmarks, such as the one here, have little value. – steve May 20 '21 at 14:53
  • @steve I use Intel Vtune to profile my code for both ifort and gfortran. Ifort ran about 20% slower and got a major hotspot for `for_array_initialize` function, which is the reason I compared array initializtion in both compilers. – nadavhalahmi May 21 '21 at 08:20