ssdscl.f 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. *DECK SSDSCL
  2. SUBROUTINE SSDSCL (N, NELT, IA, JA, A, ISYM, X, B, DINV, JOB,
  3. + ITOL)
  4. C***BEGIN PROLOGUE SSDSCL
  5. C***PURPOSE Diagonal Scaling of system Ax = b.
  6. C This routine scales (and unscales) the system Ax = b
  7. C by symmetric diagonal scaling.
  8. C***LIBRARY SLATEC (SLAP)
  9. C***CATEGORY D2E
  10. C***TYPE SINGLE PRECISION (SSDSCL-S, DSDSCL-D)
  11. C***KEYWORDS DIAGONAL, SLAP SPARSE
  12. C***AUTHOR Greenbaum, Anne, (Courant Institute)
  13. C Seager, Mark K., (LLNL)
  14. C Lawrence Livermore National Laboratory
  15. C PO BOX 808, L-60
  16. C Livermore, CA 94550 (510) 423-3141
  17. C seager@llnl.gov
  18. C***DESCRIPTION
  19. C
  20. C This routine scales (and unscales) the system Ax = b by symmetric
  21. C diagonal scaling. The new system is:
  22. C -1/2 -1/2 1/2 -1/2
  23. C D AD (D x) = D b
  24. C when scaling is selected with the JOB parameter. When unscaling
  25. C is selected this process is reversed. The true solution is also
  26. C scaled or unscaled if ITOL is set appropriately, see below.
  27. C
  28. C *Usage:
  29. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM, JOB, ITOL
  30. C REAL A(NELT), X(N), B(N), DINV(N)
  31. C
  32. C CALL SSDSCL( N, NELT, IA, JA, A, ISYM, X, B, DINV, JOB, ITOL )
  33. C
  34. C *Arguments:
  35. C N :IN Integer
  36. C Order of the Matrix.
  37. C NELT :IN Integer.
  38. C Number of elements in arrays IA, JA, and A.
  39. C IA :IN Integer IA(NELT).
  40. C JA :IN Integer JA(NELT).
  41. C A :IN Real A(NELT).
  42. C These arrays should hold the matrix A in the SLAP Column
  43. C format. See "Description", below.
  44. C ISYM :IN Integer.
  45. C Flag to indicate symmetric storage format.
  46. C If ISYM=0, all non-zero entries of the matrix are stored.
  47. C If ISYM=1, the matrix is symmetric, and only the upper
  48. C or lower triangle of the matrix is stored.
  49. C X :INOUT Real X(N).
  50. C Initial guess that will be later used in the iterative
  51. C solution.
  52. C of the scaled system.
  53. C B :INOUT Real B(N).
  54. C Right hand side vector.
  55. C DINV :INOUT Real DINV(N).
  56. C Upon return this array holds 1./DIAG(A).
  57. C This is an input if JOB = 0.
  58. C JOB :IN Integer.
  59. C Flag indicating whether to scale or not.
  60. C JOB non-zero means do scaling.
  61. C JOB = 0 means do unscaling.
  62. C ITOL :IN Integer.
  63. C Flag indicating what type of error estimation to do in the
  64. C iterative method. When ITOL = 11 the exact solution from
  65. C common block SSLBLK will be used. When the system is scaled
  66. C then the true solution must also be scaled. If ITOL is not
  67. C 11 then this vector is not referenced.
  68. C
  69. C *Common Blocks:
  70. C SOLN :INOUT Real SOLN(N). COMMON BLOCK /SSLBLK/
  71. C The true solution, SOLN, is scaled (or unscaled) if ITOL is
  72. C set to 11, see above.
  73. C
  74. C *Description
  75. C =================== S L A P Column format ==================
  76. C This routine requires that the matrix A be stored in the
  77. C SLAP Column format. In this format the non-zeros are stored
  78. C counting down columns (except for the diagonal entry, which
  79. C must appear first in each "column") and are stored in the
  80. C real array A. In other words, for each column in the matrix
  81. C put the diagonal entry in A. Then put in the other non-zero
  82. C elements going down the column (except the diagonal) in
  83. C order. The IA array holds the row index for each non-zero.
  84. C The JA array holds the offsets into the IA, A arrays for the
  85. C beginning of each column. That is, IA(JA(ICOL)),
  86. C A(JA(ICOL)) points to the beginning of the ICOL-th column in
  87. C IA and A. IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1) points to the
  88. C end of the ICOL-th column. Note that we always have
  89. C JA(N+1) = NELT+1, where N is the number of columns in the
  90. C matrix and NELT is the number of non-zeros in the matrix.
  91. C
  92. C Here is an example of the SLAP Column storage format for a
  93. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  94. C column):
  95. C
  96. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  97. C 1 2 3 4 5 6 7 8 9 10 11
  98. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  99. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  100. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  101. C | 0 0 0 44 0|
  102. C |51 0 53 0 55|
  103. C
  104. C With the SLAP format all of the "inner loops" of this
  105. C routine should vectorize on machines with hardware support
  106. C for vector gather/scatter operations. Your compiler may
  107. C require a compiler directive to convince it that there are
  108. C no implicit vector dependencies. Compiler directives for
  109. C the Alliant FX/Fortran and CRI CFT/CFT77 compilers are
  110. C supplied with the standard SLAP distribution.
  111. C
  112. C
  113. C *Cautions:
  114. C This routine assumes that the diagonal of A is all non-zero
  115. C and that the operation DINV = 1.0/DIAG(A) will not under-
  116. C flow or overflow. This is done so that the loop vectorizes.
  117. C Matrices with zero or near zero or very large entries will
  118. C have numerical difficulties and must be fixed before this
  119. C routine is called.
  120. C
  121. C***SEE ALSO SSDCG
  122. C***REFERENCES (NONE)
  123. C***ROUTINES CALLED (NONE)
  124. C***COMMON BLOCKS SSLBLK
  125. C***REVISION HISTORY (YYMMDD)
  126. C 871119 DATE WRITTEN
  127. C 881213 Previous REVISION DATE
  128. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  129. C 890922 Numerous changes to prologue to make closer to SLATEC
  130. C standard. (FNF)
  131. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  132. C 910411 Prologue converted to Version 4.0 format. (BAB)
  133. C 910502 Added C***FIRST EXECUTABLE STATEMENT line. (FNF)
  134. C 920407 COMMON BLOCK renamed SSLBLK. (WRB)
  135. C 920511 Added complete declaration section. (WRB)
  136. C 921113 Corrected C***CATEGORY line. (FNF)
  137. C 930701 Updated CATEGORY section. (FNF, WRB)
  138. C***END PROLOGUE SSDSCL
  139. C .. Scalar Arguments ..
  140. INTEGER ISYM, ITOL, JOB, N, NELT
  141. C .. Array Arguments ..
  142. REAL A(NELT), B(N), DINV(N), X(N)
  143. INTEGER IA(NELT), JA(NELT)
  144. C .. Arrays in Common ..
  145. REAL SOLN(1)
  146. C .. Local Scalars ..
  147. REAL DI
  148. INTEGER ICOL, J, JBGN, JEND
  149. C .. Intrinsic Functions ..
  150. INTRINSIC SQRT
  151. C .. Common blocks ..
  152. COMMON /SSLBLK/ SOLN
  153. C***FIRST EXECUTABLE STATEMENT SSDSCL
  154. C
  155. C SCALING...
  156. C
  157. IF( JOB.NE.0 ) THEN
  158. DO 10 ICOL = 1, N
  159. DINV(ICOL) = 1.0E0/SQRT( A(JA(ICOL)) )
  160. 10 CONTINUE
  161. ELSE
  162. C
  163. C UNSCALING...
  164. C
  165. DO 15 ICOL = 1, N
  166. DINV(ICOL) = 1.0E0/DINV(ICOL)
  167. 15 CONTINUE
  168. ENDIF
  169. C
  170. DO 30 ICOL = 1, N
  171. JBGN = JA(ICOL)
  172. JEND = JA(ICOL+1)-1
  173. DI = DINV(ICOL)
  174. DO 20 J = JBGN, JEND
  175. A(J) = DINV(IA(J))*A(J)*DI
  176. 20 CONTINUE
  177. 30 CONTINUE
  178. C
  179. DO 40 ICOL = 1, N
  180. B(ICOL) = B(ICOL)*DINV(ICOL)
  181. X(ICOL) = X(ICOL)/DINV(ICOL)
  182. 40 CONTINUE
  183. C
  184. C Check to see if we need to scale the "true solution" as well.
  185. C
  186. IF( ITOL.EQ.11 ) THEN
  187. DO 50 ICOL = 1, N
  188. SOLN(ICOL) = SOLN(ICOL)/DINV(ICOL)
  189. 50 CONTINUE
  190. ENDIF
  191. C
  192. RETURN
  193. C------------- LAST LINE OF SSDSCL FOLLOWS ----------------------------
  194. END