#pragma omp atomic

C に適用 C++ に適用

説明

omp atomic ディレクティブは、アトミックに更新しなければならない、また複数の同時書き込みスレッドに公開してはならない、特定のメモリー・ロケーションを識別します。

構文

#pragma omp atomic
    <statement_block>

ここで、statement は、以下に続く形式のいずれかを採るスカラー型の式ステートメントです。


statement 条件
x bin_op = expr ここで、

bin_op
は、以下のいずれかです。
+  *  -  /  &  ^  |  <<  >>

expr
は、x を参照しないスカラー型の式です。
x++  
++x  
x--  
--x  

ロードおよび保管の操作は、オブジェクト x に対してのみ atomic です。 expr の評価は、atomic ではありません。

プログラム内の指定オブジェクトに対するすべてのアトミック参照は、互換タイプを持っていなければなりません。

並列で更新できる、また、競合状態の対象となり得るオブジェクトは、 omp atomic ディレクティブで保護されているはずです。

extern float x[], *p = x, y;

/* Protect against race conditions among multiple updates.  */
#pragma omp atomic
x[index[i]] += y;

/* Protect against races with updates through x.            */
#pragma omp atomic
p[i] -= 1.0f;

関連参照

並列処理を制御するプラグマ IBM Copyright 2003