08-277r1 To: J3 From: David Muxworthy Subject: Revised edits for in Date: 2008 November 17 Reference: 08-203r1 Discussion 08-203r1 observes that the possibility that a might appear in the of a DO CONCURRENT construct has not been considered in 8.1.7.6.1p7. It proposes to insert a paragraph very much like 7.2.4.1p2 in 8.1.7.1 after C819 and delete 8.1.7.6.1p7. This violates the Weaver Rule. The (almost) correct paragraph, which is very much like 7.2.4.1p2, is already in 16.4p7, which is the correct place, so 7.2.4.1p2 also violates the Weaver rule. It would be better to replace 7.2.4.1p2 and 8.1.7.6 by notes that refer to 16.4, and adjust 16.4p7 to apply both to FORALL and DO CONCURRENT. JOR agrees in principle with the edits in 08-277 but notes that their application would leave 7.2.4.1 with six consecutive notes occupying one and a half pages which describe FORALL by example rather than by normative text. All but one of the sample program fragments should be moved to Annex C.4.5. Edits [162: 7.2.4.1 C744+] --------------------------------------------------- Editor: Insert a note: "NOTE 7.51a The scope and attributes of an in a are described in 16.4." [162-163: 7.2.4.1 Notes 7.53 and 7.54] -------------------------------- Editor: Delete Notes 7.53 and 7.54 [163: 7.2.4.1p2] ------------------------------------------------------- Editor: Delete the paragraph. [163-164 7.2.4.1 Notes 7.55 and 7.56] ---------------------------------- Editor: Delete Notes 7.55 and 7.56 [177: 8.1.7.2 C819+] --------------------------------------------------- Editor: Insert a note: "NOTE 8.10a The scope and attributes of an in a are described in 16.4." [178: 8.1.7.6.1p7] ----------------------------------------------------- Editor: Delete the paragraph (which is in the wrong place anyway). [442: 16.4p7] ---------------------------------------------------------- Editor: Replace the paragraph by a simpler one that applies both to FORALL and DO CONCURRENT, and is future-proof if we use somewhere else someday: "The name of a variable that appears as an in a has a scope of the statement or construct in which the appears. It is a scalar variable. If appears in the variable has the specified type and type parameters; otherwise it has the type and type parameters that it would have if it were the name of a variable in the scoping unit that includes the construct, and this type shall be integer type. It has no other attributes. The appearance of a name as an in a is not an implicit declaration of a variable whose scope is the scoping unit that contains the statement or construct." [480: C.4.5] ---------------------------------------------------------- Editor: Replace clause title "<>" by "<>" [480: 0+] ------------------------------------------------------------ Editor: Insert: Example 1: An assignment statement that is a FORALL body construct may be a scalar or array assignment statement, or a defined assignment statement. The variable being defined will normally use each index name in the forall-triplet-spec-list. For example FORALL (I = 1:N, J = 1:N) A(:, I, :, J) = 1.0 / REAL(I + J - 1) END FORALL broadcasts scalar values to rank-two subarrays of A. Example 2: An example of a FORALL construct containing a pointer assignment statement is: TYPE ELEMENT REAL ELEMENT_WT CHARACTER (32), POINTER :: NAME END TYPE ELEMENT TYPE(ELEMENT) CHART(200) REAL WEIGHTS (1000) CHARACTER (32), TARGET :: NAMES (1000) . . . FORALL (I = 1:200, WEIGHTS (I + N - 1) > .5) CHART(I) % ELEMENT_WT = WEIGHTS (I + N - 1) CHART(I) % NAME => NAMES (I + N - 1) END FORALL The results of this FORALL construct cannot be achieved with a WHERE construct because a pointer assignment statement is not permitted in a WHERE construct. Example 3: The use of index-name variables in a FORALL construct does not affect variables of the same name, for example: INTEGER :: X = -1 REAL A(5, 4) J = 100 . . . FORALL (X = 1:5, J = 1:4) ! Note that X and J are local to the FORALL. A (X, J) = J END FORALL After execution of the FORALL, the variables X and J have the values -1 and 100 and A has the value 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Example 4: The type and kind of the index-name variables may be declared independently of the type of any normal variable in the scoping unit. For example, in SUBROUTINE s(a) IMPLICIT NONE INTEGER, PARAMETER :: big = SELECTED_INT_KIND(18) REAL a(:,:), x, theta ... FORALL ( INTEGER(big) :: x=1:SIZE(a,1,big), y=1:SIZE(a,2,big), a(x,y)/=0 ) a(x,y) = 1 / a(x,y)**2 END FORALL ... the kind of the index-names X and Y is selected to be big enough for subscript values even if the array A has more than 231 elements. Since the type of the index-names X and Y in the FORALL construct are declared explicitly in the FORALL header, it is not necessary for integer variables of the same names to be declared in the containing scoping unit. In this example, there is a variable X of type real declared in the containing scoping unit, and no variable Y declared in the containing scoping unit. Example 5: Example of a FORALL construct containing a WHERE construct.