chemm.f 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. *DECK CHEMM
  2. SUBROUTINE CHEMM (SIDE, UPLO, M, N, ALPHA, A, LDA, B, LDB, BETA,
  3. $ C, LDC)
  4. C***BEGIN PROLOGUE CHEMM
  5. C***PURPOSE Multiply a complex general matrix by a complex Hermitian
  6. C matrix.
  7. C***LIBRARY SLATEC (BLAS)
  8. C***CATEGORY D1B6
  9. C***TYPE COMPLEX (SHEMM-S, DHEMM-D, CHEMM-C)
  10. C***KEYWORDS LEVEL 3 BLAS, LINEAR ALGEBRA
  11. C***AUTHOR Dongarra, J., (ANL)
  12. C Duff, I., (AERE)
  13. C Du Croz, J., (NAG)
  14. C Hammarling, S. (NAG)
  15. C***DESCRIPTION
  16. C
  17. C CHEMM performs one of the matrix-matrix operations
  18. C
  19. C C := alpha*A*B + beta*C,
  20. C
  21. C or
  22. C
  23. C C := alpha*B*A + beta*C,
  24. C
  25. C where alpha and beta are scalars, A is an hermitian matrix and B and
  26. C C are m by n matrices.
  27. C
  28. C Parameters
  29. C ==========
  30. C
  31. C SIDE - CHARACTER*1.
  32. C On entry, SIDE specifies whether the hermitian matrix A
  33. C appears on the left or right in the operation as follows:
  34. C
  35. C SIDE = 'L' or 'l' C := alpha*A*B + beta*C,
  36. C
  37. C SIDE = 'R' or 'r' C := alpha*B*A + beta*C,
  38. C
  39. C Unchanged on exit.
  40. C
  41. C UPLO - CHARACTER*1.
  42. C On entry, UPLO specifies whether the upper or lower
  43. C triangular part of the hermitian matrix A is to be
  44. C referenced as follows:
  45. C
  46. C UPLO = 'U' or 'u' Only the upper triangular part of the
  47. C hermitian matrix is to be referenced.
  48. C
  49. C UPLO = 'L' or 'l' Only the lower triangular part of the
  50. C hermitian matrix is to be referenced.
  51. C
  52. C Unchanged on exit.
  53. C
  54. C M - INTEGER.
  55. C On entry, M specifies the number of rows of the matrix C.
  56. C M must be at least zero.
  57. C Unchanged on exit.
  58. C
  59. C N - INTEGER.
  60. C On entry, N specifies the number of columns of the matrix C.
  61. C N must be at least zero.
  62. C Unchanged on exit.
  63. C
  64. C ALPHA - COMPLEX .
  65. C On entry, ALPHA specifies the scalar alpha.
  66. C Unchanged on exit.
  67. C
  68. C A - COMPLEX array of DIMENSION ( LDA, ka ), where ka is
  69. C m when SIDE = 'L' or 'l' and is n otherwise.
  70. C Before entry with SIDE = 'L' or 'l', the m by m part of
  71. C the array A must contain the hermitian matrix, such that
  72. C when UPLO = 'U' or 'u', the leading m by m upper triangular
  73. C part of the array A must contain the upper triangular part
  74. C of the hermitian matrix and the strictly lower triangular
  75. C part of A is not referenced, and when UPLO = 'L' or 'l',
  76. C the leading m by m lower triangular part of the array A
  77. C must contain the lower triangular part of the hermitian
  78. C matrix and the strictly upper triangular part of A is not
  79. C referenced.
  80. C Before entry with SIDE = 'R' or 'r', the n by n part of
  81. C the array A must contain the hermitian matrix, such that
  82. C when UPLO = 'U' or 'u', the leading n by n upper triangular
  83. C part of the array A must contain the upper triangular part
  84. C of the hermitian matrix and the strictly lower triangular
  85. C part of A is not referenced, and when UPLO = 'L' or 'l',
  86. C the leading n by n lower triangular part of the array A
  87. C must contain the lower triangular part of the hermitian
  88. C matrix and the strictly upper triangular part of A is not
  89. C referenced.
  90. C Note that the imaginary parts of the diagonal elements need
  91. C not be set, they are assumed to be zero.
  92. C Unchanged on exit.
  93. C
  94. C LDA - INTEGER.
  95. C On entry, LDA specifies the first dimension of A as declared
  96. C in the calling (sub) program. When SIDE = 'L' or 'l' then
  97. C LDA must be at least max( 1, m ), otherwise LDA must be at
  98. C least max( 1, n ).
  99. C Unchanged on exit.
  100. C
  101. C B - COMPLEX array of DIMENSION ( LDB, n ).
  102. C Before entry, the leading m by n part of the array B must
  103. C contain the matrix B.
  104. C Unchanged on exit.
  105. C
  106. C LDB - INTEGER.
  107. C On entry, LDB specifies the first dimension of B as declared
  108. C in the calling (sub) program. LDB must be at least
  109. C max( 1, m ).
  110. C Unchanged on exit.
  111. C
  112. C BETA - COMPLEX .
  113. C On entry, BETA specifies the scalar beta. When BETA is
  114. C supplied as zero then C need not be set on input.
  115. C Unchanged on exit.
  116. C
  117. C C - COMPLEX array of DIMENSION ( LDC, n ).
  118. C Before entry, the leading m by n part of the array C must
  119. C contain the matrix C, except when beta is zero, in which
  120. C case C need not be set on entry.
  121. C On exit, the array C is overwritten by the m by n updated
  122. C matrix.
  123. C
  124. C LDC - INTEGER.
  125. C On entry, LDC specifies the first dimension of C as declared
  126. C in the calling (sub) program. LDC must be at least
  127. C max( 1, m ).
  128. C Unchanged on exit.
  129. C
  130. C***REFERENCES Dongarra, J., Du Croz, J., Duff, I., and Hammarling, S.
  131. C A set of level 3 basic linear algebra subprograms.
  132. C ACM TOMS, Vol. 16, No. 1, pp. 1-17, March 1990.
  133. C***ROUTINES CALLED LSAME, XERBLA
  134. C***REVISION HISTORY (YYMMDD)
  135. C 890208 DATE WRITTEN
  136. C 910605 Modified to meet SLATEC prologue standards. Only comment
  137. C lines were modified. (BKS)
  138. C***END PROLOGUE CHEMM
  139. C .. Scalar Arguments ..
  140. CHARACTER*1 SIDE, UPLO
  141. INTEGER M, N, LDA, LDB, LDC
  142. COMPLEX ALPHA, BETA
  143. C .. Array Arguments ..
  144. COMPLEX A( LDA, * ), B( LDB, * ), C( LDC, * )
  145. C .. External Functions ..
  146. LOGICAL LSAME
  147. EXTERNAL LSAME
  148. C .. External Subroutines ..
  149. EXTERNAL XERBLA
  150. C .. Intrinsic Functions ..
  151. INTRINSIC CONJG, MAX, REAL
  152. C .. Local Scalars ..
  153. LOGICAL UPPER
  154. INTEGER I, INFO, J, K, NROWA
  155. COMPLEX TEMP1, TEMP2
  156. C .. Parameters ..
  157. COMPLEX ONE
  158. PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ) )
  159. COMPLEX ZERO
  160. PARAMETER ( ZERO = ( 0.0E+0, 0.0E+0 ) )
  161. C***FIRST EXECUTABLE STATEMENT CHEMM
  162. C
  163. C Set NROWA as the number of rows of A.
  164. C
  165. IF( LSAME( SIDE, 'L' ) )THEN
  166. NROWA = M
  167. ELSE
  168. NROWA = N
  169. END IF
  170. UPPER = LSAME( UPLO, 'U' )
  171. C
  172. C Test the input parameters.
  173. C
  174. INFO = 0
  175. IF( ( .NOT.LSAME( SIDE, 'L' ) ).AND.
  176. $ ( .NOT.LSAME( SIDE, 'R' ) ) )THEN
  177. INFO = 1
  178. ELSE IF( ( .NOT.UPPER ).AND.
  179. $ ( .NOT.LSAME( UPLO, 'L' ) ) )THEN
  180. INFO = 2
  181. ELSE IF( M .LT.0 )THEN
  182. INFO = 3
  183. ELSE IF( N .LT.0 )THEN
  184. INFO = 4
  185. ELSE IF( LDA.LT.MAX( 1, NROWA ) )THEN
  186. INFO = 7
  187. ELSE IF( LDB.LT.MAX( 1, M ) )THEN
  188. INFO = 9
  189. ELSE IF( LDC.LT.MAX( 1, M ) )THEN
  190. INFO = 12
  191. END IF
  192. IF( INFO.NE.0 )THEN
  193. CALL XERBLA( 'CHEMM ', INFO )
  194. RETURN
  195. END IF
  196. C
  197. C Quick return if possible.
  198. C
  199. IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.
  200. $ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )
  201. $ RETURN
  202. C
  203. C And when alpha.eq.zero.
  204. C
  205. IF( ALPHA.EQ.ZERO )THEN
  206. IF( BETA.EQ.ZERO )THEN
  207. DO 20, J = 1, N
  208. DO 10, I = 1, M
  209. C( I, J ) = ZERO
  210. 10 CONTINUE
  211. 20 CONTINUE
  212. ELSE
  213. DO 40, J = 1, N
  214. DO 30, I = 1, M
  215. C( I, J ) = BETA*C( I, J )
  216. 30 CONTINUE
  217. 40 CONTINUE
  218. END IF
  219. RETURN
  220. END IF
  221. C
  222. C Start the operations.
  223. C
  224. IF( LSAME( SIDE, 'L' ) )THEN
  225. C
  226. C Form C := alpha*A*B + beta*C.
  227. C
  228. IF( UPPER )THEN
  229. DO 70, J = 1, N
  230. DO 60, I = 1, M
  231. TEMP1 = ALPHA*B( I, J )
  232. TEMP2 = ZERO
  233. DO 50, K = 1, I - 1
  234. C( K, J ) = C( K, J ) + TEMP1*A( K, I )
  235. TEMP2 = TEMP2 +
  236. $ B( K, J )*CONJG( A( K, I ) )
  237. 50 CONTINUE
  238. IF( BETA.EQ.ZERO )THEN
  239. C( I, J ) = TEMP1*REAL( A( I, I ) ) +
  240. $ ALPHA*TEMP2
  241. ELSE
  242. C( I, J ) = BETA *C( I, J ) +
  243. $ TEMP1*REAL( A( I, I ) ) +
  244. $ ALPHA*TEMP2
  245. END IF
  246. 60 CONTINUE
  247. 70 CONTINUE
  248. ELSE
  249. DO 100, J = 1, N
  250. DO 90, I = M, 1, -1
  251. TEMP1 = ALPHA*B( I, J )
  252. TEMP2 = ZERO
  253. DO 80, K = I + 1, M
  254. C( K, J ) = C( K, J ) + TEMP1*A( K, I )
  255. TEMP2 = TEMP2 +
  256. $ B( K, J )*CONJG( A( K, I ) )
  257. 80 CONTINUE
  258. IF( BETA.EQ.ZERO )THEN
  259. C( I, J ) = TEMP1*REAL( A( I, I ) ) +
  260. $ ALPHA*TEMP2
  261. ELSE
  262. C( I, J ) = BETA *C( I, J ) +
  263. $ TEMP1*REAL( A( I, I ) ) +
  264. $ ALPHA*TEMP2
  265. END IF
  266. 90 CONTINUE
  267. 100 CONTINUE
  268. END IF
  269. ELSE
  270. C
  271. C Form C := alpha*B*A + beta*C.
  272. C
  273. DO 170, J = 1, N
  274. TEMP1 = ALPHA*REAL( A( J, J ) )
  275. IF( BETA.EQ.ZERO )THEN
  276. DO 110, I = 1, M
  277. C( I, J ) = TEMP1*B( I, J )
  278. 110 CONTINUE
  279. ELSE
  280. DO 120, I = 1, M
  281. C( I, J ) = BETA*C( I, J ) + TEMP1*B( I, J )
  282. 120 CONTINUE
  283. END IF
  284. DO 140, K = 1, J - 1
  285. IF( UPPER )THEN
  286. TEMP1 = ALPHA*A( K, J )
  287. ELSE
  288. TEMP1 = ALPHA*CONJG( A( J, K ) )
  289. END IF
  290. DO 130, I = 1, M
  291. C( I, J ) = C( I, J ) + TEMP1*B( I, K )
  292. 130 CONTINUE
  293. 140 CONTINUE
  294. DO 160, K = J + 1, N
  295. IF( UPPER )THEN
  296. TEMP1 = ALPHA*CONJG( A( J, K ) )
  297. ELSE
  298. TEMP1 = ALPHA*A( K, J )
  299. END IF
  300. DO 150, I = 1, M
  301. C( I, J ) = C( I, J ) + TEMP1*B( I, K )
  302. 150 CONTINUE
  303. 160 CONTINUE
  304. 170 CONTINUE
  305. END IF
  306. C
  307. RETURN
  308. C
  309. C End of CHEMM .
  310. C
  311. END