ssilur.f 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. *DECK SSILUR
  2. SUBROUTINE SSILUR (N, B, X, NELT, IA, JA, A, ISYM, ITOL, TOL,
  3. + ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW)
  4. C***BEGIN PROLOGUE SSILUR
  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 SINGLE 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 REAL B(N), X(N), A(NELT), TOL, ERR, RWORK(NL+NU+4*N)
  24. C
  25. C CALL SSILUR(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 Real B(N).
  32. C Right-hand side vector.
  33. C X :INOUT Real 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 Real 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 /SSLBLK/ 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 /SSLBLK/ 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 Real.
  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 Real.
  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*R1MACH(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 Real RWORK(LENW).
  105. C Real array used for workspace.
  106. C LENW :IN Integer.
  107. C Length of the real workspace, RWORK. LENW >= NL+NU+4*N.
  108. C NL is the number of non-zeros in the lower triangle of the
  109. C matrix (including the diagonal).
  110. C NU is the number of non-zeros in the upper triangle of the
  111. C matrix (including the diagonal).
  112. C IWORK :WORK Integer IWORK(LENIW).
  113. C Integer array used for workspace.
  114. C Upon return the following locations of IWORK hold information
  115. C which may be of use to the user:
  116. C IWORK(9) Amount of Integer workspace actually used.
  117. C IWORK(10) Amount of Real workspace actually used.
  118. C LENIW :IN Integer.
  119. C Length of integer workspace, IWORK. LENIW >= NL+NU+4*N+10.
  120. C NL is the number of non-zeros in the lower triangle of the
  121. C matrix (including the diagonal).
  122. C NU is the number of non-zeros in the upper triangle of the
  123. C matrix (including the diagonal).
  124. C
  125. C *Description
  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 real array A. In other words, for each column in the matrix
  167. C put the diagonal entry in A. Then put in the other non-zero
  168. C elements going down the column (except the diagonal) in
  169. C order. The IA array holds the row index for each non-zero.
  170. C The JA array holds the offsets into the IA, A arrays for the
  171. C beginning of each column. That is, IA(JA(ICOL)),
  172. C A(JA(ICOL)) points to the beginning of the ICOL-th column in
  173. C IA and A. IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1) points to the
  174. C end of the ICOL-th column. Note that we always have
  175. C JA(N+1) = NELT+1, where N is the number of columns in the
  176. C matrix and NELT is the number of non-zeros in the matrix.
  177. C
  178. C Here is an example of the SLAP Column storage format for a
  179. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  180. C column):
  181. C
  182. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  183. C 1 2 3 4 5 6 7 8 9 10 11
  184. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  185. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  186. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  187. C | 0 0 0 44 0|
  188. C |51 0 53 0 55|
  189. C
  190. C *Side Effects:
  191. C The SLAP Triad format (IA, JA, A) is modified internally to be
  192. C the SLAP Column format. See above.
  193. C
  194. C *Cautions:
  195. C This routine will attempt to write to the Fortran logical output
  196. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  197. C this logical unit is attached to a file or terminal before calling
  198. C this routine with a non-zero value for IUNIT. This routine does
  199. C not check for the validity of a non-zero IUNIT unit number.
  200. C
  201. C***SEE ALSO SSJAC, SSGS, SIR
  202. C***REFERENCES (NONE)
  203. C***ROUTINES CALLED SCHKW, SIR, SS2Y, SSILUS, SSLUI, SSMV
  204. C***REVISION HISTORY (YYMMDD)
  205. C 871119 DATE WRITTEN
  206. C 881213 Previous REVISION DATE
  207. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  208. C 890921 Removed TeX from comments. (FNF)
  209. C 890922 Numerous changes to prologue to make closer to SLATEC
  210. C standard. (FNF)
  211. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  212. C 910411 Prologue converted to Version 4.0 format. (BAB)
  213. C 920407 COMMON BLOCK renamed SSLBLK. (WRB)
  214. C 920511 Added complete declaration section. (WRB)
  215. C 921019 Corrected NEL to NL. (FNF)
  216. C***END PROLOGUE SSILUR
  217. C .. Parameters ..
  218. INTEGER LOCRB, LOCIB
  219. PARAMETER (LOCRB=1, LOCIB=11)
  220. C .. Scalar Arguments ..
  221. REAL ERR, TOL
  222. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, LENIW, LENW, N, NELT
  223. C .. Array Arguments ..
  224. REAL A(NELT), B(N), RWORK(LENW), X(N)
  225. INTEGER IA(NELT), IWORK(LENIW), JA(NELT)
  226. C .. Local Scalars ..
  227. INTEGER ICOL, J, JBGN, JEND, LOCDIN, LOCDZ, LOCIL, LOCIU, LOCIW,
  228. + LOCJL, LOCJU, LOCL, LOCNC, LOCNR, LOCR, LOCU, LOCW, LOCZ,
  229. + NL, NU
  230. C .. External Subroutines ..
  231. EXTERNAL SCHKW, SIR, SS2Y, SSILUS, SSLUI, SSMV
  232. C***FIRST EXECUTABLE STATEMENT SSILUR
  233. C
  234. IERR = 0
  235. IF( N.LT.1 .OR. NELT.LT.1 ) THEN
  236. IERR = 3
  237. RETURN
  238. ENDIF
  239. C
  240. C Change the SLAP input matrix IA, JA, A to SLAP-Column format.
  241. CALL SS2Y( N, NELT, IA, JA, A, ISYM )
  242. C
  243. C Count number of Non-Zero elements in preconditioner ILU
  244. C matrix. Then set up the work arrays.
  245. NL = 0
  246. NU = 0
  247. DO 20 ICOL = 1, N
  248. C Don't count diagonal.
  249. JBGN = JA(ICOL)+1
  250. JEND = JA(ICOL+1)-1
  251. IF( JBGN.LE.JEND ) THEN
  252. CVD$ NOVECTOR
  253. DO 10 J = JBGN, JEND
  254. IF( IA(J).GT.ICOL ) THEN
  255. NL = NL + 1
  256. IF( ISYM.NE.0 ) NU = NU + 1
  257. ELSE
  258. NU = NU + 1
  259. ENDIF
  260. 10 CONTINUE
  261. ENDIF
  262. 20 CONTINUE
  263. C
  264. LOCIL = LOCIB
  265. LOCJL = LOCIL + N+1
  266. LOCIU = LOCJL + NL
  267. LOCJU = LOCIU + NU
  268. LOCNR = LOCJU + N+1
  269. LOCNC = LOCNR + N
  270. LOCIW = LOCNC + N
  271. C
  272. LOCL = LOCRB
  273. LOCDIN = LOCL + NL
  274. LOCU = LOCDIN + N
  275. LOCR = LOCU + NU
  276. LOCZ = LOCR + N
  277. LOCDZ = LOCZ + N
  278. LOCW = LOCDZ + N
  279. C
  280. C Check the workspace allocations.
  281. CALL SCHKW( 'SSILUR', LOCIW, LENIW, LOCW, LENW, IERR, ITER, ERR )
  282. IF( IERR.NE.0 ) RETURN
  283. C
  284. IWORK(1) = LOCIL
  285. IWORK(2) = LOCJL
  286. IWORK(3) = LOCIU
  287. IWORK(4) = LOCJU
  288. IWORK(5) = LOCL
  289. IWORK(6) = LOCDIN
  290. IWORK(7) = LOCU
  291. IWORK(9) = LOCIW
  292. IWORK(10) = LOCW
  293. C
  294. C Compute the Incomplete LU decomposition.
  295. CALL SSILUS( N, NELT, IA, JA, A, ISYM, NL, IWORK(LOCIL),
  296. $ IWORK(LOCJL), RWORK(LOCL), RWORK(LOCDIN), NU, IWORK(LOCIU),
  297. $ IWORK(LOCJU), RWORK(LOCU), IWORK(LOCNR), IWORK(LOCNC) )
  298. C
  299. C Do the Preconditioned Iterative Refinement iteration.
  300. CALL SIR(N, B, X, NELT, IA, JA, A, ISYM, SSMV, SSLUI,
  301. $ ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT, RWORK(LOCR),
  302. $ RWORK(LOCZ), RWORK(LOCDZ), RWORK, IWORK)
  303. RETURN
  304. C------------- LAST LINE OF SSILUR FOLLOWS ----------------------------
  305. END