Re: Is C faster than fortran?




"glen herrmannsfeldt" <gah@xxxxxxxxxxxxxxxx> wrote in message
news:gPWdnZ0Jt4DDIZTbnZ2dnUVZ_hKdnZ2d@xxxxxxxxxxxxxx
user923005 wrote:
[follow-up set to c.l.f.]

Seriously. Fortran compilers can optimize more aggressively than
C because the language semantics are different. C99 plugs this
gap (mostly) with the "restrict" qualifier, but I don't know how
that plays out in practice and I would love to see data.

We need a Fortran Guru to show me what I am doing wrong, because there
is no feasible explanation for this other than I do not know how to
get performance out of my Fortran compiler.

That is what they say, and maybe on the average it is true.

There are too many variables to make it true in general.
First, the programs should be as similar as possible, and also
the data. In the (snipped) programs, the C version uses arrays of
pointers to arrays of pointers to arrays of pointers, which is not
likely true for Fortran, and might make a difference either way.

The programs are doing matrix inversion of random numbers, which
are generated using system dependent generators. There may be some
data dependence to the timing of matrix inversion, especially
if the hardware timing is different for different data.

Optimization is probably more sensitive to the number of registers
available than to the ability to rearrange expressions.
Do both Fortran and C programs have the array subscripts in the
optimal order? Most compilers won't change that.
This OP is well-known for his numerical skills in C. I can't speak to
optimizing execution speed. If OP would like to see a couple examples from
MR&C on array features, I'll be happy to donate some keystrokes.
--
LS


.



Relevant Pages

  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (comp.lang.java)
  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (comp.lang.cpp)
  • Re: Cracking DES with C++ is faster than Java?
    ... > C doesn't have multidimensional arrays, ... you must use pointers to pointers instead, ... properties from Fortran (efficient code, separate compilation, ... However C didn't borrow object orientation ...
    (sci.crypt)
  • Re: INTERFACE problem
    ... I have an integer at Fortran side, pass it by reference to C function, treat here as pointer, allocate memory and this C-pointer at Fortran side now is an integer which has represents address allocated at C side. ... I did something like this many years ago to allow dynamic allocation ... Then it was converted into a subroutine with the arrays and ... it called the sub by way of Pascal with those "pointers". ...
    (comp.lang.fortran)
  • Re: INTERFACE problem
    ... I have an integer at Fortran side, ... >it by reference to C function, treat here as pointer, allocate memory ... C pointers and arrays ... WHen the Main got the now initialized "pointers" ...
    (comp.lang.fortran)