Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Re: Final kick at the "Merced Guessing Game"
@ 1997-10-08  4:00 Robert Harley
  1997-10-08  4:00 ` David Chase
                   ` (3 more replies)
  0 siblings, 4 replies; 99+ messages in thread
From: Robert Harley @ 1997-10-08  4:00 UTC (permalink / raw)



xcc@hilbert.ncsc.org (Carlie Coats) writes:
>When I'm programming in C or C++, why the *_hell_* can't
>I do easy things like
>
>    void foo( const int m,
>              const int n,
>              const int p,
>              float a[p][n][m] ) {...}

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.  For instance you can
choose a flat array, 'float *a', or a hierarchy like 'float ***a'.

Suppose you choose the flat array, Fortran style.

  You can access a_{i,j,k} as a[(i*n+j)*m+k] or several other linear
  combinations depending on whether you like row-wise or column-wise
  access or whatever.  Your hand isn't forced like in Fortran.

  If you're doing simple constant-stride access, decent compilers will
  strength-reduce the multiplications just like decent Fortran compilers
  (or the pre-mungers that they often require to get top performance).

  However a non-trivial access pattern will use a lot of slow
  multiplications, just like in Fortran.  In that case you have the
  option of strength-reducing by hand if you know better than the compiler.

  Also, this often forces you to waste a lot of space, doubling the size
  of triangular matrices with useless zeroes, increasing the size of
  simplicial 3D arrays sixfold etc., just like in Fortran.

  Furthermore to swap rows, you have to swap all the elements, which
  takes forever just like in Fortran.


Suppose that you choose a hierarchy instead.

  Then non-trivial access patterns require pointer accesses, however
  these are typically fast since the number of pointers is very small
  compared to the size of the data.  For instance on this Alpha with a
  100x100x100 array the top level fits in L1 cache easily, the second
  level in L2, whereas the data is twice as big as L3.

  Also you can allocate exactly as much memory as you want or need.

  Furthermore you can swap rows (or columns) with a single pointer swap.


In some cases the former is best, in others the latter.  Of course, C
also lets you choose intermediate layouts such as an array 'float **a'
of pointers to rectangular matrices, if that is best for your
application.  Perhaps you'd like to tag those sub-matrices with their
dimensions:

  typedef struct { int width, height; float *data; } rectMatWithSizes;
  rectMatWithSizes funky[100];

and set it up whatever way you like.  In other languages you might be
forced to use training wheels, or you might be lucky enough to be
permitted to hack up some imitation of the C style.  I'd just use C.

Bye,
  Rob.
     .-.                     Robert.Harley@inria.fr                    .-.
    /   \           .-.                                 .-.           /   \
   /     \         /   \       .-.     _     .-.       /   \         /     \
  /       \       /     \     /   \   / \   /   \     /     \       /       \
 /         \     /       \   /     `-'   `-'     \   /       \     /         \
            \   /         `-'                     `-'         \   /
             `-'  Linux + 500MHz Alpha + 256MB SDRAM = heaven  `-'



^ permalink raw reply	[flat|nested] 99+ messages in thread

end of thread, other threads:[~1997-10-28  5:00 UTC | newest]

Thread overview: 99+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-10-08  4:00 Final kick at the "Merced Guessing Game" Robert Harley
1997-10-08  4:00 ` David Chase
1997-10-08  4:00 ` William Clodius
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-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                       ` John  Bayko
1997-10-17  4:00                       ` [Reposted due to Enlow UCE cancel]: " John  Bayko
1997-10-20  4:00                         ` Paul D. DeRocco
1997-10-18  4:00                       ` Kelly Hall
1997-10-20  4:00                         ` [Reposted due to Enlow UCE cancel]: " Eric Hildum
1997-10-13  4:00             ` Final kick at the "Merced Guessing Game" 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                   ` 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-15  4:00                   ` Achim Gratz
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           ` 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                 ` [Reposted due to Enlow UCE cancel]: " tgg
1997-10-18  4:00                 ` tgg
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-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       ` Paul DeMone
1997-10-11  4:00       ` Toon Moene
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-11  4:00         ` new languages Preston Briggs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox