Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!convex!bleikamp From: bleikamp@convex.com (Richard Bleikamp) Newsgroups: comp.lang.fortran Subject: Re: Array Notation Message-ID: <1991Jan04.154747.18673@convex.com> Date: 4 Jan 91 15:47:47 GMT Sender: news@convex.com (news access account) Organization: Convex Computer Corporation, Richardson, Tx. Lines: 51 Nntp-Posting-Host: mozart.convex.com The draft standard requires the entire right side of an assignment statement to be evaluated before any values of the left side target are updated. This requires a temporary only when there is some overlap. Unfortunately, only vectorizing/parallelizing compilers do enough dependency anaylsis to get this right all the time. So a scalar machine compiler will often introduce unnecessary temps (at least until they add dependency analysis). For example : DO 10 I=1,N-1 A(I) = B(I) + C(I) B(I+1) = D(I) * 3.14 10 CONTINUE contains a forward recurence, which most vectorizing compilers can happily vectorize. Note that the equivalent F90 statements are : B(2:N) = D(1:N-1) * 3.14 A(1:N-1) = B(1:N-1) + C(1:N-1) and the order is CRITICAL. A F90 compiler on a scalar machine will probably produce worse code for these two F90 statements than for the F77 equivalent (it will likely treat the two statements separately, in essence introducing another loop, and screwing up the cache hit rates). On a vector machine, the resulting code for the F90 statements won't be better than the F77 version, and sometimes worse. A massivelly parallel machine might do better with the F90 code, but not necessarily. In the case of a backward loop-carried dependency, i.e. DO 10 I=1,N 10 D(I+1) = D(I) * B(I) + C(I) there is NO LEGAL array notation equivalent. The real problem for array notation is that scalar compilers don't known enough to do a good job of converting array notation back into an appropriate DO loop without introducing unnecessary loops and temps. > > The end results are the same using either DO or array syntax, > right? So if the array syntax is slower, it sounds to me like the > compiler (optimizer?) writers have a problem, not the language. The moral of these examples is ARRAY NOTATION is NOT a direct replacement for DO loops. They are not always interchangeable. Array notation is sometimes a convenient shorthand for simple array operations, but will not inherently allow compilers to generate better code. -- ------------------------------------------------------------------------------ Rich Bleikamp bleikamp@convex.com Convex Computer Corporation