Statement: Ends one image segment and begins another. Each segment can then be ordered in some way with respect to segments on other images. It takes the following form:
SYNC MEMORY [([STAT=stat-var][, ERRMSG=err-var])]
stat-var |
Is a scalar integer variable in which the status of the synchronization is stored. |
err-var |
Is a scalar default character variable in which an error condition is stored if such a condition occurs. |
STAT= and ERRMSG= can appear in either order, but only once in a SYNC IMAGES statement.
Unlike the other image control statements, this statement does not have any built-in synchronization effect.
The action regarding X on image Q precedes the action regarding Y on image Q if, by execution of statements on image P, the following is true:
A variable X on image Q is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about by execution of a statement
That statement precedes a successful execution of a SYNC MEMORY statement
A variable Y on image Q is defined, referenced, becomes undefined, or has its allocation status, pointer association status, array bounds, dynamic type, or type parameters changed or inquired about by execution of a statement that succeeds execution of that SYNC MEMORY statement,
User-defined ordering of segment Pi on image P to precede segment Qj on image Q occurs when the following happens:
Image P executes an image control statement that ends segment Pi, and then executes statements that initiate a cooperative synchronization between images P and Q
Image Q executes statements that complete the cooperative synchronization between images P and Q and then executes an image control statement that begins segment Qj
Execution of the cooperative synchronization between images P and Q must include a dependency that forces execution on image P of the statements that initiate the synchronization to precede the execution on image Q of the statements that complete the synchronization. The mechanisms available for creating such a dependency are processor dependent.
SYNC MEMORY usually suppresses compiler optimizations that may reorder memory operations across the segment boundary defined by the SYNC MEMORY statement. It ensures that all memory operations initiated in the preceding segments in its image complete before any memory operations in the subsequent segment in its image are started.
The following example demonstrates how SYNC MEMORY can be used to implement segment ordering. The example uses a specialized DO loop called a spin-wait loop:
LOGICAL, VOLATILE :: LOCKED[*] = .TRUE.
INTEGER(4) :: test, G, H
test = THIS_IMAGE()
IF (test == G) THEN
SYNC MEMORY
LOCKED[b] = .FALSE.
SYNC MEMORY
ELSE IF (test == H) then
DO WHILE (LOCKED)
END DO
SYNC MEMORY
END IF
Once image H starts executing the spin-wait loop, it will continue until it finds the value .FALSE. for LOCKED. The VOLATILE attribute causes the value to be retested during each loop execution. The effect is that the segment on image G before the first SYNC MEMORY statement precedes the segment on image H that follows the third SYNC MEMORY statement.
The second SYNC MEMORY statement tells the compiler to release the lock immediately rather than later in the following segment.
Copyright © 1996-2010, Intel Corporation. All rights reserved.