Re: Fortran vs. Matlab on linear algebra
- From: wim <wim.van.hoydonck@xxxxxxxxx>
- Date: Fri, 8 Aug 2008 15:11:43 -0700 (PDT)
On Aug 6, 3:45 am, Gib Bogle <g.bo...@xxxxxxxxxxxxxxxxxxxxxx> wrote:
I have revisited a topic from 2001, using ifort 10.1.011 and Matlab 7.5.0, to compare the speed of
matmul() with the speed of a matrix multiply in Matlab.
Here is the code:
! To compare speed of Matlab and Fortran on matrix algebra
program speed
REAL(8) :: a(500,500), b(500,500), c(500,500), t1, t2
integer, parameter :: N = 20
integer :: i
call RANDOM_NUMBER(a)
call RANDOM_NUMBER(b)
call cpu_time(t1)
do i = 1,N
a(1,1) = a(1,1) + 0.1
c = MATMUL(a,b)
write(*,*) c(1,1)
enddo
call cpu_time(t2)
write(*,*) 'Time: ',t2-t1
end program
! Matlab code
!function speed
!A = rand(500);
!B = rand(500);
!C = zeros(500);
!tic
!for i = 1:20
! A(1,1) = A(1,1) + 0.1;
! C = A * B;
! C(1,1)
!end
!toc
I was a bit surprised to find that Matlab takes about 0.92 sec while ifort takes 2.73 sec (this is
the speed with O0, O1, or O2, while O3 takes 12.6 sec !?!)
I am running on a recent Intel quad core Windows PC.
Hi,
I've tried it on my laptop with an intel core 2 duo processor,
2GHz running linux, playing Pink Floyd - the Wall in the background :)
ifort: 10.1.017
mkl: 10.0.3.020
matlab: 7.4.0.287 (R2007a)
octave: 3.0.0
My results are:
Fortran using matmul:
time [sec] optimization
18.9 -O0
5.0 -O1
2.4 -O2
1.0 -O3
matlab:
time [sec]
0.76->0.81
octave (w. default atlas?):
time [sec]
1.5
Fortran using blas95 (gemm)
time [sec] optimization
0.77->0.84 -O0,-O1,-O2,-O3
So, for this program on my laptop, Matlab and fortran+mkl are
practically the same, which is not surprising as they both use mkl.
I have however seen fortran beat matlab by a factor of 1000 on a
nontrivial problem (25 minutes vs 1.5 sec).
Wim
.
- Follow-Ups:
- Re: Fortran vs. Matlab on linear algebra
- From: Gib Bogle
- Re: Fortran vs. Matlab on linear algebra
- References:
- Fortran vs. Matlab on linear algebra
- From: Gib Bogle
- Fortran vs. Matlab on linear algebra
- Prev by Date: Re: Integers and standard
- Next by Date: Re: Fortran and Python
- Previous by thread: Re: Fortran vs. Matlab on linear algebra
- Next by thread: Re: Fortran vs. Matlab on linear algebra
- Index(es):
Relevant Pages
|