13.7. Semantics and Correctness

PreviousUpNext
Up: One-Sided Communications Next: Atomicity Previous: Error Classes

The following rules specify the latest point in the execution of the application an operation must complete at the origin or the target. The update initiated by a call to MPI_GET in the origin process memory is visible when the get operation is complete at the origin (or earlier); the update initiated by a call to MPI_PUT or an accumulate procedure in the public copy of the target window is visible when the put or accumulate operation has completed at the target (or earlier). The rules also specify the latest point at which an update of one window copy becomes visible in another overlapping copy.

    1. An RMA operation is completed at the origin by the ensuing call to MPI_WIN_COMPLETE, MPI_WIN_FENCE, MPI_WIN_FLUSH, MPI_WIN_FLUSH_ALL, MPI_WIN_FLUSH_LOCAL, MPI_WIN_FLUSH_LOCAL_ALL, MPI_WIN_UNLOCK, or MPI_WIN_UNLOCK_ALL that synchronizes this access at the origin.
    2. If an RMA operation is completed at the origin by a call to MPI_WIN_FENCE then the operation is completed at the target by the matching call to MPI_WIN_FENCE by the target process.
    3. If an RMA operation is completed at the origin by a call to MPI_WIN_COMPLETE then the operation is completed at the target by the matching call to MPI_WIN_WAIT by the target process.
    4. If an RMA operation is completed at the origin by a call to MPI_WIN_UNLOCK or MPI_WIN_FLUSH (with rank =target), MPI_WIN_UNLOCK_ALL, or MPI_WIN_FLUSH_ALL, then the operation is completed at the target by that same call.
    5. An update of a location in a private window copy in MPI process memory becomes visible in the public window copy at the latest when an ensuing call to MPI_WIN_POST, MPI_WIN_FENCE, MPI_WIN_UNLOCK, MPI_WIN_UNLOCK_ALL, or MPI_WIN_SYNC is executed on that window by the window owner. In the RMA unified memory model, an update of a location in a private window in MPI process memory becomes visible without additional RMA calls.


    6. An update by a put or accumulate operation to a public window copy becomes visible in the private copy in MPI process memory at the latest when an ensuing call to MPI_WIN_WAIT, MPI_WIN_FENCE, MPI_WIN_LOCK, MPI_WIN_LOCK_ALL, or MPI_WIN_SYNC is executed on that window by the window owner. In the RMA unified memory model, an update by a put or accumulate operation to a public window copy eventually becomes visible in the private copy in MPI process memory without additional RMA calls.

The MPI_WIN_FENCE or MPI_WIN_WAIT call that completes the transfer from public copy to private copy (Rule Semantics and Correctness) is the same call that completes the put or accumulate operation in the window copy (Rule Semantics and Correctness, Rule Semantics and Correctness). If a put or accumulate access was synchronized with a lock, then the update of the public window copy is complete as soon as the updating origin process executed MPI_WIN_UNLOCK or MPI_WIN_UNLOCK_ALL. In the RMA separate memory model, the update of a private copy in the target process memory may be delayed until the target process executes a synchronization call on that window (Rule Semantics and Correctness). Thus, updates to target process memory can always be delayed in the RMA separate memory model until the target process executes a suitable synchronization call, while they must complete in the RMA unified model without additional synchronization calls. If fence or post-start-complete-wait synchronization is used, updates to a public window copy can be delayed in both memory models until the window owner executes a synchronization call. When passive target synchronization is used, it is necessary to update the public window copy even if the window owner does not execute any related synchronization call.

The rules above also define, by implication, when an update to a public window copy becomes visible in another overlapping public window copy. Consider, for example, two overlapping windows, win1 and win2. A call to MPI_WIN_FENCE on win1 by the window owner makes visible in the target process memory previous updates to window win1 by origin processes. A subsequent call to MPI_WIN_FENCE on win2 makes these updates visible in the public copy of win2.

