ssd2s.f 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. *DECK SSD2S
  2. SUBROUTINE SSD2S (N, NELT, IA, JA, A, ISYM, DINV)
  3. C***BEGIN PROLOGUE SSD2S
  4. C***PURPOSE Diagonal Scaling Preconditioner SLAP Normal Eqns Set Up.
  5. C Routine to compute the inverse of the diagonal of the
  6. C matrix A*A', where A is stored in SLAP-Column format.
  7. C***LIBRARY SLATEC (SLAP)
  8. C***CATEGORY D2E
  9. C***TYPE SINGLE PRECISION (SSD2S-S, DSD2S-D)
  10. C***KEYWORDS DIAGONAL, SLAP SPARSE
  11. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  12. C Seager, Mark K., (LLNL)
  13. C Lawrence Livermore National Laboratory
  14. C PO BOX 808, L-60
  15. C Livermore, CA 94550 (510) 423-3141
  16. C seager@llnl.gov
  17. C***DESCRIPTION
  18. C
  19. C *Usage:
  20. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM
  21. C REAL A(NELT), DINV(N)
  22. C
  23. C CALL SSD2S( N, NELT, IA, JA, A, ISYM, DINV )
  24. C
  25. C *Arguments:
  26. C N :IN Integer
  27. C Order of the Matrix.
  28. C NELT :IN Integer.
  29. C Number of elements in arrays IA, JA, and A.
  30. C IA :IN Integer IA(NELT).
  31. C JA :IN Integer JA(NELT).
  32. C A :IN Real A(NELT).
  33. C These arrays should hold the matrix A in the SLAP Column
  34. C format. See "Description", below.
  35. C ISYM :IN Integer.
  36. C Flag to indicate symmetric storage format.
  37. C If ISYM=0, all non-zero entries of the matrix are stored.
  38. C If ISYM=1, the matrix is symmetric, and only the upper
  39. C or lower triangle of the matrix is stored.
  40. C DINV :OUT Real DINV(N).
  41. C Upon return this array holds 1./DIAG(A*A').
  42. C
  43. C *Description
  44. C =================== S L A P Column format ==================
  45. C This routine requires that the matrix A be stored in the
  46. C SLAP Column format. In this format the non-zeros are stored
  47. C counting down columns (except for the diagonal entry, which
  48. C must appear first in each "column") and are stored in the
  49. C real array A. In other words, for each column in the matrix
  50. C put the diagonal entry in A. Then put in the other non-zero
  51. C elements going down the column (except the diagonal) in
  52. C order. The IA array holds the row index for each non-zero.
  53. C The JA array holds the offsets into the IA, A arrays for the
  54. C beginning of each column. That is, IA(JA(ICOL)),
  55. C A(JA(ICOL)) points to the beginning of the ICOL-th column in
  56. C IA and A. IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1) points to the
  57. C end of the ICOL-th column. Note that we always have
  58. C JA(N+1) = NELT+1, where N is the number of columns in the
  59. C matrix and NELT is the number of non-zeros in the matrix.
  60. C
  61. C Here is an example of the SLAP Column storage format for a
  62. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  63. C column):
  64. C
  65. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  66. C 1 2 3 4 5 6 7 8 9 10 11
  67. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  68. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  69. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  70. C | 0 0 0 44 0|
  71. C |51 0 53 0 55|
  72. C
  73. C With the SLAP format all of the "inner loops" of this
  74. C routine should vectorize on machines with hardware support
  75. C for vector gather/scatter operations. Your compiler may
  76. C require a compiler directive to convince it that there are
  77. C no implicit vector dependencies. Compiler directives for
  78. C the Alliant FX/Fortran and CRI CFT/CFT77 compilers are
  79. C supplied with the standard SLAP distribution.
  80. C
  81. C
  82. C *Cautions:
  83. C This routine assumes that the diagonal of A is all non-zero
  84. C and that the operation DINV = 1.0/DIAG(A*A') will not under-
  85. C flow or overflow. This is done so that the loop vectorizes.
  86. C Matrices with zero or near zero or very large entries will
  87. C have numerical difficulties and must be fixed before this
  88. C routine is called.
  89. C
  90. C***SEE ALSO SSDCGN
  91. C***REFERENCES (NONE)
  92. C***ROUTINES CALLED (NONE)
  93. C***REVISION HISTORY (YYMMDD)
  94. C 871119 DATE WRITTEN
  95. C 881213 Previous REVISION DATE
  96. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  97. C 890922 Numerous changes to prologue to make closer to SLATEC
  98. C standard. (FNF)
  99. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  100. C 910411 Prologue converted to Version 4.0 format. (BAB)
  101. C 920511 Added complete declaration section. (WRB)
  102. C 921113 Corrected C***CATEGORY line. (FNF)
  103. C 930701 Updated CATEGORY section. (FNF, WRB)
  104. C***END PROLOGUE SSD2S
  105. C .. Scalar Arguments ..
  106. INTEGER ISYM, N, NELT
  107. C .. Array Arguments ..
  108. REAL A(NELT), DINV(N)
  109. INTEGER IA(NELT), JA(NELT)
  110. C .. Local Scalars ..
  111. INTEGER I, K, KBGN, KEND
  112. C***FIRST EXECUTABLE STATEMENT SSD2S
  113. DO 10 I = 1, N
  114. DINV(I) = 0
  115. 10 CONTINUE
  116. C
  117. C Loop over each column.
  118. CVD$R NOCONCUR
  119. DO 40 I = 1, N
  120. KBGN = JA(I)
  121. KEND = JA(I+1) - 1
  122. C
  123. C Add in the contributions for each row that has a non-zero
  124. C in this column.
  125. CLLL. OPTION ASSERT (NOHAZARD)
  126. CDIR$ IVDEP
  127. CVD$ NODEPCHK
  128. DO 20 K = KBGN, KEND
  129. DINV(IA(K)) = DINV(IA(K)) + A(K)**2
  130. 20 CONTINUE
  131. IF( ISYM.EQ.1 ) THEN
  132. C
  133. C Lower triangle stored by columns => upper triangle stored by
  134. C rows with Diagonal being the first entry. Loop across the
  135. C rest of the row.
  136. KBGN = KBGN + 1
  137. IF( KBGN.LE.KEND ) THEN
  138. DO 30 K = KBGN, KEND
  139. DINV(I) = DINV(I) + A(K)**2
  140. 30 CONTINUE
  141. ENDIF
  142. ENDIF
  143. 40 CONTINUE
  144. DO 50 I=1,N
  145. DINV(I) = 1.0E0/DINV(I)
  146. 50 CONTINUE
  147. C
  148. RETURN
  149. C------------- LAST LINE OF SSD2S FOLLOWS ----------------------------
  150. END