dsics.f 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. *DECK DSICS
  2. SUBROUTINE DSICS (N, NELT, IA, JA, A, ISYM, NEL, IEL, JEL, EL, D,
  3. + R, IWARN)
  4. C***BEGIN PROLOGUE DSICS
  5. C***PURPOSE Incompl. Cholesky Decomposition Preconditioner SLAP Set Up.
  6. C Routine to generate the Incomplete Cholesky decomposition,
  7. C L*D*L-trans, of a symmetric positive definite matrix, A,
  8. C which is stored in SLAP Column format. The unit lower
  9. C triangular matrix L is stored by rows, and the inverse of
  10. C the diagonal matrix D is stored.
  11. C***LIBRARY SLATEC (SLAP)
  12. C***CATEGORY D2E
  13. C***TYPE DOUBLE PRECISION (SSICS-S, DSICS-D)
  14. C***KEYWORDS INCOMPLETE CHOLESKY FACTORIZATION,
  15. C ITERATIVE PRECONDITION, LINEAR SYSTEM, SLAP SPARSE
  16. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  17. C Seager, Mark K., (LLNL)
  18. C Lawrence Livermore National Laboratory
  19. C PO BOX 808, L-60
  20. C Livermore, CA 94550 (510) 423-3141
  21. C seager@llnl.gov
  22. C***DESCRIPTION
  23. C
  24. C *Usage:
  25. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM
  26. C INTEGER NEL, IEL(NEL), JEL(NEL), IWARN
  27. C DOUBLE PRECISION A(NELT), EL(NEL), D(N), R(N)
  28. C
  29. C CALL DSICS( N, NELT, IA, JA, A, ISYM, NEL, IEL, JEL, EL, D, R,
  30. C $ IWARN )
  31. C
  32. C *Arguments:
  33. C N :IN Integer.
  34. C Order of the Matrix.
  35. C NELT :IN Integer.
  36. C Number of elements in arrays IA, JA, and A.
  37. C IA :INOUT Integer IA(NELT).
  38. C JA :INOUT Integer JA(NELT).
  39. C A :INOUT Double Precision A(NELT).
  40. C These arrays should hold the matrix A in the SLAP Column
  41. C format. See "Description", below.
  42. C ISYM :IN Integer.
  43. C Flag to indicate symmetric storage format.
  44. C If ISYM=0, all non-zero entries of the matrix are stored.
  45. C If ISYM=1, the matrix is symmetric, and only the lower
  46. C triangle of the matrix is stored.
  47. C NEL :OUT Integer.
  48. C Number of non-zeros in the lower triangle of A. Also
  49. C corresponds to the length of the IEL, JEL, EL arrays.
  50. C IEL :OUT Integer IEL(NEL).
  51. C JEL :OUT Integer JEL(NEL).
  52. C EL :OUT Double Precision EL(NEL).
  53. C IEL, JEL, EL contain the unit lower triangular factor of the
  54. C incomplete decomposition of the A matrix stored in SLAP
  55. C Row format. The Diagonal of ones *IS* stored. See
  56. C "Description", below for more details about the SLAP Row fmt.
  57. C D :OUT Double Precision D(N)
  58. C Upon return this array holds D(I) = 1./DIAG(A).
  59. C R :WORK Double Precision R(N).
  60. C Temporary double precision workspace needed for the
  61. C factorization.
  62. C IWARN :OUT Integer.
  63. C This is a warning variable and is zero if the IC factoriza-
  64. C tion goes well. It is set to the row index corresponding to
  65. C the last zero pivot found. See "Description", below.
  66. C
  67. C *Description
  68. C =================== S L A P Column format ==================
  69. C This routine requires that the matrix A be stored in the
  70. C SLAP Column format. In this format the non-zeros are stored
  71. C counting down columns (except for the diagonal entry, which
  72. C must appear first in each "column") and are stored in the
  73. C double precision array A. In other words, for each column
  74. C in the matrix put the diagonal entry in A. Then put in the
  75. C other non-zero elements going down the column (except the
  76. C diagonal) in order. The IA array holds the row index for
  77. C each non-zero. The JA array holds the offsets into the IA,
  78. C A arrays for the beginning of each column. That is,
  79. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  80. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  81. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  82. C Note that we always have JA(N+1) = NELT+1, where N is the
  83. C number of columns in the matrix and NELT is the number of
  84. C non-zeros in the matrix.
  85. C
  86. C Here is an example of the SLAP Column storage format for a
  87. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  88. C column):
  89. C
  90. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  91. C 1 2 3 4 5 6 7 8 9 10 11
  92. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  93. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  94. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  95. C | 0 0 0 44 0|
  96. C |51 0 53 0 55|
  97. C
  98. C ==================== S L A P Row format ====================
  99. C
  100. C This routine requires that the matrix A be stored in the
  101. C SLAP Row format. In this format the non-zeros are stored
  102. C counting across rows (except for the diagonal entry, which
  103. C must appear first in each "row") and are stored in the
  104. C double precision array A. In other words, for each row in
  105. C the matrix put the diagonal entry in A. Then put in the
  106. C other non-zero elements going across the row (except the
  107. C diagonal) in order. The JA array holds the column index for
  108. C each non-zero. The IA array holds the offsets into the JA,
  109. C A arrays for the beginning of each row. That is,
  110. C JA(IA(IROW)),A(IA(IROW)) are the first elements of the IROW-
  111. C th row in JA and A, and JA(IA(IROW+1)-1), A(IA(IROW+1)-1)
  112. C are the last elements of the IROW-th row. Note that we
  113. C always have IA(N+1) = NELT+1, where N is the number of rows
  114. C in the matrix and NELT is the number of non-zeros in the
  115. C matrix.
  116. C
  117. C Here is an example of the SLAP Row storage format for a 5x5
  118. C Matrix (in the A and JA arrays '|' denotes the end of a row):
  119. C
  120. C 5x5 Matrix SLAP Row format for 5x5 matrix on left.
  121. C 1 2 3 4 5 6 7 8 9 10 11
  122. C |11 12 0 0 15| A: 11 12 15 | 22 21 | 33 35 | 44 | 55 51 53
  123. C |21 22 0 0 0| JA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  124. C | 0 0 33 0 35| IA: 1 4 6 8 9 12
  125. C | 0 0 0 44 0|
  126. C |51 0 53 0 55|
  127. C
  128. C With the SLAP format some of the "inner loops" of this
  129. C routine should vectorize on machines with hardware support
  130. C for vector gather/scatter operations. Your compiler may
  131. C require a compiler directive to convince it that there are
  132. C no implicit vector dependencies. Compiler directives for
  133. C the Alliant FX/Fortran and CRI CFT/CFT77 compilers are
  134. C supplied with the standard SLAP distribution.
  135. C
  136. C The IC factorization does not always exist for SPD matrices.
  137. C In the event that a zero pivot is found it is set to be 1.0
  138. C and the factorization proceeds. The integer variable IWARN
  139. C is set to the last row where the Diagonal was fudged. This
  140. C eventuality hardly ever occurs in practice.
  141. C
  142. C***SEE ALSO DCG, DSICCG
  143. C***REFERENCES 1. Gene Golub and Charles Van Loan, Matrix Computations,
  144. C Johns Hopkins University Press, Baltimore, Maryland,
  145. C 1983.
  146. C***ROUTINES CALLED XERMSG
  147. C***REVISION HISTORY (YYMMDD)
  148. C 890404 DATE WRITTEN
  149. C 890404 Previous REVISION DATE
  150. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  151. C 890922 Numerous changes to prologue to make closer to SLATEC
  152. C standard. (FNF)
  153. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  154. C 900805 Changed XERRWV calls to calls to XERMSG. (RWC)
  155. C 910411 Prologue converted to Version 4.0 format. (BAB)
  156. C 920511 Added complete declaration section. (WRB)
  157. C 920929 Corrected format of reference. (FNF)
  158. C 930701 Updated CATEGORY section. (FNF, WRB)
  159. C***END PROLOGUE DSICS
  160. C .. Scalar Arguments ..
  161. INTEGER ISYM, IWARN, N, NEL, NELT
  162. C .. Array Arguments ..
  163. DOUBLE PRECISION A(NELT), D(N), EL(NEL), R(N)
  164. INTEGER IA(NELT), IEL(NEL), JA(NELT), JEL(NEL)
  165. C .. Local Scalars ..
  166. DOUBLE PRECISION ELTMP
  167. INTEGER I, IBGN, IC, ICBGN, ICEND, ICOL, IEND, IR, IRBGN, IREND,
  168. + IROW, IRR, J, JBGN, JELTMP, JEND
  169. CHARACTER XERN1*8
  170. C .. External Subroutines ..
  171. EXTERNAL XERMSG
  172. C***FIRST EXECUTABLE STATEMENT DSICS
  173. C
  174. C Set the lower triangle in IEL, JEL, EL
  175. C
  176. IWARN = 0
  177. C
  178. C All matrix elements stored in IA, JA, A. Pick out the lower
  179. C triangle (making sure that the Diagonal of EL is one) and
  180. C store by rows.
  181. C
  182. NEL = 1
  183. IEL(1) = 1
  184. JEL(1) = 1
  185. EL(1) = 1
  186. D(1) = A(1)
  187. CVD$R NOCONCUR
  188. DO 30 IROW = 2, N
  189. C Put in the Diagonal.
  190. NEL = NEL + 1
  191. IEL(IROW) = NEL
  192. JEL(NEL) = IROW
  193. EL(NEL) = 1
  194. D(IROW) = A(JA(IROW))
  195. C
  196. C Look in all the lower triangle columns for a matching row.
  197. C Since the matrix is symmetric, we can look across the
  198. C IROW-th row by looking down the IROW-th column (if it is
  199. C stored ISYM=0)...
  200. IF( ISYM.EQ.0 ) THEN
  201. ICBGN = JA(IROW)
  202. ICEND = JA(IROW+1)-1
  203. ELSE
  204. ICBGN = 1
  205. ICEND = IROW-1
  206. ENDIF
  207. DO 20 IC = ICBGN, ICEND
  208. IF( ISYM.EQ.0 ) THEN
  209. ICOL = IA(IC)
  210. IF( ICOL.GE.IROW ) GOTO 20
  211. ELSE
  212. ICOL = IC
  213. ENDIF
  214. JBGN = JA(ICOL)+1
  215. JEND = JA(ICOL+1)-1
  216. IF( JBGN.LE.JEND .AND. IA(JEND).GE.IROW ) THEN
  217. CVD$ NOVECTOR
  218. DO 10 J = JBGN, JEND
  219. IF( IA(J).EQ.IROW ) THEN
  220. NEL = NEL + 1
  221. JEL(NEL) = ICOL
  222. EL(NEL) = A(J)
  223. GOTO 20
  224. ENDIF
  225. 10 CONTINUE
  226. ENDIF
  227. 20 CONTINUE
  228. 30 CONTINUE
  229. IEL(N+1) = NEL+1
  230. C
  231. C Sort ROWS of lower triangle into descending order (count out
  232. C along rows out from Diagonal).
  233. C
  234. DO 60 IROW = 2, N
  235. IBGN = IEL(IROW)+1
  236. IEND = IEL(IROW+1)-1
  237. IF( IBGN.LT.IEND ) THEN
  238. DO 50 I = IBGN, IEND-1
  239. CVD$ NOVECTOR
  240. DO 40 J = I+1, IEND
  241. IF( JEL(I).GT.JEL(J) ) THEN
  242. JELTMP = JEL(J)
  243. JEL(J) = JEL(I)
  244. JEL(I) = JELTMP
  245. ELTMP = EL(J)
  246. EL(J) = EL(I)
  247. EL(I) = ELTMP
  248. ENDIF
  249. 40 CONTINUE
  250. 50 CONTINUE
  251. ENDIF
  252. 60 CONTINUE
  253. C
  254. C Perform the Incomplete Cholesky decomposition by looping
  255. C over the rows.
  256. C Scale the first column. Use the structure of A to pick out
  257. C the rows with something in column 1.
  258. C
  259. IRBGN = JA(1)+1
  260. IREND = JA(2)-1
  261. DO 65 IRR = IRBGN, IREND
  262. IR = IA(IRR)
  263. C Find the index into EL for EL(1,IR).
  264. C Hint: it's the second entry.
  265. I = IEL(IR)+1
  266. EL(I) = EL(I)/D(1)
  267. 65 CONTINUE
  268. C
  269. DO 110 IROW = 2, N
  270. C
  271. C Update the IROW-th diagonal.
  272. C
  273. DO 66 I = 1, IROW-1
  274. R(I) = 0
  275. 66 CONTINUE
  276. IBGN = IEL(IROW)+1
  277. IEND = IEL(IROW+1)-1
  278. IF( IBGN.LE.IEND ) THEN
  279. CLLL. OPTION ASSERT (NOHAZARD)
  280. CDIR$ IVDEP
  281. CVD$ NODEPCHK
  282. DO 70 I = IBGN, IEND
  283. R(JEL(I)) = EL(I)*D(JEL(I))
  284. D(IROW) = D(IROW) - EL(I)*R(JEL(I))
  285. 70 CONTINUE
  286. C
  287. C Check to see if we have a problem with the diagonal.
  288. C
  289. IF( D(IROW).LE.0.0D0 ) THEN
  290. IF( IWARN.EQ.0 ) IWARN = IROW
  291. D(IROW) = 1
  292. ENDIF
  293. ENDIF
  294. C
  295. C Update each EL(IROW+1:N,IROW), if there are any.
  296. C Use the structure of A to determine the Non-zero elements
  297. C of the IROW-th column of EL.
  298. C
  299. IRBGN = JA(IROW)
  300. IREND = JA(IROW+1)-1
  301. DO 100 IRR = IRBGN, IREND
  302. IR = IA(IRR)
  303. IF( IR.LE.IROW ) GOTO 100
  304. C Find the index into EL for EL(IR,IROW)
  305. IBGN = IEL(IR)+1
  306. IEND = IEL(IR+1)-1
  307. IF( JEL(IBGN).GT.IROW ) GOTO 100
  308. DO 90 I = IBGN, IEND
  309. IF( JEL(I).EQ.IROW ) THEN
  310. ICEND = IEND
  311. 91 IF( JEL(ICEND).GE.IROW ) THEN
  312. ICEND = ICEND - 1
  313. GOTO 91
  314. ENDIF
  315. C Sum up the EL(IR,1:IROW-1)*R(1:IROW-1) contributions.
  316. CLLL. OPTION ASSERT (NOHAZARD)
  317. CDIR$ IVDEP
  318. CVD$ NODEPCHK
  319. DO 80 IC = IBGN, ICEND
  320. EL(I) = EL(I) - EL(IC)*R(JEL(IC))
  321. 80 CONTINUE
  322. EL(I) = EL(I)/D(IROW)
  323. GOTO 100
  324. ENDIF
  325. 90 CONTINUE
  326. C
  327. C If we get here, we have real problems...
  328. WRITE (XERN1, '(I8)') IROW
  329. CALL XERMSG ('SLATEC', 'DSICS',
  330. $ 'A and EL data structure mismatch in row '// XERN1, 1, 2)
  331. 100 CONTINUE
  332. 110 CONTINUE
  333. C
  334. C Replace diagonals by their inverses.
  335. C
  336. CVD$ CONCUR
  337. DO 120 I =1, N
  338. D(I) = 1.0D0/D(I)
  339. 120 CONTINUE
  340. RETURN
  341. C------------- LAST LINE OF DSICS FOLLOWS ----------------------------
  342. END