8.5. SOR AND MPI 337
71. call mpi_send(u(1,bn),(n+2),mpi_real,my_rank-1,50,&
72. mpi_comm_world,ierr)
73. call mpi_recv(u(1,en+2),(n+2),mpi_real,my_rank+1,50,&
74. mpi_comm_world,status,ierr)
75. call mpi_send(u(1,en+1),(n+2),mpi_real,my_rank+1,50,&
76. mpi_comm_world,ierr)
77. end if
78. if (my_rank.eq.p-1) then
79. call mpi_send(u(1,bn),(n+2),mpi_real,my_rank-1,50,&
80. mpi_comm_world,ierr)
81. call mpi_recv(u(1,bn-1),(n+2),mpi_real,my_rank-1,50,&
82. mpi_comm_world,status,ierr)
83. end if
84. if (my_rank.lt.p-1) then
85. j = en +1
86.! Do SOR for smaller interface blocks.
87. do i=2,n+1
88. utemp = (1000.*sin((i-1)*h*pi)*sin((j-1)*h*pi)*h*h&
89. + u(i-1,j) + u(i,j-1)&
90. + u(i+1,j) + u(i,j+1))*.25
91. u(i,j) = (1. -w)*u(i,j) + w*utemp
92. end do
93. errora(my_rank+1) = max1(errora(my_rank+1),&
94. maxval(abs(u(2:n+1,j)-uold(2:n+1,j))))
95. uold(2:n+1,j) = u(2:n+1,j)
96. endif
97.! Communicate computations to adjacent blocks.
98. if (my_rank.lt.p-1) then
99. call mpi_send(u(1,en+1),(n+2),mpi_real,my_rank+1,50,&
100. mpi_comm_world,ierr)
101. end if
102. if (my_rank.gt.0) then
103. call mpi_recv(u(1,bn-1),(n+2),mpi_real,my_rank-1,50,&
104. mpi_comm_world,status,ierr)
105. end if
106.! Gather local errors to pro cessor 0.
107. call mpi_gather(errora(my_rank+1),1,mpi_real,&
108. errora,1,mpi_real,0,&
109. mpi_comm_world,ierr)
110. call mpi_barrier(mpi_comm_world,ierr)
111.! On processor 0 compute the maximum of the local errors.
112. if (my_rank.eq.0) then
113. error = maxval(errora(1:p))
114. end if
115.! Send this global error to all processors so that
© 2004 by Chapman & Hall/CRC