Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: David Chase <chase@world.std.com>
Subject: Re: Final kick at the "Merced Guessing Game"
Date: 1997/10/09	[thread overview]
Message-ID: <343C33D4.5740@world.std.com> (raw)
In-Reply-To: 61gr1g$kv@news-rocq.inria.fr


Robert Harley wrote:
> ... Aren't ignorant people like me lucky to have
> mind-bogglingly condescending asses like yourself
> to bray on about the error of our ways?

Hey, someone's got to do it.  How exactly do you want this
stuff explained?  How polite am I supposed to be to someone
who says (incorrectly)

> I think your problem is that C is too flexible for you.  It doesn't
> wrongly assume that there is one way of laying out and accessing
> arrays that is appropriate for all purposes.

This is not condescending?

C's major performance fault is that as defined, and
especially as used, a compiler does not have
a great deal of freedom to move loads and stores around.
C programmers may be very careful to avoid "unnecessary" 
loads and stores, but nowadays, latency is the big problem;
performance is reduced if you do your loads "too late", or
if a conditional branch depends on a result that you computed
"too late".  A "too late" load is typically a bigger performance
hit than a "not necessary" load.  Fortran has many fewer
problems with this, because the aliasing rules make life
much easier for compilers.  The contiguously-allocated
multi-dimensional arrays help with this very much, too,
because it is easier to infer that A(i,w,x) addresses
different storage than A(i+1,y,z) than it is to infer
that

   pa+i*n*p+w*p+x != pa+(i+1)*n*p+y*p+z

Modern hardware goes to some trouble to reduce these costs
in the local sense, by predicting branches and starting
loads early, but this only gets you so much.  Parallelization
can get you superlinear speedup (as in, when I worked at 
Sun, a happy customer observed superlinear speedup on one
of their dusty decks on a 16-processor machine) on a very
good day.  Has anyone anywhere ever taken a dusty C deck,
dropped it on a multiprocessor, asked the compiler to
parallelize it, and obtained even a linear speedup?

Sun's Fortran compiler, back in 1994, would take care of loop
interchange for better cache use.  The dependence analysis
finds many "vector" operations, and these are specially
code-generated as software pipelines to get the best
possible performance.   You can get this sometimes for C
(it helps if the loop contains no stores to globally-accessible
variables) but you'll get it more often for Fortran.
Fortran performance is also pulling ahead on the newer
processors -- friends (former colleagues) told me that
the then-new version of the compilers improved Fortran
performance by 160% over the older compilers, but C and
C++, not nearly so much (I do not recall the figure).
The superoptimizer (converts control flow to very tricky
data flow) is looking better and better on these new
machines, but the combinatorial costs of searching ever-longer
instruction sequences limits usefulness (and the conditional
instructions added to many new processors also expands the
search space, though they also increase the chances of
hitting with a short sequence).

A decent combination of cache blocking, register blocking,
and software pipelining can get you a 20x speedup over
unoptimized code (if I recall, the large-matrix multiply
unoptimized ran at something like 1.5 Mflops).  C compilers,
lacking the restrict keyword, cannot do that (everyone who
knows what the restrict keyword is and what it does, raise
your hand.)  You can do this in C -- I did this in C,
apparently ineptly, since a Fortran program beat me -- but
it is incredibly tedious work, and the peak performance
is not portable (a conservative coding will improve
performance by quite a lot on most machines).
Cache blocking parameters depend on the cache size,
associativity, and line size.
Register blocking parameters depend on how many
registers you have, and registers used for blocking
are stolen from registers used for pipelining.
Pipelining depends on the latency of the loads and CPU
operations, and on where the operands are expected to come
from (dcache? ecache? main memory?  contiguous addresses that
can be prefetched or fetched in a burst?)

And, again, this is slow and tedious work; I normally write
something like 100 lines of debugged code (C, Java, x86 assembly
language) per day over long periods of time (I can count the
lines of code that I have written in the last nine months),
but writing this stuff, my rate falls down to something
under 10 lines per day.  Someone writing similar code in
i860 assembly language at Dana/Ardent/Stardent quoted me
a figure of one line of code per day, for a general case
version of the code (this one someone working on pipelined
implementations of vectorized transcendental functions).

If you were designing a new programming language ( to get back
to the original thread ) it would be a good idea to figure out
either how to make it easy to do alias analysis, or what "rules"
should come wired into the language that are both easy for
programmers to understand and obey, and useful for the compiler
to exploit.  Fortran 77's rules are well outside the bounds of
what I'd call elegant, but they work, and the optimization benefits
are substantial.

Another possibility is to make it as easy as possible
to discover that a program will terminate -- though this is
general-case intractable, there's a large class of interesting
programs for which this can be determined (for instance, all
loops are "for" loops, or all recursion is governed by a
strictly decreasing parameter).  Or, for instance, there is
some datatype that captures the notion "directed acyclic graph",
so that you know that any path traversal will terminate.

I'd also look into some way to make it more tractable to write
programs which use dataflow instead of control flow.  C* went
quite some distance in that direction, and it was a relatively
easy way to get decent performance out of a Connection Machine,
but people always seemed to want more, and I think they tended
to get it with CMF(ortran) or explicit message-passing.  (And,
as "boo" writes, some people programmed the vector units in their
assembly language.  Yuck.)

-- 
David Chase, chase@world.std.com



  parent reply	other threads:[~1997-10-09  4:00 UTC|newest]

Thread overview: 195+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-08  4:00 Final kick at the "Merced Guessing Game" 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 [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-10-09  4:00 Robert Harley
1997-10-08  4:00 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         ` Carl Perkins
1997-10-13  4:00         ` Michael Williams
1997-10-13  4:00           ` Craig Burley
1997-10-13  4:00             ` boo
1997-10-15  4:00               ` Craig Burley
     [not found]                 ` <623ek6$ef5$1@news.iastate.edu>
1997-10-16  4:00                   ` Craig Burley
1997-10-16  4:00                     ` SimGraphics
1997-10-17  4:00                       ` Craig Burley
1997-10-17  4:00                         ` William Clodius
1997-10-19  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-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             ` Paul Rubin
1997-10-13  4:00               ` Craig Burley
1997-10-13  4:00               ` William Clodius
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                       ` William Clodius
1997-10-15  4:00                       ` Joe Buck
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                     ` Craig Burley
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-18  4:00                     ` Bruce Hoult
1997-10-15  4:00                 ` Paul Hsieh
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     ` 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             ` Aaron Spink
1997-10-14  4:00             ` Jason.Ozolins
1997-10-15  4:00               ` boo
1997-10-15  4:00             ` David Chase
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-13  4:00           ` Bernd Paysan
1997-10-10  4:00     ` boo
1997-10-11  4:00       ` Paul DeMone
1997-10-11  4:00       ` Toon Moene
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               ` Jason.Ozolins
1997-10-10  4:00     ` Richard A. O'Keefe
     [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-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 ` 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-07  4:00 ` Nick Maclaren
1997-10-07  4:00 ` Martin Rodgers
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     ` 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     ` 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     ` 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
     [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-08  4:00         ` Richard A. O'Keefe
1997-10-08  4:00           ` William Clodius
1997-10-08  4:00           ` William Clodius
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 ` Tom Thornhill
1997-10-01  4:00   ` Paul DeMone
1997-10-01  4:00   ` Jim Hull
1997-10-01  4:00 ` Richard A. Schumacher
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                         ` Stefan Monnier
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-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               ` Stefan Monnier
1997-10-03  4:00                 ` Richard A. O'Keefe
1997-10-02  4:00               ` Jon Leech
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
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