dsluom.f 14 KB

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