-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmmm.cpp
46 lines (41 loc) · 1.32 KB
/
mmm.cpp
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
42
43
44
45
46
#ifdef __cplusplus
extern "C" {
#endif
void bmm(double* matrixA, double* matrixB, double* matrixC, int length, int blockSize ) {
unsigned int block = blockSize * (length/blockSize);
double sum;
for (unsigned int kk = 0; kk < block; kk += blockSize) {
for (unsigned int jj = 0; jj < block; jj += blockSize) {
for (unsigned int i = 0; i < length; i++) {
for (unsigned int j = jj; j < jj + blockSize; j++) {
sum = matrixC[i*length+j];
for (unsigned int k = kk; k < kk + blockSize; k++) {
sum += matrixA[i*length+k] * matrixB[k*length+j];
}
matrixC[i*length+j] += sum;
}
}
}
}
}
void mmmijk(double* matrixA, double* matrixB, double* matrixC, int length) {
for(unsigned int i = 0; i < length; i++){
for(unsigned int j = 0; j < length; j++) {
for(unsigned int k = 0; k < length; k++) {
matrixC[i * length + j] += (matrixA[i * length + k] * matrixB[j * length + k]);
}
}
}
}
void mmmkji(double* matrixA, double* matrixB, double* matrixC, int length) {
for(unsigned int k = 0; k < length; k++) {
for(unsigned int j = 0; j < length; j++) {
for(unsigned int i = 0; i < length; i++){
matrixC[i * length + j] += (matrixA[i * length + k] * matrixB[j * length + k]);
}
}
}
}
#ifdef __cplusplus
}
#endif