[Omp] Flush

Marcel Beemster marcel at ace.nl
Fri Aug 3 02:17:25 PDT 2007


Doug,

You wrote:
> In the OpenMP spec is says that flush "makes a thread's temporary view 
> of memory consistent with memory."  This implies that the flush can 
> result in either a read or a write.  What determines whether a read or a 
> write will be performed?  Is it based on the most recent change, i.e., 
> whether the value in memory is newer or older than that in a register 
> or cache?  Thanks for the clarification.

The flush requires the temporary view anywhere in the
implementation of OpenMP to be made consistent with the
single shared memory. The temporary view may be anywhere in
the cache, run-time system or compiler generated code. The
spec is a requirement on the whole of the implementation, but
allows a lot of freedom in how it is implemented.

Intuitively, the implementation may postpone a write
between flushes by storing the value in a local register
(for example). At the flush, the implementation is required
to write it to the memory that is shared between all threads.

OpenMP requires that that a program (running multiple threads)
has no race conditions. (Allowing no unsynchronized writes to
the same variable.) This implies that at a flush only one of
a bunch of synchronized flushes can do a write. In turn this
implies that after a flush a thread may immediately re-instate
its temporary view by reading from memory. Also, if a thread
has a temporary view during a flush but did not write after
the last flush, it is not allowed to write, but is required
to read (or forget).

Ultimately, it helps to have a good understanding of memory
consistency models. There was a lengthy thread on the flush
specification vs compiler optimization a couple of months ago
on the omp mailing list. There is also a lot of literature
on memory consistency models in more general contexts than
OpenMP.

Best,
	Marcel

-- 
Dr. Marcel Beemster, Senior Software Engineer, marcel at ace.nl,www.ace.nl
Associated Compiler Experts bv. Amsterdam, Netherlands. +31 20 6646416.
-----------------------------------------------------------------------
This e-mail and any  files transmitted  with it are  confidential.  Any
technical information contained herein is supplied as-is, and no rights
can be  derived therefrom.  If you have received this message in error,
please notify  the sender by reply  e-mail immediately,  and delete the
message and all copies thereof.




More information about the Omp mailing list