Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Speed Comparison

Subject: Speed Comparison

From: Sky

Date: 10 Apr, 2009 23:26:02

Message: 1 of 14

I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.

Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...

Is this possible? Is MATLAB this slow or am I doing something wrong?

Subject: Speed Comparison

From: James Tursa

Date: 11 Apr, 2009 00:15:03

Message: 2 of 14

"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
>
> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
>
> Is this possible? Is MATLAB this slow or am I doing something wrong?

Yes, it is certainly possible, as you have already demonstrated. Speed comparisons like this are highly dependent on how you did the port and what the MATLAB code is actually doing. There is a potentially a lot of overhead on the MATLAB side that does not exist in the Fortran. E.g., Are you building an array inside a loop without preallocating? Are you manipulating variables in a way that causes a lot of data copying that doesn't exist in the Fortran? Can your nested for-loops in the MATLAB code be vectorized? Etc. etc. Impossible to say if you did anything *wrong* without seeing the code.

James Tursa

Subject: Speed Comparison

From: Chaos

Date: 11 Apr, 2009 00:34:01

Message: 3 of 14

"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
>
> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
>
> Is this possible? Is MATLAB this slow or am I doing something wrong?

Learn how to use mex to compile your fortran code with Intel ifort and use Matlab as front-end to your code and make nice plots when done. You'll get most of your speed back.

Fortran is great! It is a THE numerical, balls to the wall, sledgehammer, especially if you implement OpenMP or MPI in your loops. Any F77/F95 code vs Matlab both at the same level of competency, Fortran will absolutely STOMP Matlab.

Matlab/C++ are 'Swiss Army' knives built for anything and everything. Fortran doesn't do many things well, you don't use it to make nice GUI's or plots but what it does well better than any other language is number crunch, high-precision, complex, 32/64 bit.

Where did you get that copy of Compaq Visual Fort? They stopped making that years ago.

Subject: Speed Comparison

From: James Tursa

Date: 11 Apr, 2009 02:04:01

Message: 4 of 14

"Chaos" <rothko.fan@gmail.com> wrote in message <groohp$l15$1@fred.mathworks.com>...
>
> Where did you get that copy of Compaq Visual Fort? They stopped making that years ago.

... and I wish I could find a copy for a reasonable price. I would like to be able to test my Fortran code on the Compaq or Digital compiler (I currently have Intel 10.0) so that when I post mex code to the FEX I can be reasonably assured that it will work for them. But I am not willing to pay hundreds of dollars just to get this capability.

James Tursa

Subject: Speed Comparison

From: Lada Kugis

Date: 11 Apr, 2009 03:29:16

Message: 5 of 14

On Sat, 11 Apr 2009 00:34:01 +0000 (UTC), "Chaos"
<rothko.fan@gmail.com> wrote:

>"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
>> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
>>
>> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
>>
>> Is this possible? Is MATLAB this slow or am I doing something wrong?
>
>Learn how to use mex to compile your fortran code with Intel ifort and use Matlab as front-end to your code and make nice plots when done. You'll get most of your speed back.
>
>Fortran is great! It is a THE numerical, balls to the wall, sledgehammer, especially if you implement OpenMP or MPI in your loops. Any F77/F95 code vs Matlab both at the same level of competency, Fortran will absolutely STOMP Matlab.
>
>Matlab/C++ are 'Swiss Army' knives built for anything and everything. Fortran doesn't do many things well, you don't use it to make nice GUI's or plots but what it does well better than any other language is number crunch, high-precision, complex, 32/64 bit.

Sorry if I'm jumping into a discussion like this, but
do you know where one can find examples of this (gui frontend for
fortran code) - maybe a book or two where such is explained for
someone who's never done much gui programming ?

best regards
Lada

>
>Where did you get that copy of Compaq Visual Fort? They stopped making that years ago.

Subject: Speed Comparison

From: Chaos

Date: 11 Apr, 2009 03:38:01

Message: 6 of 14

Lada Kugis <lada.kugis@gmail.com> wrote in message <q530u4tftttaenhbov4p9apjuv3am44bb2@4ax.com>...
> On Sat, 11 Apr 2009 00:34:01 +0000 (UTC), "Chaos"
> <rothko.fan@gmail.com> wrote:
>
> >"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> >> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
> >>
> >> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
> >>
> >> Is this possible? Is MATLAB this slow or am I doing something wrong?
> >
> >Learn how to use mex to compile your fortran code with Intel ifort and use Matlab as front-end to your code and make nice plots when done. You'll get most of your speed back.


