My demo tests:
A website online, you can get different versions of the Fortran compiler, such as gfortran/ifort/ifx/flang
: Compiler Explorer (godbolt.org)
Code: Array 1000*1000
program demo_1
real :: stime, etime
real(kind=8), allocatable :: A(:,:), B(:,:)
call cpu_time(stime)
A = empty_allocation(1000,1000)
call cpu_time(etime)
print "(A,ES10.3)", "etime - stime (seconds) : ", etime - stime !! 8.184E-03 (gfortran); 1.101E-02 (ifort)
call cpu_time(stime)
B = empty_automatic(1000,1000)
call cpu_time(etime)
print "(A,ES10.3)", "etime - stime (seconds) : ", etime - stime !! 8.000E-06 (gfortran); 9.549E-03 (ifort)
contains
!> ALlocation.
pure function empty_allocation(ndim1, ndim2) result(result)
integer, intent(in) :: ndim1, ndim2
real(kind=8), allocatable :: result(:,:)
allocate(result(ndim1, ndim2))
end function empty_allocation
!> Automatic.
pure function empty_automatic(ndim1, ndim2) result(result)
integer, intent(in) :: ndim1, ndim2
real(kind=8) :: result(ndim1, ndim2)
end function empty_automatic
end program demo_1
Screenshot:
Loose conclusion
On the 1000*1000
matrix, it seems that gfortran
is more efficient in the automatic
scheme, while ifort
has the same efficiency in the two schemes.
Code: continue to increase the matrix dimension, 3000*3000
program demo_2
real :: stime, etime
real(kind=8), allocatable :: A(:,:), B(:,:)
call cpu_time(stime)
A = empty_allocation(3000,3000)
call cpu_time(etime)
print "(A,ES10.3)", "etime - stime (seconds) : ", etime - stime !! 6.153E-02 (gfortran); 9.206E-02 (ifort)
call cpu_time(stime)
B = empty_automatic(3000,3000)
call cpu_time(etime)
print "(A,ES10.3)", "etime - stime (seconds) : ", etime - stime !! 1.100E-05 (gfortran); segmentation fault occurred (ifort)
contains
!> ALlocation.
pure function empty_allocation(ndim1, ndim2) result(result)
integer, intent(in) :: ndim1, ndim2
real(kind=8), allocatable :: result(:,:)
allocate(result(ndim1, ndim2))
end function empty_allocation
!> Automatic.
pure function empty_automatic(ndim1, ndim2) result(result)
integer, intent(in) :: ndim1, ndim2
real(kind=8) :: result(ndim1, ndim2)
end function empty_automatic
end program demo_2
Screenshot:
Loose conclusion
With the default ifort/ifx
setting, if you use the automatic
scheme to encounter an array of 3000*3000
, a segmentation error will be reported.