dsdomn.f 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. *DECK DSDOMN
  2. SUBROUTINE DSDOMN (N, B, X, NELT, IA, JA, A, ISYM, NSAVE, ITOL,
  3. + TOL, ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW)
  4. C***BEGIN PROLOGUE DSDOMN
  5. C***PURPOSE Diagonally Scaled Orthomin Sparse Iterative Ax=b Solver.
  6. C Routine to solve a general linear system Ax = b using
  7. C the Orthomin method with diagonal scaling.
  8. C***LIBRARY SLATEC (SLAP)
  9. C***CATEGORY D2A4, D2B4
  10. C***TYPE DOUBLE PRECISION (SSDOMN-S, DSDOMN-D)
  11. C***KEYWORDS ITERATIVE PRECONDITION, NON-SYMMETRIC LINEAR SYSTEM SOLVE,
  12. C SLAP, SPARSE
  13. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  14. C Seager, Mark K., (LLNL)
  15. C Lawrence Livermore National Laboratory
  16. C PO BOX 808, L-60
  17. C Livermore, CA 94550 (510) 423-3141
  18. C seager@llnl.gov
  19. C***DESCRIPTION
  20. C
  21. C *Usage:
  22. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, NSAVE, ITOL, ITMAX
  23. C INTEGER ITER, IERR, IUNIT, LENW, IWORK(10), LENIW
  24. C DOUBLE PRECISION B(N), X(N), A(NELT), TOL, ERR
  25. C DOUBLE PRECISION RWORK(7*N+3*N*NSAVE+NSAVE)
  26. C
  27. C CALL DSDOMN(N, B, X, NELT, IA, JA, A, ISYM, NSAVE, 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 :IN Integer IA(NELT).
  41. C JA :IN Integer JA(NELT).
  42. C A :IN 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 NSAVE :IN Integer.
  53. C Number of direction vectors to save and orthogonalize against.
  54. C ITOL :IN Integer.
  55. C Flag to indicate type of convergence criterion.
  56. C If ITOL=1, iteration stops when the 2-norm of the residual
  57. C divided by the 2-norm of the right-hand side is less than TOL.
  58. C If ITOL=2, iteration stops when the 2-norm of M-inv times the
  59. C residual divided by the 2-norm of M-inv times the right hand
  60. C side is less than TOL, where M-inv is the inverse of the
  61. C diagonal of A.
  62. C ITOL=11 is often useful for checking and comparing different
  63. C routines. For this case, the user must supply the "exact"
  64. C solution or a very accurate approximation (one with an error
  65. C much less than TOL) through a common block,
  66. C COMMON /DSLBLK/ SOLN( )
  67. C If ITOL=11, iteration stops when the 2-norm of the difference
  68. C between the iterative approximation and the user-supplied
  69. C solution divided by the 2-norm of the user-supplied solution
  70. C is less than TOL.
  71. C TOL :INOUT Double Precision.
  72. C Convergence criterion, as described above. (Reset if IERR=4.)
  73. C ITMAX :IN Integer.
  74. C Maximum number of iterations.
  75. C ITER :OUT Integer.
  76. C Number of iterations required to reach convergence, or
  77. C ITMAX+1 if convergence criterion could not be achieved in
  78. C ITMAX iterations.
  79. C ERR :OUT Double Precision.
  80. C Error estimate of error in final approximate solution, as
  81. C defined by ITOL.
  82. C IERR :OUT Integer.
  83. C Return error flag.
  84. C IERR = 0 => All went well.
  85. C IERR = 1 => Insufficient space allocated for WORK or IWORK.
  86. C IERR = 2 => Method failed to converge in ITMAX steps.
  87. C IERR = 3 => Error in user input.
  88. C Check input values of N, ITOL.
  89. C IERR = 4 => User error tolerance set too tight.
  90. C Reset to 500*D1MACH(3). Iteration proceeded.
  91. C IERR = 5 => Preconditioning matrix, M, is not positive
  92. C definite. (r,z) < 0.
  93. C IERR = 6 => Breakdown of method detected.
  94. C (p,Ap) < epsilon**2.
  95. C IUNIT :IN Integer.
  96. C Unit number on which to write the error at each iteration,
  97. C if this is desired for monitoring convergence. If unit
  98. C number is 0, no writing will occur.
  99. C RWORK :WORK Double Precision RWORK(LENW).
  100. C Double Precision array used for workspace.
  101. C LENW :IN Integer.
  102. C Length of the double precision workspace, RWORK.
  103. C LENW >= 7*N+NSAVE*(3*N+1).
  104. C IWORK :WORK Integer IWORK(LENIW).
  105. C Used to hold pointers into the RWORK array.
  106. C LENIW :IN Integer.
  107. C Length of the integer workspace, IWORK. LENIW >= 10.
  108. C
  109. C *Description:
  110. C This routine is simply a driver for the DOMN routine. It
  111. C calls the DSDS routine to set up the preconditioning and
  112. C then calls DOMN with the appropriate MATVEC and MSOLVE
  113. C routines.
  114. C
  115. C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
  116. C data structures: 1) the SLAP Triad format or 2) the SLAP
  117. C Column format. The user can hand this routine either of the
  118. C of these data structures and SLAP will figure out which on
  119. C is being used and act accordingly.
  120. C
  121. C =================== S L A P Triad format ===================
  122. C
  123. C In this format only the non-zeros are stored. They may
  124. C appear in *ANY* order. The user supplies three arrays of
  125. C length NELT, where NELT is the number of non-zeros in the
  126. C matrix: (IA(NELT), JA(NELT), A(NELT)). For each non-zero
  127. C the user puts the row and column index of that matrix
  128. C element in the IA and JA arrays. The value of the non-zero
  129. C matrix element is placed in the corresponding location of
  130. C the A array. This is an extremely easy data structure to
  131. C generate. On the other hand it is not too efficient on
  132. C vector computers for the iterative solution of linear
  133. C systems. Hence, SLAP changes this input data structure to
  134. C the SLAP Column format for the iteration (but does not
  135. C change it back).
  136. C
  137. C Here is an example of the SLAP Triad storage format for a
  138. C 5x5 Matrix. Recall that the entries may appear in any order.
  139. C
  140. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  141. C 1 2 3 4 5 6 7 8 9 10 11
  142. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  143. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  144. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  145. C | 0 0 0 44 0|
  146. C |51 0 53 0 55|
  147. C
  148. C =================== S L A P Column format ==================
  149. C
  150. C In this format the non-zeros are stored counting down
  151. C columns (except for the diagonal entry, which must appear
  152. C first in each "column") and are stored in the double pre-
  153. C cision array A. In other words, for each column in the
  154. C matrix first put the diagonal entry in A. Then put in the
  155. C other non-zero elements going down the column (except the
  156. C diagonal) in order. The IA array holds the row index for
  157. C each non-zero. The JA array holds the offsets into the IA,
  158. C A arrays for the beginning of each column. That is,
  159. C IA(JA(ICOL)),A(JA(ICOL)) are the first elements of the ICOL-
  160. C th column in IA and A, and IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1)
  161. C are the last elements of the ICOL-th column. Note that we
  162. C always have JA(N+1)=NELT+1, where N is the number of columns
  163. C in the matrix and NELT is the number of non-zeros in the
  164. C matrix.
  165. C
  166. C Here is an example of the SLAP Column storage format for a
  167. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  168. C column):
  169. C
  170. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  171. C 1 2 3 4 5 6 7 8 9 10 11
  172. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  173. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  174. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  175. C | 0 0 0 44 0|
  176. C |51 0 53 0 55|
  177. C
  178. C *Side Effects:
  179. C The SLAP Triad format (IA, JA, A) is modified internally to
  180. C be the SLAP Column format. See above.
  181. C
  182. C *Cautions:
  183. C This routine will attempt to write to the Fortran logical output
  184. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  185. C this logical unit is attached to a file or terminal before calling
  186. C this routine with a non-zero value for IUNIT. This routine does
  187. C not check for the validity of a non-zero IUNIT unit number.
  188. C
  189. C***SEE ALSO DOMN, DSLUOM
  190. C***REFERENCES (NONE)
  191. C***ROUTINES CALLED DCHKW, DOMN, DS2Y, DSDI, DSDS, DSMV
  192. C***REVISION HISTORY (YYMMDD)
  193. C 890404 DATE WRITTEN
  194. C 890404 Previous REVISION DATE
  195. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  196. C 890921 Removed TeX from comments. (FNF)
  197. C 890922 Numerous changes to prologue to make closer to SLATEC
  198. C standard. (FNF)
  199. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  200. C 910411 Prologue converted to Version 4.0 format. (BAB)
  201. C 920407 COMMON BLOCK renamed DSLBLK. (WRB)
  202. C 920511 Added complete declaration section. (WRB)
  203. C 921113 Corrected C***CATEGORY line. (FNF)
  204. C***END PROLOGUE DSDOMN
  205. C .. Parameters ..
  206. INTEGER LOCRB, LOCIB
  207. PARAMETER (LOCRB=1, LOCIB=11)
  208. C .. Scalar Arguments ..
  209. DOUBLE PRECISION ERR, TOL
  210. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, LENIW, LENW, N,
  211. + NELT, NSAVE
  212. C .. Array Arguments ..
  213. DOUBLE PRECISION A(N), B(N), RWORK(LENW), X(N)
  214. INTEGER IA(NELT), IWORK(LENIW), JA(NELT)
  215. C .. Local Scalars ..
  216. INTEGER LOCAP, LOCCSA, LOCDIN, LOCDZ, LOCEMA, LOCIW, LOCP, LOCR,
  217. + LOCW, LOCZ
  218. C .. External Subroutines ..
  219. EXTERNAL DCHKW, DOMN, DS2Y, DSDI, DSDS, DSMV
  220. C***FIRST EXECUTABLE STATEMENT DSDOMN
  221. C
  222. IERR = 0
  223. IF( N.LT.1 .OR. NELT.LT.1 ) THEN
  224. IERR = 3
  225. RETURN
  226. ENDIF
  227. C
  228. C Change the SLAP input matrix IA, JA, A to SLAP-Column format.
  229. CALL DS2Y( N, NELT, IA, JA, A, ISYM )
  230. C
  231. C Set up the workspace.
  232. LOCIW = LOCIB
  233. C
  234. LOCDIN = LOCRB
  235. LOCR = LOCDIN + N
  236. LOCZ = LOCR + N
  237. LOCP = LOCZ + N
  238. LOCAP = LOCP + N*(NSAVE+1)
  239. LOCEMA = LOCAP + N*(NSAVE+1)
  240. LOCDZ = LOCEMA + N*(NSAVE+1)
  241. LOCCSA = LOCDZ + N
  242. LOCW = LOCCSA + NSAVE
  243. C
  244. C Check the workspace allocations.
  245. CALL DCHKW( 'DSDOMN', LOCIW, LENIW, LOCW, LENW, IERR, ITER, ERR )
  246. IF( IERR.NE.0 ) RETURN
  247. C
  248. IWORK(4) = LOCDIN
  249. IWORK(9) = LOCIW
  250. IWORK(10) = LOCW
  251. C
  252. C Compute the inverse of the diagonal of the matrix.
  253. CALL DSDS(N, NELT, IA, JA, A, ISYM, RWORK(LOCDIN))
  254. C
  255. C Perform the Diagonally Scaled Orthomin iteration algorithm.
  256. CALL DOMN(N, B, X, NELT, IA, JA, A, ISYM, DSMV,
  257. $ DSDI, NSAVE, ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT,
  258. $ RWORK(LOCR), RWORK(LOCZ), RWORK(LOCP), RWORK(LOCAP),
  259. $ RWORK(LOCEMA), RWORK(LOCDZ), RWORK(LOCCSA),
  260. $ RWORK, IWORK )
  261. RETURN
  262. C------------- LAST LINE OF DSDOMN FOLLOWS ----------------------------
  263. END