Ian Harvey <
ian_h...@bigpond.com> wrote:
(snip, someone wrote)
>> indices in the variable on the left-hand side of the assignment. The
>> uses of these statements are almost certainly not standard
>> conforming. A simple example is
>> X = 0.0 FORALL (I=1:N) X = X + A(I)
>> That statement is not standard conforming, and is unlikely to do what
>> is expected.
> Absence of a reference to all indicies on the left hand side should
> presumably be easy enough to detect. Are *all* cases of that
> non-conforming?
I think with a WHERE it could be valid. Or if N is 1.
Seems to me that there are many cases where the compiler couldn't
detect it, and some might even be useful.
> Again, considering what things look like with the alternative (rather
> than "this feature has flaws"), the naive transcription to DO CONCURRENT
> is equivalently not standard conforming. Like forall, the
> non-conformance is not (and in the case of DO CONCURRENT, cannot ever
> be) called out by constraint.
> DO CONCURRENT (I=1:N) ; X = X + A(I) ; END DO
In the case of FORALL, if the compiler can't be sure that there
is no overlap between source and destination, a temporary is needed.
There could be many cases where you know that there is no overlap,
but the compiler doesn't.
For DO CONCURRENT, it is your responsibility to get it right.
> There's a danger that focussing on isolated simple examples, as I'm
> about to do, detracts from a more reasoned overall view, but still - why
> is DO CONCURRENT "better" here? If I can botch one form of construct
> up, I can botch another that looks very similar!
> This is similarly [silly and] nonconforming (though perhaps here
> consider X to be an array, and the programmer forgot to subscript it):
> FORALL (I=1:N) X = A(I)
Well, one could forget to subscript arrays in a lot of places,
such as READ or WRITE statements, and get surprising results.
> This naive transcription conforms... but is still completely useless and
> likely to result in non-conforming program in subsequent statements:
> DO CONCURRENT (I=1:N) ; X = A(I) ; END DO
> Perhaps out of ignorance, I assume the semantics of DO CONCURRENT mean
> that a performant compiler has to understand what's going on inside a
> simple construct body (vs a construct body where the programmer is being
> a little malicious with their complexity) to the extent that it can
> identify the "many to one" dependence".
Well, it seems to me that DO CONCURRENT has some similarity to
what you can do with MPI or OpenMP. In both cases, the result is
that X is undefined.
> If you can do that analysis for DO CONCURRENT, then you can do it for
> FORALL and issue an error diagnostic.
The interesting cases are the ones the compiler can't figure out.
Consider (from the Fortran 2008 standard in 7.2.4.4)
FORALL (I=1:10)
A(INDEX(I))=B(I)
END FORALL
is valid if there are no repeated values in INDEX(1:10).
Note that this can be conveniently done using vector registers
in a processor with scatter/gather capability.
Now, consider:
FORALL (I=1:10)
B(INDEX(I))=B(I)
END FORALL
and again, the values in INDEX(1:10) are unique. Even more,
consider that none of the values of INDEX(1:10) are between 1 and 10.
> Presumably in the DO CONCURRENT case a compiler that realises it has a
> many to one dependence would in this case also realise that it has an
> assignment that has no useful effect and could issue a warning
> diagnostic. But is the programmer better off?
In the easy cases, the compiler should probably give a diagnostic,
but then again, the easy cases us using a variable before assigning
it a value should also be diagnosed, and many compilers don't.
(They are getting better, though.)
>> The more serious problems are with the FORALL and WHERE constructs.
>> Many programmers seem to think that FORALL and WHERE constructs are
>> looping constructs that execute the statements that forms their
>> bodies repeatedly from top to bottom for the each set of active
>> indices. Instead FORALL and WHERE constructs execute each statement
>> in the body of the construct for all active indices before advancing
>> to the next statement.
> A fair enough observation. In that case, why not ditch the
> construct forms and keep the single statement forms?
> Misconceptions about what you can and can't do inside DO CONCURRENT will
> emerge with time too, though - though perhaps debatable whether to the
> same extent.
-- glen