PageRenderTime 80ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/UAFWLIS2.4/slatec/dsdcg.f

http://ua-fwlis.googlecode.com/
FORTRAN Legacy | 276 lines | 30 code | 0 blank | 246 comment | 0 complexity | 604323e75571c20cb35203d9f4bc436c MD5 | raw file
Possible License(s): GPL-3.0
  1. *DECK DSDCG
  2. SUBROUTINE DSDCG (N, B, X, NELT, IA, JA, A, ISYM, ITOL, TOL,
  3. + ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW)
  4. C***BEGIN PROLOGUE DSDCG
  5. C***PURPOSE Diagonally Scaled Conjugate Gradient Sparse Ax=b Solver.
  6. C Routine to solve a symmetric positive definite linear
  7. C system Ax = b using the Preconditioned Conjugate
  8. C Gradient method. The preconditioner is diagonal scaling.
  9. C***LIBRARY SLATEC (SLAP)
  10. C***CATEGORY D2B4
  11. C***TYPE DOUBLE PRECISION (SSDCG-S, DSDCG-D)
  12. C***KEYWORDS 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(10), LENIW
  25. C DOUBLE PRECISION B(N), X(N), A(NELT), TOL, ERR, RWORK(5*N)
  26. C
  27. C CALL DSDCG(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 IUNIT :IN Integer.
  100. C Unit number on which to write the error at each iteration,
  101. C if this is desired for monitoring convergence. If unit
  102. C number is 0, no writing will occur.
  103. C RWORK :WORK Double Precision RWORK(LENW).
  104. C Double Precision array used for workspace.
  105. C LENW :IN Integer.
  106. C Length of the double precision workspace, RWORK. LENW >= 5*N.
  107. C IWORK :WORK Integer IWORK(LENIW).
  108. C Used to hold pointers into the double precision workspace,
  109. C RWORK. Upon return the following locations of IWORK hold
  110. C information which may be of use to the user:
  111. C IWORK(9) Amount of Integer workspace actually used.
  112. C IWORK(10) Amount of Double Precision workspace actually used.
  113. C LENIW :IN Integer.
  114. C Length of the integer workspace, IWORK. LENIW >= 10.
  115. C
  116. C *Description:
  117. C This routine performs preconditioned conjugate gradient
  118. C method on the symmetric positive definite linear system
  119. C Ax=b. The preconditioner is M = DIAG(A), the diagonal of
  120. C the matrix A. This is the simplest of preconditioners and
  121. C vectorizes very well. This routine is simply a driver for
  122. C the DCG routine. It calls the DSDS routine to set up the
  123. C preconditioning and then calls DCG with the appropriate
  124. C MATVEC and MSOLVE routines.
  125. C
  126. C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
  127. C data structures: 1) the SLAP Triad format or 2) the SLAP
  128. C Column format. The user can hand this routine either of the
  129. C of these data structures and SLAP will figure out which on
  130. C is being used and act accordingly.
  131. C
  132. C =================== S L A P Triad format ===================
  133. C
  134. C This routine requires that the matrix A be stored in the
  135. C SLAP Triad format. In this format only the non-zeros are
  136. C stored. They may appear in *ANY* order. The user supplies
  137. C three arrays of length NELT, where NELT is the number of
  138. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  139. C each non-zero the user puts the row and column index of that
  140. C matrix element in the IA and JA arrays. The value of the
  141. C non-zero matrix element is placed in the corresponding
  142. C location of the A array. This is an extremely easy data
  143. C structure to generate. On the other hand it is not too
  144. C efficient on vector computers for the iterative solution of
  145. C linear systems. Hence, SLAP changes this input data
  146. C structure to the SLAP Column format for the iteration (but
  147. C does not change it back).
  148. C
  149. C Here is an example of the SLAP Triad storage format for a
  150. C 5x5 Matrix. Recall that the entries may appear in any order.
  151. C
  152. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  153. C 1 2 3 4 5 6 7 8 9 10 11
  154. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  155. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  156. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  157. C | 0 0 0 44 0|
  158. C |51 0 53 0 55|
  159. C
  160. C =================== S L A P Column format ==================
  161. C
  162. C This routine requires that the matrix A be stored in the
  163. C SLAP Column format. In this format the non-zeros are stored
  164. C counting down columns (except for the diagonal entry, which
  165. C must appear first in each "column") and are stored in the
  166. C double precision array A. In other words, for each column
  167. C in the matrix put the diagonal entry in A. Then put in the
  168. C other non-zero elements going down the column (except the
  169. C diagonal) in order. The IA array holds the row index for
  170. C each non-zero. The JA array holds the offsets into the IA,
  171. C A arrays for the beginning of each column. That is,
  172. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  173. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  174. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  175. C Note that we always have JA(N+1) = NELT+1, where N is the
  176. C number of columns in the matrix and NELT is the number of
  177. C non-zeros in the matrix.
  178. C
  179. C Here is an example of the SLAP Column storage format for a
  180. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  181. C column):
  182. C
  183. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  184. C 1 2 3 4 5 6 7 8 9 10 11
  185. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  186. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  187. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  188. C | 0 0 0 44 0|
  189. C |51 0 53 0 55|
  190. C
  191. C *Side Effects:
  192. C The SLAP Triad format (IA, JA, A) is modified internally to
  193. C be the SLAP Column format. See above.
  194. C
  195. C *Cautions:
  196. C This routine will attempt to write to the Fortran logical output
  197. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  198. C this logical unit is attached to a file or terminal before calling
  199. C this routine with a non-zero value for IUNIT. This routine does
  200. C not check for the validity of a non-zero IUNIT unit number.
  201. C
  202. C***SEE ALSO DCG, DSICCG
  203. C***REFERENCES 1. Louis Hageman and David Young, Applied Iterative
  204. C Methods, Academic Press, New York, 1981.
  205. C 2. Concus, Golub and O'Leary, A Generalized Conjugate
  206. C Gradient Method for the Numerical Solution of
  207. C Elliptic Partial Differential Equations, in Sparse
  208. C Matrix Computations, Bunch and Rose, Eds., Academic
  209. C Press, New York, 1979.
  210. C***ROUTINES CALLED DCG, DCHKW, DS2Y, DSDI, DSDS, DSMV
  211. C***REVISION HISTORY (YYMMDD)
  212. C 890404 DATE WRITTEN
  213. C 890404 Previous REVISION DATE
  214. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  215. C 890921 Removed TeX from comments. (FNF)
  216. C 890922 Numerous changes to prologue to make closer to SLATEC
  217. C standard. (FNF)
  218. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  219. C 910411 Prologue converted to Version 4.0 format. (BAB)
  220. C 920407 COMMON BLOCK renamed DSLBLK. (WRB)
  221. C 920511 Added complete declaration section. (WRB)
  222. C 920929 Corrected format of references. (FNF)
  223. C***END PROLOGUE DSDCG
  224. C .. Parameters ..
  225. INTEGER LOCRB, LOCIB
  226. PARAMETER (LOCRB=1, LOCIB=11)
  227. C .. Scalar Arguments ..
  228. DOUBLE PRECISION ERR, TOL
  229. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, LENIW, LENW, N, NELT
  230. C .. Array Arguments ..
  231. DOUBLE PRECISION A(NELT), B(N), RWORK(LENW), X(N)
  232. INTEGER IA(NELT), IWORK(LENIW), JA(NELT)
  233. C .. Local Scalars ..
  234. INTEGER LOCD, LOCDZ, LOCIW, LOCP, LOCR, LOCW, LOCZ
  235. C .. External Subroutines ..
  236. EXTERNAL DCG, DCHKW, DS2Y, DSDI, DSDS, DSMV
  237. C***FIRST EXECUTABLE STATEMENT DSDCG
  238. C
  239. IERR = 0
  240. IF( N.LT.1 .OR. NELT.LT.1 ) THEN
  241. IERR = 3
  242. RETURN
  243. ENDIF
  244. C
  245. C Modify the SLAP matrix data structure to YSMP-Column.
  246. CALL DS2Y( N, NELT, IA, JA, A, ISYM )
  247. C
  248. C Set up the work arrays.
  249. LOCIW = LOCIB
  250. C
  251. LOCD = LOCRB
  252. LOCR = LOCD + N
  253. LOCZ = LOCR + N
  254. LOCP = LOCZ + N
  255. LOCDZ = LOCP + N
  256. LOCW = LOCDZ + N
  257. C
  258. C Check the workspace allocations.
  259. CALL DCHKW( 'DSDCG', LOCIW, LENIW, LOCW, LENW, IERR, ITER, ERR )
  260. IF( IERR.NE.0 ) RETURN
  261. C
  262. IWORK(4) = LOCD
  263. IWORK(9) = LOCIW
  264. IWORK(10) = LOCW
  265. C
  266. C Compute the inverse of the diagonal of the matrix. This
  267. C will be used as the preconditioner.
  268. CALL DSDS(N, NELT, IA, JA, A, ISYM, RWORK(LOCD))
  269. C
  270. C Do the Preconditioned Conjugate Gradient.
  271. CALL DCG(N, B, X, NELT, IA, JA, A, ISYM, DSMV, DSDI,
  272. $ ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, RWORK(LOCR),
  273. $ RWORK(LOCZ), RWORK(LOCP), RWORK(LOCDZ), RWORK, IWORK)
  274. RETURN
  275. C------------- LAST LINE OF DSDCG FOLLOWS -----------------------------
  276. END