原子最小操作的高性能工具 [英] High performance implement of atomic minimal operation

查看:125
本文介绍了原子最小操作的高性能工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 variable x 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读取和更新(按您想要的顺序);实际上,capturereadupdate构造的组合:

  • 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;}
    

  • 最后还有另外的readupdate,它们仅以结构块形式存在:

  • 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;}
    

  • 在前面的表达式中:

    • xv均为 l值表达式
    • expr是标量类型的表达式;
    • binop+*-/&^|<<>>之一;
    • binopbinop=++--不是重载运算符.
    • x and v 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