dslucs.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. *DECK DSLUCS
  2. SUBROUTINE DSLUCS (N, B, X, NELT, IA, JA, A, ISYM, ITOL, TOL,
  3. + ITMAX, ITER, ERR, IERR, IUNIT, RWORK, LENW, IWORK, LENIW)
  4. C***BEGIN PROLOGUE DSLUCS
  5. C***PURPOSE Incomplete LU BiConjugate Gradient Squared Ax=b Solver.
  6. C Routine to solve a linear system Ax = b using the
  7. C BiConjugate Gradient Squared method with Incomplete LU
  8. C decomposition preconditioning.
  9. C***LIBRARY SLATEC (SLAP)
  10. C***CATEGORY D2A4, D2B4
  11. C***TYPE DOUBLE PRECISION (SSLUCS-S, DSLUCS-D)
  12. C***KEYWORDS ITERATIVE INCOMPLETE LU PRECONDITION,
  13. C NON-SYMMETRIC LINEAR SYSTEM, SLAP, SPARSE
  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+NU+4*N+2), LENIW
  25. C DOUBLE PRECISION B(N), X(N), A(NELT), TOL, ERR, RWORK(NL+NU+8*N)
  26. C
  27. C CALL DSLUCS(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 This routine must calculate the residual from R = A*X - B.
  57. C This is unnatural and hence expensive for this type of iter-
  58. C ative method. ITOL=2 is *STRONGLY* recommended.
  59. C If ITOL=2, iteration stops when the 2-norm of M-inv times the
  60. C residual divided by the 2-norm of M-inv times the right hand
  61. C side is less than TOL, where M-inv time a vector is the pre-
  62. C conditioning step. This is the *NATURAL* stopping for this
  63. C iterative method and is *STRONGLY* recommended.
  64. C TOL :INOUT Double Precision.
  65. C Convergence criterion, as described above. (Reset if IERR=4.)
  66. C ITMAX :IN Integer.
  67. C Maximum number of iterations.
  68. C ITER :OUT Integer.
  69. C Number of iterations required to reach convergence, or
  70. C ITMAX+1 if convergence criterion could not be achieved in
  71. C ITMAX iterations.
  72. C ERR :OUT Double Precision.
  73. C Error estimate of error in final approximate solution, as
  74. C defined by ITOL.
  75. C IERR :OUT Integer.
  76. C Return error flag.
  77. C IERR = 0 => All went well.
  78. C IERR = 1 => Insufficient space allocated for WORK or IWORK.
  79. C IERR = 2 => Method failed to converge in ITMAX steps.
  80. C IERR = 3 => Error in user input.
  81. C Check input values of N, ITOL.
  82. C IERR = 4 => User error tolerance set too tight.
  83. C Reset to 500*D1MACH(3). Iteration proceeded.
  84. C IERR = 5 => Breakdown of the method detected.
  85. C (r0,r) approximately 0.
  86. C IERR = 6 => Stagnation of the method detected.
  87. C (r0,v) approximately 0.
  88. C IERR = 7 => Incomplete factorization broke down and was
  89. C fudged. Resulting preconditioning may be less
  90. C than the best.
  91. C IUNIT :IN Integer.
  92. C Unit number on which to write the error at each iteration,
  93. C if this is desired for monitoring convergence. If unit
  94. C number is 0, no writing will occur.
  95. C RWORK :WORK Double Precision RWORK(LENW).
  96. C Double Precision array used for workspace. NL is the number
  97. C of non-zeros in the lower triangle of the matrix (including
  98. C the diagonal). NU is the number of non-zeros in the upper
  99. C triangle of the matrix (including the diagonal).
  100. C LENW :IN Integer.
  101. C Length of the double precision workspace, RWORK.
  102. C LENW >= NL+NU+8*N.
  103. C IWORK :WORK Integer IWORK(LENIW).
  104. C Integer array used for workspace. NL is the number of non-
  105. C zeros in the lower triangle of the matrix (including the
  106. C diagonal). NU is the number of non-zeros in the upper
  107. C triangle of the matrix (including the diagonal).
  108. C Upon return the following locations of IWORK hold information
  109. C which may be of use to the user:
  110. C IWORK(9) Amount of Integer workspace actually used.
  111. C IWORK(10) Amount of Double Precision workspace actually used.
  112. C LENIW :IN Integer.
  113. C Length of the integer workspace, IWORK.
  114. C LENIW >= NL+NU+4*N+12.
  115. C
  116. C *Description:
  117. C This routine is simply a driver for the DCGSN routine. It
  118. C calls the DSILUS routine to set up the preconditioning and
  119. C then calls DCGSN with the appropriate MATVEC, MTTVEC and
  120. C MSOLVE, MTSOLV routines.
  121. C
  122. C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
  123. C data structures: 1) the SLAP Triad format or 2) the SLAP
  124. C Column format. The user can hand this routine either of the
  125. C of these data structures and SLAP will figure out which on
  126. C is being used and act accordingly.
  127. C
  128. C =================== S L A P Triad format ===================
  129. C
  130. C This routine requires that the matrix A be stored in the
  131. C SLAP Triad format. In this format only the non-zeros are
  132. C stored. They may appear in *ANY* order. The user supplies
  133. C three arrays of length NELT, where NELT is the number of
  134. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  135. C each non-zero the user puts the row and column index of that
  136. C matrix element in the IA and JA arrays. The value of the
  137. C non-zero matrix element is placed in the corresponding
  138. C location of the A array. This is an extremely easy data
  139. C structure to generate. On the other hand it is not too
  140. C efficient on vector computers for the iterative solution of
  141. C linear systems. Hence, SLAP changes this input data
  142. C structure to the SLAP Column format for the iteration (but
  143. C does not change it back).
  144. C
  145. C Here is an example of the SLAP Triad storage format for a
  146. C 5x5 Matrix. Recall that the entries may appear in any order.
  147. C
  148. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  149. C 1 2 3 4 5 6 7 8 9 10 11
  150. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  151. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  152. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  153. C | 0 0 0 44 0|
  154. C |51 0 53 0 55|
  155. C
  156. C =================== S L A P Column format ==================
  157. C
  158. C This routine requires that the matrix A be stored in the
  159. C SLAP Column format. In this format the non-zeros are stored
  160. C counting down columns (except for the diagonal entry, which
  161. C must appear first in each "column") and are stored in the
  162. C double precision array A. In other words, for each column
  163. C in the matrix put the diagonal entry in A. Then put in the
  164. C other non-zero elements going down the column (except the
  165. C diagonal) in order. The IA array holds the row index for
  166. C each non-zero. The JA array holds the offsets into the IA,
  167. C A arrays for the beginning of each column. That is,
  168. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  169. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  170. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  171. C Note that we always have JA(N+1) = NELT+1, where N is the
  172. C number of columns in the matrix and NELT is the number of
  173. C non-zeros in the matrix.
  174. C
  175. C Here is an example of the SLAP Column storage format for a
  176. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  177. C column):
  178. C
  179. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  180. C 1 2 3 4 5 6 7 8 9 10 11
  181. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  182. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  183. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  184. C | 0 0 0 44 0|
  185. C |51 0 53 0 55|
  186. C
  187. C *Side Effects:
  188. C The SLAP Triad format (IA, JA, A) is modified internally to
  189. C be the SLAP Column format. See above.
  190. C
  191. C *Cautions:
  192. C This routine will attempt to write to the Fortran logical output
  193. C unit IUNIT, if IUNIT .ne. 0. Thus, the user must make sure that
  194. C this logical unit is attached to a file or terminal before calling
  195. C this routine with a non-zero value for IUNIT. This routine does
  196. C not check for the validity of a non-zero IUNIT unit number.
  197. C
  198. C***SEE ALSO DCGS, DSDCGS
  199. C***REFERENCES 1. P. Sonneveld, CGS, a fast Lanczos-type solver
  200. C for nonsymmetric linear systems, Delft University
  201. C of Technology Report 84-16, Department of Mathe-
  202. C matics and Informatics, Delft, The Netherlands.
  203. C 2. E. F. Kaasschieter, The solution of non-symmetric
  204. C linear systems by biconjugate gradients or conjugate
  205. C gradients squared, Delft University of Technology
  206. C Report 86-21, Department of Mathematics and Informa-
  207. C tics, Delft, The Netherlands.
  208. C***ROUTINES CALLED DCGS, DCHKW, DS2Y, DSILUS, DSLUI, DSMV
  209. C***REVISION HISTORY (YYMMDD)
  210. C 890404 DATE WRITTEN
  211. C 890404 Previous REVISION DATE
  212. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  213. C 890921 Removed TeX from comments. (FNF)
  214. C 890922 Numerous changes to prologue to make closer to SLATEC
  215. C standard. (FNF)
  216. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  217. C 910411 Prologue converted to Version 4.0 format. (BAB)
  218. C 920511 Added complete declaration section. (WRB)
  219. C 920929 Corrected format of references. (FNF)
  220. C 921113 Corrected C***CATEGORY line. (FNF)
  221. C***END PROLOGUE DSLUCS
  222. C .. Parameters ..
  223. INTEGER LOCRB, LOCIB
  224. PARAMETER (LOCRB=1, LOCIB=11)
  225. C .. Scalar Arguments ..
  226. DOUBLE PRECISION ERR, TOL
  227. INTEGER IERR, ISYM, ITER, ITMAX, ITOL, IUNIT, LENIW, LENW, N, NELT
  228. C .. Array Arguments ..
  229. DOUBLE PRECISION A(NELT), B(N), RWORK(LENW), X(N)
  230. INTEGER IA(NELT), IWORK(LENIW), JA(NELT)
  231. C .. Local Scalars ..
  232. INTEGER ICOL, J, JBGN, JEND, LOCDIN, LOCIL, LOCIU, LOCIW, LOCJL,
  233. + LOCJU, LOCL, LOCNC, LOCNR, LOCP, LOCQ, LOCR, LOCR0, LOCU,
  234. + LOCUU, LOCV1, LOCV2, LOCW, NL, NU
  235. C .. External Subroutines ..
  236. EXTERNAL DCGS, DCHKW, DS2Y, DSILUS, DSLUI, DSMV
  237. C***FIRST EXECUTABLE STATEMENT DSLUCS
  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 Change the SLAP input matrix IA, JA, A to SLAP-Column format.
  246. CALL DS2Y( N, NELT, IA, JA, A, ISYM )
  247. C
  248. C Count number of Non-Zero elements preconditioner ILU matrix.
  249. C Then set up the work arrays.
  250. NL = 0
  251. NU = 0
  252. DO 20 ICOL = 1, N
  253. C Don't count diagonal.
  254. JBGN = JA(ICOL)+1
  255. JEND = JA(ICOL+1)-1
  256. IF( JBGN.LE.JEND ) THEN
  257. CVD$ NOVECTOR
  258. DO 10 J = JBGN, JEND
  259. IF( IA(J).GT.ICOL ) THEN
  260. NL = NL + 1
  261. IF( ISYM.NE.0 ) NU = NU + 1
  262. ELSE
  263. NU = NU + 1
  264. ENDIF
  265. 10 CONTINUE
  266. ENDIF
  267. 20 CONTINUE
  268. C
  269. LOCIL = LOCIB
  270. LOCJL = LOCIL + N+1
  271. LOCIU = LOCJL + NL
  272. LOCJU = LOCIU + NU
  273. LOCNR = LOCJU + N+1
  274. LOCNC = LOCNR + N
  275. LOCIW = LOCNC + N
  276. C
  277. LOCL = LOCRB
  278. LOCDIN = LOCL + NL
  279. LOCUU = LOCDIN + N
  280. LOCR = LOCUU + NU
  281. LOCR0 = LOCR + N
  282. LOCP = LOCR0 + N
  283. LOCQ = LOCP + N
  284. LOCU = LOCQ + N
  285. LOCV1 = LOCU + N
  286. LOCV2 = LOCV1 + N
  287. LOCW = LOCV2 + N
  288. C
  289. C Check the workspace allocations.
  290. CALL DCHKW( 'DSLUCS', LOCIW, LENIW, LOCW, LENW, IERR, ITER, ERR )
  291. IF( IERR.NE.0 ) RETURN
  292. C
  293. IWORK(1) = LOCIL
  294. IWORK(2) = LOCJL
  295. IWORK(3) = LOCIU
  296. IWORK(4) = LOCJU
  297. IWORK(5) = LOCL
  298. IWORK(6) = LOCDIN
  299. IWORK(7) = LOCUU
  300. IWORK(9) = LOCIW
  301. IWORK(10) = LOCW
  302. C
  303. C Compute the Incomplete LU decomposition.
  304. CALL DSILUS( N, NELT, IA, JA, A, ISYM, NL, IWORK(LOCIL),
  305. $ IWORK(LOCJL), RWORK(LOCL), RWORK(LOCDIN), NU, IWORK(LOCIU),
  306. $ IWORK(LOCJU), RWORK(LOCUU), IWORK(LOCNR), IWORK(LOCNC) )
  307. C
  308. C Perform the incomplete LU preconditioned
  309. C BiConjugate Gradient Squared algorithm.
  310. CALL DCGS(N, B, X, NELT, IA, JA, A, ISYM, DSMV,
  311. $ DSLUI, ITOL, TOL, ITMAX, ITER, ERR, IERR, IUNIT,
  312. $ RWORK(LOCR), RWORK(LOCR0), RWORK(LOCP),
  313. $ RWORK(LOCQ), RWORK(LOCU), RWORK(LOCV1),
  314. $ RWORK(LOCV2), RWORK, IWORK )
  315. RETURN
  316. C------------- LAST LINE OF DSLUCS FOLLOWS ----------------------------
  317. END