1

我正在尝试在 UPC 中编写矩阵乘法代码。如果我不使用 b_local 并直接使用 b,它的工作正常。但是当我通过 memget 函数使用 b_local 时,它会在“upc_memget”行崩溃并出现上述错误。

#define N 10   //Input  Matrix A = N*P
#define P 10   //Input  Matrix B = P*M
#define M 10   //Result Matrix C = N*M

shared [N*P /THREADS] double a[N][P] , c[N][M]; 
shared [M / THREADS] double b[P][M] ;
double b_local[P][M];

int main() {

//Initialization

if(MYTHREAD==0)
        gettimeofday(&start_time,NULL); 
    upc_barrier;

    upc_memget(b_local, b, P*M*sizeof(double));

    for (k=0; k<ITER; k++) {
        /* UPC_FORALL work-sharing construct for matrix multiplication */
        upc_forall(i=0;i<N;i++;&a[i][0])  {
            // &a[i][0] determines affinity
            for (j=0; j<M; j++) { 
                c[i][j] = 0; 
                for(l=0; l< P; l++) c[i][j] +=a[i][l]*b_local[l][j];    
            }
        }
    }

    upc_barrier;

if(MYTHREAD==0)
        gettimeofday(&end_time,NULL);



}
4

1 回答 1

2

upc_memget 获取与单个线程具有关联性的连续内存块。鉴于您对 b 的声明,大致存在P*M/THREADS与线程 0 具有关联性的元素,并且您的调用尝试P*M从该线程中获取元素 - 发生崩溃是因为您试图将未分配的内存复制到与线程 0 具有关联性的元素末尾之外。

于 2015-10-09T23:49:01.250 回答