Subject: reprint of Digital's NUMBER_OF_PROCESSORS proposal

From: David Loveman <[email-masked]>
Date: Mon, 11 May 92 06:44:32 PDT

Attached is a reprint from the HPFF January meeting of Digital's
proposal for the introduction of a new class of intrinsic functions
(system inquiry functions), the specific function NUMBER_OF_PROCESSORS,
and the appropriate modification to the Fortran 90 definition of
restricted expression.

-David
[email-masked]

------------------------------------------------------------------------

New Intrinsic Function

In addition to the intrinsic functions of Fortran 90, High Performance
Fortran has a new intrinsic function, NUMBER_OF_PROCESSORS, which takes
no arguments and returns an integer value giving the number of
processors in the system. This number is expected to remain constant
for (at least) the duration of one program execution. Accordingly,
NUMBER_OF_PROCESSORS() is a constant expression and can be used
wherever any other Fortran 90 constant expression can be used. In
particular, NUMBER_OF_PROCESSORS can be used in an initialization
expression or in a specification expression.  None of the categories of
intrinsic functions listed in Chapter 13 of the Fortran 90 standard
seem quite apt to describe the nature of this new intrinsic function,
so we add a new category of "system inquiry functions" and place
NUMBER_OF_PROCESSORS in that category.

Note that treating NUMBER_OF_PROCESSORS as a constant expression does
not force a compiler to bind the number of processors at compile time
(although that is one possible implementation) -- with the right linker
or code-generation technology the choice could be deferred until run
time, possibly at some performance cost.

A definition of NUMBER_OF_PROCESSORS, in the style of Chapter 13 of the
Fortran 90 standard is:

13.13.77a  NUMBER_OF_PROCESSORS(DIM)

Optional Argument.  DIM

Description.  Returns the total number of processors available to the
program, the dimensionality of the processor array, or the number of
processors available to the program along a specified dimension of the
processor array.

Class.  System inquiry function.

Arguments.
DIM (optional)  must be scalar and of type integer with a value in the
range 0<=DIM<=n where n is the rank of the processor array.

Result Type, Type Parameter, and Shape.  Default integer scalar.

Result Value.  The result has a value equal to the rank of the
processor array if the value of DIM is 0, the extent of dimension DIM
(1<=DIM<=n, where n is the rank of the processor array) of the
processor-dependent hardware processor array or, if DIM is absent, the
total number of elements, equal to or greater than one, of the
processor-dependent hardware processor array.

The value of NUMBER_OF_PROCESSORS() need not be a constant, if the
processor allows for a variable number of processors to execute the
program.  However, the value must not change during the execution of the program.

Example. For a DECmpp 12000 Model 8B with 8192 processors, the value of
NUMBER_OF_PROCESSORS( ) is 8192, the value of
NUMBER_OF_PROCESSORS(DIM=0) is 2, the value of
NUMBER_OF_PROCESSORS(DIM=1) is 128, and the value of NUMBER_OF_PROCE is 64.

The list of alternatives in a Fortran 90 restricted expression is
expanded to include NUMBER_OF_PROCESSORS, as follows:

A  *restricted expression* is an expression in which each operation is
intrinsic and each primary is:

1.   A constant or subobject of a constant,

2.   A variable that is a dummy argument that has neither the OPTIONAL
nor the INTENT (OUT) attribute, or a variable that is a subobject of such as dummy
argument,

3.   A variable that is in a common block or a variable that is a
subobject of a variable in a common block,

4.   A variable that is made accessible by use association or host
association or a variable that is a subobject of such a variable,

5.   An array constructor where each element and the bounds and strides
of each implied-DO are expressions whose primaries are either restricted expressions
or implied-DO variables, 

6.   A structure constructor where each component is a restricted expression,

7.   An elemental intrinsic function reference of type integer or
character where each argument is a restricted expression of type
integer or character,

8.   One of the transformational functions REPEAT, RESHAPE,
SELECTED_INT_KIND, SELECTED_REAL_KIND, TRANSFER, and TRIM, where each
argument is a restricted expression of type integer or character,

9.   A reference to an array inquiry function (13.10.15) other than
ALLOCATED, the bit inquiry function BIT_SIZE, the character inquiry
function LEN, the kind inquiry function KIND, or a numeric inquiry
function (13.10.8), where each argument is either a restricted
expression or a variable whose type parameters or bounds inquired about
are not assumed or defined by an ALLOCATE statement or a pointer
assignment, or

10.   A restricted expression enclosed in parentheses, or

11.   The HPF system inquiry function NUMBER_OF_PROCESSORS.

---

From: Guy Steele <[email-masked]>
Date: Mon, 11 May 92 12:13:35 EDT

Thanks for retransmitting the NUMBER_OF_PROCESSORS text, David.
I have two suggestions:

[a] Using DIM=0 to convey rank information is one of those
clever-but-strange encoding tricks.  Inasmuch as there is no
precedent for it already in Fortrasn 90, I recommend considering a
separate intrinsic that would be analogous to something already in
Fortran 90, to wit, PROCESSORS_SHAPE(), returning a rank-1 vector.
Thus SIZE(PROCESSOR_SHAPE()) is the rank of the processor array.

Example.  For a DECmpp 12000 Model 8B with 8192 processors, the value of
PROCESSORS_SHAPE() is (/ 128, 64 /).

Example.  For a Connection Machine CM-2 with 8192 processors, the value of
PROCESSORS_SHAPE() might be (/ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 /).

Example.  For a Connection Machine CM-5 with 8192 processors, the value of
PROCESSORS_SHAPE() might be (/ 8192 /).

[b] Perhaps NUMBER_OF_PROCESSORS and PROCESSORS_SHAPE should take
another optional argument, the name of a processors arrangement
as declared in a PROCESSORS directive:

	NUMBER_OF_PROCESSORS(procs, dim)
	PROCESSORS_SHAPE(procs)

If "procs" is omitted, then the information returned concerns the
"natural" processors arrangement of the hardware; if included,
then it serves as an inquiry intrinsic for the declared processors
arrangement.  Perhaps this latter form should be restricted to use
within HPF directives (inasmuch as the referenced name is defined
by an HPF directive).

Example.

!HPF$ PROCESSORS FOO(40,80)
!HPF$ ... PROCESSORS_SHAPE(FOO) ...           ! (/ 40, 80 /)
!HPF$ ... NUMBER_OF_PROCESSORS(FOO) ...       ! 3200