-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmult_omp.c
34 lines (32 loc) · 1.04 KB
/
mmult_omp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "mat.h"
/**
* An parallelized algorithm for matrix multiplication using OMP.
*
* @param c : the matrix in which to place the result of the matrix multiplication.
* @param a : the first matrix.
* @param aRows : the number of rows in a.
* @param aCols : the number of columns in a.
* @param b : the second matrix.
* @param bRows : the number of rows in b.
* @param bCols : the number of columns in b.
* @return 0 if the matrix multiplication is successful.
*/
int mmult_omp(double *c,
double *a, int aRows, int aCols,
double *b, int bRows, int bCols) {
int i, j, k;
#pragma omp parallel default(none) \
shared(a, b, c, aRows, aCols, bRows, bCols) private(i, k, j)
#pragma omp for
for (i = 0; i < aRows; i++) {
for (j = 0; j < bCols; j++) {
c[i*bCols + j] = 0;
}
for (k = 0; k < aCols; k++) {
for (j = 0; j < bCols; j++) {
c[i*bCols + j] += a[i*aCols + k] * b[k*bCols + j];
}
}
}
return 0;
}