dsiccg.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. *DECK DSICCG
  2. SUBROUTINE DSICCG (N, B, X, NELT, IA, JA, A, ISYM, ITOL, TOL,
  3. + ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW)
  4. C***BEGIN PROLOGUE DSICCG
  5. C***PURPOSE Incomplete Cholesky Conjugate Gradient Sparse Ax=b Solver.
  6. C Routine to solve a symmetric positive definite linear
  7. C system Ax = b using the incomplete Cholesky
  8. C Preconditioned Conjugate Gradient method.
  9. C***LIBRARY SLATEC (SLAP)
  10. C***CATEGORY D2B4
  11. C***TYPE DOUBLE PRECISION (SSICCG-S, DSICCG-D)
  12. C***KEYWORDS INCOMPLETE CHOLESKY, ITERATIVE PRECONDITION, SLAP, SPARSE,
  13. C SYMMETRIC LINEAR SYSTEM
  14. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  15. C Seager, Mark K., (LLNL)
  16. C Lawrence Livermore National Laboratory
  17. C PO BOX 808, L-60
  18. C Livermore, CA 94550 (510) 423-3141
  19. C seager@llnl.gov
  20. C***DESCRIPTION
  21. C
  22. C *Usage:
  23. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, ITOL, ITMAX
  24. C INTEGER ITER, IERR, IUNIT, LENW, IWORK(NL+2*N+1), LENIW
  25. C DOUBLE PRECISION B(N), X(N), A(NELT), TOL, ERR, RWORK(NL+5*N)
  26. C
  27. C CALL DSICCG(N, B, X, NELT, IA, JA, A, ISYM, ITOL, TOL,
  28. C $ ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW )
  29. C
  30. C *Arguments:
  31. C N :IN Integer.
  32. C Order of the Matrix.
  33. C B :IN Double Precision B(N).
  34. C Right-hand side vector.
  35. C X :INOUT Double Precision X(N).
  36. C On input X is your initial guess for solution vector.
  37. C On output X is the final approximate solution.
  38. C NELT :IN Integer.
  39. C Number of Non-Zeros stored in A.
  40. C IA :INOUT Integer IA(NELT).
  41. C JA :INOUT Integer JA(NELT).
  42. C A :INOUT Double Precision A(NELT).
  43. C These arrays should hold the matrix A in either the SLAP
  44. C Triad format or the SLAP Column format. See "Description",
  45. C below. If the SLAP Triad format is chosen it is changed
  46. C internally to the SLAP Column format.
  47. C ISYM :IN Integer.
  48. C Flag to indicate symmetric storage format.
  49. C If ISYM=0, all non-zero entries of the matrix are stored.
  50. C If ISYM=1, the matrix is symmetric, and only the upper
  51. C or lower triangle of the matrix is stored.
  52. C ITOL :IN Integer.
  53. C Flag to indicate type of convergence criterion.
  54. C If ITOL=1, iteration stops when the 2-norm of the residual
  55. C divided by the 2-norm of the right-hand side is less than TOL.
  56. C If ITOL=2, iteration stops when the 2-norm of M-inv times the
  57. C residual divided by the 2-norm of M-inv times the right hand
  58. C side is less than TOL, where M-inv is the inverse of the
  59. C diagonal of A.
  60. C ITOL=11 is often useful for checking and comparing different
  61. C routines. For this case, the user must supply the "exact"
  62. C solution or a very accurate approximation (one with an error
  63. C much less than TOL) through a common block,
  64. C COMMON /DSLBLK/ SOLN( )
  65. C If ITOL=11, iteration stops when the 2-norm of the difference
  66. C between the iterative approximation and the user-supplied
  67. C solution divided by the 2-norm of the user-supplied solution
  68. C is less than TOL. Note that this requires the user to set up
  69. C the "COMMON /DSLBLK/ SOLN(LENGTH)" in the calling routine.
  70. C The routine with this declaration should be loaded before the
  71. C stop test so that the correct length is used by the loader.
  72. C This procedure is not standard Fortran and may not work
  73. C correctly on your system (although it has worked on every
  74. C system the authors have tried). If ITOL is not 11 then this
  75. C common block is indeed standard Fortran.
  76. C TOL :INOUT Double Precision.
  77. C Convergence criterion, as described above. (Reset if IERR=4.)
  78. C ITMAX :IN Integer.
  79. C Maximum number of iterations.
  80. C ITER :OUT Integer.
  81. C Number of iterations required to reach convergence, or
  82. C ITMAX+1 if convergence criterion could not be achieved in
  83. C ITMAX iterations.
  84. C ERR :OUT Double Precision.
  85. C Error estimate of error in final approximate solution, as
  86. C defined by ITOL.
  87. C IERR :OUT Integer.
  88. C Return error flag.
  89. C IERR = 0 => All went well.
  90. C IERR = 1 => Insufficient space allocated for WORK or IWORK.
  91. C IERR = 2 => Method failed to converge in ITMAX steps.
  92. C IERR = 3 => Error in user input.
  93. C Check input values of N, ITOL.
  94. C IERR = 4 => User error tolerance set too tight.
  95. C Reset to 500*D1MACH(3). Iteration proceeded.
  96. C IERR = 5 => Preconditioning matrix, M, is not positive
  97. C definite. (r,z) < 0.
  98. C IERR = 6 => Matrix A is not positive definite. (p,Ap) < 0.
  99. C IERR = 7 => Incomplete factorization broke down and was
  100. C fudged. Resulting preconditioning may be less
  101. C than the best.
  102. C IUNIT :IN Integer.
  103. C Unit number on which to write the error at each iteration,
  104. C if this is desired for monitoring convergence. If unit
  105. C number is 0, no writing will occur.
  106. C RWORK :WORK Double Precision RWORK(LENW).
  107. C Double Precision array used for workspace.
  108. C LENW :IN Integer.
  109. C Length of the double precision workspace, RWORK.
  110. C LENW >= NL+5*N.
  111. C NL is the number of non-zeros in the lower triangle of the
  112. C matrix (including the diagonal).
  113. C IWORK :WORK Integer IWORK(LENIW).
  114. C Integer array used for workspace.
  115. C Upon return the following locations of IWORK hold information
  116. C which may be of use to the user:
  117. C IWORK(9) Amount of Integer workspace actually used.
  118. C IWORK(10) Amount of Double Precision workspace actually used.
  119. C LENIW :IN Integer.
  120. C Length of the integer workspace, IWORK. LENIW >= NL+N+11.
  121. C NL is the number of non-zeros in the lower triangle of the
  122. C matrix (including the diagonal).
  123. C
  124. C *Description:
  125. C This routine performs preconditioned conjugate gradient
  126. C method on the symmetric positive definite linear system
  127. C Ax=b. The preconditioner is the incomplete Cholesky (IC)
  128. C factorization of the matrix A. See DSICS for details about
  129. C the incomplete factorization algorithm. One should note
  130. C here however, that the IC factorization is a slow process
  131. C and that one should save factorizations for reuse, if
  132. C possible. The MSOLVE operation (handled in DSLLTI) does
  133. C vectorize on machines with hardware gather/scatter and is
  134. C quite fast.
  135. C
  136. C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
  137. C data structures: 1) the SLAP Triad format or 2) the SLAP
  138. C Column format. The user can hand this routine either of the
  139. C of these data structures and SLAP will figure out which on
  140. C is being used and act accordingly.
  141. C
  142. C =================== S L A P Triad format ===================
  143. C
  144. C This routine requires that the matrix A be stored in the
  145. C SLAP Triad format. In this format only the non-zeros are
  146. C stored. They may appear in *ANY* order. The user supplies
  147. C three arrays of length NELT, where NELT is the number of
  148. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  149. C each non-zero the user puts the row and column index of that
  150. C matrix element in the IA and JA arrays. The value of the
  151. C non-zero matrix element is placed in the corresponding
  152. C location of the A array. This is an extremely easy data
  153. C structure to generate. On the other hand it is not too
  154. C efficient on vector computers for the iterative solution of
  155. C linear systems. Hence, SLAP changes this input data
  156. C structure to the SLAP Column format for the iteration (but
  157. C does not change it back).
  158. C
  159. C Here is an example of the SLAP Triad storage format for a
  160. C 5x5 Matrix. Recall that the entries may appear in any order.
  161. C
  162. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  163. C 1 2 3 4 5 6 7 8 9 10 11
  164. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  165. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  166. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  167. C | 0 0 0 44 0|
  168. C |51 0 53 0 55|
  169. C
  170. C =================== S L A P Column format ==================
  171. C
  172. C This routine requires that the matrix A be stored in the
  173. C SLAP Column format. In this format the non-zeros are stored
  174. C counting down columns (except for the diagonal entry, which
  175. C must appear first in each "column") and are stored in the
  176. C double precision array A. In other words, for each column
  177. C in the matrix put the diagonal entry in A. Then put in the
  178. C other non-zero elements going down the column (except the
  179. C diagonal) in order. The IA array holds the row index for
  180. C each non-zero. The JA array holds the offsets into the IA,
  181. C A arrays for the beginning of each column. That is,
  182. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  183. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  184. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  185. C Note that we always have JA(N+1) = NELT+1, where N is the
  186. C number of columns in the matrix and NELT is the number of
  187. C non-zeros in the matrix.
  188. C
  189. C Here is an example of the SLAP Column storage format for a
  190. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  191. C column):
  192. C
  193. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  194. C 1 2 3 4 5 6 7 8 9 10 11
  195. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  196. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  197. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  198. C | 0 0 0 44 0|
  199. C |51 0 53 0 55|
  200. C
  201. C *Side Effects:
  202. C The SLAP Triad format (IA, JA, A) is modified internally to be
  203. C the SLAP Column format. See above.
  204. C
  205. C *Cautions:
  206. C This routine will attempt to write to the Fortran logical output
  207. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  208. C this logical unit is attached to a file or terminal before calling
  209. C this routine with a non-zero value for IUNIT. This routine does
  210. C not check for the validity of a non-zero IUNIT unit number.
  211. C
  212. C***SEE ALSO DCG, DSLLTI
  213. C***REFERENCES 1. Louis Hageman and David Young, Applied Iterative
  214. C Methods, Academic Press, New York, 1981.
  215. C 2. Concus, Golub and O'Leary, A Generalized Conjugate
  216. C Gradient Method for the Numerical Solution of
  217. C Elliptic Partial Differential Equations, in Sparse
  218. C Matrix Computations, Bunch and Rose, Eds., Academic
  219. C Press, New York, 1979.
  220. C***ROUTINES CALLED DCG, DCHKW, DS2Y, DSICS, DSLLTI, DSMV, XERMSG
  221. C***REVISION HISTORY (YYMMDD)
  222. C 890404 DATE WRITTEN
  223. C 890404 Previous REVISION DATE
  224. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  225. C 890921 Removed TeX from comments. (FNF)
  226. C 890922 Numerous changes to prologue to make closer to SLATEC
  227. C standard. (FNF)
  228. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  229. C 900805 Changed XERRWV calls to calls to XERMSG. (RWC)
  230. C 910411 Prologue converted to Version 4.0 format. (BAB)
  231. C 920407 COMMON BLOCK renamed DSLBLK. (WRB)
  232. C 920511 Added complete declaration section. (WRB)
  233. C 920929 Corrected format of references. (FNF)
  234. C 921019 Corrected NEL to NL. (FNF)
  235. C***END PROLOGUE DSICCG
  236. C .. Parameters ..
  237. INTEGER LOCRB, LOCIB
  238. PARAMETER (LOCRB=1, LOCIB=11)
  239. C .. Scalar Arguments ..
  240. DOUBLE PRECISION ERR, TOL
  241. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, LENIW, LENW, N, NELT
  242. C .. Array Arguments ..
  243. DOUBLE PRECISION A(NELT), B(N), RWORK(LENW), X(N)
  244. INTEGER IA(NELT), IWORK(LENIW), JA(NELT)
  245. C .. Local Scalars ..
  246. INTEGER LOCDIN, LOCDZ, LOCEL, LOCIEL, LOCIW, LOCJEL, LOCP, LOCR,
  247. + LOCW, LOCZ, NL
  248. CHARACTER XERN1*8
  249. C .. External Subroutines ..
  250. EXTERNAL DCG, DCHKW, DS2Y, DSICS, DSLLTI, DSMV, XERMSG
  251. C***FIRST EXECUTABLE STATEMENT DSICCG
  252. C
  253. IERR = 0
  254. IF( N.LT.1 .OR. NELT.LT.1 ) THEN
  255. IERR = 3
  256. RETURN
  257. ENDIF
  258. C
  259. C Change the SLAP input matrix IA, JA, A to SLAP-Column format.
  260. CALL DS2Y( N, NELT, IA, JA, A, ISYM )
  261. C
  262. C Count number of elements in lower triangle of the matrix.
  263. C Then set up the work arrays.
  264. IF( ISYM.EQ.0 ) THEN
  265. NL = (NELT + N)/2
  266. ELSE
  267. NL = NELT
  268. ENDIF
  269. C
  270. LOCJEL = LOCIB
  271. LOCIEL = LOCJEL + NL
  272. LOCIW = LOCIEL + N + 1
  273. C
  274. LOCEL = LOCRB
  275. LOCDIN = LOCEL + NL
  276. LOCR = LOCDIN + N
  277. LOCZ = LOCR + N
  278. LOCP = LOCZ + N
  279. LOCDZ = LOCP + N
  280. LOCW = LOCDZ + N
  281. C
  282. C Check the workspace allocations.
  283. CALL DCHKW( 'DSICCG', LOCIW, LENIW, LOCW, LENW, IERR, ITER, ERR )
  284. IF( IERR.NE.0 ) RETURN
  285. C
  286. IWORK(1) = NL
  287. IWORK(2) = LOCJEL
  288. IWORK(3) = LOCIEL
  289. IWORK(4) = LOCEL
  290. IWORK(5) = LOCDIN
  291. IWORK(9) = LOCIW
  292. IWORK(10) = LOCW
  293. C
  294. C Compute the Incomplete Cholesky decomposition.
  295. C
  296. CALL DSICS(N, NELT, IA, JA, A, ISYM, NL, IWORK(LOCIEL),
  297. $ IWORK(LOCJEL), RWORK(LOCEL), RWORK(LOCDIN),
  298. $ RWORK(LOCR), IERR )
  299. IF( IERR.NE.0 ) THEN
  300. WRITE (XERN1, '(I8)') IERR
  301. CALL XERMSG ('SLATEC', 'DSICCG',
  302. $ 'IC factorization broke down on step ' // XERN1 //
  303. $ '. Diagonal was set to unity and factorization proceeded.',
  304. $ 1, 1)
  305. IERR = 7
  306. ENDIF
  307. C
  308. C Do the Preconditioned Conjugate Gradient.
  309. CALL DCG(N, B, X, NELT, IA, JA, A, ISYM, DSMV, DSLLTI,
  310. $ ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, RWORK(LOCR),
  311. $ RWORK(LOCZ), RWORK(LOCP), RWORK(LOCDZ), RWORK(1),
  312. $ IWORK(1))
  313. RETURN
  314. C------------- LAST LINE OF DSICCG FOLLOWS ----------------------------
  315. END