首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >任务是使用p线程并行化矩阵乘法,并使用Intel ISPC编译器向量化

任务是使用p线程并行化矩阵乘法,并使用Intel ISPC编译器向量化
EN

Stack Overflow用户
提问于 2020-04-25 02:39:28
回答 1查看 187关注 0票数 1

在.ispc文件中使用pthread会产生如下错误:(1) t.ispc:2:13:错误:从导出函数"matrix_mult_pl“export void * matrix_mult_pl( void *arg )返回"varying”或向量类型是非法的。

(2) t.ispc:2:36:错误:变量指针类型参数"arg“在导出函数中非法。导出void * matrix_mult_pl( void *arg )

(3) t.ispc:6:11:错误:语法错误,意外的'int‘。tid = *(int *)(arg);//获取顺序分配的线程ID。^^^

还有更多的错误。编码器附在下面。请研究一下在ISPC中使用pthread的问题。

threads.c文件

代码语言:javascript
复制
/**
 * Thread routine.
 * Each thread works on a portion of the 'matrix1'.
 * The start and end of the portion depend on the 'arg' which
 * is the ID assigned to threads sequentially. 
 */
void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

threads.ispc文件

代码语言:javascript
复制
export void * matrix_mult_pl( void *arg )
{
  int rows, cols, j, tid, portion_size, row_start, row_end;

  tid = *(int *)(arg); // get the thread ID assigned sequentially.
  portion_size = size / num_threads;
  row_start = tid * portion_size;
  row_end = (tid+1) * portion_size;

  for (rows = row_start; rows < row_end; ++rows) { // hold row index of 'matrix1'
    for (j = 0; j < size; ++j) { // hold column index of 'matrix2'
     // hold value of a cell
      /* one pass to sum the multiplications of corresponding cells
     in the row vector and column vector. */
      for(cols=0; cols<size; cols++) { 
        result_pl[ rows ][ cols ] += matrix1[ rows ][ j ] * matrix2[ j ][ cols ];
      }
    }
  }
}

为什么ISPC文件不能通过pthread并行化来向量化执行?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-09 16:06:10

您遇到的问题是因为ISPC默认为varying类型。int x = 0varying int x = 0相同。这同样适用于指针类型以及void varying * uniform arg,并且你不能在导出的函数中有不同的类型。在移植和第一次开始使用ISPC时,最好明确使用uniformvarying关键字。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61415258

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档