aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/matmult.c
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/examples/matmult.c
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/examples/matmult.c')
-rw-r--r--src/examples/matmult.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/examples/matmult.c b/src/examples/matmult.c
new file mode 100644
index 0000000..4f0615f
--- /dev/null
+++ b/src/examples/matmult.c
@@ -0,0 +1,57 @@
+/* matmult.c
+
+ Test program to do matrix multiplication on large arrays.
+
+ Intended to stress virtual memory system.
+
+ Ideally, we could read the matrices off of the file system,
+ and store the result back to the file system!
+ */
+
+#include <stdio.h>
+#include <syscall.h>
+
+/* You should define DIM to be large enough that the arrays
+ don't fit in physical memory.
+
+ Dim Memory
+ ------ --------
+ 16 3 kB
+ 64 48 kB
+ 128 192 kB
+ 256 768 kB
+ 512 3,072 kB
+ 1,024 12,288 kB
+ 2,048 49,152 kB
+ 4,096 196,608 kB
+ 8,192 786,432 kB
+ 16,384 3,145,728 kB */
+#define DIM 128
+
+int A[DIM][DIM];
+int B[DIM][DIM];
+int C[DIM][DIM];
+
+int
+main (void)
+{
+ int i, j, k;
+
+ /* Initialize the matrices. */
+ for (i = 0; i < DIM; i++)
+ for (j = 0; j < DIM; j++)
+ {
+ A[i][j] = i;
+ B[i][j] = j;
+ C[i][j] = 0;
+ }
+
+ /* Multiply matrices. */
+ for (i = 0; i < DIM; i++)
+ for (j = 0; j < DIM; j++)
+ for (k = 0; k < DIM; k++)
+ C[i][j] += A[i][k] * B[k][j];
+
+ /* Done. */
+ exit (C[DIM - 1][DIM - 1]);
+}