ssmtv.f 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. *DECK SSMTV
  2. SUBROUTINE SSMTV (N, X, Y, NELT, IA, JA, A, ISYM)
  3. C***BEGIN PROLOGUE SSMTV
  4. C***PURPOSE SLAP Column Format Sparse Matrix Transpose Vector Product.
  5. C Routine to calculate the sparse matrix vector product:
  6. C Y = A'*X, where ' denotes transpose.
  7. C***LIBRARY SLATEC (SLAP)
  8. C***CATEGORY D1B4
  9. C***TYPE SINGLE PRECISION (SSMTV-S, DSMTV-D)
  10. C***KEYWORDS MATRIX TRANSPOSE VECTOR MULTIPLY, 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 X(N), Y(N), A(NELT)
  22. C
  23. C CALL SSMTV(N, X, Y, NELT, IA, JA, A, ISYM )
  24. C
  25. C *Arguments:
  26. C N :IN Integer.
  27. C Order of the Matrix.
  28. C X :IN Real X(N).
  29. C The vector that should be multiplied by the transpose of
  30. C the matrix.
  31. C Y :OUT Real Y(N).
  32. C The product of the transpose of the matrix and the vector.
  33. C NELT :IN Integer.
  34. C Number of Non-Zeros stored in A.
  35. C IA :IN Integer IA(NELT).
  36. C JA :IN Integer JA(NELT).
  37. C A :IN Real A(NELT).
  38. C These arrays should hold the matrix A in the SLAP Column
  39. C format. See "Description", below.
  40. C ISYM :IN Integer.
  41. C Flag to indicate symmetric storage format.
  42. C If ISYM=0, all non-zero entries of the matrix are stored.
  43. C If ISYM=1, the matrix is symmetric, and only the upper
  44. C or lower triangle of the matrix is stored.
  45. C
  46. C *Description
  47. C =================== S L A P Column format ==================
  48. C This routine requires that the matrix A be stored in the
  49. C SLAP Column format. In this format the non-zeros are stored
  50. C counting down columns (except for the diagonal entry, which
  51. C must appear first in each "column") and are stored in the
  52. C real array A. In other words, for each column in the matrix
  53. C put the diagonal entry in A. Then put in the other non-zero
  54. C elements going down the column (except the diagonal) in
  55. C order. The IA array holds the row index for each non-zero.
  56. C The JA array holds the offsets into the IA, A arrays for the
  57. C beginning of each column. That is, IA(JA(ICOL)),
  58. C A(JA(ICOL)) points to the beginning of the ICOL-th column in
  59. C IA and A. IA(JA(ICOL+1)-1), A(JA(ICOL+1)-1) points to the
  60. C end of the ICOL-th column. Note that we always have
  61. C JA(N+1) = NELT+1, where N is the number of columns in the
  62. C matrix and NELT is the number of non-zeros in the matrix.
  63. C
  64. C Here is an example of the SLAP Column storage format for a
  65. C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
  66. C column):
  67. C
  68. C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
  69. C 1 2 3 4 5 6 7 8 9 10 11
  70. C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
  71. C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
  72. C | 0 0 33 0 35| JA: 1 4 6 8 9 12
  73. C | 0 0 0 44 0|
  74. C |51 0 53 0 55|
  75. C
  76. C With the SLAP format the "inner loops" of this routine
  77. C should vectorize on machines with hardware support for
  78. C vector gather/scatter operations. Your compiler may require
  79. C a compiler directive to convince it that there are no
  80. C implicit vector dependencies. Compiler directives for the
  81. C Alliant FX/Fortran and CRI CFT/CFT77 compilers are supplied
  82. C with the standard SLAP distribution.
  83. C
  84. C *Cautions:
  85. C This routine assumes that the matrix A is stored in SLAP
  86. C Column format. It does not check for this (for speed) and
  87. C evil, ugly, ornery and nasty things will happen if the matrix
  88. C data structure is, in fact, not SLAP Column. Beware of the
  89. C wrong data structure!!!
  90. C
  91. C***SEE ALSO SSMV
  92. C***REFERENCES (NONE)
  93. C***ROUTINES CALLED (NONE)
  94. C***REVISION HISTORY (YYMMDD)
  95. C 871119 DATE WRITTEN
  96. C 881213 Previous REVISION DATE
  97. C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
  98. C 890922 Numerous changes to prologue to make closer to SLATEC
  99. C standard. (FNF)
  100. C 890929 Numerous changes to reduce SP/DP differences. (FNF)
  101. C 910411 Prologue converted to Version 4.0 format. (BAB)
  102. C 920511 Added complete declaration section. (WRB)
  103. C 930701 Updated CATEGORY section. (FNF, WRB)
  104. C***END PROLOGUE SSMTV
  105. C .. Scalar Arguments ..
  106. INTEGER ISYM, N, NELT
  107. C .. Array Arguments ..
  108. REAL A(NELT), X(N), Y(N)
  109. INTEGER IA(NELT), JA(NELT)
  110. C .. Local Scalars ..
  111. INTEGER I, IBGN, ICOL, IEND, IROW, J, JBGN, JEND
  112. C***FIRST EXECUTABLE STATEMENT SSMTV
  113. C
  114. C Zero out the result vector.
  115. C
  116. DO 10 I = 1, N
  117. Y(I) = 0
  118. 10 CONTINUE
  119. C
  120. C Multiply by A-Transpose.
  121. C A-Transpose is stored by rows...
  122. CVD$R NOCONCUR
  123. DO 30 IROW = 1, N
  124. IBGN = JA(IROW)
  125. IEND = JA(IROW+1)-1
  126. CVD$ ASSOC
  127. DO 20 I = IBGN, IEND
  128. Y(IROW) = Y(IROW) + A(I)*X(IA(I))
  129. 20 CONTINUE
  130. 30 CONTINUE
  131. C
  132. IF( ISYM.EQ.1 ) THEN
  133. C
  134. C The matrix is non-symmetric. Need to get the other half in...
  135. C This loops assumes that the diagonal is the first entry in
  136. C each column.
  137. C
  138. DO 50 ICOL = 1, N
  139. JBGN = JA(ICOL)+1
  140. JEND = JA(ICOL+1)-1
  141. IF( JBGN.GT.JEND ) GOTO 50
  142. CLLL. OPTION ASSERT (NOHAZARD)
  143. CDIR$ IVDEP
  144. CVD$ NODEPCHK
  145. DO 40 J = JBGN, JEND
  146. Y(IA(J)) = Y(IA(J)) + A(J)*X(ICOL)
  147. 40 CONTINUE
  148. 50 CONTINUE
  149. ENDIF
  150. RETURN
  151. C------------- LAST LINE OF SSMTV FOLLOWS ----------------------------
  152. END