The behavior of some MPI RMA operations may be undefined in certain situations. For example, the result of several origin processes performing concurrent put operations to the same target location is undefined. In addition, the result of a single origin process performing multiple put operations to the same target location within the same access epoch is also undefined. The result at the target may have all of the data from one of the put operations (the ``last'' one, in some sense), some bytes from each of the operations, or something else. In MPI-2, such operations were erroneous. That meant that an MPI implementation was permitted to raise an error. Thus, user programs or tools that used MPI RMA could not portably permit such operations, even if the application code could function correctly with such an undefined result. Starting with MPI-3, these operations are not erroneous, but do not have a defined behavior.
Rationale.

As discussed in [8], requiring operations such as overlapping puts to be erroneous makes it difficult to use MPI RMA to implement programming models---such as Unified Parallel C (UPC) or SHMEM---that permit these operations. Further, while MPI-2 defined these operations as erroneous, the MPI Forum is unaware of any implementation that enforces this rule, as it would require significant overhead. Thus, relaxing this condition does not impact existing implementations or applications. ( End of rationale.)

Advice to implementors.

Overlapping accesses are undefined. However, to assist users in debugging code, implementations may wish to provide a mode in which such operations are detected and reported to the user. Note, however, that starting with MPI-3, such operations must not raise an error. ( End of advice to implementors.)
A program with a well-defined outcome in the MPI_WIN_SEPARATE memory model must obey the following rules.

    1. A location in a window must not be accessed with load/store accesses once an update to that location has started, until the update becomes visible in the private window copy in target process memory.
    2. A location in a window must not be accessed as a target of an RMA operation once an update to that location has started, until the update becomes visible in the public window copy. There is one exception to this rule, in the case where the same variable is updated by two concurrent accumulates with the same predefined datatype, on the same window. Additional restrictions on the operation apply, see the info key accumulate_ops in Section Window Creation.
    3. A put or accumulate must not access a target window once a storeor a put or accumulate update to another (overlapping) window has started on a location in the target window, until the update becomes visible in the public copy of the window. Conversely, a store to MPI process memory to a location in a window must not start once a put or accumulate update to that target window has started, until the put or accumulate update becomes visible in target process memory. In both cases, the restriction applies to operations even if they access disjoint locations in the window.

Rationale.

The last constraint on correct RMA accesses may seem unduly restrictive, as it forbids concurrent accesses to nonoverlapping locations in a window. The reason for this constraint is that, on some architectures, explicit coherence restoring operations may be needed at synchronization points. A different operation may be needed for locations that were updated by stores and for locations that were remotely updated by put or accumulate operations. Without this constraint, the MPI library would have to track precisely which locations in a window were updated by a put or accumulate operation. The additional overhead of maintaining such information is considered prohibitive. ( End of rationale.)
Note that MPI_WIN_SYNC may be used within a passive target epoch to synchronize the private and public window copies (that is, updates to one are made visible to the other).

