08-299 To: J3 From: Malcolm Cohen Subject: Elemental interpretation/feature request Date: 2008 November 18 1. Introduction This paper contains an interp request against Fortran 2003. There are three possible answers (with different edits); these are ranked beginning with the least restrictive going on to the most restrictive. Also, if the answer is anything other than the least restrictive we should consider whether it should be less restrictive in Fortran 2008. (I have not included any separate material for that process as it can be mechanically derived from the interp request should that route be followed.) 2. Interp Request ---------------------------------------------------------------------- NUMBER: ? TITLE: KEYWORDS: DEFECT TYPE: STATUS: J3 consideration in progress QUESTION: Constraint C1279 says "In the scoping unit of an elemental subprogram, an object designator with a dummy argument as the base object shall not appear in a except as the argument to one of the intrinsic functions BIT_SIZE, KIND, LEN, or the numeric inquiry functions (13.5.6)." It has been stated in previous J3 papers that the reason for this restriction is to ensure that every iteration of a single invocation of an elemental procedure will have the same stack size: and this desire was achieved in Fortran 95. However, the situation changes with deferred-length character components. For example, with the type TYPE T CHARACTER(:),ALLOCATABLE :: CP END TYPE and the elemental procedure SUBROUTINE ZAP(X) TYPE(T),INTENT(INOUT) :: x REAL WORK(LEN(X%CP)) ... and the variable TYPE(T) ARRAY(100) initialized as DO I=1,100; ARRAY(I)%CP = REPEAT('x',I); END DO then in the invocation CALL ZAP(ARRAY) the invoked procedure will have a different size for its WORK array for every element of ARRAY. Thus the restriction no longer achieves its aim (though this aim is not actually stated in the standard). Is this restriction still correct and useful? That is, (a) is the above example standard-conforming, (b) is the below example standard-conforming. Program below_example Integer :: ARRAY(100) = (/ (I,I=1,100) /) Call ES(ARRAY) Print *,ARRAY Contains Elemental Subroutine ES(X) Integer,Intent(Inout) :: X Real WORK(X) ... End Subroutine End Program DISCUSSION: The purpose of the constraint was to facilitate the optimisation of moving the loop traversal into the elemental procedure, and then hoisting the stack frame setup outside the loop. Few processors do this optimisation right now. In fact, even in the absence of the constraint the optimisation can still be done for all the previously-valid cases: the analysis required is no more complicated than the analysis the constraint requires for producing the error message. ANSWER: Pick one of: (1) It is not useful; this restriction no longer serves its purpose and should be removed. An edit is supplied to make the second example standard-conforming. (2) It might not be useful, but the standard is not in error and so the first example is standard-conforming but the second is not. (3) The need to modify the constraint to achieve the desired result was inadvertantly overlooked: an edit is supplied to make the first example not conforming. EDITS: (1) [288:2-4] Delete constraint C1279. (2) None. (3) [288:4] Append to constraint C1279 "The object designator shall not have a deferred length parameter." SUBMITTED BY: Malcolm Cohen HISTORY: 08-258 m185 Submitted 08-nnn m186 Revised ---------------------------------------------------------------------- ===END===