From: Craig Burley <burley@tweedledumb.cygnus.com>
Subject: Re: Final kick at the "Merced Guessing Game"
Date: 1997/10/13 [thread overview]
Message-ID: <y6bu0tv9h6.fsf@tweedledumb.cygnus.com> (raw)
In-Reply-To: 61tfaa$9fr@sis.cambridge.arm.com
michael.williams@arm-sponge.com (Michael Williams) writes:
> In article <3440F805.C98BB347@tonys.ecology.umn.edu>,
> boo <boo@tonys.ecology.umn.edu> wrote:
> >I did not say there was ONE efficient way. If you are just looking
> >for ONE efficient way, then perhaps you should stick with Fortran.
> >As I said before, Fortran is for the lazy, the feeble-minded,
> >the incompetent, and for those who aren't doing anything beyond
> >simple-minded number crunching.
>
> I've tried to read both sides of the argument in this thread so
> far. As far as I can tell, the argument is that, whereas it is
> possible to do multi-dimensional arrays in C, it's not possible to
> deal with them efficiently, if you write the 'natural' code.
It's *possible* for a compiler to deal with them efficiently. It's
rare for a compiler to *actually* do so in practice. Programmers
with sufficient time and/or interest can always "lower" their code
in C -- or Fortran, a fact which nobody seems to have bothered with,
since Fortran already lets you just type it in the "natural" way and
let the compiler do the work for you.
For example, a Fortran compiler in beta test that is nevertheless
widely used, GNU Fortran (g77), in some cases generates substantially
better code if you replace array declarations and references like
"REAL A(M,N)...A(I,J)" with "lowered" ones like "REAL A(0:M*N)...
A((J-1)*M+(I-1))" (or whatever the equivalence would be).
The reason is that the back end it uses is C-oriented, and it has
been pretty well optimized to produce good code for "lowered" C code
to do some of these things, whereas g77, given the higher-level Fortran
constructs (which cannot be expressed in C, ANSI C, or C++), implements
them via back-end mechanisms that are not as well optimized. (Although
this is being worked on....)
However, some g77 users have discovered that turning on an old
macro definition in the g77 sources causes it to convert the
higher-level Fortran constructs directly into the lower-level C-like
form when it comes to calling on the back end -- and this *also* results
in generating (the same, or similar) faster code.
In other words, while using C *requires* you to "lower" your code
to get anything like decent efficiency *and* use a pretty sophisticated
optimizing compiler to "discern" what you're really trying to do, using
Fortran *allows* you to leave your code in its "original", higher form.
Then, if your Fortran compiler produces great code from it, wonderful;
if not, you can then lower your Fortran code just like you can with C
(though a C preprocessor is not standard with Fortran, you can use
statement functions where you'd use C macros for this) *or* you can
just modify your compiler -- the latter being far easier to do when
it's a Fortran compiler than a C compiler, as illustrated by the g77
example.
Since g77 is in beta test and has only recently had performance issues
come under some scrutiny in terms of actual improvements to the
compiler, I suspect few production Fortran compilers *require* lowering
of Fortran code to get substantially better performance, except perhaps
in rare cases.
Of course, once you "lower" your code -- either by changing your Fortran
code, or by writing your application in C -- you've lost some *other*
features, like ease of debugging, and catching out-of-bounds references
(especially the kind that are out of the bounds of their dimension,
where the complete array-offset calculation is *not* out of bounds --
which is nevertheless a programming error).
A similar example of C *requiring* lowering because it doesn't provide
linguistic features other languages (like Fortran) have is illustrated
by the following Fortran snippet:
IMPLICIT LOGICAL(A-Z)
BOOL = F() .AND. (G() .OR. H())
C has no way to express the above. It *requires* you to lower it, to,
for example,
bool = f() & (g() | h())
or:
bool = f() && (g() || h())
C programmers typically claim this "low-level" nature of their language
*allows* them to write "faster" code for a particular machine, but,
in practice, that isn't true in cases like the above, because even
Fortran allows such a thing. The Fortran versions of the above "lowered"
code are
BOOL1 = F()
BOOL2 = G()
BOOL3 = H()
BOOL = BOOL1 .AND. (BOOL2 .OR. BOOL3)
and
IF (F()) THEN
IF (G()) THEN
BOOL = .TRUE.
ELSE IF (H()) THEN
BOOL = .TRUE.
ELSE
BOOL = .FALSE.
END IF
ELSE
BOOL = .FALSE.
END IF
(respectively).
In both cases clunkier, but in both cases *semantically equivalent*
when it comes to code generation. That is, aside from other,
unrelated semantic differences between C and Fortran, the compilers
have pretty much the exact same degrees of freedom when it
comes to generating fast code. E.g. in the first lowered versions,
each compiler *must* ensure that all three functions are called
(and thus their side effects performed), whereas in the second
lowered versions, each compiler must ensure that the functions
are called in order and only depending on the results from the
previous calls, again, due to side effects.
However, the *original* Fortran code is (assuming it's correct)
most faithful in expressing the original problem. As soon as you
write it in C, you've lost information regarding how flexibly the
implementation can be in calculating the answer, but while it's
in Fortran, the implementation can even do things like run-time
determination of which of F(), G(), and H() will take longest to
run and call them in any order, or call them in parallel, or call
only one or two of them, or whatever -- stuff a C compiler can do
*only* if it does far more global analysis than the Fortran compiler
typically needs to do. (Although, just as C programmers often overstep
what the standard lets them do, meaning compilers must sometimes avoid
doing otherwise-okay optimizations, the same is true for Fortran.
E.g. a C compiler could, but users might otherwise complain if it
does, optimize "*p1 ^= *p2 ^= *p3 ^= *p4;" in a way that "breaks"
if p1==p3 and/or p2==p4. But, similarly, Fortran users might complain
if "BOOL = F() .AND. G()" doesn't actually perform the side effects
of F() when G() evaluates to .FALSE.. In both cases, the users are
requiring the compiler to implement a more strict form of their
respective language, something real-world compiler writers must
take into account.)
In summary, C often *requires* you to write *lowered* code instead
of expressing what you mean directly, whereas languages like Fortran
merely *allow* this.
In fact, I was talking with someone at Dakota Scientific Systems (sp?)
a few months ago. They take (normally Fortran) code doing real
number-crunching and optimize the heck out of it for a particular
platform/chipset/whatever. E.g. stuff like BLAS, IIRC.
Anyway, what *really* surprised me was that the guy explained that
they do *not* simply take the compiler's output and optimize the
assembly -- instead, they optimize the *original Fortran*, leaving
the optimized code in Fortran! That is, they move assignment
statements around, and, I'd guess, "lower" the code when necessary
(probably rare), to get the *compiler* to produce the native code.
And, apparently, they get at or near industry-best results this way.
Proof, or persuasive evidence, that pretty much any lowering C requires
you to do, Fortran *allows* you to do, especially in the realm of
numerical computing.
There's little doubt in my mind that C offers great notational
convenience, though. I'm much happier, for now, writing compilers in
C than Fortran or, say, PL/I, *because* it has `&&' and `||', among
other things. Yes, sometimes I'd like to use the (missing)
higher-level constructs and let the compiler decide, but in the
kind of code I write (non-numerical), it doesn't usually matter --
the performance relates more to algorithm selection and overall
design than to low-level implementation issues.
But, in my experience, the numerical types who use Fortran *already*
have their algorithm issues worked out, because they're engineers,
not programmers, and because they *have* to. E.g. it doesn't bother
me much if my compiler is twice as slow as it could otherwise be
on my home PC, at least, not compared to how much these numerical
types are bothered when their latest number-cruncher is 2% slower than
it could otherwise be, when that 2% costs them $10,000 per week due
to it being run on a supercomputer on which they're buying time.
C programmers just don't usually have as much vested interest in
squeezing out that last 2% or so -- after all, their users can just
wait for the next Pentium to come out anyway, while Fortran programmers
include a pretty substantial group that depends on today's fastest
and most expensive computers, and a newer, faster computer only
means they can stuff more data into, or make more accurate
calculations in, their programs, instead of using the next generation
to cover up their programming inefficiencies.
(My take on the difference between an engineer and a programmer:
an engineer takes real-world complexities into account when designing
his system, and thus tends to produce a simple, robust system; a
programmer ignores real-world complexities so he can design an
unnecessarily complicated system. For example, if Microsoft designed
the Golden Gate Bridge, it'd allow traffic in only one direction at
any given time; if two cars got on at the same time in opposite
directions, it'd fall into the sea ("user error"); you'd have to drive
a Microsoft-approved car to go 10mph, otherwise you'd have to go below
5mph; you'd have to use that bridge to drive from LA to San Diego in
your Microsoft-approved car; you'd be unable to drive over any
*non*-Microsoft bridge in your Microsoft-approved car; and they'd
expect to be funded to "upgrade" the bridge two years later, which
would mean they'd take the money, tear down the old bridge, and build
a new bridge, requiring slower speeds, somewhere else. :)
> The other part of the argument probably centers around the way the
> various Fortran advocates[1] seem to know what they're talking about,
> whilst being insulted and derided by their opponents. I don't know
> about the intel and dec groups, but it's a bit out of place on
> comp.arch.
Well, if the Dallas Cowboys played a "real" game against some high
school's team, I wouldn't consider the high-school team to be their
"opponents", no matter how good that team was at trash-talking.
Even if the score ended up in favor of the high-school team, nobody
in their right mind would assume that meant they were "better" than
the Cowboys or (most) any other NFL team.
In other words: there's been no real "contest" here. Childish insults
from the (umn).edu side of things, yes, but no contest.
--
"Practice random senselessness and act kind of beautiful."
James Craig Burley, Software Craftsperson burley@gnu.ai.mit.edu
next prev parent reply other threads:[~1997-10-13 4:00 UTC|newest]
Thread overview: 207+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-10-08 4:00 Final kick at the "Merced Guessing Game" Robert Harley
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` David Chase
1997-10-08 4:00 ` brianh
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` Eric Hildum
1997-10-09 4:00 ` brianh
1997-10-11 4:00 ` Jan Vorbrueggen
1997-10-12 4:00 ` boo
1997-10-13 4:00 ` Michael Williams
1997-10-13 4:00 ` Craig Burley [this message]
1997-10-13 4:00 ` Paul Rubin
1997-10-13 4:00 ` William Clodius
1997-10-13 4:00 ` Craig Burley
1997-10-14 4:00 ` Richard A. O'Keefe
1997-10-14 4:00 ` Shankar Unni
1997-10-15 4:00 ` Achim Gratz
1997-10-15 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` Paul D. DeRocco
1997-10-15 4:00 ` Joe Buck
1997-10-15 4:00 ` William Clodius
1997-10-16 4:00 ` Richard A. O'Keefe
1997-10-16 4:00 ` Craig Burley
1997-10-17 4:00 ` Shankar Unni
1997-10-14 4:00 ` Michael Williams
1997-10-14 4:00 ` Richard Black
1997-10-15 4:00 ` Michael Williams
1997-10-15 4:00 ` Dr. Richard Black
1997-10-16 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` Craig Burley
1997-10-18 4:00 ` Bruce Hoult
1997-10-15 4:00 ` Paul Hsieh
1997-10-13 4:00 ` boo
1997-10-15 4:00 ` Craig Burley
1997-10-16 4:00 ` Flexible Choice of Language (Nothing to do with: Final kick at the "Merced Guessing Game") Ian Dall
1997-10-16 4:00 ` Craig Burley
1997-10-17 4:00 ` Richard A. O'Keefe
1997-10-17 4:00 ` Keith Adams
1997-10-17 4:00 ` [Reposted due to Enlow UCE cancel]: " John Bayko
1997-10-20 4:00 ` Paul D. DeRocco
1997-10-17 4:00 ` John Bayko
1997-10-18 4:00 ` Kelly Hall
1997-10-20 4:00 ` [Reposted due to Enlow UCE cancel]: " Eric Hildum
[not found] ` <623ek6$ef5$1@news.iastate.edu>
1997-10-16 4:00 ` Final kick at the "Merced Guessing Game" Craig Burley
1997-10-16 4:00 ` SimGraphics
1997-10-17 4:00 ` Craig Burley
1997-10-17 4:00 ` David Chase
1997-10-18 4:00 ` Victor Yodaiken
1997-10-20 4:00 ` Eric Hildum
1997-10-17 4:00 ` William Clodius
1997-10-19 4:00 ` Craig Burley
1997-10-18 4:00 ` Peter L. Montgomery
1997-10-19 4:00 ` Craig Burley
[not found] ` <3456700e.14141203@news.demon.co.uk>
1997-10-28 5:00 ` Dirk van der Knijff
1997-10-20 4:00 ` Richard A. O'Keefe
1997-10-20 4:00 ` Peter L. Montgomery
1997-10-13 4:00 ` Carl Perkins
1997-10-09 4:00 ` Gregg E Economou
1997-10-10 4:00 ` Jan Vorbrueggen
[not found] ` <61ho3v$3m0$1@goanna.cs.rmit.edu.au>
1997-10-09 4:00 ` boo
1997-10-09 4:00 ` William Clodius
1997-10-10 4:00 ` Richard A. O'Keefe
1997-10-10 4:00 ` Tyson Richard DOWD
1997-10-12 4:00 ` boo
1997-10-13 4:00 ` Patricia Shanahan
1997-10-15 4:00 ` boo
1997-10-15 4:00 ` Patricia Shanahan
1997-10-13 4:00 ` Steve Tate
1997-10-13 4:00 ` boo
1997-10-13 4:00 ` Victor Yodaiken
1997-10-14 4:00 ` Jason.Ozolins
1997-10-15 4:00 ` boo
1997-10-14 4:00 ` Aaron Spink
1997-10-15 4:00 ` David Chase
1997-10-13 4:00 ` Bernd Paysan
1997-10-13 4:00 ` boo
1997-10-13 4:00 ` Aaron Spink
1997-10-14 4:00 ` boo
1997-10-18 4:00 ` tgg
1997-10-18 4:00 ` [Reposted due to Enlow UCE cancel]: " tgg
1997-10-10 4:00 ` boo
1997-10-11 4:00 ` Patricia Shanahan
1997-10-13 4:00 ` Gregg E Economou
1997-10-13 4:00 ` Patricia Shanahan
1997-10-14 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` boo
1997-10-16 4:00 ` Timothy A. Seufert
1997-10-16 4:00 ` boo
1997-10-16 4:00 ` Toon Moene
1997-10-17 4:00 ` Richard A. O'Keefe
1997-10-20 4:00 ` [Reposted due to Enlow UCE cancel]: " tgg
1997-10-20 4:00 ` Jason.Ozolins
1997-10-11 4:00 ` Toon Moene
1997-10-11 4:00 ` Paul DeMone
[not found] ` <EHrwv9.2w3@world.std.com>
1997-10-10 4:00 ` David Gould
1997-10-16 4:00 ` Patricia Shanahan
1997-10-10 4:00 ` David Gould
1997-10-10 4:00 ` Maynard Handley
1997-10-11 4:00 ` new languages Preston Briggs
-- strict thread matches above, loose matches on Subject: below --
1997-10-09 4:00 Final kick at the "Merced Guessing Game" Robert Harley
1997-10-08 4:00 Robert Harley
[not found] ` <343C0387.41C6@lanl.gov>
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` David Chase
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` William Clodius
1997-10-09 4:00 ` Patrick Chase
1997-10-10 4:00 ` boo
1997-10-09 4:00 ` David Chase
1997-10-08 4:00 Robert Harley
1997-10-08 4:00 ` Michael Meissner
1997-10-09 4:00 ` Richard A. O'Keefe
1997-10-07 4:00 Robert Harley
1997-10-07 4:00 ` Martin Rodgers
1997-10-07 4:00 ` Nick Maclaren
1997-10-07 4:00 ` Shankar Unni
1997-10-08 4:00 ` boo
1997-10-09 4:00 ` Patrick F. McGehearty
1997-10-10 4:00 ` Richard A. O'Keefe
1997-10-15 4:00 ` David Chase
1997-10-16 4:00 ` William Clodius
1997-10-03 4:00 Robert Harley
1997-10-06 4:00 ` Richard A. O'Keefe
1997-10-06 4:00 ` boo
1997-10-07 4:00 ` Serge Pachkovsky
1997-10-07 4:00 ` Martin Rodgers
1997-10-07 4:00 ` Greg Weeks
1997-10-07 4:00 ` Martin Rodgers
[not found] ` <343AAE5A.A3FCC9D@no.informatik.spam.tu-muenchen.thanks.de>
1997-10-09 4:00 ` Torben AEgidius Mogensen
[not found] ` <EHsr7B.Dt8@bit3.com>
1997-10-10 4:00 ` Torben AEgidius Mogensen
[not found] ` <61cv5e$qn$6@vixen.cso.uiuc.edu>
1997-10-08 4:00 ` William Clodius
1997-10-07 4:00 ` Carlie Coats
1997-10-07 4:00 ` Paul Hsieh
1997-10-07 4:00 ` boo
1997-10-08 4:00 ` Carlie Coats
1997-10-07 4:00 ` Richard A. O'Keefe
1997-10-06 4:00 ` Graham Hughes
1997-10-07 4:00 ` boo
1997-10-07 4:00 ` William Clodius
1997-10-07 4:00 ` William Clodius
1997-10-08 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` William Clodius
[not found] ` <y4wwjon203.fsf@mailhost.neuroinformatik.ruhr-uni-bochum.de>
1997-10-08 4:00 ` William Clodius
1997-10-08 4:00 ` Stanley Chow
1997-10-09 4:00 ` William Clodius
1997-10-10 4:00 ` Larry Kilgallen
1997-10-10 4:00 ` Zalman Stern
1997-10-11 4:00 ` Andrew Cruickshank
1997-10-12 4:00 ` Paul D. DeRocco
1997-10-13 4:00 ` Michael Williams
1997-10-08 4:00 ` Gregg E Economou
1997-10-08 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 ` David Chase
1997-10-08 4:00 ` James C. Stutts
1997-10-02 4:00 Robert Harley
1997-10-02 4:00 ` Nick Maclaren
1997-10-02 4:00 ` Stanley Chow
1997-10-02 4:00 Robert Harley
1997-10-02 4:00 ` Nick Maclaren
1997-10-03 4:00 ` Richard A. O'Keefe
1997-09-30 4:00 Paul DeMone
1997-09-30 4:00 ` Guy Harris
1997-10-01 4:00 ` Tom Thornhill
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` Paul DeMone
1997-10-01 4:00 ` J. Corbally
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` Ketil Z Malde
1997-10-01 4:00 ` Michael D. Nahas
1997-10-01 4:00 ` Stefan Monnier
1997-10-01 4:00 ` Nick Maclaren
1997-10-01 4:00 ` Allen Kim
1997-10-01 4:00 ` John Wilson
1997-10-01 4:00 ` P Murray
1997-10-01 4:00 ` Nick Maclaren
1997-10-02 4:00 ` Vesa Karvonen
1997-10-02 4:00 ` Joseph H Allen
1997-10-02 4:00 ` Wilco Dijkstra
1997-10-03 4:00 ` Jason.Ozolins
1997-10-03 4:00 ` Alex Colvin
1997-10-06 4:00 ` Richard A. O'Keefe
1997-10-08 4:00 ` Zalman Stern
1997-10-03 4:00 ` Stefan Monnier
1997-10-03 4:00 ` Stefan Monnier
1997-10-02 4:00 ` Andrew Glew
1997-10-02 4:00 ` Torben AEgidius Mogensen
1997-10-02 4:00 ` Patrick F. McGehearty
1997-10-02 4:00 ` brianh
1997-10-03 4:00 ` Michael Williams
1997-10-02 4:00 ` Jon Leech
1997-10-02 4:00 ` Stefan Monnier
1997-10-03 4:00 ` Richard A. O'Keefe
1997-10-03 4:00 ` Mike Smith
1997-10-03 4:00 ` Nick Maclaren
1997-10-03 4:00 ` Rob Barris
1997-10-03 4:00 ` Andrew Glew
1997-10-05 4:00 ` Gianni Mariani
1997-10-04 4:00 ` Nick Maclaren
1997-10-04 4:00 ` H. Eckert
1997-10-05 4:00 ` Andy "Krazy" Glew
1997-10-06 4:00 ` Nick Maclaren
1997-10-01 4:00 ` brianh
1997-10-02 4:00 ` Eric Hildum
1997-10-01 4:00 ` Richard A. Schumacher
1997-10-01 4:00 ` Tom Thornhill
1997-10-01 4:00 ` Jim Hull
1997-10-01 4:00 ` Paul DeMone
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox