Skip to content

Commit 24eef22

Browse files
authored
Update matrix_mul_omp.cpp with #pragma omp parallel (#2328)
1 parent 3385824 commit 24eef22

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

DirectProgramming/C++SYCL/DenseLinearAlgebra/matrix_mul/src/matrix_mul_omp.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ void MatrixMulOpenMpCpu(float (*a)[N], float (*b)[P], float (*c)[P]) {
7575
for (i = 0; i < M; i++)
7676
for (j = 0; j < P; j++) c[i][j] = 0.0f;
7777

78-
// Parallelize by row. The threads don't need to synchronize at
79-
// loop end, so "nowait" can be used.
80-
#pragma omp for nowait private(i, j, k)
81-
for (i = 0; i < M; i++) {
82-
for (k = 0; k < N; k++) {
83-
// Each element of the product is just the sum 1+2+...+n
84-
for (j = 0; j < P; j++) {
85-
c[i][j] += a[i][k] * b[k][j];
78+
// Parallelize by row. The threads don't need to synchronize at
79+
// loop end, so "nowait" can be used.
80+
#pragma omp parallel
81+
{
82+
#pragma omp for nowait private(i, j, k)
83+
for (i = 0; i < M; i++) {
84+
for (k = 0; k < N; k++) {
85+
// Each element of the product is just the sum 1+2+...+n
86+
for (j = 0; j < P; j++) {
87+
c[i][j] += a[i][k] * b[k][j];
88+
}
8689
}
8790
}
8891
}

0 commit comments

Comments
 (0)