retagged by
2,173 views
3 votes
3 votes

Given an array A[100] of which each element size is 4 words. Processor uses a Cache Memory which is divided into 4 lines each of size 8 words to execute the following code

for(i=0; i<100; ++i)
{
    A[i] = A[i] + 10;
}

What is the Hit Rate?
(assume storage in Row Major Order)


point I needed to extract from this question is : for calculation of hit ratio do we count a write operation as Hit or only Read operations are counted

retagged by

2 Answers

Best answer
7 votes
7 votes
We consider both read and write operation for hit ratio.

{a[0] a[1]} stored in one block as each block is of 8 words and each array element takes 4 words (array start assumed to be a block start - aligned).

For first access to a[0] (read), it is miss. For write it is not miss. For a[1] both read and write are hits.
So, out of 4 memory access we got 3 hits. And this continues for all $i$ till 100.
So, hit  ratio$ =3/4.$
selected by
0 votes
0 votes

till yet wt i have studied is :only READ operation is counted..

solution :

each element is of 4 words. 

no of blocks in cache memory is 4 and each line size is of 8 wordsmeans  each cache line will hold TWO elements

as all elements are stored in row major order..

a[0]=a[0]+10

=0+10

=10

a[1]=a[1]+10

=1+10

=11

means one block of cache contain two words ie 10 th and 11 th word therefore now total we have to access 90 elements. when block will be mapped in cache than first reference will always be miss and next cosecutive element in cache line  will be HIT .therefore in total of 45 blocks will be accessed from main memory giving 45 MISS and 45 HIT.

HIT RATIO =45/90

HIT RATIO=0.5 

 

Related questions

0 votes
0 votes
0 answers
1
amitqy asked Mar 16, 2019
305 views
Can someone please provide a link to an article or a video explaining cache and arrays concept. Im having a hard time understanding that concept.