9.6. GMRES(M) AND MPI 373
The following is a partial listing of an MPI implementation of GMRES(m).
It solves the same partial di
erential equation as in the previous section where
the M
ATLA B code pcgmres.m used GMRES. Lines 1-66 are the initialization of
the code. The outer loop of GMRES(m) is executed in the while loop in lines
66-256. The inner loop is expected in lines 135-230, and here the restart m is
given by kmax. The new initial guess is defined in lines 112-114 where the new
initial residual is computed. The GMRES implementation is similar to that used
in the M
AT LAB code pcgmres.m. The additive Schwarz SSOR preconditioner
is also used, but here it changes with the number of processors. Concurrent
calculations used to do the matrix products, dot products and vector updates
are similar to the MPI code cgssormpi.f.
MPI/Fortran Code gmresmmpi.f
1. program gmres
2.! This code approximates the solution of
3.! -u_xx - u_yy + a1 u_x + a2 u_y + a3 u = f
4.! GMRES(m) is used with a SSOR verson of the
5.! Schwarz additive preconditioner.
6.! The sparse matrix product, dot products and updates
7.! are also done in parallel.
8. implicit none
9. include ’mpif.h’
10. real, dimension(0:1025,0:1025,1:51):: v
11. real, dimension(0:1025,0:1025):: r,b,x,rhat
12. real, dimension(0:1025):: xx,yy
13. real, dimension(1:51,1:51):: h
14. real, dimension(1:51):: g,c,s,y,mag
15. real:: errtol,rho,hik,hipk,nu,gk,gkp,w,t0,timef,tend
16. real :: loc_rho,loc_ap,loc_error,temp
17. real :: hh,a1,a2,a3,ac,ae,aw,an,as,rac
18. integer :: nx,ny,n,kmax,k,i,j,mmax,m,sbn
19. integer :: my_rank,proc,source,dest,tag,ierr,loc_n
20. integer :: status(mpi_status_size),bn,en
Lines 21-56 initialize arrays and are not listed
57. call mpi_init(ierr)
58. call mpi_comm_rank(mpi_comm_world,my_rank,ierr)
59. call mpi_comm_size(mpi_comm_world,proc,ierr)
60. loc_n = (n-1)/proc
61. bn = 1+(my_rank)*loc_n
62. en = bn + loc_n -1
63. call mpi_barrier(mpi_comm_world,ierr)
64. if (my_rank.eq.0) then
65. t0 = timef()
66. end if
67.! Begin restart loop.
© 2004 by Chapman & Hall/CRC