Question

Consider matrix transpose written in C. Which array is exhibiting spatial locality: array "a", "b", or...

Consider matrix transpose written in C. Which array is exhibiting spatial locality: array "a", "b", or both? (Note that NROWS and NCOLS could each be relatively large compared to the size of the cache.)

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

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

         b[i][j] = a[j][i];

       }

     }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Array 'b' exhibits spatial locality
Array 'a' does not.



Add a comment
Know the answer?
Add Answer to:
Consider matrix transpose written in C. Which array is exhibiting spatial locality: array "a", "b", or...
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
  • 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...

  • The following code is written in C, where elements within the same row are stored contiguously....

    The following code is written in C, where elements within the same row are stored contiguously. Assume each word is a 32-bit integer. for (I = 0; I < 8; I++) for (J = 0; J < 8000; J++) A[I][J] = B[I][0] + A[J][I]; 5.1.1 How many 32-bit integers can be stored in a 16-byte cache block? 5.1.2 References to which variables exhibit temporal locality? 5.1.3 References to which variables exhibit spatial locality?

  • 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...

  • Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written...

    Problem1: BMPmain.c, BMPfns.c, BMPfns.h, Makefile The file 'BMPmain.c' contains a main() function which is already written for you and attached with this homework. When appropriate functions are provided, main() will create a .bmp image file. Your job is to write 'BMPfns.c' which contains the functions which main() uses to create .bmp image files. You must also write the header file 'BMPfns.h' to #include in BMPmain.c and which contains prototypes of the functions defined in BMPfns.c . Problem2: BMPcheckerboard.c, BMPfns.c, BMPfns.h,...

  • The second problem, the one I'm asking about, is only making changes to the first problem, which ...

    The second problem, the one I'm asking about, is only making changes to the first problem, which I have included the correct code for. Thank you!! een be modeled by diding the plate io adiscrese grid of cels and sulting the change in tenspentureof ell over 90 2.2 3) dared es dlebel css (saggestion:use5 both ves w fint, ut increme this 1o 20asee you get yeur pragranı warking. Your progrars shcald do the Sllasing lain the cs alus of the...

  • Given the following code sequence calculating a matrix norm. double c[96], a[96][96]; for (i=0; i<95; i=++...

    Given the following code sequence calculating a matrix norm. double c[96], a[96][96]; for (i=0; i<95; i=++ ) { c[i] = c[i] + a[i][i]*a[i][i+1]; } with a and c being arrays of double precision floating point numbers with each element being 8 bytes. No element of a or c is in the cache before executing this code. Please assume row-major ordering. Assuming that the cache is large enough to hold both a and c, and has a cache block size of...

  • Implement optimized C/C++ code using code optimization techniques Consider an image to be represented as a...

    Implement optimized C/C++ code using code optimization techniques Consider an image to be represented as a two-dimensional matrix M, where Mi,j denotes the value of M[i][j] th pixel of M. Pixel values are triples of red, green, and blue (RGB) values. We will only consider square images. Let N denote the number of rows (or columns) of an image (NxN square image). Rows and columns are numbered, in C-style, from 0 to N-1. Given this representation, the rotate operation can...

  • 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...

  • I need this written in C++. Magic Squares. An n x n matrix that is filled...

    I need this written in C++. Magic Squares. An n x n matrix that is filled with the numbers 1,2,3,…,n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. The following algorithm will construct magic n x n squares; it only works if n is odd: Place 1 in the middle of the bottom row. After k has been placed in the (i,j) square,...

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