> >
> >Fortran is great! It is a THE numerical, balls to the wall, sledgehammer, especially if you implement OpenMP or MPI in your loops. Any F77/F95 code vs Matlab both at the same level of competency, Fortran will absolutely STOMP Matlab.
> >
> >Matlab/C++ are 'Swiss Army' knives built for anything and everything. Fortran doesn't do many things well, you don't use it to make nice GUI's or plots but what it does well better than any other language is number crunch, high-precision, complex, 32/64 bit.
>
> Sorry if I'm jumping into a discussion like this, but
> do you know where one can find examples of this (gui frontend for
> fortran code) - maybe a book or two where such is explained for
> someone who's never done much gui programming ?
>
> best regards
> Lada

The GUI front-end would be a collection of Matlab widgets, plots, etc. whatever is needed. The main engine would be a mex call to the compiled fortran code. I don't use GUI's I'm hardcore command line person but look for here

grep the help docs for "Creating Graphical User Interfaces"

Subject: Speed Comparison

From: Chaos

Date: 11 Apr, 2009 03:49:01

Message: 7 of 14

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <grotqh$b3$1@fred.mathworks.com>...
> "Chaos" <rothko.fan@gmail.com> wrote in message <groohp$l15$1@fred.mathworks.com>...
> >
> > Where did you get that copy of Compaq Visual Fort? They stopped making that years ago.
>
> ... and I wish I could find a copy for a reasonable price. I would like to be able to test my Fortran code on the Compaq or Digital compiler (I currently have Intel 10.0) so that when I post mex code to the FEX I can be reasonably assured that it will work for them. But I am not willing to pay hundreds of dollars just to get this capability.
>
> James Tursa

Did you check Ebay?

After HP dropped 'Compaq' Fortran, i read most of the developers are now working at Intel, must be why the latest version 11.0 is posting some impressive numbers.

I remember that old MS version of Fortran, what a piece of junk.

Subject: Speed Comparison

From: Steve Amphlett

Date: 11 Apr, 2009 09:15:02

Message: 8 of 14

"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
>
> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
>
> Is this possible? Is MATLAB this slow or am I doing something wrong?

I can understand the speedup from MATAB to CVF, a factor of up to 20. But a factor of 1000 between CVF and for ifort? I don't remember anything that dramatic when we switched from CVF to ifort.

Subject: Speed Comparison

From: Chaos

Date: 11 Apr, 2009 10:57:01

Message: 9 of 14

"Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
>
> Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
>
> Is this possible? Is MATLAB this slow or am I doing something wrong?

CVF -> no OpenMP, no SSE2, no SSE3, no parallelzation, no Real(16), old version of IMSL

Subject: Speed Comparison

From: Sky

Date: 12 Apr, 2009 03:34:01

Message: 10 of 14

@Tursa: I took the necessary precautions i.e. pre-allocation, vectorization wherever possible etc.

@Chaos: I dusted off an old copy of CVF6 just to run this comparison. I am going to take your advice and stick to FORTRAN. I am turning the old code into a COM server. I think that will give me the most choice as far as interoperability is concerned.

Thanks to everyone for their comments.

Subject: Speed Comparison

From: Steve Amphlett

Date: 12 Apr, 2009 12:29:01

Message: 11 of 14

"Chaos" <rothko.fan@gmail.com> wrote in message <grpt1t$i1e$1@fred.mathworks.com>...
> "Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> > I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
> >
> > Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
> >
> > Is this possible? Is MATLAB this slow or am I doing something wrong?
>
> CVF -> no OpenMP, no SSE2, no SSE3, no parallelzation, no Real(16), old version of IMSL

True, but it still doesn't add up to a 1000 speed multiplier. OpenMP for a 2 CPU, maybe 1.7x, SSE2 and/or SSE3, maybe 2x more.

If I saw these ratios, I'd be woderring if we were comparing bebug with mega-complied code.

The outputs of some profiling tests would be interesting.

Subject: Speed Comparison

From: Steve Amphlett

Date: 12 Apr, 2009 12:34:01

Message: 12 of 14

"Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <grsmqd$6e3$1@fred.mathworks.com>...
> "Chaos" <rothko.fan@gmail.com> wrote in message <grpt1t$i1e$1@fred.mathworks.com>...
> > "Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> > > I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
> > >
> > > Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
> > >
> > > Is this possible? Is MATLAB this slow or am I doing something wrong?
> >
> > CVF -> no OpenMP, no SSE2, no SSE3, no parallelzation, no Real(16), old version of IMSL
>
> True, but it still doesn't add up to a 1000 speed multiplier. OpenMP for a 2 CPU, maybe 1.7x, SSE2 and/or SSE3, maybe 2x more.
>
> If I saw these ratios, I'd be woderring if we were comparing bebug with mega-complied code.
>
> The outputs of some profiling tests would be interesting.

