Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Now matrices are not square

  • Loading branch information...
commit 2f210136d44d0e7025a3d1bdff0b52ca1389110f 1 parent 4a32809
@pksunkara authored
Showing with 33 additions and 38 deletions.
  1. +10 −11 INPUT
  2. +5 −6 access.cpp
  3. +3 −3 access.h
  4. +13 −16 main.cpp
  5. +2 −2 matrix/unaware.cpp
View
21 INPUT
@@ -1,11 +1,10 @@
-10
-0 1 2 3 4 5 6 7 8 9
-1 2 3 4 5 6 7 8 9 10
-2 3 4 5 6 7 8 9 10 11
-3 4 5 6 7 8 9 10 11 12
-4 5 6 7 8 9 10 11 12 13
-5 6 7 8 9 10 11 12 13 14
-6 7 8 9 10 11 12 13 14 15
-7 8 9 10 11 12 13 14 15 16
-8 9 10 11 12 13 14 15 16 17
-9 10 11 12 13 14 15 16 17 18
+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
+9 0 1 2 3 4
View
11 access.cpp
@@ -4,8 +4,7 @@
using namespace std;
-Access::Access(int matrix_n, int memory_size) {
- this->matrix_n = matrix_n;
+Access::Access(int memory_size) {
this->memory = new Memory(memory_size);
}
@@ -13,12 +12,12 @@ void Access::write(int value) {
this->memory->write(value);
}
-void Access::set(int x, int y, int value) {
- this->memory->store(x*matrix_n+y, value);
+void Access::set(int addr, int value) {
+ this->memory->store(addr, value);
}
-int Access::get(int x, int y) {
- return this->memory->read(x*matrix_n+y);
+int Access::get(int addr) {
+ return this->memory->read(addr);
}
Access::~Access(void) {
View
6 access.h
@@ -6,11 +6,11 @@
class Access {
public:
- Access(int matrix_n, int memory_size);
+ Access(int memory_size);
void write(int value);
- void set(int x, int y, int value);
- int get(int x, int y);
+ void set(int addr, int value);
+ int get(int addr);
~Access(void);
View
29 main.cpp
@@ -11,9 +11,6 @@ using namespace std;
// Global variable declaration
Access* accessor;
-// Global prototype decalaration
-int M(int, int);
-
int main(int argc, char** argv) {
if(argc!=5) {
printf("Usage: %s <cache_size_inKB> <block_size_inB> <associativity> <memory_size_inKB>\n", argv[0]);
@@ -22,7 +19,7 @@ int main(int argc, char** argv) {
// Declaring variables
int i, j, buf;
- int matrix_n;
+ int matrix_n, matrix_m, matrix_p;
ifstream inFile;
// Opening files
@@ -34,26 +31,26 @@ int main(int argc, char** argv) {
return 1;
}
- // Reading Matrix Length
- inFile >> matrix_n;
-
// Initalize accessor
- accessor = new Access(matrix_n, atoi(argv[4]));
+ accessor = new Access(atoi(argv[4]));
+
+ // Reading matrix lengths
+ inFile >> matrix_n >> matrix_m >> matrix_p;
- // Reading matrix
- for(i=0; i<matrix_n; i++) {
- for(j=0; j<matrix_n; j++) {
+ // Reading matrices A & B
+ for(i=0; i<matrix_n; i++)
+ for(j=0; j<matrix_m; j++) {
+ inFile >> buf;
+ accessor->write(buf);
+ }
+ for(i=0; i<matrix_m; i++)
+ for(j=0; j<matrix_p; j++) {
inFile >> buf;
accessor->write(buf);
}
- }
// Closing files
inFile.close();
return 0;
}
-
-int M(int x, int y) {
- return accessor->get(x, y);
-}
View
4 matrix/unaware.cpp
@@ -1,6 +1,6 @@
#include <iostream>
-#include <cstdio>
#include <cstdlib>
#include "../access.h"
-void cache_unaware(Access* accessor) {}
+void cache_unaware(Access* accessor, int n, int m, int p) {
+}
Please sign in to comment.
Something went wrong with that request. Please try again.