-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmultOpt.c
43 lines (34 loc) · 1011 Bytes
/
mmultOpt.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
35
36
37
38
39
40
41
/**
* An unoptimized implementation of matrix multiplication.
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include "mat.h"
/**
* An unoptimized algorithm for matrix multiplication.
*
* @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 mmultOpt(double *c,
double *a, int aRows, int aCols,
double *b, int bRows, int bCols) {
for(int i = 0; i < aCols; i++) {
for(int j = 0; j < bRows; j++) {
c[i * bCols + j] = 0;
}
for(int k = 0; k < aCols; k++) {
for(int l = 0; l < bRows; l++){
c[i * bCols + l] += a[i * aRows + k] * b[k * bCols + l];
}
}
}
return 0;
}