dsmv.f 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. *DECK DSMV
  2. SUBROUTINE DSMV (N, X, Y, NELT, IA, JA, A, ISYM)
  3. C***BEGIN PROLOGUE DSMV
  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 DOUBLE 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 DOUBLE PRECISION X(N), Y(N), A(NELT)
  22. C
  23. C CALL DSMV(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 Double Precision X(N).
  29. C The vector that should be multiplied by the matrix.
  30. C Y :OUT Double Precision 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 Double Precision 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 double precision array A. In other words, for each column
  52. C in the matrix put the diagonal entry in A. Then put in the
  53. C other non-zero elements going down the column (except the
  54. C diagonal) in order. The IA array holds the row index for
  55. C each non-zero. The JA array holds the offsets into the IA,
  56. C A arrays for the beginning of each column. That is,
  57. C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
  58. C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
  59. C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
  60. C Note that we always have JA(N+1) = NELT+1, where N is the
  61. C number of columns in the matrix and NELT is the number of
  62. C 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 DSMTV
  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 DSMV
  105. C .. Scalar Arguments ..
  106. INTEGER ISYM, N, NELT
  107. C .. Array Arguments ..
  108. DOUBLE PRECISION 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 DSMV
  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.
  121. C
  122. CVD$R NOCONCUR
  123. DO 30 ICOL = 1, N
  124. IBGN = JA(ICOL)
  125. IEND = JA(ICOL+1)-1
  126. CLLL. OPTION ASSERT (NOHAZARD)
  127. CDIR$ IVDEP
  128. CVD$ NODEPCHK
  129. DO 20 I = IBGN, IEND
  130. Y(IA(I)) = Y(IA(I)) + A(I)*X(ICOL)
  131. 20 CONTINUE
  132. 30 CONTINUE
  133. C
  134. IF( ISYM.EQ.1 ) THEN
  135. C
  136. C The matrix is non-symmetric. Need to get the other half in...
  137. C This loops assumes that the diagonal is the first entry in
  138. C each column.
  139. C
  140. DO 50 IROW = 1, N
  141. JBGN = JA(IROW)+1
  142. JEND = JA(IROW+1)-1
  143. IF( JBGN.GT.JEND ) GOTO 50
  144. DO 40 J = JBGN, JEND
  145. Y(IROW) = Y(IROW) + A(J)*X(IA(J))
  146. 40 CONTINUE
  147. 50 CONTINUE
  148. ENDIF
  149. RETURN
  150. C------------- LAST LINE OF DSMV FOLLOWS ----------------------------
  151. END