ds2y.f 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. *DECK DS2Y
  2. SUBROUTINE DS2Y (N, NELT, IA, JA, A, ISYM)
  3. C***BEGIN PROLOGUE DS2Y
  4. C***PURPOSE SLAP Triad to SLAP Column Format Converter.
  5. C Routine to convert from the SLAP Triad to SLAP Column
  6. C format.
  7. C***LIBRARY SLATEC (SLAP)
  8. C***CATEGORY D1B9
  9. C***TYPE DOUBLE PRECISION (SS2Y-S, DS2Y-D)
  10. C***KEYWORDS LINEAR SYSTEM, SLAP SPARSE
  11. C***AUTHOR Seager, Mark K., (LLNL)
  12. C Lawrence Livermore National Laboratory
  13. C PO BOX 808, L-60
  14. C Livermore, CA 94550 (510) 423-3141
  15. C seager@llnl.gov
  16. C***DESCRIPTION
  17. C
  18. C *Usage:
  19. C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM
  20. C DOUBLE PRECISION A(NELT)
  21. C
  22. C CALL DS2Y( N, NELT, IA, JA, A, ISYM )
  23. C
  24. C *Arguments:
  25. C N :IN Integer
  26. C Order of the Matrix.
  27. C NELT :IN Integer.
  28. C Number of non-zeros stored in A.
  29. C IA :INOUT Integer IA(NELT).
  30. C JA :INOUT Integer JA(NELT).
  31. C A :INOUT Double Precision A(NELT).
  32. C These arrays should hold the matrix A in either the SLAP
  33. C Triad format or the SLAP Column format. See "Description",
  34. C below. If the SLAP Triad format is used, this format is
  35. C translated to the SLAP Column format by this routine.
  36. C ISYM :IN Integer.
  37. C Flag to indicate symmetric storage format.
  38. C If ISYM=0, all non-zero entries of the matrix are stored.
  39. C If ISYM=1, the matrix is symmetric, and only the lower
  40. C triangle of the matrix is stored.
  41. C
  42. C *Description:
  43. C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
  44. C data structures: 1) the SLAP Triad format or 2) the SLAP
  45. C Column format. The user can hand this routine either of the
  46. C of these data structures. If the SLAP Triad format is give
  47. C as input then this routine transforms it into SLAP Column
  48. C format. The way this routine tells which format is given as
  49. C input is to look at JA(N+1). If JA(N+1) = NELT+1 then we
  50. C have the SLAP Column format. If that equality does not hold
  51. C then it is assumed that the IA, JA, A arrays contain the
  52. C SLAP Triad format.
  53. C
  54. C =================== S L A P Triad format ===================
  55. C This routine requires that the matrix A be stored in the
  56. C SLAP Triad format. In this format only the non-zeros are
  57. C stored. They may appear in *ANY* order. The user supplies
  58. C three arrays of length NELT, where NELT is the number of
  59. C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
  60. C each non-zero the user puts the row and column index of that
  61. C matrix element in the IA and JA arrays. The value of the
  62. C non-zero matrix element is placed in the corresponding
  63. C location of the A array. This is an extremely easy data
  64. C structure to generate. On the other hand it is not too
  65. C efficient on vector computers for the iterative solution of
  66. C linear systems. Hence, SLAP changes this input data
  67. C structure to the SLAP Column format for the iteration (but
  68. C does not change it back).
  69. C
  70. C Here is an example of the SLAP Triad storage format for a
  71. C 5x5 Matrix. Recall that the entries may appear in any order.
  72. C
  73. C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
  74. C 1 2 3 4 5 6 7 8 9 10 11
  75. C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
  76. C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
  77. C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
  78. C | 0 0 0 44 0|
  79. C |51 0 53 0 55|
  80. C
  81. C =================== S L A P Column format ==================
  82. C
  83. C This routine requires that the matrix A be stored in the
  84. C SLAP Column format. In this format the non-zeros are stored
  85. C counting down columns (except for the diagonal entry, which
  86. C must appear first in each "column") and are stored in the
  87. C double precision array A. In other words, for each column
  88. C in the matrix put the diagonal entry in A. Then put in the
  89. C other non-zero elements going down the column (except the
  90. C diagonal) in order. The IA array holds the row index for
  91. C each non-zero. The JA array holds the offsets into the IA,
  92. C A arrays for the beginning of each column. That is,
  93. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  94. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  95. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  96. C Note that we always have JA(N+1) = NELT+1, where N is the
  97. C number of columns in the matrix and NELT is the number of
  98. C non-zeros in the matrix.
  99. C
  100. C Here is an example of the SLAP Column storage format for a
  101. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  102. C column):
  103. C
  104. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  105. C 1 2 3 4 5 6 7 8 9 10 11
  106. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  107. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  108. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  109. C | 0 0 0 44 0|
  110. C |51 0 53 0 55|
  111. C
  112. C***REFERENCES (NONE)
  113. C***ROUTINES CALLED QS2I1D
  114. C***REVISION HISTORY (YYMMDD)
  115. C 871119 DATE WRITTEN
  116. C 881213 Previous REVISION DATE
  117. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  118. C 890922 Numerous changes to prologue to make closer to SLATEC
  119. C standard. (FNF)
  120. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  121. C 910411 Prologue converted to Version 4.0 format. (BAB)
  122. C 910502 Corrected C***FIRST EXECUTABLE STATEMENT line. (FNF)
  123. C 920511 Added complete declaration section. (WRB)
  124. C 930701 Updated CATEGORY section. (FNF, WRB)
  125. C***END PROLOGUE DS2Y
  126. C .. Scalar Arguments ..
  127. INTEGER ISYM, N, NELT
  128. C .. Array Arguments ..
  129. DOUBLE PRECISION A(NELT)
  130. INTEGER IA(NELT), JA(NELT)
  131. C .. Local Scalars ..
  132. DOUBLE PRECISION TEMP
  133. INTEGER I, IBGN, ICOL, IEND, ITEMP, J
  134. C .. External Subroutines ..
  135. EXTERNAL QS2I1D
  136. C***FIRST EXECUTABLE STATEMENT DS2Y
  137. C
  138. C Check to see if the (IA,JA,A) arrays are in SLAP Column
  139. C format. If it's not then transform from SLAP Triad.
  140. C
  141. IF( JA(N+1).EQ.NELT+1 ) RETURN
  142. C
  143. C Sort into ascending order by COLUMN (on the ja array).
  144. C This will line up the columns.
  145. C
  146. CALL QS2I1D( JA, IA, A, NELT, 1 )
  147. C
  148. C Loop over each column to see where the column indices change
  149. C in the column index array ja. This marks the beginning of the
  150. C next column.
  151. C
  152. CVD$R NOVECTOR
  153. JA(1) = 1
  154. DO 20 ICOL = 1, N-1
  155. DO 10 J = JA(ICOL)+1, NELT
  156. IF( JA(J).NE.ICOL ) THEN
  157. JA(ICOL+1) = J
  158. GOTO 20
  159. ENDIF
  160. 10 CONTINUE
  161. 20 CONTINUE
  162. JA(N+1) = NELT+1
  163. C
  164. C Mark the n+2 element so that future calls to a SLAP routine
  165. C utilizing the YSMP-Column storage format will be able to tell.
  166. C
  167. JA(N+2) = 0
  168. C
  169. C Now loop through the IA array making sure that the diagonal
  170. C matrix element appears first in the column. Then sort the
  171. C rest of the column in ascending order.
  172. C
  173. DO 70 ICOL = 1, N
  174. IBGN = JA(ICOL)
  175. IEND = JA(ICOL+1)-1
  176. DO 30 I = IBGN, IEND
  177. IF( IA(I).EQ.ICOL ) THEN
  178. C
  179. C Swap the diagonal element with the first element in the
  180. C column.
  181. C
  182. ITEMP = IA(I)
  183. IA(I) = IA(IBGN)
  184. IA(IBGN) = ITEMP
  185. TEMP = A(I)
  186. A(I) = A(IBGN)
  187. A(IBGN) = TEMP
  188. GOTO 40
  189. ENDIF
  190. 30 CONTINUE
  191. 40 IBGN = IBGN + 1
  192. IF( IBGN.LT.IEND ) THEN
  193. DO 60 I = IBGN, IEND
  194. DO 50 J = I+1, IEND
  195. IF( IA(I).GT.IA(J) ) THEN
  196. ITEMP = IA(I)
  197. IA(I) = IA(J)
  198. IA(J) = ITEMP
  199. TEMP = A(I)
  200. A(I) = A(J)
  201. A(J) = TEMP
  202. ENDIF
  203. 50 CONTINUE
  204. 60 CONTINUE
  205. ENDIF
  206. 70 CONTINUE
  207. RETURN
  208. C------------- LAST LINE OF DS2Y FOLLOWS ----------------------------
  209. END