正在加载图片...
11.4.3 The Flush Operation The memory model has relaxed-consistency because a thread's temporary view of memory is not required to be consistent with memory at all times.A value written to a variable can remain in the thread's temporary view until it is forced to memory at a later time.Likewise,a read from a variable may retrieve the value from the thread's 67 unless it is for ced to read fro ry.The OpenMP fush operation rteney betwcen the temporary view and memory The flush operation is applied to a set of variables called the flush-set.The flush 101 otherwise do.Impler mentatio ns must not r 12 operation that refers to the same variable. 1 If a thread has performed a write to its temporary view of a shared variable since its last 14 flush of that variable,then when it executes another flush of the variable,the flush does 1516 not complete until the value of the in memory If a thread performs multiple writes to the same variable between two flushes of that 17 variable,the flush ensures that the value of the last write is written to the variable in 1 memory.A flush of a variable executed by a thread also causes its temporary view of the 19 variable to be discarded,so that if its next memory operation for that variable is a read. then the thread will read from memory when itn gain capture the value in the 21 temporary view.When a fush,no ater memory operation by that 2 thread for a variable involved in that flush is allowed to start until the flush completes The completion of a flush of a set of variables executed by a thread is defined as the point at which all writes to those variables performed by the thread before the flush are visible in memory to all other threads and that thread's temporary view of all variables involved is discarded 27 The flush operation provides a guarantee of consistency between a thread's temporary view and memory.Therefore,the flush operation can be used to guarantee that a value written to a variable by one thread may be read by a second thread.To accomplish this 31 ogrammer must ensure that the second thread has not written to the variable si the p flush of the variable,and that the following sequence of events happens in the 3 specified order: 33 1.The value is written to the variable by the first thread. 34 2.The variable is flushed by the first thread. 35 3.The variable is flushed by the second thread. 36 4.The value is read from the variable by the second thread Chapter 1 Introduction 19Chapter 1 Introduction 19 1.4.3 The Flush Operation The memory model has relaxed-consistency because a thread’s temporary view of memory is not required to be consistent with memory at all times. A value written to a variable can remain in the thread’s temporary view until it is forced to memory at a later time. Likewise, a read from a variable may retrieve the value from the thread’s temporary view, unless it is forced to read from memory. The OpenMP flush operation enforces consistency between the temporary view and memory. The flush operation is applied to a set of variables called the flush-set. The flush operation restricts reordering of memory operations that an implementation might otherwise do. Implementations must not reorder the code for a memory operation for a given variable, or the code for a flush operation for the variable, with respect to a flush operation that refers to the same variable. If a thread has performed a write to its temporary view of a shared variable since its last flush of that variable, then when it executes another flush of the variable, the flush does not complete until the value of the variable has been written to the variable in memory. If a thread performs multiple writes to the same variable between two flushes of that variable, the flush ensures that the value of the last write is written to the variable in memory. A flush of a variable executed by a thread also causes its temporary view of the variable to be discarded, so that if its next memory operation for that variable is a read, then the thread will read from memory when it may again capture the value in the temporary view. When a thread executes a flush, no later memory operation by that thread for a variable involved in that flush is allowed to start until the flush completes. The completion of a flush of a set of variables executed by a thread is defined as the point at which all writes to those variables performed by the thread before the flush are visible in memory to all other threads and that thread’s temporary view of all variables involved is discarded. The flush operation provides a guarantee of consistency between a thread’s temporary view and memory. Therefore, the flush operation can be used to guarantee that a value written to a variable by one thread may be read by a second thread. To accomplish this, the programmer must ensure that the second thread has not written to the variable since its last flush of the variable, and that the following sequence of events happens in the specified order: 1. The value is written to the variable by the first thread. 2. The variable is flushed by the first thread. 3. The variable is flushed by the second thread. 4. The value is read from the variable by the second thread. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有