我正在使用具有动态数组分配的 OpenACC。以下是我的分配方式:
float **a;
float **b;
float **c;
float **seq;
a=(float**)malloc(SIZE*sizeof(float*));
b=(float**)malloc(SIZE*sizeof(float*));
c=(float**)malloc(SIZE*sizeof(float*));
seq=(float**)malloc(SIZE*sizeof(float*));
for(i=0; i<SIZE; i++){
a[i]=(float*)malloc(SIZE*sizeof(float));
b[i]=(float*)malloc(SIZE*sizeof(float));
c[i]=(float*)malloc(SIZE*sizeof(float));
seq[i]=(float*)malloc(SIZE*sizeof(float));
}
这是我如何并行矩阵添加:
#pragma acc kernels copyin(a[0:SIZE][0:SIZE],b[0:SIZE][0:SIZE]) copy(c[0:SIZE][0:SIZE])
for (i = 0; i < SIZE; ++i) {
for (j = 0; j < SIZE; ++j) {
c[i][j] = a[i][j] + b[i][j];
}
}
当我用它编译这段代码时,pgcc
它会检测循环迭代上对指针的依赖float**
并生成所有标量内核(每块 1 个块 1 个线程),其性能不如预期:
40, Complex loop carried dependence of '*(*(b))' prevents parallelization
Complex loop carried dependence of '*(*(a))' prevents parallelization
Complex loop carried dependence of '*(*(c))' prevents parallelization
Accelerator scalar kernel generated
CC 1.0 : 11 registers; 40 shared, 4 constant, 0 local memory bytes
CC 2.0 : 22 registers; 0 shared, 56 constant, 0 local memory bytes
循环显然是并行的,我认为编译器也可以检测到这一点。我很好奇如何解释它pgcc
?
提前致谢。