Is C faster than fortran?

A

Arjen Markus

In comp.lang.fortran Arjen Markus said:
I used the above program with two different compilers on one Linux
machine and got the following results:
[ifort] total = 24.2 sec
[g95] total =124.9 sec

This comparison does not make sense: Ifort uses by default -O2
optimization and GCC (gfortran, g95, g77) uses -O0.
[ifort -O2 -ipo -static] total = 34.4 sec
(Slower, surprisingly, a second run showed 24.9 total)
[g95 -O3] total = 92.7 sec

For comparison (without thinking too much about the options; on x86-64
Linux):

gfortran [4.3] -march=opteron -ffast-math -funroll-loops -ftree-
vectorize -msse3 -O3 TEST_FPU.f90
total = 19.2 sec

ifort [9.1] -O3 -xW -ipo -static TEST_FPU.f90
total = 17.7 sec

sunf95 [8.3] -w4 -fast -xarch=amd64a -xipo=0 TEST_FPU.f90
total = 15.5 sec

NAG f95 [5.1/gcc 4.1.2] -O4 -ieee=full -Bstatic -march=opteron -ffast-
math -funroll-loops -ftree-vectorize -msse3 TEST_FPU.f90
total = 20.2 sec

g95 [0.91-Feb23/gcc 4.0.3] -march=opteron -ffast-math -funroll-loops -
ftree-vectorize -msse3 -O3 TEST_FPU.f90
total = 31.7 sec

Tobias


Oh, I was not aware of the default settings - that explains why there
was little
effect of the optimisation. I should try again on my Linux machine and
see
what happens with the above.

Regards,

Arjen
 
P

Pierre Asselin

I suspect the difference in array addressing and its influence on
the memory cache might explain most of the differences.

Maybe, but I transposed the arrays between Fortran and C,
so the access patterns ought to be similar. It was not
a big difference, mind you.
 
M

Michael Delaney

CBFalconer said:
During WWII we derided the practice of carrying papers in
dictatorial realms.

We also respected habeas corpus, the Geneva Convention, Congress' right
to declare war, court authorization to spy on citizens, democratically
elected officials. Today all gone...bushit is right down there with adolph.
 
K

Keith Thompson

Michael Delaney said:
We also respected habeas corpus, the Geneva Convention, Congress'
right to declare war, court authorization to spy on citizens,
democratically elected officials. Today all gone...bushit is right
down there with adolph.

This newsgroup discusses the C programming language, not US politics.
There are plenty of newsgroups where your post would be topical. This
clearly is not one of them. Are you a deliberate troll?

(I express no opinion on the content of your article, other than the
fact that it's off-topic.)

Followups set appropriately.
 
P

Peter Nilsson

Richard Heathfield wrote: <snip OT>
Nelu wrote: <snip OT>
CBFalconer wrote: <snip OT>
Al Balmer wrote: <snip OT>
CBFalconer wrote: <snip provocative OT>
Michael Delaney wrote: <snip provocative OT>
Keith Thompson wrote: ...Are you a deliberate troll?

Some people might call that entrapment, Keith! ;)
 
F

Fernando M. Roxo da Motta

I used the above program with two different compilers on one Linux
machine and got the following results:

% ifort -o test_fpu test_fpu.f90
% test_fpu
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 3.1 sec Err= 0.000000000000002
Test2 - Crout 2000 (101x101) inverts 4.9 sec Err= 0.000000000000003
Test3 - Crout 2 (1001x1001) inverts 9.6 sec Err= 0.000000000000073
Test4 - Lapack 2 (1001x1001) inverts 6.6 sec Err= 0.000000000000537
total = 24.2 sec

and:
% g95 -o test_fpu test_fpu.f90
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 56.5 sec Err= 0.000000000000002
Test2 - Crout 2000 (101x101) inverts 21.1 sec Err= 0.000000000000001
Test3 - Crout 2 (1001x1001) inverts 13.1 sec Err= 0.000000000000001
Test4 - Lapack 2 (1001x1001) inverts 34.2 sec Err= 0.000000000000329
total =124.9 sec

That is a factor of 6 in the total time!

Usually Intel Fortran uses a quite complete set of optimization options
by default. Gnu Fortran (gfortran or g95) dos not apply any special
optimization.

I don't have Intel Fortran installed, but the differences between
gfortran with and without optimzations goes as :

$ gfortran gfortran TEST_FPU.f90 -o TEST_FPU
$ ./TEST_FPU
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 18.4 sec Err= 0.000000000000006
Test2 - Crout 2000 (101x101) inverts 18.6 sec Err= 0.000000000000023
Test3 - Crout 2 (1001x1001) inverts 16.0 sec Err= 0.000000000000031
Test4 - Lapack 2 (1001x1001) inverts 23.9 sec Err= 0.000000000000250
total = 77.0 sec

$ gfortran -O2 -msse3 TEST_FPU.f90 -o TEST_FPU
$ ./TEST_FPU
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 3.9 sec Err= 0.000000000000006
Test2 - Crout 2000 (101x101) inverts 4.4 sec Err= 0.000000000000023
Test3 - Crout 2 (1001x1001) inverts 3.9 sec Err= 0.000000000000031
Test4 - Lapack 2 (1001x1001) inverts 3.9 sec Err= 0.000000000000250
total = 16.1 sec

It's about a factor of 5 from nooptimization to some optimization. I'm
pretty sure that this result can be improved.

By the way, it was run on a Core(TM)2 CPU T7200 @ 2.00GHz Laptop.


Roxo
 
T

Tim Prince

