dsilur.f 13 KB

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