tags:

views:

174

answers:

2

My matrix multiplication code is

int matMul(int ld, double** matrix)
{ 

  //local variables initialize

  omp_set_num_threads(nthreads);


  \#pragma omp parallel private(tid,diag,ld) shared(i,j,k,matrix)

  {
    /* Obtain and print thread id */

    tid = omp_get_thread_num();

    for ( k=0; k<ld; k++)  {
    if (matrix[k][k] == 0.0) {
      error = 1;
      return error;
    }
    diag = 1.0 / matrix[k][k];
\#pragma omp for 

    for ( i=k+1; i < ld; i++) {

      matrix[i][k] = diag * matrix[i][k];

    }
    for ( j=k+1; j<ld; j++) {

      for ( i=k+1; i<ld; i++) {

        matrix[i][j] = matrix[i][j] - matrix[i][k] * matrix[k][j];

      }

    }
  } 

  }  
  return error;

}

I assume that it is because of matrix object only but why will it be null even though it is passed as a parameter..

A: 

I assume that your "matrix" is an array of pointers to the actual matrix' rows, something like:

double *matrix[NROWS];
for (i = 0; i < NROWS; ++i) {
    matrix[i] = malloc(sizeof(double)*NCOL);
}

But if "matrix" is defined this way

double matrix[NROWS][NCOL];

your program can't work. If your matrix id defined properly, a possible reason of crash mey be an incorrect size ("ld").

Regards

Giuseppe Guerrini
A: 

I ran into the same problem while compiling my code under Linux using GCC 4.2. The line that is causing the problem is:

omp_set_num_threads(nthreads);

You should try to set the number of threads by specifying it under pragma omp for:

#pragma omp for num_threads(nthreads)

Hope it helps!

sovarm