How is loop loop loop parallel?

I read about the methods of tranformation of a loop, and it is very difficult for me to understand how the distortions in the loop make the loop parallelizable. Here are two cycles: the initial and the second, what is the difference between the two? Both of them depend on the previous iteration on both i and j, what makes the second cycle paralyzed? Or why can we make an exchange on the second, and not on the first? Both of them have dependencies on i and j

for(int i =2; i < 5; i++){
            for(int j =2; j < 5; j++){
                A[i][j] = A[i-1][j] + A[i][j-1];
            }
        }
for(int i =2; i < 5; i++){
            for(int j =2+i; j < 5+i; j++){
                A[i][j-i] = A[i-1][j-i] + A[i][j-1-i];
            }
        }
+4
source share
1 answer

I have no advantage to this, I just formatted it for you and copied it from another source, and I hope that it will help you

[: ECE 1754, , Eric LaForest, 19 2010 .]

, 1 , .

, : . , , . , {(1, 0), (0, 1)}. . , , .

do i = 2, n-1
do j = 2, m-1
a[i,j] =
      (a[a-1,j] + a[i,j-1] + a[i+1,j] + a[i,j+1]) / 4
end do
end do

, f, . , . - f , . , (a, b), (a, f a + b). , . :

do i = 2, n-1
do j = 2+i, m-1+i
a[i,j-i] =
(a[a-1,j-i] + a[i,j-1-i] + a[i+1,j-i] + a[i,j+1-i]) / 4
end do
end do

, {(1, 1), (0, 1)}. - . {(1, 0), (1, 1)}, :

do j = 4, m+n-2
do i = max(2, j-m+1), min(n-1, j-2)
a[i,j-i] =
(a[a-1,j-i] + a[i,j-1-i] + a[i+1,j-i] + a[i,j+1-i]) / 4
end do
end do

, j, . , : .

+2

Source: https://habr.com/ru/post/1536691/


All Articles