【发布时间】:2017-11-15 08:33:42
【问题描述】:
我正在学习一点关于 openMP 的知识,并尝试在这里使用它来将两个矩阵相乘。
void matrix_multiply(matrix *A, matrix *B, matrix *C) {
#pragma omp parallel
{
#pragma omp for
for(int i = 0; i < A->dim.rows; i++) {
for(int j = 0; j < B->dim.cols; j++) {
C->data[i][j] = 0;
for (int k = 0; k < A->dim.cols; k++) {
C->data[i][j] += A->data[i][k] * B->data[k][j];
}
}
}
}
}
typedef struct shape {
int rows;
int cols;
} shape;
typedef struct matrix {
shape dim;
float** data;
} matrix;
对此还有点新意,那么是否有任何简单的更改来提高性能或者我已经这样做了?我是否也因为不使用归约而陷入任何数据竞争?
【问题讨论】: