Re: Identity Matrix



Ron Shepard wrote:
(snip)

The problem with FORALL in general is that it is not a looping structure, it is another way of writing an array assignment. This is not what programmers said that they needed in the 80's when the semantics of the feature were being discussed, and the feature was not added to f90 because of this disagreement between the programers and the compiler writers.

Yes. FORALL still requires all expressions on the right side to
be evaluated before any variable on the left side is changed.

FORALL doesn't restrict the order of evaluation on the right side,
or the order of assignment after the values have been determined.

When it was included in f95, the compiler writers won and the programmers did not get what they needed. This distinction probably does not apply to the above code because the right hand side expression is so simple, the optimization steps in the compiler will probably do the right thing in the end anyway.

Yes. Well, I suppose most of the time there are no variables
used on both sides of the assignment. If the compiler can assume
no aliasing, then it can do the assignment in any order.

But in general, the semantics of the FORALL require the rhs to be fully evaluated and stored in a temporary array, and then the results are moved into the variable locations specified on the lhs of the statement. This makes FORALL less useful and more prone to inefficiencies than it should have been.

Most of the time the programmer knows when changes on the left
can affect expressions on the right. FORALL doesn't leave any
way for the programmer to indicate that to the compiler.

The most useful semantics, certainly in hindsight, was what fortran programmers in the 80's recognized was important, namely a looping structure in which the order of assignments could be rearranged by the compiler in any way at all. This allows for efficient vectorization on vector processors and efficient pipelining on RISC processors, it allows for elimination of memory bank conflicts, it allows for reduction of cache overflows and other NUMA optimizations, it allows very general loop unrolling and out-of-order execution, for parallel execution it allows for asynchronous execution of separate threads, and it does not require allocation of temporary vectors within innermost loops. The semantics of FORALL prevent some or all of those things from occurring.

Well, FORALL does allow the assignment in any order, but only
after all the expressions have been evaluated. Not quite
good enough for the cases listed above, though. Vector
processors are pretty much out of style now, though.
The other cases are still important.

-- glen

.



Relevant Pages

  • Re: Paying developers to get features faster
    ... >> compiler up, with absolutely no effect on the generated code. ... Well, C programmers have a history of writing things tersely, and the ... Although it's possible to factor the assignment out of the conditional, ... loop, at the bottom of the loop, and before any "continue" statements). ...
    (comp.os.linux.development.system)
  • Re: Paying developers to get features faster
    ... >> compiler up, with absolutely no effect on the generated code. ... Well, C programmers have a history of writing things tersely, and the ... Although it's possible to factor the assignment out of the conditional, ... loop, at the bottom of the loop, and before any "continue" statements). ...
    (comp.security.misc)
  • Re: Paying developers to get features faster
    ... >> compiler up, with absolutely no effect on the generated code. ... Well, C programmers have a history of writing things tersely, and the ... Although it's possible to factor the assignment out of the conditional, ... loop, at the bottom of the loop, and before any "continue" statements). ...
    (comp.os.linux.security)
  • Re: Paying developers to get features faster
    ... >> compiler up, with absolutely no effect on the generated code. ... Well, C programmers have a history of writing things tersely, and the ... Although it's possible to factor the assignment out of the conditional, ... loop, at the bottom of the loop, and before any "continue" statements). ...
    (comp.os.linux.misc)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... what experienced programmers do, ... optimization, ... Thugs" ad nauseum fits that a lot more closely than discussing compiler ... be modified outside a loop, and guessing ...
    (comp.programming)

Loading