To: J3 08-297r1 From: Bill Long Subject: Atomic memory operations Date: 2008 November 19 References: J3/08-007r2 (WG5/N1723), WG5/N1751, 08-291r2 Discussion: The ability to use volatile coarray variables for spin-loops relies on their definitions and references being atomic. Instead of specifying semantics for that case, we propose to add two intrinsic procedures that have the effect of atomic definition and reference separate from the volatile attribute. This approach has the advantage that the variable could be a structure component without declaring the whole structure volatile. An intrinsic subroutine, ATOMIC_DEFINE, assigns the value of the second argument atomically to the variable specified by the first argument. An intrinsic subroutine ATOMIC_REF assigns the value of its first argument to the second argument atomically. These can be used as direct replacements for the definition and reference of a spin-loop variable. The allowed variables are of type integer and logical, and shall be of a processor-defined kind. Given the unique nature of these routines, and a long standing feature request for other atomic memory operations, a separate category of atomic intrinsic subroutines is created. Edits are provided to add these intrinsic subroutines and to remove the special status of the volatile attribute for coarrays. EDITS: [100:5.3.19p1] At the end of the first paragraph of "5.3.19 VOLATILE attribute" delete ", or by another image without synchronization". [188:p6] Replace the first sentence of paragraph 6 of "8.5.1 Image control statements", which reads "A coarray that is default ... coarray in defined." with "A coarray may be referenced or defined by execution of an atomic intrinsic subroutine during the execution of a segment that is unordered relative to the execution of a segment in which the coarray is referenced or defined by execution of an atomic intrinsic subroutine." [191:Note 8.38] In Note 8.38 of "8.5.4 SYNC MEMORY", in the example code segment Replace the first line with these two lines: "USE,INTRINSIC :: ISO_FORTRAN_ENV LOGICAL(ATOMIC_LOGICAL_KIND),SAVE :: LOCKED[*] = .TRUE. LOGICAL :: VAL" in line 7 replace "LOCKED[Q] = .FALSE." with "CALL ATOMIC_DEFINE (LOCKED[Q], .FALSE.)", replace line 10 with these four lines: "VAL = .TRUE. DO WHILE (VAL) ! segment CALL ATOMIC_REF (LOCKED, VAL) END DO" [313:13.1p1] In "13.1 Classes of intrinsic procedures" paragraph 1, replace the whole paragraph with: [Note to Editor: this edit would replace the corresponding edit in 08-291r2.] "Intrinsic procedures are divided into seven classes: inquiry functions, elemental functions, transformational functions, elemental subroutines, pure subroutines, atomic subroutines, and (impure) subroutines." [313:13.1p2+] After paragraph 2 of "13.1 Classes of intrinsic procedures" add a new paragraph: "An <> is an intrinsic subroutine that performs an action on its ATOM argument atomically. The effect of executing an atomic subroutine is as if the action on the ATOM argument occurs instantaneously, and thus does not interfere with other atomic actions that might occur asynchronously." [316:13.5p2] In the table of Class identifiers in paragraph 2 of "13.5 Standard generic intrinsic procedures" add a new line at the beginning: " A indicates that the procedure is an atomic subroutine" [317:Table 13.1] In the generic intrinsic procedure summary table add "ATOMIC_DEFINE (ATOM, VALUE) A Defines ATOM with the value of VALUE" "ATOMIC_REF (VALUE, ATOM) A Defines VALUE with the value of ATOM" [327] After "13.7.11 ALLOCATED ..." add two new intrinsic subroutine: "13.7.11a ATOMIC_DEFINE (ATOM, VALUE) Description: Defines ATOM atomically with the value of VALUE. Class: Atomic subroutine. Arguments: ATOM shall be a scalar of type integer with kind ATOMIC_INT_KIND, or type logical with kind ATOMIC_LOGICAL_KIND. ATOMIC_INT_KIND and ATOMIC_LOGICAL_KIND are named constants in the ISO_FORTRAN_ENV intrinsic module. It is an INTENT(OUT) argument. ATOM becomes defined with the value of VALUE. VALUE shall have the same type as ATOM. It is an INTENT(IN) argument. Example: CALL ATOMIC_DEFINE (I[3], 4) causes I on image 3 to become defined with the value 4. 13.7.11b ATOMIC_REF (VALUE, ATOM) Description: Defines VALUE with the value of ATOM referenced atomically. Class: Atomic subroutine. Arguments: VALUE shall have same type as ATOM. It is an INTENT(OUT) argument. VALUE becomes defined with the value of ATOM. ATOM shall be a scalar of type integer with kind ATOMIC_INT_KIND, or type logical with kind ATOMIC_LOGICAL_KIND. ATOMIC_INT_KIND and ATOMIC_LOGICAL_KIND are named constants in the ISO_FORTRAN_ENV intrinsic module. It is an INTENT(IN) argument. Example: CALL ATOMIC_REF (I[3], VAL) causes VAL to become defined with the value of I on image 3." [395:13.8.2.1+] Add two new subsubclauses to "13.8.2 The ISO_FORTRAN_ENV intrinsic module" following "13.8.2.1 General": "13.8.2.1a ATOMIC_INT_KIND The value of the integer scalar constant ATOMIC_INT_KIND is the kind type parameter value of type integer variables for which the processor supports atomic operations specified by atomic subroutines. 13.8.2.1b ATOMIC_LOGICAL_KIND The value of the integer scalar constant ATOMIC_LOGICAL_KIND is the kind type parameter value of type logical variables for which the processor supports atomic operations specified by atomic subroutines."