Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some small part of cache aware

  • Loading branch information...
commit a9b5e0e9f21c32b875139e43e84abcab1cdb2f02 1 parent 60e8c2d
@pksunkara authored
Showing with 19 additions and 7 deletions.
  1. +2 −2 main.cpp
  2. +16 −2 matrix/aware.cpp
  3. +1 −3 matrix/unaware.cpp
View
4 main.cpp
@@ -10,7 +10,7 @@ using namespace std;
// External functions
extern void cache_unaware(void);
-extern void cache_aware(void);
+extern void cache_aware(int);
extern void cache_oblivious(void);
// Global variable declaration
@@ -65,7 +65,7 @@ int main(int argc, char** argv) {
// Cache Aware matrix multiplication
cout << "Cache Aware:" << endl;
- cache_aware();
+ cache_aware(atoi(argv[2])/4);
cout << endl << "\tCache Statistics:" << endl << endl;
// Cache Oblivious matrix multiplication
View
18 matrix/aware.cpp
@@ -9,11 +9,25 @@ 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;
+void cache_aware(int s) {
+ int i, j, k, ibuf, jbuf, kbuf;
int** C = new int*[matrix_n];
for(i=0; i<matrix_n; i++) {
C[i] = new int[matrix_p];
}
+
+ for(ibuf=0; ibuf<matrix_n/s; ibuf++)
+ for(jbuf=0; jbuf<matrix_n/s; jbuf++)
+ for(kbuf=0; kbuf<matrix_n/s; kbuf++)
+ for(i=ibuf; i<min(ibuf+s-1,matrix_n); i++)
+ for(j=jbuf; j<min(jbuf+s-1,matrix_n); j++)
+ for(k=kbuf; k<min(kbuf+s-1,matrix_n); k++)
+ C[i][j] += A(i,k)*B(k,j);
+
+ for(i=0; i<matrix_n; i++) {
+ for(j=0; j<matrix_p; j++)
+ cout << "\t" << C[i][j];
+ cout << endl;
+ }
}
View
4 matrix/unaware.cpp
@@ -19,10 +19,8 @@ void cache_unaware(void) {
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++) {
+ 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.