ss2y.f 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. *DECK SS2Y
  2. SUBROUTINE SS2Y (N, NELT, IA, JA, A, ISYM)
  3. C***BEGIN PROLOGUE SS2Y
  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 SINGLE 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 REAL A(NELT)
  21. C
  22. C CALL SS2Y( 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 Real 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 real array A. In other words, for each column in the matrix
  88. C put the diagonal entry in A. Then put in the other non-zero
  89. C elements going down the column (except the diagonal) in
  90. C order. The IA array holds the row index for each non-zero.
  91. C The JA array holds the offsets into the IA, A arrays for the
  92. C beginning of each column. That is, IA(JA(ICOL)),
  93. C A(JA(ICOL)) points to the beginning of the ICOL-th column in
  94. C IA and A. IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1) points to the
  95. C end of the ICOL-th column. Note that we always have
  96. C JA(N+1) = NELT+1, where N is the number of columns in the
  97. C matrix and NELT is the number of non-zeros in the matrix.
  98. C
  99. C Here is an example of the SLAP Column storage format for a
  100. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  101. C column):
  102. C
  103. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  104. C 1 2 3 4 5 6 7 8 9 10 11
  105. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  106. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  107. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  108. C | 0 0 0 44 0|
  109. C |51 0 53 0 55|
  110. C
  111. C***REFERENCES (NONE)
  112. C***ROUTINES CALLED QS2I1R
  113. C***REVISION HISTORY (YYMMDD)
  114. C 871119 DATE WRITTEN
  115. C 881213 Previous REVISION DATE
  116. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  117. C 890922 Numerous changes to prologue to make closer to SLATEC
  118. C standard. (FNF)
  119. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  120. C 910411 Prologue converted to Version 4.0 format. (BAB)
  121. C 910502 Corrected C***FIRST EXECUTABLE STATEMENT line. (FNF)
  122. C 920511 Added complete declaration section. (WRB)
  123. C 930701 Updated CATEGORY section. (FNF, WRB)
  124. C***END PROLOGUE SS2Y
  125. C .. Scalar Arguments ..
  126. INTEGER ISYM, N, NELT
  127. C .. Array Arguments ..
  128. REAL A(NELT)
  129. INTEGER IA(NELT), JA(NELT)
  130. C .. Local Scalars ..
  131. REAL TEMP
  132. INTEGER I, IBGN, ICOL, IEND, ITEMP, J
  133. C .. External Subroutines ..
  134. EXTERNAL QS2I1R
  135. C***FIRST EXECUTABLE STATEMENT SS2Y
  136. C
  137. C Check to see if the (IA,JA,A) arrays are in SLAP Column
  138. C format. If it's not then transform from SLAP Triad.
  139. C
  140. IF( JA(N+1).EQ.NELT+1 ) RETURN
  141. C
  142. C Sort into ascending order by COLUMN (on the ja array).
  143. C This will line up the columns.
  144. C
  145. CALL QS2I1R( JA, IA, A, NELT, 1 )
  146. C
  147. C Loop over each column to see where the column indices change
  148. C in the column index array ja. This marks the beginning of the
  149. C next column.
  150. C
  151. CVD$R NOVECTOR
  152. JA(1) = 1
  153. DO 20 ICOL = 1, N-1
  154. DO 10 J = JA(ICOL)+1, NELT
  155. IF( JA(J).NE.ICOL ) THEN
  156. JA(ICOL+1) = J
  157. GOTO 20
  158. ENDIF
  159. 10 CONTINUE
  160. 20 CONTINUE
  161. JA(N+1) = NELT+1
  162. C
  163. C Mark the n+2 element so that future calls to a SLAP routine
  164. C utilizing the YSMP-Column storage format will be able to tell.
  165. C
  166. JA(N+2) = 0
  167. C
  168. C Now loop through the IA array making sure that the diagonal
  169. C matrix element appears first in the column. Then sort the
  170. C rest of the column in ascending order.
  171. C
  172. DO 70 ICOL = 1, N
  173. IBGN = JA(ICOL)
  174. IEND = JA(ICOL+1)-1
  175. DO 30 I = IBGN, IEND
  176. IF( IA(I).EQ.ICOL ) THEN
  177. C
  178. C Swap the diagonal element with the first element in the
  179. C column.
  180. C
  181. ITEMP = IA(I)
  182. IA(I) = IA(IBGN)
  183. IA(IBGN) = ITEMP
  184. TEMP = A(I)
  185. A(I) = A(IBGN)
  186. A(IBGN) = TEMP
  187. GOTO 40
  188. ENDIF
  189. 30 CONTINUE
  190. 40 IBGN = IBGN + 1
  191. IF( IBGN.LT.IEND ) THEN
  192. DO 60 I = IBGN, IEND
  193. DO 50 J = I+1, IEND
  194. IF( IA(I).GT.IA(J) ) THEN
  195. ITEMP = IA(I)
  196. IA(I) = IA(J)
  197. IA(J) = ITEMP
  198. TEMP = A(I)
  199. A(I) = A(J)
  200. A(J) = TEMP
  201. ENDIF
  202. 50 CONTINUE
  203. 60 CONTINUE
  204. ENDIF
  205. 70 CONTINUE
  206. RETURN
  207. C------------- LAST LINE OF SS2Y FOLLOWS ----------------------------
  208. END