ssics.f 13 KB

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