To: J3 J3/19-136r1 From: Daniel Chen & Malcolm Cohen Subject: F2018 interp: In array element order execution should apply to IMPURE elemental function only Date: 2019-February-12 0. Response from /INTERP 0.1 Summary There is no problem, therefore this does not warrant processing as a defect report. 0.2 Discussion The quoted sentence is "In the array case, the values of the elements, if any, of the result are the same AS WOULD HAVE BEEN OBTAINED IF the scalar function had been applied separately, in array element order..." (emphasis mine). That is, this sentence makes no requirement on the actual evaluation order, only that the result is the same AS IF it were evaluated in array element order. Because the rules for PURE guarantee order-independence, this statement makes no requirement on the evaluation order for a PURE procedure, and indeed allows for parallel evaluation. Thus, there is no problem with this sentence, which has been carefully constructed to work for both PURE and IMPURE procedures. Thus, the recommendation is that this not be processed as a defect. 0.3 Further discussion Even in the case of IMPURE, the sentence requires sequential ordered evaluation only if the result or side effects would differ. For example, an IMPURE procedure that assigned the value .TRUE. to a global variable if an argument were zero, made no assignment to the variable if the argument were non-zero, and had no other "impure" effects, could potentially be processed in any order or even in parallel. 0.4 The original paper The original paper is reproduced below for reference. -------------------------------------------------------------------------- 1. Introduction In F2003, the standard says (12.7.2), "In the array case, the values of the elements, if any, of the result are the same as would have been obtained if the scalar function had been applied separately, in any order, to corresponding elements of each array actual argument." In F2008, we added the following in the Introduction section[xvi] "An impure elemental procedure processes array arguments in array element order." However, we changed p1 of 12.8.2 Elemental function actual arguments and results from "in any order" to "in array element order" without saying this should apply to IMPURE elemental function only. In F2018, we kept the same wording as F2008 (15.8.2) 2. Interpretation Request ---------------------------------------------------------------------- NUMBER: F18/xxxx TITLE: PURE Elemental function should be executed in any order. KEYWORDS: ELEMENTAL, PURE DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: If the argument of an pure elemental function is an array, should the result be the same as it would have been obtained if the scalar function had been applied, in any order, to corresponding elements of each array actual argument. ANSWER: Yes. This is an oversight. EDITS to 18-007r1: [326: 22] In 15.8.2 Elemental function actual arguments and results Change "in array element order" to "in array element order if it has the PURE prefix or in any order otherwise" It makes the whole sentence read, "In the array case, the values of the elements, if any, of the result are the same as would have been obtained if the scalar function had been applied separately, in array element order if it has the PURE prefix or in any order otherwise, to corresponding elements of each array actual argument." SUBMITTED BY: Daniel HISTORY: 19-xxx m218 submitted ----------------------------------------------------------------------