Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finished cache_unaware

  • Loading branch information...
commit 60e8c2db9452e7d8ecc02653456c748817b6f043 1 parent 2f21013
@pksunkara authored
View
2  INPUT
@@ -1,9 +1,11 @@
5 4 6
+
0 1 2 3
4 5 6 7
8 9 0 1
2 3 4 5
6 7 8 9
+
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 6 7 8
View
33 main.cpp
@@ -8,8 +8,18 @@
using namespace std;
+// External functions
+extern void cache_unaware(void);
+extern void cache_aware(void);
+extern void cache_oblivious(void);
+
// Global variable declaration
Access* accessor;
+int matrix_n, matrix_m, matrix_p;
+
+// Function prototype declaration
+int A(int x, int y);
+int B(int x, int y);
int main(int argc, char** argv) {
if(argc!=5) {
@@ -19,7 +29,6 @@ int main(int argc, char** argv) {
// Declaring variables
int i, j, buf;
- int matrix_n, matrix_m, matrix_p;
ifstream inFile;
// Opening files
@@ -49,8 +58,30 @@ int main(int argc, char** argv) {
accessor->write(buf);
}
+ // Cache Unaware matrix multiplication
+ cout << "Cache Unaware:" << endl;
+ cache_unaware();
+ cout << endl << "\tCache Statistics:" << endl << endl;
+
+ // Cache Aware matrix multiplication
+ cout << "Cache Aware:" << endl;
+ cache_aware();
+ cout << endl << "\tCache Statistics:" << endl << endl;
+
+ // Cache Oblivious matrix multiplication
+ cout << "Cache Oblivious:" << endl;
+ cache_oblivious();
+ cout << endl << "\tCache Statistics:" << endl << endl;
// Closing files
inFile.close();
return 0;
}
+
+int A(int x, int y) {
+ return accessor->get(x*matrix_m+y);
+}
+
+int B(int x, int y) {
+ return accessor->get(matrix_n*matrix_m+x*matrix_p+y);
+}
View
17 matrix/aware.cpp
@@ -1,6 +1,19 @@
#include <iostream>
-#include <cstdio>
#include <cstdlib>
#include "../access.h"
-void cache_aware(Access* accessor) {}
+using namespace std;
+
+// External variables & functions
+extern int matrix_n, matrix_m, matrix_p;
+extern int A(int, int);
+extern int B(int, int);
+
+void cache_aware(void) {
+ int i, j, k;
+
+ int** C = new int*[matrix_n];
+ for(i=0; i<matrix_n; i++) {
+ C[i] = new int[matrix_p];
+ }
+}
View
10 matrix/oblivious.cpp
@@ -1,6 +1,12 @@
#include <iostream>
-#include <cstdio>
#include <cstdlib>
#include "../access.h"
-void cache_oblivious(Access* accessor) {}
+using namespace std;
+
+// External variables & functions
+extern int matrix_n, matrix_m, matrix_p;
+extern int A(int, int);
+extern int B(int, int);
+
+void cache_oblivious(void) {}
View
26 matrix/unaware.cpp
@@ -2,5 +2,29 @@
#include <cstdlib>
#include "../access.h"
-void cache_unaware(Access* accessor, int n, int m, int p) {
+using namespace std;
+
+// External variables & functions
+extern int matrix_n, matrix_m, matrix_p;
+extern int A(int, int);
+extern int B(int, int);
+
+void cache_unaware(void) {
+ int i, j, k;
+
+ int** C = new int*[matrix_n];
+ for(i=0; i<matrix_n; i++) {
+ C[i] = new int[matrix_p];
+ }
+
+ for(i=0; i<matrix_n; i++) {
+ for(j=0; j<matrix_p; j++) {
+ C[i][j] = 0;
+ for(k=0; k<matrix_m; k++) {
+ C[i][j] += A(i,k)*B(k,j);
+ }
+ cout << "\t" << C[i][j];
+ }
+ cout << endl;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.