

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


/ Before / int val[SIZE];
int key[SIZE];
/ After /
struct merge {
int val;
int key; };
struct merge merged_array[SIZE];
A(4,5)
A(5,3)
A(6,1)
A(4,6) A(5,6) A(6,6)
A(5,4) A(6,4) A(1,5) A(2,5) A(3,5) A(5,5) A(6,5) A(1,6) A(2,6) A(3,6)
A(6,2) A(1,3) A(2,3) A(3,3) A(4,3) A(6,3) A(1,4) A(2,4) A(3,4) A(4,4)
A(1,1) A(2,1) A(3,1) A(4,1) A(5,1) A(1,2) A(2,2) A(3,2) A(4,2) A(5,2)
A(5,4)
A(3,5)
A(1,6)
A(6,4) A(6,5) A(6,6)
A(4,5) A(4,6) A(5,1) A(5,2) A(5,3) A(5,5) A(5,6) A(6,1) A(6,2) A(6,3)
A(2,6) A(3,1) A(3,2) A(3,3) A(3,4) A(3,6) A(4,1) A(4,2) A(4,3) A(4,4)
A(1,1) A(1,2) A(1,3) A(1,4) A(1,5) A(2,1) A(2,2) A(2,3) A(2,4) A(2,5)
/ Before / for (j = 0; j < 100; j = j+1) for (i = 0; i < 5000; i = i+1) x[i][j] = 2 * x[i][j];
/ After / for (i = 0; i < 5000; i = i+1) for (j = 0; j < 100; j = j+1) x[i][j] = 2 * x[i][j];
A(3,5)
A(1,6)
A(2,6)A(3,1) A(3,2) A(3,3) A(3,4) A(3,6) A(4,1) A(4,2) A(4,3) A(4,4)
A(1,1)A(1,2) A(1,3) A(1,4) A(1,5) A(2,1) A(2,2) A(2,3) A(2,4) A(2,5)
Temporal locality: 2 misses per access to a & c vs. one miss per access
6x16x26x36x46x5 6x
5x15x25x35x45x55x
4x14x24x34x44x54x
3x13x23x33x43x53x
2x12x22x32x42x52x
1x11x21x31x41x51x
for ( i = 0; i < N; i = i+1) for ( j = 0; j < N; j = j+1) {r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][ k]z[k][ j];}; x[i] [j] = r; };*
Read all N x N elements of z[ ] Read N elements of 1 row of y[ ] repeatedly
Write N elements of 1 row of x[ ]
6x16x26x36x46x5 6x
5x15x25x35x45x55x
4x14x24x34x44x54x
3x13x23x33x43x53x
2x12x22x32x42x52x
1x11x21x31x41x51x
–When no capacity misses: O(3 NxN)
temporal locality)
6x 6
6x 5
6x 4
6x 3
6x 2
6x 1
5x 6
5x 5
5x 4
5x 3
5x 2
5x 1
4x 6
4x 5
4x 4
4x 3
4x 2
4x 1
3x 6
3x 5
3x 4
3x 3
3x 2
3x 1
2x 6
2x 5
2x 4
2x 3
2x 2
2x 1
1 x 6
1 x 5
1 x 4
1 x 3
1 x 2
1x
/ After / for ( jj = 0; jj < N; jj = jj+B) for ( kk = 0; kk < N; kk = kk+B) for ( i = 0; i < N; i = i+1) for (j = jj; j < m i n (jj+ B-1,N); j = j+ 1 ) {r = 0; for (k = kk; k < m i n (kk+ B-1,N); k = k+1) { r = r + y[i][ k]z[k][ j];}; x[i] [j] = x[ i][j ] + r; };*
jj
kk
jj
kk
jj
kk
jj
kk
jj jj kk kk
reduce conflicts
Blocking Factor
Fully Associative Cache
Direct Mapped Cache