Question

Cache performance The starting code would have: struct position { int x; int y; } int...

Cache performance

The starting code would have:

struct position {

int x; int y; }

int N;

struct position grid[N][N];

int totalX=0;

int totalY=0;

int i, j;

//For X loop

for( i = 0; i < N; i ++){

for( j = 0; j < N; j++){

totalX += grid[i][j].x; } }

//For Y loop

for( j = 0; j < N; j++){

for( i = 0; i < N; i++){

totalY += grid[i][j].y; } }

Part I: This part does not require coding. Given that: N = 16, the cache is 1024-byte direct-mapped data cache with 16-byte blocks (B=16), sizeof(int) =4, grid begins at memory address 0, the cache is initially empty, The only memory accesses are to the entries of the array grid. Variables i, j, totalX, totalY are stored in registers.

1) Calculate the total number of reads in the X loop.

2) Calculate the total number of read that miss in the cache in the X loop.

Part II: Use the code above as a template. For each case N=1000, N=2000, N=5000, N=8000: Randomize the values of x and y for all the position object inside the grid struct. Then record the time it takes to finish X loop and Y loop. The time should be in milliseconds.

3) Compare these 2 time values and give me your thoughts on the difference.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Cache performance The starting code would have: struct position { int x; int y; } int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • D Question 10 1 pts Suppose that we have an L1 cache of this configuration: •...

    D Question 10 1 pts Suppose that we have an L1 cache of this configuration: • B=32 bytes • S= 64 • E = 1 • C = 2048 bytes What is the cache miss rate (as a percentage) when we execute the following C code? Assume that the grid data structure is aligned on a cache block boundary in memory and that the cache is cold. struct { double x; double y; } grid[16][16]; for(i = 0; i <...

  • Suppose that we have an L1 cache of this configuration: Block size 32 bytes Number of...

    Suppose that we have an L1 cache of this configuration: Block size 32 bytes Number of sets 64 Associativity = 1 Capacity-2048 bytes What is the cache miss rate (as a percentage) when we execute the following C code? Assume that the grid data structure is aligned on a cache block boundary in memory and that the cache contains no valid lines initially. struct double x; double y; grid[16] [16]; forCi = 0; i < 16; i++) for(j 0; j...

  • Incorrect 0/1 pts Question 10 Suppose that we have an L1 cache of this configuration: •...

    Incorrect 0/1 pts Question 10 Suppose that we have an L1 cache of this configuration: • B = 32 bytes • S= 64 • E = 1 • C = 2048 bytes What is the cache miss rate (as a percentage) when we execute the following C code? Assume that the grid data structure is aligned on a cache block boundary in memory and that the cache is cold. struct { double x; double y; } grid[16][16]; for(i = 0;...

  • Consider the C program shown below int i int a [1024 1024] int x = 0;...

    Consider the C program shown below int i int a [1024 1024] int x = 0; for (iso; i 1024, i++) { x = x + a[i] + a[1024 * i]; Suppose the code above is executed on a system with a direct mapped 16 KB data cache with block size 4. Assume that the address of matrix starts at o and I and x are in registers and initially the cache is empty. a) b) What is the miss...

  • Consider a 64-bit computer with a simplified memory hierarchy. This hierarchy contains a single cache and...

    Consider a 64-bit computer with a simplified memory hierarchy. This hierarchy contains a single cache and an unbounded backing memory. The cache has the following characteristics: • Direct-Mapped, Write-through, Write allocate. • Cache blocks are 4 words each. • The cache has 256 sets. (a) Calculate the cache’s size in bytes. (b) Consider the following code fragment in the C programming language to be run on the described computer. Assume that: program instructions are not stored in cache, arrays are...

  • 14 Points Bonus Question: Consider the following transpose routine: typedef int array (212): void transposel (array...

    14 Points Bonus Question: Consider the following transpose routine: typedef int array (212): void transposel (array dst, array sre) int i, j; for(i=0; i<2; i++) { for (-0; j 2; j++){ dst sre[BG); Assume that this code runs on a machine with the following properties: • sizeof(int) = 4 • The src array starts at address and the dst array starts at address 16 There is a single L1 cache that is direct-mapped, write through, write allocate, with a block...

  • 12,21,13,32,27,23,34,19,34,23,36,39 estion 16 12 points A direct-mapped cache has 4 blocks and each block holds four...

    12,21,13,32,27,23,34,19,34,23,36,39 estion 16 12 points A direct-mapped cache has 4 blocks and each block holds four bytes of data. The memory system is byte addressable Determine if each of the memory references below is a hit H) or miss (Ml. You assume the cach Reference 12 21 13 32 27 23 HIM? Moving to another question will save this response Question 16 of 18 Case Window 888 Am 4 @ JN 5 3 8 0 D W E 70 T...

  • Consider the following matrix transpose routines: typedef int array[4][4]; void transpose (array dst, array src) {...

    Consider the following matrix transpose routines: typedef int array[4][4]; void transpose (array dst, array src) {     int i, j;     for (i=0; i<4; i++) {    for (j=0; j<4; j++) {           dst[i][j] = src[i][j];    }     } } void transpose2 (array dst, array src) {     int i, j;     for (i=0; i<4; i++) {    for (j=0; j<4; j++) {           dst[j][i] = src[j][i];    }     } } Assume this code runs on...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • task1 code: #include <stdio.h> #include <sys/time.h> int main() { struct timeval start,end; //to store time of starting and ending of program gettimeofday(&start,0); printf("Time...

    task1 code: #include <stdio.h> #include <sys/time.h> int main() { struct timeval start,end; //to store time of starting and ending of program gettimeofday(&start,0); printf("Time in microsecond for every second: \n"); //output for(int i=0;i<100;i++) //outer loop to run 100 times { struct timeval loopstart,loopend; //to store time of starting and ending of loop gettimeofday(&loopstart,0); //measuring time at start of loop for(int j=0;j<1000000;j++); //outer loop to run 1000000 times gettimeofday(&loopend,0); //measuring time at end of loop //calculating time for one iteration long ms=(loopend.tv_sec-loopstart.tv_sec)*1000000...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT