upc

Issue with upc_memget: Caught a fatal signal : SIGSEGV(11) on node 2/4


I'm trying to write a matrix multiplication code in UPC. If I don't use b_local and directly use b, its working fine. But when I use b_local via memget function, it crashes at the line "upc_memget" with the above error.

#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);



}

Solution

  • upc_memget fetches a contiguous block of memory with affinity to a single thread. Given your declaration of b, there are roughly P*M/THREADS elements with affinity to thread 0 and your call tries to fetch P*M elements from that one thread - the crash occurs because you are trying to copy unallocated memory beyond the end of the elements with affinity to thread 0.