Subject: User-defined elemental procedures (Page/July20 responding to >Merlin/July16)

From: [email-masked] (Rector L. Page)
Date: Mon, 20 Jul 92 14:38:39 CDT

----------
> Question:  How did F8x propose to check that [elemental] procedures 
> are free of side-effects? 
> ...stuff omitted...  I assume it didn't check these things.

Essentially correct, no checking required.
No Fortran standard has required checking for errors.  A program that
violates constraints does not conform to the standard, and its
interpretation is entirely up to the processor.  Deadlock would, for
example, be a legitimate interpretation (as far as the F90 standard is
concerned) of any program failing to conform to the standard.

The sole restriction on elemental functions in the Fortran 8x proposal
was that the result of an elemental reference could not depend on the
order in which the elemental references were made.  HPF will have to
specify more restrictions than this to permit parallel evaluation of
elemental references.  (Defining a global variable, for example, might not
preclude any particular order of evaluation of elemental references as 
long as the evaluations aren't overlapped; the function might simply be
using the variable for temporary space.)  The Merlin 5 plus i/o would be
an adequate set of restrictions, I think.

> I'd be glad to avoid new syntax.  I just want some way of annotating
> a procedure to assert that it obeys my constraints, so that the
> constraints can be checked.  I'd be happy with an HPF directive like:
>
> 	!HPF$ ELEMENTAL proc-name
>
> at the end of the procedure statement or on the next line.  Is that
> an acceptable solution?

Constraints can be checked with or without an assertion of their validity.
When the compiler encounters an elemental reference (that is a reference
containing array actual arguments where the function expects scalars),
the compiler can check to make sure the function is suitable.  A model for
implementation might be for the compiler to record with each procedure the
information needed for such checks.  The compiler could then use the
information upon encountering an elemental reference.

Such information would probably be recorded anyway if the compiler were
to check for conformance to constraints on elemental functions.  For example,
consider a function that calls a subroutine that defines a global variable.
Such a function could not be called elementally, but the compiler could not
check for conformance to the constraints unless it knew, while compiling the
function, that the suboutine defined a global variable.  Therefore, the
needed information would have to be recorded with every procedure whether or
not HPF requires an ELEMENTAL assertion in functions that the programmer 
wants to invoke elementally.

In summary, it seems to me that the ELEMENTAL assertion is superfluous.
It makes things no easier for the compiler that checks for conformance,
but it increases the size of the language and complicates life for
programmers.  I do like the idea of including elemental functions in HPF,
however, because they appear to provide a facility for SPMD programming 
that covers everything one might want to do in that mode except i/o.

> Incidentally, if subroutines are an outmoded concept in Fortran 90,
> why does it introduce new intrinsic subroutines (for date, time,
> clock, random numbers, etc)?

Fortran 90 has five intrinsic subroutines: date_and_time, system_clock,
random_number, random_seed, and mvbits.  Except for mvbits, which would
have been a function had it not been inherited from a MIL STD, all of
these are properly subroutines.  The value of a function depends only
on its arguments.  None of these instrinsics have any (input) arguments.
Therefore, if they were functions, they would have to deliver the same
value at every invocation.  Time would appear to stand still.

Fortran 90's intrinsic subroutines are "packaging for side effects."
The time functions report a system state, random_number reports
an internal state (assuming it's pseudo-random--otherwise, it reports a
state of the universe), and random_seed sets an internal state.