PKUOS - Pintos
Pintos source browser for PKU Operating System course
src
examples
matmult.c
Go to the documentation of this file.
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
}
exit
void exit(int status)
Definition:
syscall.c:72
A
int A[DIM][DIM]
Definition:
matmult.c:31
C
int C[DIM][DIM]
Definition:
matmult.c:33
main
int main(void)
Definition:
matmult.c:36
B
int B[DIM][DIM]
Definition:
matmult.c:32
DIM
#define DIM
matmult.c
Definition:
matmult.c:29
Generated on Thu Nov 4 2021 19:31:00 for PKUOS - Pintos by
1.9.2