To: J3 J3/14-158 From: Reinhold Bader Subject: atomic subroutine semantics and example for Annex Date: 2014 May 26 References: N1999, N2007 Discussion: ~~~~~~~~~~~ Starting from my comments on section A.3.2.2 in N1999, this paper proposes a rewording of the text that defines the atomic subroutine semantics as well as addition of another example to A.3.2.2. The text in N2007/[34:4-7] does not appear in section 7.2; conversely, the changes made in 7.2 are not completely applied in section 8.8. Fixes for both these issues are included. EDITS to N2007: ~~~~~~~~~~~~~~~ [17:12-15] Replace "The effect ... any other." by "For any two executions of atomic subroutines in unordered segments by different images on the same atomic object, the effect is as if one of the executions is performed before the other in one segment on a single image, without access to the object in either execution interleaving with access to the object in the other. Which is executed first is indeterminate." [[Reword in terms of the simplest building block that provides full generality, based on a suggestion by John Reid. Assure that the implementation is obliged to make the effect of all atomic updates visible on all images, independent of the presence of image control statements. "processor-dependent" appears misleading since the ordering may change between subsequent program runs as well as appear to be different on different images.]] [17:16+] After "2010.", insert "If two variables on image P are updated by a sequence of atomic memory operations, and the changes to them are observed by atomic accesses from an unordered segment on image Q, the changes need not be observed on image Q in the same order as they are made on image P, even if the updates on image P are made in ordered segments." [[This is a reworded version of the text from [34:4-7] essentially suggested by Bill Long, including a replacement of "sequence or atomic" by "sequence of atomic" - presumably a typo. Also, I've moved the text to an earlier location since this seems topically appropriate; in fact it may be desirable to turn [17:16-19] "For invocation ... atomic action." into a separate para.]] [17:19+] Add "NOTE 7.1- These properties support the use of atomic subroutines for designing customized synchronization mechanisms. The programmer needs to account for all possible orderings of sequences of atomic subroutine executions that may arise as a consequence of the above rules; the orderings may appear to be different on different images for the same program run." [[The above is intended to replace NOTE 13.1 of 10-007]] [34:1-7] Replace para by {In 13.1 Classes of intrinsic procedures, replace paragraph 3 by paragraph 1 [[maybe 1 and 2, see above]] of 7.2 Atomic subroutines, with these changes: Delete "of ISO/IEC 1539-1:2010"} {In 13.1 Classes of intrinsic procedures, replace the text of NOTE 13.1 with that of NOTE 7.1- in 7.2 Atomic subroutines.} [47:26+] "Example 4: Assuming the declarations INTEGER(ATOMIC_INT_KIND) :: x[*]= 0, z = 0 the statements CALL ATOMIC_ADD(x[1], 1) ! (A) IF (THIS_IMAGE() == 2) THEN wait : DO CALL ATOMIC_REF(z, x[1]) ! (B) IF (z == NUM_IMAGES()) EXIT wait END DO : wait ! (C) END IF will execute the "wait" loop on image 2 until all images have completed statement (A). The updates of x[1] are performed by each image in the same manner, but arbitrary order. Because the result from the complete set of updates will eventually become visible by execution of statement (B) for some loop iteration on image 2, the termination condition is guaranteed to be eventually fulfilled, provided that no image failure occurs, no image branches around the above code, and no other code is executed in an unordered segment that performs updates to x[1]. Furthermore, if two SYNC MEMORY statements are inserted in the above code before statement (A) and after statement (C), respectively, the segment started by the second SYNC MEMORY on image 2 is ordered after the segments on all images that end with the first SYNC MEMORY."