Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Fortran --> Python (was linux engineer)



Nicolas Limare writes:

 > I also suppose that FORTRAN array operations like WHERE()
 > translated very well into vector processor systems such as the NEC
 > SX machines.

I would think so; it was designed to encourage such usage.

 > I also heard that on NEC machines, the (NEC) compiler could
 > recognize a matrix multiplication and replace all the code by a
 > single processor instruction. Of cource, the execution of this
 > instruction would take some time, but the hardcoded routine is
 > finely optimized for the architecture, cache, pipeline, etc.

Not to mention written in microcode so much faster than stored
program.

I think that one of the big things about FORTRAN vs. C, though, is
that *inside* a module[1], most FORTRAN subroutines are glorified
GOTOs, and so extremely fast.  Work is done on COMMON blocks, which
amount to implicit references to global variables, so no messing with
the stack or loading registers to pass parameters as in C.  No copying
to local variables on the stack.  Arrays are easy to reconfigure with
different dimensionality, so element-wise operations are done with a
single DO loop rather than nested for loops, saving a lot of
test-and-loop logic, as well as multiple initializations of inner loop
indicies.

All of these things are horrible style in C, of course.  They're
possible, but not taught.  I suspect that FORTRAN code and data areas
tend to be smaller than in C, with less copying (C copies structs
unless passed by pointer or reference) as well, so that there will be
better locality (especially if the C program uses malloc, which
FORTRAN programs are less likely to do).

ISTR that C also has the problem that standard C doesn't (didn't?)
have ways for the programmer to access processor flags and exceptions,
so you either had to go to assembler for speed or do look-before-you-
leap checking in C to have code robust to edge conditions.

Bottom line: FORTRAN is designed to encourage efficient numerical
coding techniques, and C is not.

Footnotes: 
[1]  Of course library APIs have parameters.  I doubt that code that
passes variables between modules is going to have any advantage in
FORTRAN over C.



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links