yohhoyの日記

技術的メモをしていきたい日記

volatile変数とOpenMP flush操作の短い関係

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 a flush 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.

OpenMP 3.0以降

OpenMP API Version 3.0仕様*3, APPENDIX Fより一部引用。

Changes from Version 2.5 to Version 3.0

  • The OpenMP memory model now covers atomicity of memory accesses (see Section 1.4.1 on page 13). The description of the behavior of volatile in terms of flush was removed.

関連URL