ssmv.f 5.7 KB

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