Fernando said:
Usually Intel Fortran uses a quite complete set of optimization options
by default. Gnu Fortran (gfortran or g95) dos not apply any special
optimization.

I don't have Intel Fortran installed, but the differences between
gfortran with and without optimzations goes as :

$ gfortran gfortran TEST_FPU.f90 -o TEST_FPU
$ ./TEST_FPU
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 18.4 sec Err= 0.000000000000006
Test2 - Crout 2000 (101x101) inverts 18.6 sec Err= 0.000000000000023
Test3 - Crout 2 (1001x1001) inverts 16.0 sec Err= 0.000000000000031
Test4 - Lapack 2 (1001x1001) inverts 23.9 sec Err= 0.000000000000250
total = 77.0 sec

$ gfortran -O2 -msse3 TEST_FPU.f90 -o TEST_FPU
$ ./TEST_FPU
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 3.9 sec Err= 0.000000000000006
Test2 - Crout 2000 (101x101) inverts 4.4 sec Err= 0.000000000000023
Test3 - Crout 2 (1001x1001) inverts 3.9 sec Err= 0.000000000000031
Test4 - Lapack 2 (1001x1001) inverts 3.9 sec Err= 0.000000000000250
total = 16.1 sec

It's about a factor of 5 from nooptimization to some optimization. I'm
pretty sure that this result can be improved.

By the way, it was run on a Core(TM)2 CPU T7200 @ 2.00GHz Laptop.

Yes, I wonder why people don't use the usual vectorizing options at
least for a starting point:
ifort -xW
gfortran -O2 -ftree-vectorize -funroll-loops -msse2

gfortran -msse2 is redundant on 64-bit platforms.

ifort defaults are totally different between 32- and 64-bit targets.
I wonder also why people don't give more details about their platform,
including whether they are running 32- or 64-bit compilation.
 
F

Fernando M. Roxo da Motta

Yes, I wonder why people don't use the usual vectorizing options at
least for a starting point:

I agree completely, for some time almost all processors has some
vectorization support, so it should be the very first thing to look at.
ifort -xW
gfortran -O2 -ftree-vectorize -funroll-loops -msse2

Unroll can have an important impact too. Simply adding the unroll
option the timing above becomes :

$ gfortran -O2 -funroll-loops -msse2 TEST_FPU.f90 -o TEST_FPU
$ ./TEST_FPU
Benchmark running, hopefully as only ACTIVE task
Test1 - Gauss 2000 (101x101) inverts 3.1 sec Err= 0.000000000000006
Test2 - Crout 2000 (101x101) inverts 3.7 sec Err= 0.000000000000023
Test3 - Crout 2 (1001x1001) inverts 3.5 sec Err= 0.000000000000031
Test4 - Lapack 2 (1001x1001) inverts 3.1 sec Err= 0.000000000000250
total = 13.5 sec
gfortran -msse2 is redundant on 64-bit platforms.

Why ? I was not aware of it. At least in newer Intel processors you
have the option of SSE3 vector processor.
ifort defaults are totally different between 32- and 64-bit targets.
I wonder also why people don't give more details about their platform,
including whether they are running 32- or 64-bit compilation.

For sure, any information about platform can be useful do figure out
what is going on.



Roxo
 
B

Bruce Bowler

On Sun, 08 Apr 2007 18:42:23 +0200, Fernando M. Roxo da Motta wrote:

In advance, let me say "I can't help myself, mea culpa, I'm sorry". It's
been one of those days, I need to inject some humor somewhere. I'm also
a HUGE fan of Fortran - I use it every day - I don't particularly care
for C. What I'm about to say has probably been said in this thread
already and I just missed it. Having said that...

Of course C is faster faster the Fortran.
Fortran is from the dark ages (of computing) and
C is the speed of light.

Thanks, I feel better now. We now return you to your regularly scheduled
discussion.
 
J

James Giles

Bruce said:
On Sun, 08 Apr 2007 18:42:23 +0200, Fernando M. Roxo da Motta wrote: ....
Of course C is faster faster the Fortran.
Fortran is from the dark ages (of computing) and
C is the speed of light.

Well, C is a case sensitive language (whose name is
upper-case). While the speed of light is c (lower case).
Physically, C (upper case) is a coulomb: a moderate
amount of electrical current. How that corresponds to
speed at all is questionable.

--
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
 
D

David Thompson

Learning additional computer languages is often good. Note (as
someone else did) that there are lots of different versions of
Fortran, though. The current standard is F95.
It's now 'F03' which was actually approved in 04, although as one
would expect there is variation in how fast different implementations
are being upgraded, if at all. (If you care about specific F03
features as opposed to F95, or F95 + TRs, 'goto' comp.lang.fortran .)

But the BIG difference was F77 to F90; in terms of new syntax and
features this was at least as big as the difference from C to C++. The
changes from F90 to F95 were barely more than a TC, and from F95 to
F03 less than C90 to C99, perhaps a little more than C90 to NA1.
As for the question in the "subject" line, "is C faster than
fortran?": the answer is the same as the answer to the question,
"is chocolate ice cream tastier than strawberry?".

And of course that answer is, test, test, and test some more. <G!>

<OT>Aside to downthread: although -- in my opinion as a US native who
does not find 'USAnian' inherently insulting, although like almost any
descriptive it can be used so, viz 'French leave', 'Dutch treat',
'Gypsy $various' etc. -- Bush#2 has done plenty of stupid and wrong
things, the new requirement for passports on (re)entry to US from the
rest of the Americas, called the Western Hemisphere Travel Initiative,
is actually Congress' fault, which the administration (executive)
actually delayed and weakened some.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top