dpigmr.f 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. *DECK DPIGMR
  2. SUBROUTINE DPIGMR (N, R0, SR, SZ, JSCAL, MAXL, MAXLP1, KMP, NRSTS,
  3. + JPRE, MATVEC, MSOLVE, NMSL, Z, V, HES, Q, LGMR, RPAR, IPAR, WK,
  4. + DL, RHOL, NRMAX, B, BNRM, X, XL, ITOL, TOL, NELT, IA, JA, A,
  5. + ISYM, IUNIT, IFLAG, ERR)
  6. C***BEGIN PROLOGUE DPIGMR
  7. C***SUBSIDIARY
  8. C***PURPOSE Internal routine for DGMRES.
  9. C***LIBRARY SLATEC (SLAP)
  10. C***CATEGORY D2A4, D2B4
  11. C***TYPE DOUBLE PRECISION (SPIGMR-S, DPIGMR-D)
  12. C***KEYWORDS GENERALIZED MINIMUM RESIDUAL, ITERATIVE PRECONDITION,
  13. C NON-SYMMETRIC LINEAR SYSTEM, SLAP, SPARSE
  14. C***AUTHOR Brown, Peter, (LLNL), pnbrown@llnl.gov
  15. C Hindmarsh, Alan, (LLNL), alanh@llnl.gov
  16. C Seager, Mark K., (LLNL), seager@llnl.gov
  17. C Lawrence Livermore National Laboratory
  18. C PO Box 808, L-60
  19. C Livermore, CA 94550 (510) 423-3141
  20. C***DESCRIPTION
  21. C This routine solves the linear system A * Z = R0 using a
  22. C scaled preconditioned version of the generalized minimum
  23. C residual method. An initial guess of Z = 0 is assumed.
  24. C
  25. C *Usage:
  26. C INTEGER N, JSCAL, MAXL, MAXLP1, KMP, NRSTS, JPRE, NMSL, LGMR
  27. C INTEGER IPAR(USER DEFINED), NRMAX, ITOL, NELT, IA(NELT), JA(NELT)
  28. C INTEGER ISYM, IUNIT, IFLAG
  29. C DOUBLE PRECISION R0(N), SR(N), SZ(N), Z(N), V(N,MAXLP1),
  30. C $ HES(MAXLP1,MAXL), Q(2*MAXL), RPAR(USER DEFINED),
  31. C $ WK(N), DL(N), RHOL, B(N), BNRM, X(N), XL(N),
  32. C $ TOL, A(NELT), ERR
  33. C EXTERNAL MATVEC, MSOLVE
  34. C
  35. C CALL DPIGMR(N, R0, SR, SZ, JSCAL, MAXL, MAXLP1, KMP,
  36. C $ NRSTS, JPRE, MATVEC, MSOLVE, NMSL, Z, V, HES, Q, LGMR,
  37. C $ RPAR, IPAR, WK, DL, RHOL, NRMAX, B, BNRM, X, XL,
  38. C $ ITOL, TOL, NELT, IA, JA, A, ISYM, IUNIT, IFLAG, ERR)
  39. C
  40. C *Arguments:
  41. C N :IN Integer
  42. C The order of the matrix A, and the lengths
  43. C of the vectors SR, SZ, R0 and Z.
  44. C R0 :IN Double Precision R0(N)
  45. C R0 = the right hand side of the system A*Z = R0.
  46. C R0 is also used as workspace when computing
  47. C the final approximation.
  48. C (R0 is the same as V(*,MAXL+1) in the call to DPIGMR.)
  49. C SR :IN Double Precision SR(N)
  50. C SR is a vector of length N containing the non-zero
  51. C elements of the diagonal scaling matrix for R0.
  52. C SZ :IN Double Precision SZ(N)
  53. C SZ is a vector of length N containing the non-zero
  54. C elements of the diagonal scaling matrix for Z.
  55. C JSCAL :IN Integer
  56. C A flag indicating whether arrays SR and SZ are used.
  57. C JSCAL=0 means SR and SZ are not used and the
  58. C algorithm will perform as if all
  59. C SR(i) = 1 and SZ(i) = 1.
  60. C JSCAL=1 means only SZ is used, and the algorithm
  61. C performs as if all SR(i) = 1.
  62. C JSCAL=2 means only SR is used, and the algorithm
  63. C performs as if all SZ(i) = 1.
  64. C JSCAL=3 means both SR and SZ are used.
  65. C MAXL :IN Integer
  66. C The maximum allowable order of the matrix H.
  67. C MAXLP1 :IN Integer
  68. C MAXPL1 = MAXL + 1, used for dynamic dimensioning of HES.
  69. C KMP :IN Integer
  70. C The number of previous vectors the new vector VNEW
  71. C must be made orthogonal to. (KMP .le. MAXL)
  72. C NRSTS :IN Integer
  73. C Counter for the number of restarts on the current
  74. C call to DGMRES. If NRSTS .gt. 0, then the residual
  75. C R0 is already scaled, and so scaling of it is
  76. C not necessary.
  77. C JPRE :IN Integer
  78. C Preconditioner type flag.
  79. C MATVEC :EXT External.
  80. C Name of a routine which performs the matrix vector multiply
  81. C Y = A*X given A and X. The name of the MATVEC routine must
  82. C be declared external in the calling program. The calling
  83. C sequence to MATVEC is:
  84. C CALL MATVEC(N, X, Y, NELT, IA, JA, A, ISYM)
  85. C where N is the number of unknowns, Y is the product A*X
  86. C upon return, X is an input vector, and NELT is the number of
  87. C non-zeros in the SLAP IA, JA, A storage for the matrix A.
  88. C ISYM is a flag which, if non-zero, denotes that A is
  89. C symmetric and only the lower or upper triangle is stored.
  90. C MSOLVE :EXT External.
  91. C Name of the routine which solves a linear system Mz = r for
  92. C z given r with the preconditioning matrix M (M is supplied via
  93. C RPAR and IPAR arrays. The name of the MSOLVE routine must
  94. C be declared external in the calling program. The calling
  95. C sequence to MSOLVE is:
  96. C CALL MSOLVE(N, R, Z, NELT, IA, JA, A, ISYM, RPAR, IPAR)
  97. C Where N is the number of unknowns, R is the right-hand side
  98. C vector and Z is the solution upon return. NELT, IA, JA, A and
  99. C ISYM are defined as below. RPAR is a double precision array
  100. C that can be used to pass necessary preconditioning information
  101. C and/or workspace to MSOLVE. IPAR is an integer work array
  102. C for the same purpose as RPAR.
  103. C NMSL :OUT Integer
  104. C The number of calls to MSOLVE.
  105. C Z :OUT Double Precision Z(N)
  106. C The final computed approximation to the solution
  107. C of the system A*Z = R0.
  108. C V :OUT Double Precision V(N,MAXLP1)
  109. C The N by (LGMR+1) array containing the LGMR
  110. C orthogonal vectors V(*,1) to V(*,LGMR).
  111. C HES :OUT Double Precision HES(MAXLP1,MAXL)
  112. C The upper triangular factor of the QR decomposition
  113. C of the (LGMR+1) by LGMR upper Hessenberg matrix whose
  114. C entries are the scaled inner-products of A*V(*,I)
  115. C and V(*,K).
  116. C Q :OUT Double Precision Q(2*MAXL)
  117. C A double precision array of length 2*MAXL containing the
  118. C components of the Givens rotations used in the QR
  119. C decomposition of HES. It is loaded in DHEQR and used in
  120. C DHELS.
  121. C LGMR :OUT Integer
  122. C The number of iterations performed and
  123. C the current order of the upper Hessenberg
  124. C matrix HES.
  125. C RPAR :IN Double Precision RPAR(USER DEFINED)
  126. C Double Precision workspace passed directly to the MSOLVE
  127. C routine.
  128. C IPAR :IN Integer IPAR(USER DEFINED)
  129. C Integer workspace passed directly to the MSOLVE routine.
  130. C WK :IN Double Precision WK(N)
  131. C A double precision work array of length N used by routines
  132. C MATVEC and MSOLVE.
  133. C DL :INOUT Double Precision DL(N)
  134. C On input, a double precision work array of length N used for
  135. C calculation of the residual norm RHO when the method is
  136. C incomplete (KMP.lt.MAXL), and/or when using restarting.
  137. C On output, the scaled residual vector RL. It is only loaded
  138. C when performing restarts of the Krylov iteration.
  139. C RHOL :OUT Double Precision
  140. C A double precision scalar containing the norm of the final
  141. C residual.
  142. C NRMAX :IN Integer
  143. C The maximum number of restarts of the Krylov iteration.
  144. C NRMAX .gt. 0 means restarting is active, while
  145. C NRMAX = 0 means restarting is not being used.
  146. C B :IN Double Precision B(N)
  147. C The right hand side of the linear system A*X = b.
  148. C BNRM :IN Double Precision
  149. C The scaled norm of b.
  150. C X :IN Double Precision X(N)
  151. C The current approximate solution as of the last
  152. C restart.
  153. C XL :IN Double Precision XL(N)
  154. C An array of length N used to hold the approximate
  155. C solution X(L) when ITOL=11.
  156. C ITOL :IN Integer
  157. C A flag to indicate the type of convergence criterion
  158. C used. See the driver for its description.
  159. C TOL :IN Double Precision
  160. C The tolerance on residuals R0-A*Z in scaled norm.
  161. C NELT :IN Integer
  162. C The length of arrays IA, JA and A.
  163. C IA :IN Integer IA(NELT)
  164. C An integer array of length NELT containing matrix data.
  165. C It is passed directly to the MATVEC and MSOLVE routines.
  166. C JA :IN Integer JA(NELT)
  167. C An integer array of length NELT containing matrix data.
  168. C It is passed directly to the MATVEC and MSOLVE routines.
  169. C A :IN Double Precision A(NELT)
  170. C A double precision array of length NELT containing matrix
  171. C data. It is passed directly to the MATVEC and MSOLVE routines.
  172. C ISYM :IN Integer
  173. C A flag to indicate symmetric matrix storage.
  174. C If ISYM=0, all non-zero entries of the matrix are
  175. C stored. If ISYM=1, the matrix is symmetric and
  176. C only the upper or lower triangular part is stored.
  177. C IUNIT :IN Integer
  178. C The i/o unit number for writing intermediate residual
  179. C norm values.
  180. C IFLAG :OUT Integer
  181. C An integer error flag..
  182. C 0 means convergence in LGMR iterations, LGMR.le.MAXL.
  183. C 1 means the convergence test did not pass in MAXL
  184. C iterations, but the residual norm is .lt. norm(R0),
  185. C and so Z is computed.
  186. C 2 means the convergence test did not pass in MAXL
  187. C iterations, residual .ge. norm(R0), and Z = 0.
  188. C ERR :OUT Double Precision.
  189. C Error estimate of error in final approximate solution, as
  190. C defined by ITOL.
  191. C
  192. C *Cautions:
  193. C This routine will attempt to write to the Fortran logical output
  194. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  195. C this logical unit is attached to a file or terminal before calling
  196. C this routine with a non-zero value for IUNIT. This routine does
  197. C not check for the validity of a non-zero IUNIT unit number.
  198. C
  199. C***SEE ALSO DGMRES
  200. C***ROUTINES CALLED DAXPY, DCOPY, DHELS, DHEQR, DNRM2, DORTH, DRLCAL,
  201. C DSCAL, ISDGMR
  202. C***REVISION HISTORY (YYMMDD)
  203. C 890404 DATE WRITTEN
  204. C 890404 Previous REVISION DATE
  205. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  206. C 890922 Numerous changes to prologue to make closer to SLATEC
  207. C standard. (FNF)
  208. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  209. C 910411 Prologue converted to Version 4.0 format. (BAB)
  210. C 910502 Removed MATVEC and MSOLVE from ROUTINES CALLED list. (FNF)
  211. C 910506 Made subsidiary to DGMRES. (FNF)
  212. C 920511 Added complete declaration section. (WRB)
  213. C***END PROLOGUE DPIGMR
  214. C The following is for optimized compilation on LLNL/LTSS Crays.
  215. CLLL. OPTIMIZE
  216. C .. Scalar Arguments ..
  217. DOUBLE PRECISION BNRM, ERR, RHOL, TOL
  218. INTEGER IFLAG, ISYM, ITOL, IUNIT, JPRE, JSCAL, KMP, LGMR, MAXL,
  219. + MAXLP1, N, NELT, NMSL, NRMAX, NRSTS
  220. C .. Array Arguments ..
  221. DOUBLE PRECISION A(NELT), B(*), DL(*), HES(MAXLP1,*), Q(*), R0(*),
  222. + RPAR(*), SR(*), SZ(*), V(N,*), WK(*), X(*),
  223. + XL(*), Z(*)
  224. INTEGER IA(NELT), IPAR(*), JA(NELT)
  225. C .. Subroutine Arguments ..
  226. EXTERNAL MATVEC, MSOLVE
  227. C .. Local Scalars ..
  228. DOUBLE PRECISION C, DLNRM, PROD, R0NRM, RHO, S, SNORMW, TEM
  229. INTEGER I, I2, INFO, IP1, ITER, ITMAX, J, K, LL, LLP1
  230. C .. External Functions ..
  231. DOUBLE PRECISION DNRM2
  232. INTEGER ISDGMR
  233. EXTERNAL DNRM2, ISDGMR
  234. C .. External Subroutines ..
  235. EXTERNAL DAXPY, DCOPY, DHELS, DHEQR, DORTH, DRLCAL, DSCAL
  236. C .. Intrinsic Functions ..
  237. INTRINSIC ABS
  238. C***FIRST EXECUTABLE STATEMENT DPIGMR
  239. C
  240. C Zero out the Z array.
  241. C
  242. DO 5 I = 1,N
  243. Z(I) = 0
  244. 5 CONTINUE
  245. C
  246. IFLAG = 0
  247. LGMR = 0
  248. NMSL = 0
  249. C Load ITMAX, the maximum number of iterations.
  250. ITMAX =(NRMAX+1)*MAXL
  251. C -------------------------------------------------------------------
  252. C The initial residual is the vector R0.
  253. C Apply left precon. if JPRE < 0 and this is not a restart.
  254. C Apply scaling to R0 if JSCAL = 2 or 3.
  255. C -------------------------------------------------------------------
  256. IF ((JPRE .LT. 0) .AND.(NRSTS .EQ. 0)) THEN
  257. CALL DCOPY(N, R0, 1, WK, 1)
  258. CALL MSOLVE(N, WK, R0, NELT, IA, JA, A, ISYM, RPAR, IPAR)
  259. NMSL = NMSL + 1
  260. ENDIF
  261. IF (((JSCAL.EQ.2) .OR.(JSCAL.EQ.3)) .AND.(NRSTS.EQ.0)) THEN
  262. DO 10 I = 1,N
  263. V(I,1) = R0(I)*SR(I)
  264. 10 CONTINUE
  265. ELSE
  266. DO 20 I = 1,N
  267. V(I,1) = R0(I)
  268. 20 CONTINUE
  269. ENDIF
  270. R0NRM = DNRM2(N, V, 1)
  271. ITER = NRSTS*MAXL
  272. C
  273. C Call stopping routine ISDGMR.
  274. C
  275. IF (ISDGMR(N, B, X, XL, NELT, IA, JA, A, ISYM, MSOLVE,
  276. $ NMSL, ITOL, TOL, ITMAX, ITER, ERR, IUNIT, V(1,1), Z, WK,
  277. $ RPAR, IPAR, R0NRM, BNRM, SR, SZ, JSCAL,
  278. $ KMP, LGMR, MAXL, MAXLP1, V, Q, SNORMW, PROD, R0NRM,
  279. $ HES, JPRE) .NE. 0) RETURN
  280. TEM = 1.0D0/R0NRM
  281. CALL DSCAL(N, TEM, V(1,1), 1)
  282. C
  283. C Zero out the HES array.
  284. C
  285. DO 50 J = 1,MAXL
  286. DO 40 I = 1,MAXLP1
  287. HES(I,J) = 0
  288. 40 CONTINUE
  289. 50 CONTINUE
  290. C -------------------------------------------------------------------
  291. C Main loop to compute the vectors V(*,2) to V(*,MAXL).
  292. C The running product PROD is needed for the convergence test.
  293. C -------------------------------------------------------------------
  294. PROD = 1
  295. DO 90 LL = 1,MAXL
  296. LGMR = LL
  297. C -------------------------------------------------------------------
  298. C Unscale the current V(LL) and store in WK. Call routine
  299. C MSOLVE to compute(M-inverse)*WK, where M is the
  300. C preconditioner matrix. Save the answer in Z. Call routine
  301. C MATVEC to compute VNEW = A*Z, where A is the the system
  302. C matrix. save the answer in V(LL+1). Scale V(LL+1). Call
  303. C routine DORTH to orthogonalize the new vector VNEW =
  304. C V(*,LL+1). Call routine DHEQR to update the factors of HES.
  305. C -------------------------------------------------------------------
  306. IF ((JSCAL .EQ. 1) .OR.(JSCAL .EQ. 3)) THEN
  307. DO 60 I = 1,N
  308. WK(I) = V(I,LL)/SZ(I)
  309. 60 CONTINUE
  310. ELSE
  311. CALL DCOPY(N, V(1,LL), 1, WK, 1)
  312. ENDIF
  313. IF (JPRE .GT. 0) THEN
  314. CALL MSOLVE(N, WK, Z, NELT, IA, JA, A, ISYM, RPAR, IPAR)
  315. NMSL = NMSL + 1
  316. CALL MATVEC(N, Z, V(1,LL+1), NELT, IA, JA, A, ISYM)
  317. ELSE
  318. CALL MATVEC(N, WK, V(1,LL+1), NELT, IA, JA, A, ISYM)
  319. ENDIF
  320. IF (JPRE .LT. 0) THEN
  321. CALL DCOPY(N, V(1,LL+1), 1, WK, 1)
  322. CALL MSOLVE(N,WK,V(1,LL+1),NELT,IA,JA,A,ISYM,RPAR,IPAR)
  323. NMSL = NMSL + 1
  324. ENDIF
  325. IF ((JSCAL .EQ. 2) .OR.(JSCAL .EQ. 3)) THEN
  326. DO 65 I = 1,N
  327. V(I,LL+1) = V(I,LL+1)*SR(I)
  328. 65 CONTINUE
  329. ENDIF
  330. CALL DORTH(V(1,LL+1), V, HES, N, LL, MAXLP1, KMP, SNORMW)
  331. HES(LL+1,LL) = SNORMW
  332. CALL DHEQR(HES, MAXLP1, LL, Q, INFO, LL)
  333. IF (INFO .EQ. LL) GO TO 120
  334. C -------------------------------------------------------------------
  335. C Update RHO, the estimate of the norm of the residual R0-A*ZL.
  336. C If KMP < MAXL, then the vectors V(*,1),...,V(*,LL+1) are not
  337. C necessarily orthogonal for LL > KMP. The vector DL must then
  338. C be computed, and its norm used in the calculation of RHO.
  339. C -------------------------------------------------------------------
  340. PROD = PROD*Q(2*LL)
  341. RHO = ABS(PROD*R0NRM)
  342. IF ((LL.GT.KMP) .AND.(KMP.LT.MAXL)) THEN
  343. IF (LL .EQ. KMP+1) THEN
  344. CALL DCOPY(N, V(1,1), 1, DL, 1)
  345. DO 75 I = 1,KMP
  346. IP1 = I + 1
  347. I2 = I*2
  348. S = Q(I2)
  349. C = Q(I2-1)
  350. DO 70 K = 1,N
  351. DL(K) = S*DL(K) + C*V(K,IP1)
  352. 70 CONTINUE
  353. 75 CONTINUE
  354. ENDIF
  355. S = Q(2*LL)
  356. C = Q(2*LL-1)/SNORMW
  357. LLP1 = LL + 1
  358. DO 80 K = 1,N
  359. DL(K) = S*DL(K) + C*V(K,LLP1)
  360. 80 CONTINUE
  361. DLNRM = DNRM2(N, DL, 1)
  362. RHO = RHO*DLNRM
  363. ENDIF
  364. RHOL = RHO
  365. C -------------------------------------------------------------------
  366. C Test for convergence. If passed, compute approximation ZL.
  367. C If failed and LL < MAXL, then continue iterating.
  368. C -------------------------------------------------------------------
  369. ITER = NRSTS*MAXL + LGMR
  370. IF (ISDGMR(N, B, X, XL, NELT, IA, JA, A, ISYM, MSOLVE,
  371. $ NMSL, ITOL, TOL, ITMAX, ITER, ERR, IUNIT, DL, Z, WK,
  372. $ RPAR, IPAR, RHOL, BNRM, SR, SZ, JSCAL,
  373. $ KMP, LGMR, MAXL, MAXLP1, V, Q, SNORMW, PROD, R0NRM,
  374. $ HES, JPRE) .NE. 0) GO TO 200
  375. IF (LL .EQ. MAXL) GO TO 100
  376. C -------------------------------------------------------------------
  377. C Rescale so that the norm of V(1,LL+1) is one.
  378. C -------------------------------------------------------------------
  379. TEM = 1.0D0/SNORMW
  380. CALL DSCAL(N, TEM, V(1,LL+1), 1)
  381. 90 CONTINUE
  382. 100 CONTINUE
  383. IF (RHO .LT. R0NRM) GO TO 150
  384. 120 CONTINUE
  385. IFLAG = 2
  386. C
  387. C Load approximate solution with zero.
  388. C
  389. DO 130 I = 1,N
  390. Z(I) = 0
  391. 130 CONTINUE
  392. RETURN
  393. 150 IFLAG = 1
  394. C
  395. C Tolerance not met, but residual norm reduced.
  396. C
  397. IF (NRMAX .GT. 0) THEN
  398. C
  399. C If performing restarting (NRMAX > 0) calculate the residual
  400. C vector RL and store it in the DL array. If the incomplete
  401. C version is being used (KMP < MAXL) then DL has already been
  402. C calculated up to a scaling factor. Use DRLCAL to calculate
  403. C the scaled residual vector.
  404. C
  405. CALL DRLCAL(N, KMP, MAXL, MAXL, V, Q, DL, SNORMW, PROD,
  406. $ R0NRM)
  407. ENDIF
  408. C -------------------------------------------------------------------
  409. C Compute the approximation ZL to the solution. Since the
  410. C vector Z was used as workspace, and the initial guess
  411. C of the linear iteration is zero, Z must be reset to zero.
  412. C -------------------------------------------------------------------
  413. 200 CONTINUE
  414. LL = LGMR
  415. LLP1 = LL + 1
  416. DO 210 K = 1,LLP1
  417. R0(K) = 0
  418. 210 CONTINUE
  419. R0(1) = R0NRM
  420. CALL DHELS(HES, MAXLP1, LL, Q, R0)
  421. DO 220 K = 1,N
  422. Z(K) = 0
  423. 220 CONTINUE
  424. DO 230 I = 1,LL
  425. CALL DAXPY(N, R0(I), V(1,I), 1, Z, 1)
  426. 230 CONTINUE
  427. IF ((JSCAL .EQ. 1) .OR.(JSCAL .EQ. 3)) THEN
  428. DO 240 I = 1,N
  429. Z(I) = Z(I)/SZ(I)
  430. 240 CONTINUE
  431. ENDIF
  432. IF (JPRE .GT. 0) THEN
  433. CALL DCOPY(N, Z, 1, WK, 1)
  434. CALL MSOLVE(N, WK, Z, NELT, IA, JA, A, ISYM, RPAR, IPAR)
  435. NMSL = NMSL + 1
  436. ENDIF
  437. RETURN
  438. C------------- LAST LINE OF DPIGMR FOLLOWS ----------------------------
  439. END