Solution
The correct answer is 0
EXPLANATION:
To determine the number of page faults, let's analyze the memory accesses in the given program. Since the table T is stored in row-major format, the program accesses elements in a contiguous manner within rows. Each row has 1024 elements, and there are 17 rows.
| 0, 0 |
0, 1 |
0, 2 |
... |
... |
... |
0, 1024 |
| 1, 0 |
|
|
|
|
|
|
| 2, 0 |
|
|
|
|
|
|
| ... |
|
|
|
|
|
|
| 17, 0 |
17, 1 |
17, 2 |
... |
... |
... |
17, 1024 |
The memory page size is 1024 words, and there are 16 pages. Each page can hold one row of the table.
Now, let's consider the nested loops:
for j in range(1024):
temp = 0
for i in range(17):
temp = temp + T[i][j]
print(temp/17.0)
The inner loop iterates over rows, so it sequentially accesses elements in a column (same column index j) for each iteration of the outer loop. This means that for each column, the inner loop will access 17 consecutive elements, which are located in 17 different rows.
Since each page can hold a full row (17 elements), accessing a column will result in a page fault for each iteration of the outer loop (for each column).
Therefore, the total number of page faults will be the number of columns multiplied by the number of page faults per column:
\(\text{Number of Page Faults} = \text{Number of Columns} \times \text{Number of Page Faults per Column}\)
\( \text{Number of Page Faults} = 1024 \times 17 = 17,408\)
According to above solution no any page hit in the main memory
So, the correct answer is: 1) 0