... My work PC might still have DVF/CVF on it (I still have the media) as well an ifort (v10 I think, possibly v11). I may run some speed tests using some trivial FORTRAN code with FP loops. If there really is a 1000 speedup I'd like to know how to get it.

Subject: Speed Comparison

From: Chaos

Date: 12 Apr, 2009 13:12:01

Message: 13 of 14

"Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <grsn3p$n9l$1@fred.mathworks.com>...
> "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <grsmqd$6e3$1@fred.mathworks.com>...
> > "Chaos" <rothko.fan@gmail.com> wrote in message <grpt1t$i1e$1@fred.mathworks.com>...
> > > "Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> > > > I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
> > > >
> > > > Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
> > > >
> > > > Is this possible? Is MATLAB this slow or am I doing something wrong?
> > >
> > > CVF -> no OpenMP, no SSE2, no SSE3, no parallelzation, no Real(16), old version of IMSL
> >
> > True, but it still doesn't add up to a 1000 speed multiplier. OpenMP for a 2 CPU, maybe 1.7x, SSE2 and/or SSE3, maybe 2x more.
> >
> > If I saw these ratios, I'd be woderring if we were comparing bebug with mega-complied code.
> >
> > The outputs of some profiling tests would be interesting.
>
> ... My work PC might still have DVF/CVF on it (I still have the media) as well an ifort (v10 I think, possibly v11). I may run some speed tests using some trivial FORTRAN code with FP loops. If there really is a 1000 speedup I'd like to know how to get it.

if his routine using quad cpu, he'll get at almost 3.8X speed, if he's liked to MKL FFTW or ACML lib at least another 2 to 4X per cpu

Subject: Speed Comparison

From: Steve Amphlett

Date: 12 Apr, 2009 17:38:00

Message: 14 of 14

"Chaos" <rothko.fan@gmail.com> wrote in message <grspb1$ds8$1@fred.mathworks.com>...
> "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <grsn3p$n9l$1@fred.mathworks.com>...
> > "Steve Amphlett" <Firstname.Lastname@Where-I-Work.com> wrote in message <grsmqd$6e3$1@fred.mathworks.com>...
> > > "Chaos" <rothko.fan@gmail.com> wrote in message <grpt1t$i1e$1@fred.mathworks.com>...
> > > > "Sky " <theskyishigh@yahoo.com> wrote in message <grokia$rcq$1@fred.mathworks.com>...
> > > > > I have ported a code from FORTRAN95 to MATLAB. Replicated it almost exactly. About 500 lines in length, it contains a lot of double precision arithmetic and nested iterations. Very little linear algebra.
> > > > >
> > > > > Under MATLAB R2008b it executes in 7.3 seconds. Compiled under Compaq Visual Fortran 6 it takes 375 milliseconds. Under the Intel Fortran 11 compiler, it takes 473 MICROseconds. These times are for a WinXP system, Core 2 Duo 2 GHz (4MB L2 Cache), 2GB RAM...
> > > > >
> > > > > Is this possible? Is MATLAB this slow or am I doing something wrong?
> > > >
> > > > CVF -> no OpenMP, no SSE2, no SSE3, no parallelzation, no Real(16), old version of IMSL
> > >
> > > True, but it still doesn't add up to a 1000 speed multiplier. OpenMP for a 2 CPU, maybe 1.7x, SSE2 and/or SSE3, maybe 2x more.
> > >
> > > If I saw these ratios, I'd be woderring if we were comparing bebug with mega-complied code.
> > >
> > > The outputs of some profiling tests would be interesting.
> >
> > ... My work PC might still have DVF/CVF on it (I still have the media) as well an ifort (v10 I think, possibly v11). I may run some speed tests using some trivial FORTRAN code with FP loops. If there really is a 1000 speedup I'd like to know how to get it.
>
> if his routine using quad cpu, he'll get at almost 3.8X speed, if he's liked to MKL FFTW or ACML lib at least another 2 to 4X per cpu

With all respect, do the multiplications. OP has 2 cores, 4x speedup per core is still only 8x (assuming OMP). Add in another (unlikely) 2x for compiler tech and (optimistically) 2x for chip instruction set optimization and you're still only at 32x. Need to find a reason for the additional 30x.

A big problem that takes many tens of seconds needs to be benchmarked.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us