c - OpenMP 4.0 的卸载指令

标签 c openmp intel xeon-phi

我正在测试一个带有三个 Intel Xeon Phi 卡的节点。我的 想法是使用 OpenMP 4.0 指令来卸载任务 协处理器。代码如下(取自http://goo.gl/9Ztq0e):

/***************************************************************************************************
* FILE          : openmp4x-reduce-1Darray.c
*
* INPUT         : Nil
*
* OUTPUT        : Displays Host and device reduce sum
*
* CREATED       : August,2013
*
* EMAIL         : hpcfte@cdac.in
*
***************************************************************************************************/

#include <stdio.h>

 #define SIZE 10000
 #pragma omp declare target

int reduce(int *inarray)
{

  int sum = 0;
  #pragma omp target map(inarray[0:SIZE]) map(sum)
  {
    for(int i=0;i<SIZE;i++)
    sum += inarray[i];
  }
  return sum;
}

int main()
{
  int inarray[SIZE], sum, validSum;

  validSum=0;
  for(int i=0; i<SIZE; i++){
  inarray[i]=i;
  validSum+=i;
  }

 sum=0;
 sum = reduce(inarray);

 printf("sum reduction = %d,validSum=%d\n",sum, validSum);
}

我用 intel/16.0.1.150 编译器编译了它(我在 Intel 网站上读到 这个编译器支持OpenMP 4.0,也许我错了)。除此之外 我使用了变量:

export MIC_ENV_PREFIX=MIC
export MIC_OMP_NUM_THREADS=240
export MIC_KMP_AFFINITY=granularity=fine,compact

icc -openmp -std=c99 -qopt-report2 openmp_4.0_reduce_1Darray.c -o exec

问题是当我运行代码时,然后我使用 micsmc-gui(图形界面)来查看协处理器上内核的性能。我什么 不明白为什么每个协处理器似乎只使用一个核心 与我在 MIC 上使用的线程数无关,请参见红色矩形 在图中的每个 MIC 上。

performance of MICs

有什么建议吗?

谢谢。

最佳答案

您尚未指定任何并行指令,因此循环是顺序的。 尝试添加 openmp 并行指令,以便将循环迭代分布在 MIC 的多个核心上

    int reduce(int *inarray)
    {

      int sum = 0;
      #pragma omp target map(inarray[0:SIZE]) map(sum)
      {
        #pragma omp parallel for reduction(+:sum)
        for(int i=0;i<SIZE;i++)
          sum += inarray[i];
      }
      return sum;
    }

一些基本文档: https://computing.llnl.gov/tutorials/openMP/#DO

关于c - OpenMP 4.0 的卸载指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35152278/

相关文章:

c - 在 C 中使用 union 将 double float 分解为字节

c - 如何将自上次打开文件以来经过的秒数转换为小时、分钟和秒?

c - 当我在 While 循环中使用浮点值时,为什么我的程序会进入无限循环?

android - OpenMp 与 IOS/Android 的兼容性

python - 多线程prange循环抛出 "double free or corruption (fasttop)"错误

c++ - 使用 OpenMP 的较慢代码如何并行化?

intel - 混洗两个 __m128i 的 64 位部分的最佳方法

assembly - intel 8086处理器标志寄存器中保留位和未定义位之间的区别

c - 删除链表中的连续元素

javascript - 英特尔 xdk 不工作的通知警报