retagged by
1,277 views
4 votes
4 votes

Consider an array A[200] and each element occupies 8-words. A 64-word cache is used and divided into 16-word blocks. What is the hit ratio for the following code segment:

for(int i=0; i<200; i++)
A[i] = A[i]+5

  1.   0.85
  2.  0.65
  3.   0.95
  4.   0.75
retagged by

3 Answers

4 votes
4 votes
In the cache, there will be 4 blocks as 1 block=16 words. Now In main memory, we will require 100 blocks to hold the 200 elements of the array. Further, In one block there can be two elements present.

And each element of the array is referred two times.

At first, it will generate miss for A[0] while reading the value of A[0] but when it comes to writing its value, the reference will be a hit as the element is already present in the cache. For A[1] both for reading and writing it will be a hit coz it is already in cache because it was present in the same block as that of A[0].

So For each block, there will be 3 hits and 1 miss

hit ratio=total hits/total references

            =(3*100)/2*200

            =0.75
0 votes
0 votes
For one instruction A[i] = A[i] + 5;

          No. of hits = 1 +1 + 1 = 3

          No. of misses = 1

For 200 instructions,

          No. of hits =  3 * 200 = 600

          No. of misses = 1 * 200 = 200

hit ratio = 600 / (600 + 200) = 0.75
0 votes
0 votes

Read A[0] will bring A[0], A[1] in cache with one miss 

now write A[0], read A[1] and write A[1] will be hit 

and this will continue upto A[198], A[199]

Related questions

8 votes
8 votes
4 answers
1
0 votes
0 votes
1 answer
2
nirupama thakur asked Mar 17, 2018
2,004 views
In some problems we multiply only with the second part of the equation with (1-H1) component and leave the first part. Whereas in other cases we multiply with cache hit a...