On Wed, Nov 21, 2007 at 09:40:00AM -0500, Robert G. Brown wrote: > where n, > l, and m are range restricted so that the most efficient allocation of > memory would be a triangular one and where one wishes to access the > particle by means of something like x[i][n][l][m],
This problem pre-dates languages with pointers -- matrix algebra often uses triangular arrays, and nobody liked wasting memory in the old days. And the solution was the ugly index thingie you didn't like, and a one-dimensional array. To make it pretty, in C you can use a #define to hide the computation; in Fortran77 (and earlier) the usual solution was to use a statement function. In both cases this is much, much more efficient than your pointer solution, which cannot really be optimized by a compiler; it has to fetch the actual pointers. But a compiler can frequently strength reduce the integer computation, so a loop along any of the dimensions would be efficient. And this speed difference could easily be 100X in the worst case of pointers not residing in cache. But hey, don't let me stop you from using your preferred solution ;-) I know better to stand in the way of religion. > In C exponentiation is a library > function. In fortran it PROBABLY is as well Uh, not for integer powers -- compilers generally emit inline code, which leaves the opportunity of common subexpression elimination with nearby exponentiation or arithmetic. And good C compilers recognize the integer case, of course. > Fortran's I/O commands are terrible. Yep, but isn't it amazing how you can flip a switch and your Fortran code magically switches endian-ness? Every style of I/O has its strengths and weaknesses. Perl's pack() and unpack() are pretty similar to Fortran I/O, so I guess Larry gets it. -- greg _______________________________________________ Beowulf mailing list, [email protected] To change your subscription (digest mode or unsubscribe) visit http://www.beowulf.org/mailman/listinfo/beowulf