In the MPI_WIN_UNIFIED memory model, the rules are simpler because the public and private windows are the same. However, there are restrictions to avoid concurrent access to the same memory locations by different MPI processes. The rules that a program with a well-defined outcome must obey in this case are:

    1. A location in a window must not be accessed with load/store accesses once an update to that location has started, until the update is complete, subject to the special case laid out in Rule Semantics and Correctness.
    2. Accessing a location in the window that is also the target of a remote update is valid (not erroneous) but the precise result will depend on the behavior of the implementation. Updates from an origin process will appear in the memory of the target, but there are no atomicity or ordering guarantees if more than one byte is updated. Updates are stable in the sense that once data appears in the memory of the target, the data remains until replaced by another update. This permits polling on a location for a change from zero to nonzero or for a particular value, but not polling and comparing the relative magnitude of values. Users are cautioned that polling on one memory location and then accessing a different memory location has defined behavior only if the other rules given here and in this chapter are followed.


    Advice to users.

    Some compiler optimizations can result in code that maintains the sequential semantics of the program, but violates this rule by introducing temporary values into locations in memory. Most compilers only apply such transformations under very high levels of optimization and users should be aware that such aggressive optimization may produce unexpected results. ( End of advice to users.)

    3. Updating a location in the window with a store access that is also the target of a remote read (but not update) is valid (not erroneous) but the precise result will depend on the behavior of the implementation. Store updates will appear in memory, but there are no atomicity or ordering guarantees if more than one byte is updated. Updates are stable in the sense that once data appears in memory, the data remains until replaced by another update. This permits updates to memory with store accesses without requiring an RMA epoch. Users are cautioned that remote accesses to a window that is updated by the local MPI process has defined behavior only if the other rules given here and elsewhere in this chapter are followed.
    4. A location in a window must not be accessed as a target of an RMA operation once an update to that location has started and until the update completes at the target. There is one exception to this rule: in the case where the same location is updated by two concurrent accumulates with the same predefined datatype on the same window. Additional restrictions on the operation apply; see the info key accumulate_ops in Section Window Creation.
    5. A put or accumulate must not access a target window once a store, put, or accumulate update to another (overlapping) target window has started on the same location in the target window and until the update completes at the target window. Conversely, a store access to a location in a window must not be executed once a put or accumulate update to the same location in that target window has started and until the put or accumulate update completes at the target.


Advice to users. In the unified memory model, in the case where the window is in shared memory, MPI_WIN_SYNC can be used to order store accesses and make store updates to the window visible to other MPI processes and threads. Use of this routine is necessary to ensure portable behavior when point-to-point, collective, or shared memory synchronization is used in place of an RMA synchronization routine. MPI_WIN_SYNC should be called by both the reader and the writer of a shared memory variable between any non- RMA synchronization and access to that variable, as shown in Example Examples. The calls to MPI_WIN_SYNC can be replaced by language level memory synchronization operations, if available. ( End of advice to users.)
A program that violates these rules has undefined behavior.


Advice to users.

A user can write correct programs by following the following rules:

fence:
During each period between fence calls, each window is either updated by put or accumulate operation, or updated by stores, but not both. Locations updated by put or accumulate operations should not be accessed during the same period (with the exception of concurrent updates to the same location by accumulate operations). Locations accessed by get operations should not be updated during the same period.
post-start-complete-wait:
A window should not be updated with store accesses while posted if it is being updated by put or accumulate operations. Locations updated by put or accumulate operations should not be accessed while the window is posted (with the exception of concurrent updates to the same location by accumulate operations). Locations accessed by get operations should not be updated while the window is posted.

With the post-start synchronization, the target process can tell the origin process that its window is now ready for RMA access; with the complete-wait synchronization, the origin process can tell the target process that it has finished its RMA accesses to the window.

lock:
Updates to the window are protected by exclusive locks if they may conflict. Nonconflicting accesses (such as read-only accesses or accumulate accesses) are protected by shared locks, both for load/store accesses and for RMA accesses.
changing window or synchronization mode:
    One can change synchronization mode, or change the window used to access a location that belongs to two overlapping windows, when the MPI process memory and the window copy are guaranteed to have the same values. This is true for an MPI process after it has returned from MPI_WIN_FENCE, if RMA accesses to the window are synchronized with fences; after it has returned from MPI_WIN_WAIT, if the accesses are synchronized with post-start-complete-wait; it is true at the origin and target after the origin returned from a call to MPI_WIN_UNLOCK or MPI_WIN_UNLOCK_ALL if the accesses are synchronized with locks.

In addition, an origin process should not access the local buffer of a get operation until the operation is complete, and should not update the local buffer of a put or accumulate operation until that operation is complete.

The RMA synchronization operations define when updates are guaranteed to become visible in public and private windows. Updates may become visible earlier, but such behavior is implementation dependent. ( End of advice to users.)
The following examples illustrate these semantics.


