아래는 모두 psudo code
대체먼뜻이노 컴공아니라서 모르겠다
1. Memory Use
- Bad
For j = 1:n
For i = 1:n
a(i,j) = f(i, j)
b(i,j) = g(i, j)
total = a(i, j) + b(i,j)
- Good
For j = 1:n
For i = 1:n
a(i,j) = f(i, j)
For j = 1:n
For i = 1:n
b(i,j) = g(i, j)
For j = 1:n
For i = 1:n
total = a(i, j) + b(i,j)
2. Discontinuous Memory
- Bad
Common x, y(9), part(9), zpart1(50000), zpart2(50000), w(9)
For j = 1:n
y(j) = x * part(j) / w(9)
-Good
Common x, y(9), part(9), w(9), zpart1(50000), zpart2(50000)
For j = 1:n
y(j) = x * part(j) / w(J)
It is difficult to ensure the placement of variables in page boundaries. Improve program by grouping data elements together.
3. Cash Flow
- Bad (Stride jdim fetch)
Dimension Vec(idim, jdim)
For i=1, idim
For j=1, jdim
Ans = Ans + Norm Vec(i,j)
- Good (Stride 1 fetch)
Dimension Vec(idim, jdim)
For j=1, jdim
For i=1, idim
Ans = Ans + Norm Vec(i,j)