[英]Task is to parallelize matrix multiplication with p-threads and vectorized with Intel ISPC compiler
In.ispc file using pthread generates errors as follows: (1) t.ispc:2:13: Error: Illegal to return a "varying" or vector type from exported function "matrix_mult_pl" export void * matrix_mult_pl( void *arg ) In.ispc 文件使用 pthread 生成错误如下: (1) t.ispc:2:13: Error: Illegal to return a "variating" or vector type from export function "matrix_mult_pl" export void * matrix_mult_pl( void *arg )
(2) t.ispc:2:36: Error: Varying pointer type parameter "arg" is illegal in an exported function. (2) t.ispc:2:36: Error: Varying pointer type parameter "arg" 在导出的 function 中是非法的。 export void * matrix_mult_pl( void *arg )
导出 void * matrix_mult_pl( void *arg )
(3) t.ispc:6:11: Error: syntax error, unexpected 'int'. (3) t.ispc:6:11: 错误:语法错误,意外'int'。 tid = *(int *)(arg);
tid = *(int *)(arg); // get the thread ID assigned sequentially.
// 获取顺序分配的线程 ID。 ^^^
^^^
and many more errors.以及更多错误。 Coder is attached below.
编码器附在下面。 Kindly look into the issue of using pthreads in ISPC.
请查看在 ISPC 中使用 pthreads 的问题。
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 ];
}
}
}
}
threads.ispc file线程.ispc 文件
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 ]; } } } }
Why is ISPC file not vectorizing the execution with parallelization by pthreads?为什么 ISPC 文件没有通过 pthreads 对执行进行矢量化处理?
The problem you're having is because ISPC defaults to varying
type.您遇到的问题是因为 ISPC 默认为
varying
的类型。 int x = 0
is the same as varying int x = 0
. int x = 0
与varying int x = 0
相同。 This applies to pointer types as well void *arg
as void varying * uniform arg
and you can't have varying types in exported functions.这适用于指针类型以及
void *arg
和void varying * uniform arg
并且在导出的函数中不能有不同的类型。 When porting and first getting started with ISPC it's best to be explicit with uniform
and varying
keywords.当移植和第一次开始使用 ISPC 时,最好使用
uniform
和varying
的关键字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.