diff options
Diffstat (limited to 'examples/matmult.c')
| -rw-r--r-- | examples/matmult.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/matmult.c b/examples/matmult.c new file mode 100644 index 0000000..4f0615f --- /dev/null +++ b/examples/matmult.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* matmult.c | ||
| 2 | |||
| 3 | Test program to do matrix multiplication on large arrays. | ||
| 4 | |||
| 5 | Intended to stress virtual memory system. | ||
| 6 | |||
| 7 | Ideally, we could read the matrices off of the file system, | ||
| 8 | and store the result back to the file system! | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <stdio.h> | ||
| 12 | #include <syscall.h> | ||
| 13 | |||
| 14 | /* You should define DIM to be large enough that the arrays | ||
| 15 | don't fit in physical memory. | ||
| 16 | |||
| 17 | Dim Memory | ||
| 18 | ------ -------- | ||
| 19 | 16 3 kB | ||
| 20 | 64 48 kB | ||
| 21 | 128 192 kB | ||
| 22 | 256 768 kB | ||
| 23 | 512 3,072 kB | ||
| 24 | 1,024 12,288 kB | ||
| 25 | 2,048 49,152 kB | ||
| 26 | 4,096 196,608 kB | ||
| 27 | 8,192 786,432 kB | ||
| 28 | 16,384 3,145,728 kB */ | ||
| 29 | #define DIM 128 | ||
| 30 | |||
| 31 | int A[DIM][DIM]; | ||
| 32 | int B[DIM][DIM]; | ||
| 33 | int C[DIM][DIM]; | ||
| 34 | |||
| 35 | int | ||
| 36 | main (void) | ||
| 37 | { | ||
| 38 | int i, j, k; | ||
| 39 | |||
| 40 | /* Initialize the matrices. */ | ||
| 41 | for (i = 0; i < DIM; i++) | ||
| 42 | for (j = 0; j < DIM; j++) | ||
| 43 | { | ||
| 44 | A[i][j] = i; | ||
| 45 | B[i][j] = j; | ||
| 46 | C[i][j] = 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | /* Multiply matrices. */ | ||
| 50 | for (i = 0; i < DIM; i++) | ||
| 51 | for (j = 0; j < DIM; j++) | ||
| 52 | for (k = 0; k < DIM; k++) | ||
| 53 | C[i][j] += A[i][k] * B[k][j]; | ||
| 54 | |||
| 55 | /* Done. */ | ||
| 56 | exit (C[DIM - 1][DIM - 1]); | ||
| 57 | } | ||
