dsdscl.f 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. *DECK DSDSCL
  2. SUBROUTINE DSDSCL (N, NELT, IA, JA, A, ISYM, X, B, DINV, JOB,
  3. + ITOL)
  4. C***BEGIN PROLOGUE DSDSCL
  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 DOUBLE 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 DOUBLE PRECISION A(NELT), X(N), B(N), DINV(N)
  31. C
  32. C CALL DSDSCL( 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 Double Precision 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 Double Precision 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 Double Precision B(N).
  54. C Right hand side vector.
  55. C DINV :INOUT Double Precision 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 DSLBLK 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 Double Precision SOLN(N). COMMON BLOCK /DSLBLK/
  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 double precision array A. In other words, for each column
  81. C in the matrix put the diagonal entry in A. Then put in the
  82. C other non-zero elements going down the column (except the
  83. C diagonal) in order. The IA array holds the row index for
  84. C each non-zero. The JA array holds the offsets into the IA,
  85. C A arrays for the beginning of each column. That is,
  86. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  87. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  88. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  89. C Note that we always have JA(N+1) = NELT+1, where N is the
  90. C number of columns in the matrix and NELT is the number of
  91. C non-zeros in the matrix.
  92. C
  93. C Here is an example of the SLAP Column storage format for a
  94. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  95. C column):
  96. C
  97. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  98. C 1 2 3 4 5 6 7 8 9 10 11
  99. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  100. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  101. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  102. C | 0 0 0 44 0|
  103. C |51 0 53 0 55|
  104. C
  105. C With the SLAP format all of the "inner loops" of this
  106. C routine should vectorize on machines with hardware support
  107. C for vector gather/scatter operations. Your compiler may
  108. C require a compiler directive to convince it that there are
  109. C no implicit vector dependencies. Compiler directives for
  110. C the Alliant FX/Fortran and CRI CFT/CFT77 compilers are
  111. C supplied with the standard SLAP distribution.
  112. C
  113. C
  114. C *Cautions:
  115. C This routine assumes that the diagonal of A is all non-zero
  116. C and that the operation DINV = 1.0/DIAG(A) will not under-
  117. C flow or overflow. This is done so that the loop vectorizes.
  118. C Matrices with zero or near zero or very large entries will
  119. C have numerical difficulties and must be fixed before this
  120. C routine is called.
  121. C
  122. C***SEE ALSO DSDCG
  123. C***REFERENCES (NONE)
  124. C***ROUTINES CALLED (NONE)
  125. C***COMMON BLOCKS DSLBLK
  126. C***REVISION HISTORY (YYMMDD)
  127. C 890404 DATE WRITTEN
  128. C 890404 Previous REVISION DATE
  129. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  130. C 890922 Numerous changes to prologue to make closer to SLATEC
  131. C standard. (FNF)
  132. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  133. C 910411 Prologue converted to Version 4.0 format. (BAB)
  134. C 910502 Added C***FIRST EXECUTABLE STATEMENT line. (FNF)
  135. C 920407 COMMON BLOCK renamed DSLBLK. (WRB)
  136. C 920511 Added complete declaration section. (WRB)
  137. C 921113 Corrected C***CATEGORY line. (FNF)
  138. C 930701 Updated CATEGORY section. (FNF, WRB)
  139. C***END PROLOGUE DSDSCL
  140. C .. Scalar Arguments ..
  141. INTEGER ISYM, ITOL, JOB, N, NELT
  142. C .. Array Arguments ..
  143. DOUBLE PRECISION A(NELT), B(N), DINV(N), X(N)
  144. INTEGER IA(NELT), JA(NELT)
  145. C .. Arrays in Common ..
  146. DOUBLE PRECISION SOLN(1)
  147. C .. Local Scalars ..
  148. DOUBLE PRECISION DI
  149. INTEGER ICOL, J, JBGN, JEND
  150. C .. Intrinsic Functions ..
  151. INTRINSIC SQRT
  152. C .. Common blocks ..
  153. COMMON /DSLBLK/ SOLN
  154. C***FIRST EXECUTABLE STATEMENT DSDSCL
  155. C
  156. C SCALING...
  157. C
  158. IF( JOB.NE.0 ) THEN
  159. DO 10 ICOL = 1, N
  160. DINV(ICOL) = 1.0D0/SQRT( A(JA(ICOL)) )
  161. 10 CONTINUE
  162. ELSE
  163. C
  164. C UNSCALING...
  165. C
  166. DO 15 ICOL = 1, N
  167. DINV(ICOL) = 1.0D0/DINV(ICOL)
  168. 15 CONTINUE
  169. ENDIF
  170. C
  171. DO 30 ICOL = 1, N
  172. JBGN = JA(ICOL)
  173. JEND = JA(ICOL+1)-1
  174. DI = DINV(ICOL)
  175. DO 20 J = JBGN, JEND
  176. A(J) = DINV(IA(J))*A(J)*DI
  177. 20 CONTINUE
  178. 30 CONTINUE
  179. C
  180. DO 40 ICOL = 1, N
  181. B(ICOL) = B(ICOL)*DINV(ICOL)
  182. X(ICOL) = X(ICOL)/DINV(ICOL)
  183. 40 CONTINUE
  184. C
  185. C Check to see if we need to scale the "true solution" as well.
  186. C
  187. IF( ITOL.EQ.11 ) THEN
  188. DO 50 ICOL = 1, N
  189. SOLN(ICOL) = SOLN(ICOL)/DINV(ICOL)
  190. 50 CONTINUE
  191. ENDIF
  192. C
  193. RETURN
  194. C------------- LAST LINE OF DSDSCL FOLLOWS ----------------------------
  195. END