J3/05-237r2 Date: 09 August 2005 To: J3 From: Bill Long Subject: Specification, Syntax, and Edits for DO CONCURRENT References: Feature j3-046, 05-133r2 -------------------------------------------------------------- Summary ------- The DO CONCURRENT construct is a new form of the DO construct using loop control syntax like that of FORALL. It would allow the iterations of the loop to be executed in any order. Restrictions on the statements in the loop block are required, but the restrictions are significantly fewer than for FORALL constructs. DO CONCURRENT is feature J3-046. Specification and Syntax ------------------------- The syntax for DO CONCURRENT specifies a new for the existing that uses the FORALL header syntax: [,] CONCURRENT The scope rules for an in the are the same as in a FORALL construct (7.4.4.1). The values of the index variables for the iterations of the construct are determined by the rules for the index variables of the FORALL construct (7.4.4.2.1 and 7.4.4.2.2). The number of distinct index value tuples is the iteration count for the construct. The iterations may be executed in any order. A statement in the loop range shall not cause a branch out of the loop range. The loop range shall not contain an EXIT statement that would cause the DO CONCURRENT construct to terminate. A variable that is referenced in an iteration of a DO CONCURRENT construct shall either be previously defined during that iteration, or shall not have its definition status changed during any other iteration. A variable that has its definition status change in more than one iteration becomes undefined when execution of the construct completes. A pointer that is referenced in an iteration of a DO CONCURRENT construct either shall be previously pointer associated during that iteration, or shall not have its pointer association status changed in the loop range. A pointer that has its pointer association status changed in more than one iteration has a processor dependent association status when the execution of the construct completes. An allocatable object that is allocated in more than one iteration of a DO CONCURRENT construct shall be subsequently deallocated during the same iteration in which it was allocated. An object that is allocated or deallocated in only one iteration of a DO CONCURRENT construct shall not be deallocated, allocated, or referenced, or have its definition status changed in a different iteration. An input/output statement in a DO CONCURRENT construct shall not write data to a file record or position in one iteration and read from the same record or position in a different iteration. Procedures referenced in the loop range of a DO CONCURRENT construct shall be PURE. If the IEEE_EXCEPTIONS intrinsic module is accessible, references to the IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, and IEEE_GET_HALTING_MODE subroutines shall not appear in the loop range. Note: The restrictions on referencing variables defined in an iteration apply to any procedure invoked by the loop. Note 12.44 in section 12.6 (Pure procedures) should be updated to include the DO CONCURRENT construct as well as the FORALL construct. EDITS ----- Note: < and > are used to delimit italic font. << and >> are used to delimit bold font. All page and line numbers refer to j3/04-007. ..................................................................... In the Introduction section (page xiii), the list of new Fortran 2008 features should include Performance enhancements: The DO CONCURRENT construct, which allows loop iterations to be executed in any order or potentially concurrently. ..................................................................... In section 1.6 Compatibility, there are no changes needed. ..................................................................... 164:3. In the second sentence of the first paragraph in 8.1.6, DO construct, replace "The EXIT and CYCLE statements" with: The EXIT statement, except in a DO CONCURRENT construct, and the CYCLE statement ..................................................................... 164:6. In the second sentence of the second paragraph in 8.1.6, DO construct, replace "In either case," with: Except in the case of a DO CONCURRENT construct, ..................................................................... 164:8+. After the second paragraph of 8.1.6, add the following paragraph: A <> construct is a DO construct with a of [,] CONCURRENT . ..................................................................... 165:15+. Add an new line to R830, in 8.1.6.1.1, Form of the block DO construct: or [,] CONCURRENT ..................................................................... 167:7+. Before the last sentence of 8.1.6.4.1, Loop initiation, add a new paragraph: For a DO CONCURRENT construct, the values of the index variables for the iterations of the construct are determined by the rules for the index variables of the FORALL construct (7.4.4.2.1 and 7.4.4.2.2). The number of distinct index value combinations in the active combination of values is the iteration count for the construct. An in a DO CONCURRENT construct has a scope of the construct (16.3). It is a scalar variable that 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 DO CONCURRENT, and this type shall be integer type; it has no other attributes. ..................................................................... 167:10. In the first sentence of 8.1.6.4.2, The execution cycle, replace "The <> of a DO construct consists of" with: The <> of a DO construct that is not a DO CONCURRENT construct consists of ..................................................................... 167:23+. At the end of 8.1.6.4.2, The execution cycle, add a new paragraph: The range of a DO CONCURRENT construct is executed for all of the active combinations of the values. Each execution of the range is an <>. The executions may occur in any order. ..................................................................... 167:25. In the first sentence of 8.1.6.4.3, CYCLE statement, replace "Step (2) in the above execution cycle may be curtailed" with: Execution of the range of the loop may be curtailed ..................................................................... 167:29+. After constraint C828 in 8.1.6.4.3, add a new constraint: C828a (R843) A shall not appear within the range of a DO CONCURRENT construct if it belongs to a construct that contains the DO CONCURRENT construct. ..................................................................... 167:33. At the beginning of the first sentence of the second to last paragraph of subsection 8.1.6.4.3, replace "Execution of a CYCLE statement causes" with: Execution of a CYCLE statement that belongs to a DO construct that is not a DO CONCURRENT construct causes ..................................................................... 167:34. After the first sentence of the second to last paragraph of subsection 8.1.6.4.3, add a new sentence: Execution of a CYCLE statement that belongs to a DO CONCURRENT construct completes that iteration of the construct. ..................................................................... 168:7+ Add a new constraint to subsection 8.1.6.4.4, Loop termination: C829a (R844) An shall not belong to a DO CONCURRENT construct, nor shall it appear within the range of a DO CONCURRENT construct if it belongs to a construct that contains that DO CONCURRENT construct. ..................................................................... 168:11. At the beginning of the sentence before the list of items in subsection 8.1.6.4.4, replace "The loop terminates" with: For a DO construct that is not a DO CONCURRENT construct, the loop terminates ..................................................................... 168:23+. After the last paragraph of subsection 8.1.6.4.4, add a new paragraph: For a DO CONCURRENT construct, the loop terminates, and the DO construct becomes inactive when all of the iterations have completed execution. ..................................................................... 168:24-. Add a new subsection and two Notes between 8.1.6.4.4 and 8.1.6.5: 8.1.6.4a Restrictions on DO CONCURRENT constructs Restrictions on the statements in the range of a DO CONCURRENT construct allow the iterations of the loop to be executed in any order. A statement in the loop range shall not cause a branch out of the construct. A variable that is referenced in an iteration shall either be previously defined during that iteration, or shall not have its definition status changed during any other iteration of the current execution of the construct. A variable that has its definition status changed by more than one iteration of the current execution of the construct becomes undefined when the current execution of the construct terminates. A pointer that is referenced in an iteration either shall be previously pointer associated during that iteration, or shall not have its pointer association status changed during any iteration. A pointer that has its pointer association status changed in more than one iteration has a processor dependent association status when the construct terminates. An allocatable object that is allocated in more than one iteration shall be subsequently deallocated during the same iteration in which it was allocated. An object that is allocated or deallocated in only one iteration shall not be deallocated, allocated, or referenced, or have its definition status changed in a different iteration. An input/output statement shall not write data to a file record or position in one iteration and read from the same record or position in a different iteration of the same execution of the construct. Records written by output statements in the loop range to a sequential access file appear in the file in an indeterminate order. Procedures referenced in the loop range shall be PURE. If the IEEE_EXCEPTIONS intrinsic module is accessible, calls to the IEEE_GET_FLAG, IEEE_SET_HALTING_MODE, and IEEE_GET_HALTING_MODE subroutines shall not appear in the loop range. Note 8.15a The restrictions on referencing variables defined in an iteration of a DO CONCURRENT construct apply to any procedure invoked within the loop. [end Note] Note 8.15b The restrictions on the statements in the loop range of a DO CONCURRENT construct are designed to ensure there are no data dependencies between iterations of the loop. This permits code optimizations that might otherwise be difficult or impossible because they would depend on characteristics of the program not visible to the compiler. [end Note] ..................................................................... 169:1-- After Note 8.18, add a new Note: Note 8.18a The following example represents a common case in which the user knows that the elements of the array IND form a permutation of the integers 1..N. The DO CONCURRENT construct will allow the compiler to generate vector gather/scatter code, loop unrolled code, or parallel threaded code for this loop, significantly improving performance. INTEGER :: A(N),IND(N) DO CONCURRENT (I=1:N) A(IND(I)) = A(IND(I)) + 1 END DO ..................................................................... 287:7+. In the third line of Note 12.44, replace "FORALL where" with FORALL , or a DO CONCURRENT construct, where ..................................................................... 287:7+. In the last sentence of Note 12.44, replace "referenced in FORALL statements and constructs and within" with: referenced in FORALL statements and constructs, DO CONCURRENT constructs, and within ..................................................................... 409:15-410:4. In section 16.3, Statement and construct entities, replace "FORALL construct" with "FORALL or DO CONCURRENT construct" in the following eight locations: 409:15 409:24 409:28 409:42 409:43 410:1 410:2 410:4 ..................................................................... 409:26. In the third line of the third paragraph of section 16.3, replace "FORALL" with "FORALL statement or FORALL or DO CONCURRENT construct". ..................................................................... 423:18. In item (15) of section 16.5.6, replace "FORALL construct" with "FORALL or DO CONCURRENT construct". ..................................................................... 423:18+. After item (15) of section 16.5.6, add the following item: When a DO CONCURRENT construct terminates, a variable that has its definition status changed by more than one iteration of the construct becomes undefined.