第十五章 并行程序设计环境与工具
习题例题:
分析下列代码段中三条语句间的相关关系;给出相应的相关方向向量和相关距离向量:
DO I=I,N
DO J=2,N
S1: A(I,J)=A(1,J-1)+B(I,J)
S2: c(r,J)=A(I,J)+D(I+1,J)
S3: D(I,J)=0.1
ENDDO
ENDDO
2、判定下列的循环,哪些是可向量化的:
DO I=1,N
S1: A(I)=B(I)
S2: C(I)=A(I) +B(I)
S3: E(I) =C(I+1)
ENDDO
② DO 1=1,N
S1; AM --B(I)+C(I+1)
S2: C(I)=A(I) * D(I)
ENDDO
③ DO I=1,N
Sl: A(I)=A(1-1)+1
ENDDO
④ Do I=1,N
Sl: A(I)=A(I+1)+1
ENDDO
⑤ DO I=2,N
DO J =2,M
A(I, J)=A(t,J-I)+1
ENDDO
ENDDO
试向量化下列代码段:
① DIMENSION A(200,200),B(200,200),C(200,200)
DO I =1, 200
DO J =1, 200
A(I,J) = B(I,J) * C(I.J)
ENDDO
ENDDO
② DO i=1,100
C(I)=0.0
DO J=1,100
C(I)=C(I) +A(I,J) * B(J)
ENDDO
ENDDO
③ DO 1=1,N
B(1,1)=0
DO 1=1,M
A(I) =A(I) + B(I, J) * C(I,J)
ENDDO
D(I)=E(I)+A(I)
ENDDO
④ DO I=2,N
S1: T(I)=A(I-1)+A(I+1)
S2: A(I)=B(I)+C(I)
ENDDO
分析下列循环,那些是可并行化的:
①DO I=2,N
A(I) =B(I)-A(I-1)
ENDDO
②DO I=2,N,2
A(I) =B(I)-A(I-1)
ENDDO
③DO I=I,N
X= SQRT(A(I) )
B(I)=X*C(I)+X*D(I)
ENDDO
④INDX=O
DO I=A,N
INDX= INDX+ 1
A(I) = B(I) + C(INDX)
ENDDO
⑤DO I=I,N
IF(A(I ) · LT· EPSILON) GOTO 320
A(I)=A(I) * B(I)
ENDDO
320 CONTINUE
分析下列循环的语句数据相关性;如何进行循环调度并行化:
DO I=I,N
DO J=2,N
S1: A(1,J)=B(1,J)+C(I,J)
S2: C(I,J)=D(I,J)/2
S3: E(I,J)=A(I,J-1) * *2+E(I,J-1)
ENDDO
ENDDO