Example The following example demonstrates updating a memory location inside a window for the separate memory model, according to Rule Semantics and Correctness. The MPI_WIN_LOCK and MPI_WIN_UNLOCK calls around the store to X in process B are necessary to ensure consistency between the public and private copies of the window.

Image file


Example In the RMA unified model, although the public and private copies of the windows are synchronized, caution must be used when combining load/store accesses with multi-process synchronization. Although the following example appears correct, the compiler or hardware may delay the store to X after the barrier, possibly resulting in the MPI_GET returning an incorrect value of X.

Image file

MPI_BARRIER provides process synchronization, but not memory synchronization. The example could potentially be made safe through the use of compiler- and hardware-specific notations to ensure the store to X occurs before process B enters the MPI_BARRIER. The use of one-sided synchronization calls, as shown in Example Semantics and Correctness, also ensures the correct result.


Example The following example demonstrates the reading of a memory location updated by an origin process (Rule Semantics and Correctness) in the RMA separate memory model. Although the call to MPI_WIN_UNLOCK on process A and the MPI_BARRIER ensure that the public copy on process B reflects the updated value of X, the call to MPI_WIN_LOCK by process B is necessary to synchronize the private copy with the public copy.

Image file

Note that in this example, the barrier is not critical to the semantic correctness. The use of exclusive locks guarantees no other MPI process will modify the public copy after MPI_WIN_LOCK synchronizes the private and public copies. A polling implementation looking for changes in X on process B would be semantically correct. The barrier is required to ensure that process A completes the put operation at the target before process B executes the load of X.


Example Similar to Example Semantics and Correctness, the following example is unsafe even in the unified model, because the load of X cannot be guaranteed to occur after the MPI_BARRIER. While Process B does not need to explicitly synchronize the public and private copies through MPI_WIN_LOCK as the MPI_PUT will update both the public and private copies of the window, the scheduling of the load could result in old values of X being returned. Compiler and hardware specific notations could ensure the load occurs after the data is updated, or explicit one-sided synchronization calls can be used to ensure the proper result.

Image file


Example The following example further clarifies Rule Semantics and Correctness. MPI_WIN_LOCK and MPI_WIN_LOCK_ALL do not update the public copy of a window with changes to the private copy. Therefore, there is no guarantee that process A in the following sequence will see the value of X as updated by the store by process B before the lock.

Image file

The addition of a call to MPI_WIN_SYNC before the call to MPI_BARRIER by process B would guarantee process A would see the updated value of X, as the public copy of the window would be explicitly synchronized with the private copy.


Example Similar to the previous example, Rule Semantics and Correctness can have unexpected implications for general active target synchronization with the RMA separate memory model. It is not guaranteed that process B reads the value of X as per the local update by process A, because neither the call to MPI_WIN_WAIT nor the call to MPI_WIN_COMPLETE by process A ensure visibility in the public window copy.

Image file

To allow process B to read the value of X stored by A, the local store must be replaced by a local put operation that updates the public window copy. Note that by this replacement X may become visible in the private copy of process A only after the MPI_WIN_WAIT call in process A. The update to Y made before the MPI_WIN_POST call is visible in the public window after the MPI_WIN_POST call and therefore process B will read the proper value of Y. The get of Y could be moved to the epoch opened by MPI_WIN_START, and process B would still get the value stored by process A.


Example The following example demonstrates the interaction of general active target synchronization with load accesses in the RMA separate memory model. Rules Semantics and Correctness and Semantics and Correctness do not guarantee that the private copy of X at process B has been updated before the load access is executed.

Image file

To ensure that the value put by process A is read, the load access must be replaced with a get operation, or must be placed after the call to MPI_WIN_WAIT.


PreviousUpNext
Up: One-Sided Communications Next: Atomicity Previous: Error Classes


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023