原子最小操作的高性能工具 [英] High performance implement of atomic minimal operation
问题描述
OpenMP中没有原子的最小操作,英特尔MIC的指令集中也没有固有的最小操作.
There is no atomic minimal operation in OpenMP, also no intrinsic in Intel MIC's instruction set.
#pragmma omp critial
的性能非常不足.
我想知道是否有用于Intel MIC的atomic minimal
高性能工具.
I want to know if there is a high performance implement of atomic minimal
for Intel MIC.
推荐答案
根据 OpenMP 4.0规范(第2.12.6节),有很多快速的原子最小操作,您可以使用#pragma omp atomic
构造代替#pragma omp critical
(从而避免其锁定的巨大开销.
According to the OpenMP 4.0 Specifications (Section 2.12.6), there is a lot of fast atomic minimal operations you can do by using the #pragma omp atomic
construct in place of #pragma omp critical
(and thereby avoid the huge overhead of its lock).
让x
作为您的线程共享变量:
Let x
be your thread-shared variable:
-
使用
#pragma omp atomic read
,您可以自动让您的共享变量x
被读取:
With
#pragma omp atomic read
you can atomically let your shared variablex
be read:
v = x;
使用#pragma omp atomic write
,您可以为共享变量x
原子分配一个新值;新值表达式(expr
)必须与x
无关:
With #pragma omp atomic write
you can atomically assign a new value to your shared variable x
; the new value expression (expr
) has to be x
-independant:
x = expr;
使用#pragma omp atomic update
,您可以自动更新共享变量x
;实际上,您只能在独立于x
的表达式和x
之间将新值分配为二进制运算(binop
):
With #pragma omp atomic update
you can atomically update your shared variable x
; in fact you can only assign a new value as a binary operation (binop
) between an x
-independant expression and x
:
x++;
x--;
++x;
--x;
x binop= expr;
x = x binop expr;
x = expr binop x;
使用#pragma omp atomic capture
,您可以自动地让共享变量x
读取和更新(按您想要的顺序);实际上,capture
是read
和update
构造的组合:
With #pragma omp atomic capture
you can atomically let your shared variable x
be read and updated (in the order you want); in fact capture
is a combination of the read
and update
construct:
-
您有
update
然后是read
的简写形式:
v = ++x;
v = --x;
v = x binop= expr;
v = x = x binop expr;
v = x = expr binop x;
和它们的结构块类似物:
And their structured-block analogs:
{--x; v = x;}
{x--; v = x;}
{++x; v = x;}
{x++; v = x;}
{x binop= expr; v = x;}
{x = x binop expr; v = x;}
{x = expr binop x; v = x;}
您可以使用read
然后是update
的几种缩写形式:
And you have a few short forms for read
and then update
:
v = x++;
v = x--;
以及它们的结构块类似物:
And again their structured-block analogs:
{v = x; x++;}
{v = x; ++x;}
{v = x; x--;}
{v = x; --x;}
最后还有另外的read
和update
,它们仅以结构块形式存在:
And finally you have additional read
then update
, which only exists in structured-block forms :
{v = x; x binop= expr;}
{v = x; x = x binop expr;}
{v = x; x = expr binop x;}
{v = x; x = expr;}
在前面的表达式中:
-
x
和v
均为 l值表达式; -
expr
是标量类型的表达式; -
binop
是+
,*
,-
,/
,&
,^
,|
,<<
或>>
之一; -
binop
,binop=
,++
和--
不是重载运算符.
x
andv
are both l-value expressions with scalar type;expr
is an expression with scalar type;binop
is one of+
,*
,-
,/
,&
,^
,|
,<<
or>>
;binop
,binop=
,++
and--
are not overloaded operators.
这篇关于原子最小操作的高性能工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!