[英]Segmentation fault while matrix multiplication using openMp?
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.. 我假设这仅是因为矩阵对象,但是即使将其作为参数传递,为什么也会为null。
I ran into the same problem while compiling my code under Linux using GCC 4.2. 在使用GCC 4.2的Linux下编译代码时,我遇到了同样的问题。 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
下指定以下项来设置线程数:
#pragma omp for num_threads(nthreads)
Hope it helps! 希望能帮助到你!
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").
如果正确定义了矩阵ID,则崩溃的可能原因是大小不正确(“ ld”)。
Regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.