C/C++言語 volatile修飾とOpenMP flush操作の関係についてメモ。
要約:
- OpenMP 2.5以前:volatile変数への読込/書込アクセスは、それぞれ暗黙のOpenMP flush操作を伴う。
- OpenMP 3.0以降:volatile変数アクセスはOpenMPメモリモデル(≒Memory Consistency)に影響を与えない。
OpenMP 2.5以前
OpenMP C/C++ API Version 2.0仕様*1, 2.6.5 flush Directiveより該当箇所を引用。
A reference that accesses the value of an object with a volatile-qualified type behaves as if there were a
flush
directive specifying that object at the previous sequence point. A reference that modifies the value of an object with a volatile-qualified type behaves as if there were aflush
directive specifying that object at the subsequent sequence point.
OpenMP API Version 2.5仕様*2, 1.4.2 The Flush Operationより該当箇所を引用。
The
volatile
keyword in the C and C++ languages specifies a consistency mechanism that is related to the OpenMP memory consistency mechanism in the following way: a reference that reads the value of an object with a volatile-qualified type behaves as if there were a flush operation on that object at the previous sequence point, while a reference that modifies the value of an object with a volatile-qualified type behaves as if there were a flush operation on that object at the next sequence point.