Fortran vs. Matlab on linear algebra
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Fortran vs. Matlab on linear algebra         


Author: Gib Bogle
Date: Aug 5, 2008 18:45

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
Show full article (1.22Kb)
22 Comments
Re: Fortran vs. Matlab on linear algebra         


Author: rusi_pathan
Date: Aug 5, 2008 19:56

On Aug 5, 9:45 pm, Gib Bogle auckland.no.spam.ac.nz> 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 ...
Show full article (1.94Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: Ken.Fairfield
Date: Aug 6, 2008 08:14

On Aug 5, 6:45 pm, Gib Bogle auckland.no.spam.ac.nz> 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 ...
Show full article (1.32Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: mecej4
Date: Aug 6, 2008 08:53

Ken.Fairfield@gmail.com wrote:
> On Aug 5, 6:45 pm, Gib Bogle auckland.no.spam.ac.nz> 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 ...
Show full article (1.57Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: dpb
Date: Aug 6, 2008 14:20

Ken.Fairfield@gmail.com wrote:
...
>> ! Matlab code
>> !function speed
>> !A = rand(500);
...
> Forgive me for not knowing Matlab syntax, but the
> above (commented) Matlab code sure *looks* like
> A and B get 500 random numbers. At that point,
> how does Matlab know A and B are 2 dimensional
> and that 250,000 random numbers are required
> for each (which is what the Fortran code clearly
> does)? Yes, I see the usage *later* referencing
> A(1,1), but that's the only clue in the whole script
> that A, B and C are 2-D.

That's the definition of rand() in Matlab that rand(N) returns a square
NxN matrix.

Matlab does the allocation of A on the fly and knows its size thereon as
part of the language feature behind the scenes.
Show full article (1.41Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: Gib Bogle
Date: Aug 6, 2008 14:30

rusi_pathan wrote:
> On Aug 5, 9:45 pm, Gib Bogle auckland.no.spam.ac.nz> 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 ...
Show full article (3.03Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: dpb
Date: Aug 6, 2008 14:42

Gib Bogle wrote:
...
> I will see if I can the comparison with MKL. The reason I did this
> quick test is that I have a student who is solving a nonlinear system of
> PDEs using Matlab, and this problem requires extremely long execution
> times. I've always had the idea (prejudice?) that Matlab was slow
> compared with Fortran, and thought that in the last resort he could
> recode it in Fortran (with his level of programming skill, not a
> decision to take lightly). What this test tells me is that for this
> kind of matrix operation Matlab is much better than I'd realized. I do
> understand that it is inefficient on code with nested loops etc.
...
If you're looking to optimize an existing solution in Matlab, you'll get
lots of suggestions from comp.soft-sys.matlab regarding any...
Show full article (1.42Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: none
Date: Aug 6, 2008 15:04

On Wed, 06 Aug 2008 13:45:21 +1200, Gib Bogle 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...
Show full article (1.34Kb)
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: James Giles
Date: Aug 6, 2008 15:45

dpb wrote:
...
> But, as has been noted, once one gets to the core routines in ML it's
> likely they're about as good as it gets w/o really serious work unless
> have multi-processor and can take advantage of them.

I understand you intend ML to be an abbreviation for Matlab in
this context. But there is a language called ML. Probably better
not to confuse them.

--
J. Giles

"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."
-- C. A. R. Hoare

"Simplicity is prerequisite for reliability" -- E. W. Dijkstra
no comments
Re: Fortran vs. Matlab on linear algebra         


Author: nospam
Date: Aug 6, 2008 15:52

James Giles worldnet.att.net> wrote:
> dpb wrote:
> ...
>> But, as has been noted, once one gets to the core routines in ML it's
>> likely they're about as good as it gets w/o really serious work unless
>> have multi-processor and can take advantage of them.
>
> I understand you intend ML to be an abbreviation for Matlab in
> this context. But there is a language called ML. Probably better
> not to confuse them.

Is that Mock Lisp or something else? Hmm. A quick google answers my own
question. It appears to be something else. But that just reinforces your
point about the confusion, as Mock Lisp was one of the things that
occurred to me when I read your post.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
no comments
1 2 3