Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!nrl-cmf!cmcl2!phri!marob!djs!samperi From: samperi@djs.UUCP (Dominick Samperi) Newsgroups: comp.lang.fortran Subject: Re: Fortran versus C for numerical analysis Message-ID: <183@djs.UUCP> Date: 13 Sep 88 16:59:35 GMT References: <410@marob.MASA.COM> <3445@lanl.gov> Reply-To: samperi@djs.UUCP (Dominick Samperi) Organization: Village Software Lines: 44 In article <3445@lanl.gov> jlg@lanl.gov (Jim Giles) writes: |that's why dynamically allocated multi- |dimensional arrays don't optimize well in C - they are implemented as |an array of pointers which _can_ point to aliased areas of memory). The emphasis on _can_ is important here, for C permits many freedoms that you need not use for routine numerical applications. Arrays can be declared or created at runtime that are no different from FORTRAN arrays (except that the rows/columns are swapped); there is no need to use any tricks that result in obscure aliasing. It is true though that because of the freedoms, the compiler may not be able to optimize the way it does for FORTRAN arrays (how does it do this, by the way?). The use of the autoincrement/decrement operators might be classified along with these aliasing tricks and other lower-level C constructs as "advanced" features of the language, and avoided entirely in numerical applications. Then obscure code like while(*dest++ = *source++) ; could be written like this instead: i = 0 ; while(source[i] != 0) { dest[i] = source[i] ; i = i + 1 ; } dest[i] = 0 ; This would also rule out those tricky expressions of the form b[i] = a[i++], for example. On the other hand, using some of the low-level features might be useful at times. For example, a lower-triangular matrix a[i][j], j <= i, can be created, where memory is not allocated for the zero elements above the diagonal. A more exotic example might be one where it is possible to arrange for the various rows of a matrix to be allocated in different memory modules/banks. This functionality could easily be added to FORTRAN by simply providing a standardized macro facility. -- Dominick Samperi samperi@acf8.nyu.edu uunet!hombre!samperi cmcl2!acf8!samperi rutgers!acf8.nyu.edu!samperi (^ ell)