Slow MATMUL
Tobias Burnus
burnus@net-b.de
Sun Dec 12 10:16:00 GMT 2010
Hello,
I am not sure what to do but using the NAG or Intel compiler, a MATMUL
can be 4 times faster than the gfortran version. Using a the MATMUL from
Intel's MKL, the performance is regained.
Thus, a possible solution would be to see whether one can (by
algorithmic changes in libgfortran or by middle end changes?) make the
built-in mathmul faster.
If one tries the NETLIB version directly, the performance is improved:
gfortran -O3 -march=native -fexternal-blas test.f90 dgemm.f lsame.f xerbla.f
Time, MATMUL: 1.0120630
dgemm: 1.0160630
However, as soon as I enable LTO (-flto -fwhole-program), even with
--param hot-bb-frequency-fraction=2000, I am back to the slow
performance of:
Time, MATMUL: 1.4760920
dgemm: 1.4760920
Based on
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/1cba8e6ce5080197
The following program needs with GCC 2.5 (Athlon64) to 4.1 (Core2) times
as long as with the Intel compiler (all: x86-64-linux).
On an Intel Core2 Duo E8400 (intel = ifort 11.1; gfortran = GCC 4.6.0):
(number = time in seconds)
0.4579300 ifort -O2
0.1929710 ifort -xHost -O3
[0.1509770 when using dgemm (MKL) manually]
0.76688403 gfortran -O2
0.79987901 gfortran -march=native -Ofast -funroll-loops
0.80287802 gfortran -funroll-loops -floop-strip-mine -floop-block \
-floop-interchange -march=native -Ofast -funroll-loops
[0.17097399 when using dgemm (MKL) via -fexternal-blas]
[0.15197700 when using dgemm (MKL) manually]
On a Athlon 64 X2 Dual Core Processor 4800+ (2.4 GHz):
0.9760600 ifort -O2
0.6840420 ifort -O3 -xHost
[0.4360271 using dgemm (MKL) manually]
[1.584099 using dgemm (BLAS, gfortran -O2 compiled)]
1.6761041 gfortran -O2
1.6721040 gfortran -O3 -march=native -funroll-loops
1.6801040 gfortran -flto -fwhole-program -floop-strip-mine \
-floop-block -floop-interchange -ffast-math \
-O3 -march=native -funroll-loops
MKL BLAS (call via -O2
1.5800979 gfortran -march=native -fexternal-blas -O3 -lblas
gfortran -O2 compiled BLAS:
0.43602699 gfortran -march=native -fexternal-blas -O3 -lblas
using dgemm (BLAS, gfortran -O2 compiled)]
0.4200000 nagf95 -O3 -kind=byte
Note: gfortran calls _gfortran_matmul_r8, NAG calls __NAGf90_dgemm. The
version which manually calls dgemm (cf. c.l.f) is with a normal
"gfortran -O2"-compiled LAPACK also not faster.
! "mult_test.f90"
program t2
implicit none
REAL time_begin, time_end
integer, parameter :: n=200;
REAL(8) :: a(n,n), b(n,n), c(n,n)
integer, parameter :: m = 100
integer :: i
call RANDOM_NUMBER(a)
call RANDOM_NUMBER(b)
call cpu_time(time_begin)
do i = 1,m
a(1,1) = a(1,1) + 0.1
c = MATMUL(a,b)
enddo
call cpu_time(time_end)
PRINT *, 'Time, MATMUL: ',time_end-time_begin
! call cpu_time(time_begin)
! do i = 1,m
! a(1,1) = a(1,1) + 0.1
! call dgemm('n','n',n, n, n, dble(1.0), a, n, b, n, dble(0.0), c, n)
! enddo
!
! call cpu_time(time_end)
! PRINT *, 'dgemm: ',time_end-time_begin
end program
Tobias
More information about the Fortran
mailing list