chemm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /* chemm.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Subroutine */ int chemm_(char *side, char *uplo, integer *m, integer *n,
  14. complex *alpha, complex *a, integer *lda, complex *b, integer *ldb,
  15. complex *beta, complex *c__, integer *ldc)
  16. {
  17. /* System generated locals */
  18. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2,
  19. i__3, i__4, i__5, i__6;
  20. real r__1;
  21. complex q__1, q__2, q__3, q__4, q__5;
  22. /* Builtin functions */
  23. void r_cnjg(complex *, complex *);
  24. /* Local variables */
  25. integer i__, j, k, info;
  26. complex temp1, temp2;
  27. extern logical lsame_(char *, char *);
  28. integer nrowa;
  29. logical upper;
  30. extern /* Subroutine */ int xerbla_(char *, integer *);
  31. /* .. Scalar Arguments .. */
  32. /* .. */
  33. /* .. Array Arguments .. */
  34. /* .. */
  35. /* Purpose */
  36. /* ======= */
  37. /* CHEMM performs one of the matrix-matrix operations */
  38. /* C := alpha*A*B + beta*C, */
  39. /* or */
  40. /* C := alpha*B*A + beta*C, */
  41. /* where alpha and beta are scalars, A is an hermitian matrix and B and */
  42. /* C are m by n matrices. */
  43. /* Arguments */
  44. /* ========== */
  45. /* SIDE - CHARACTER*1. */
  46. /* On entry, SIDE specifies whether the hermitian matrix A */
  47. /* appears on the left or right in the operation as follows: */
  48. /* SIDE = 'L' or 'l' C := alpha*A*B + beta*C, */
  49. /* SIDE = 'R' or 'r' C := alpha*B*A + beta*C, */
  50. /* Unchanged on exit. */
  51. /* UPLO - CHARACTER*1. */
  52. /* On entry, UPLO specifies whether the upper or lower */
  53. /* triangular part of the hermitian matrix A is to be */
  54. /* referenced as follows: */
  55. /* UPLO = 'U' or 'u' Only the upper triangular part of the */
  56. /* hermitian matrix is to be referenced. */
  57. /* UPLO = 'L' or 'l' Only the lower triangular part of the */
  58. /* hermitian matrix is to be referenced. */
  59. /* Unchanged on exit. */
  60. /* M - INTEGER. */
  61. /* On entry, M specifies the number of rows of the matrix C. */
  62. /* M must be at least zero. */
  63. /* Unchanged on exit. */
  64. /* N - INTEGER. */
  65. /* On entry, N specifies the number of columns of the matrix C. */
  66. /* N must be at least zero. */
  67. /* Unchanged on exit. */
  68. /* ALPHA - COMPLEX . */
  69. /* On entry, ALPHA specifies the scalar alpha. */
  70. /* Unchanged on exit. */
  71. /* A - COMPLEX array of DIMENSION ( LDA, ka ), where ka is */
  72. /* m when SIDE = 'L' or 'l' and is n otherwise. */
  73. /* Before entry with SIDE = 'L' or 'l', the m by m part of */
  74. /* the array A must contain the hermitian matrix, such that */
  75. /* when UPLO = 'U' or 'u', the leading m by m upper triangular */
  76. /* part of the array A must contain the upper triangular part */
  77. /* of the hermitian matrix and the strictly lower triangular */
  78. /* part of A is not referenced, and when UPLO = 'L' or 'l', */
  79. /* the leading m by m lower triangular part of the array A */
  80. /* must contain the lower triangular part of the hermitian */
  81. /* matrix and the strictly upper triangular part of A is not */
  82. /* referenced. */
  83. /* Before entry with SIDE = 'R' or 'r', the n by n part of */
  84. /* the array A must contain the hermitian matrix, such that */
  85. /* when UPLO = 'U' or 'u', the leading n by n upper triangular */
  86. /* part of the array A must contain the upper triangular part */
  87. /* of the hermitian matrix and the strictly lower triangular */
  88. /* part of A is not referenced, and when UPLO = 'L' or 'l', */
  89. /* the leading n by n lower triangular part of the array A */
  90. /* must contain the lower triangular part of the hermitian */
  91. /* matrix and the strictly upper triangular part of A is not */
  92. /* referenced. */
  93. /* Note that the imaginary parts of the diagonal elements need */
  94. /* not be set, they are assumed to be zero. */
  95. /* Unchanged on exit. */
  96. /* LDA - INTEGER. */
  97. /* On entry, LDA specifies the first dimension of A as declared */
  98. /* in the calling (sub) program. When SIDE = 'L' or 'l' then */
  99. /* LDA must be at least max( 1, m ), otherwise LDA must be at */
  100. /* least max( 1, n ). */
  101. /* Unchanged on exit. */
  102. /* B - COMPLEX array of DIMENSION ( LDB, n ). */
  103. /* Before entry, the leading m by n part of the array B must */
  104. /* contain the matrix B. */
  105. /* Unchanged on exit. */
  106. /* LDB - INTEGER. */
  107. /* On entry, LDB specifies the first dimension of B as declared */
  108. /* in the calling (sub) program. LDB must be at least */
  109. /* max( 1, m ). */
  110. /* Unchanged on exit. */
  111. /* BETA - COMPLEX . */
  112. /* On entry, BETA specifies the scalar beta. When BETA is */
  113. /* supplied as zero then C need not be set on input. */
  114. /* Unchanged on exit. */
  115. /* C - COMPLEX array of DIMENSION ( LDC, n ). */
  116. /* Before entry, the leading m by n part of the array C must */
  117. /* contain the matrix C, except when beta is zero, in which */
  118. /* case C need not be set on entry. */
  119. /* On exit, the array C is overwritten by the m by n updated */
  120. /* matrix. */
  121. /* LDC - INTEGER. */
  122. /* On entry, LDC specifies the first dimension of C as declared */
  123. /* in the calling (sub) program. LDC must be at least */
  124. /* max( 1, m ). */
  125. /* Unchanged on exit. */
  126. /* Level 3 Blas routine. */
  127. /* -- Written on 8-February-1989. */
  128. /* Jack Dongarra, Argonne National Laboratory. */
  129. /* Iain Duff, AERE Harwell. */
  130. /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */
  131. /* Sven Hammarling, Numerical Algorithms Group Ltd. */
  132. /* .. External Functions .. */
  133. /* .. */
  134. /* .. External Subroutines .. */
  135. /* .. */
  136. /* .. Intrinsic Functions .. */
  137. /* .. */
  138. /* .. Local Scalars .. */
  139. /* .. */
  140. /* .. Parameters .. */
  141. /* .. */
  142. /* Set NROWA as the number of rows of A. */
  143. /* Parameter adjustments */
  144. a_dim1 = *lda;
  145. a_offset = 1 + a_dim1;
  146. a -= a_offset;
  147. b_dim1 = *ldb;
  148. b_offset = 1 + b_dim1;
  149. b -= b_offset;
  150. c_dim1 = *ldc;
  151. c_offset = 1 + c_dim1;
  152. c__ -= c_offset;
  153. /* Function Body */
  154. if (lsame_(side, "L")) {
  155. nrowa = *m;
  156. } else {
  157. nrowa = *n;
  158. }
  159. upper = lsame_(uplo, "U");
  160. /* Test the input parameters. */
  161. info = 0;
  162. if (! lsame_(side, "L") && ! lsame_(side, "R")) {
  163. info = 1;
  164. } else if (! upper && ! lsame_(uplo, "L")) {
  165. info = 2;
  166. } else if (*m < 0) {
  167. info = 3;
  168. } else if (*n < 0) {
  169. info = 4;
  170. } else if (*lda < max(1,nrowa)) {
  171. info = 7;
  172. } else if (*ldb < max(1,*m)) {
  173. info = 9;
  174. } else if (*ldc < max(1,*m)) {
  175. info = 12;
  176. }
  177. if (info != 0) {
  178. xerbla_("CHEMM ", &info);
  179. return 0;
  180. }
  181. /* Quick return if possible. */
  182. if (*m == 0 || *n == 0 || alpha->r == 0.f && alpha->i == 0.f && (beta->r
  183. == 1.f && beta->i == 0.f)) {
  184. return 0;
  185. }
  186. /* And when alpha.eq.zero. */
  187. if (alpha->r == 0.f && alpha->i == 0.f) {
  188. if (beta->r == 0.f && beta->i == 0.f) {
  189. i__1 = *n;
  190. for (j = 1; j <= i__1; ++j) {
  191. i__2 = *m;
  192. for (i__ = 1; i__ <= i__2; ++i__) {
  193. i__3 = i__ + j * c_dim1;
  194. c__[i__3].r = 0.f, c__[i__3].i = 0.f;
  195. /* L10: */
  196. }
  197. /* L20: */
  198. }
  199. } else {
  200. i__1 = *n;
  201. for (j = 1; j <= i__1; ++j) {
  202. i__2 = *m;
  203. for (i__ = 1; i__ <= i__2; ++i__) {
  204. i__3 = i__ + j * c_dim1;
  205. i__4 = i__ + j * c_dim1;
  206. q__1.r = beta->r * c__[i__4].r - beta->i * c__[i__4].i,
  207. q__1.i = beta->r * c__[i__4].i + beta->i * c__[
  208. i__4].r;
  209. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  210. /* L30: */
  211. }
  212. /* L40: */
  213. }
  214. }
  215. return 0;
  216. }
  217. /* Start the operations. */
  218. if (lsame_(side, "L")) {
  219. /* Form C := alpha*A*B + beta*C. */
  220. if (upper) {
  221. i__1 = *n;
  222. for (j = 1; j <= i__1; ++j) {
  223. i__2 = *m;
  224. for (i__ = 1; i__ <= i__2; ++i__) {
  225. i__3 = i__ + j * b_dim1;
  226. q__1.r = alpha->r * b[i__3].r - alpha->i * b[i__3].i,
  227. q__1.i = alpha->r * b[i__3].i + alpha->i * b[i__3]
  228. .r;
  229. temp1.r = q__1.r, temp1.i = q__1.i;
  230. temp2.r = 0.f, temp2.i = 0.f;
  231. i__3 = i__ - 1;
  232. for (k = 1; k <= i__3; ++k) {
  233. i__4 = k + j * c_dim1;
  234. i__5 = k + j * c_dim1;
  235. i__6 = k + i__ * a_dim1;
  236. q__2.r = temp1.r * a[i__6].r - temp1.i * a[i__6].i,
  237. q__2.i = temp1.r * a[i__6].i + temp1.i * a[
  238. i__6].r;
  239. q__1.r = c__[i__5].r + q__2.r, q__1.i = c__[i__5].i +
  240. q__2.i;
  241. c__[i__4].r = q__1.r, c__[i__4].i = q__1.i;
  242. i__4 = k + j * b_dim1;
  243. r_cnjg(&q__3, &a[k + i__ * a_dim1]);
  244. q__2.r = b[i__4].r * q__3.r - b[i__4].i * q__3.i,
  245. q__2.i = b[i__4].r * q__3.i + b[i__4].i *
  246. q__3.r;
  247. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  248. temp2.r = q__1.r, temp2.i = q__1.i;
  249. /* L50: */
  250. }
  251. if (beta->r == 0.f && beta->i == 0.f) {
  252. i__3 = i__ + j * c_dim1;
  253. i__4 = i__ + i__ * a_dim1;
  254. r__1 = a[i__4].r;
  255. q__2.r = r__1 * temp1.r, q__2.i = r__1 * temp1.i;
  256. q__3.r = alpha->r * temp2.r - alpha->i * temp2.i,
  257. q__3.i = alpha->r * temp2.i + alpha->i *
  258. temp2.r;
  259. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  260. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  261. } else {
  262. i__3 = i__ + j * c_dim1;
  263. i__4 = i__ + j * c_dim1;
  264. q__3.r = beta->r * c__[i__4].r - beta->i * c__[i__4]
  265. .i, q__3.i = beta->r * c__[i__4].i + beta->i *
  266. c__[i__4].r;
  267. i__5 = i__ + i__ * a_dim1;
  268. r__1 = a[i__5].r;
  269. q__4.r = r__1 * temp1.r, q__4.i = r__1 * temp1.i;
  270. q__2.r = q__3.r + q__4.r, q__2.i = q__3.i + q__4.i;
  271. q__5.r = alpha->r * temp2.r - alpha->i * temp2.i,
  272. q__5.i = alpha->r * temp2.i + alpha->i *
  273. temp2.r;
  274. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  275. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  276. }
  277. /* L60: */
  278. }
  279. /* L70: */
  280. }
  281. } else {
  282. i__1 = *n;
  283. for (j = 1; j <= i__1; ++j) {
  284. for (i__ = *m; i__ >= 1; --i__) {
  285. i__2 = i__ + j * b_dim1;
  286. q__1.r = alpha->r * b[i__2].r - alpha->i * b[i__2].i,
  287. q__1.i = alpha->r * b[i__2].i + alpha->i * b[i__2]
  288. .r;
  289. temp1.r = q__1.r, temp1.i = q__1.i;
  290. temp2.r = 0.f, temp2.i = 0.f;
  291. i__2 = *m;
  292. for (k = i__ + 1; k <= i__2; ++k) {
  293. i__3 = k + j * c_dim1;
  294. i__4 = k + j * c_dim1;
  295. i__5 = k + i__ * a_dim1;
  296. q__2.r = temp1.r * a[i__5].r - temp1.i * a[i__5].i,
  297. q__2.i = temp1.r * a[i__5].i + temp1.i * a[
  298. i__5].r;
  299. q__1.r = c__[i__4].r + q__2.r, q__1.i = c__[i__4].i +
  300. q__2.i;
  301. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  302. i__3 = k + j * b_dim1;
  303. r_cnjg(&q__3, &a[k + i__ * a_dim1]);
  304. q__2.r = b[i__3].r * q__3.r - b[i__3].i * q__3.i,
  305. q__2.i = b[i__3].r * q__3.i + b[i__3].i *
  306. q__3.r;
  307. q__1.r = temp2.r + q__2.r, q__1.i = temp2.i + q__2.i;
  308. temp2.r = q__1.r, temp2.i = q__1.i;
  309. /* L80: */
  310. }
  311. if (beta->r == 0.f && beta->i == 0.f) {
  312. i__2 = i__ + j * c_dim1;
  313. i__3 = i__ + i__ * a_dim1;
  314. r__1 = a[i__3].r;
  315. q__2.r = r__1 * temp1.r, q__2.i = r__1 * temp1.i;
  316. q__3.r = alpha->r * temp2.r - alpha->i * temp2.i,
  317. q__3.i = alpha->r * temp2.i + alpha->i *
  318. temp2.r;
  319. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  320. c__[i__2].r = q__1.r, c__[i__2].i = q__1.i;
  321. } else {
  322. i__2 = i__ + j * c_dim1;
  323. i__3 = i__ + j * c_dim1;
  324. q__3.r = beta->r * c__[i__3].r - beta->i * c__[i__3]
  325. .i, q__3.i = beta->r * c__[i__3].i + beta->i *
  326. c__[i__3].r;
  327. i__4 = i__ + i__ * a_dim1;
  328. r__1 = a[i__4].r;
  329. q__4.r = r__1 * temp1.r, q__4.i = r__1 * temp1.i;
  330. q__2.r = q__3.r + q__4.r, q__2.i = q__3.i + q__4.i;
  331. q__5.r = alpha->r * temp2.r - alpha->i * temp2.i,
  332. q__5.i = alpha->r * temp2.i + alpha->i *
  333. temp2.r;
  334. q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
  335. c__[i__2].r = q__1.r, c__[i__2].i = q__1.i;
  336. }
  337. /* L90: */
  338. }
  339. /* L100: */
  340. }
  341. }
  342. } else {
  343. /* Form C := alpha*B*A + beta*C. */
  344. i__1 = *n;
  345. for (j = 1; j <= i__1; ++j) {
  346. i__2 = j + j * a_dim1;
  347. r__1 = a[i__2].r;
  348. q__1.r = r__1 * alpha->r, q__1.i = r__1 * alpha->i;
  349. temp1.r = q__1.r, temp1.i = q__1.i;
  350. if (beta->r == 0.f && beta->i == 0.f) {
  351. i__2 = *m;
  352. for (i__ = 1; i__ <= i__2; ++i__) {
  353. i__3 = i__ + j * c_dim1;
  354. i__4 = i__ + j * b_dim1;
  355. q__1.r = temp1.r * b[i__4].r - temp1.i * b[i__4].i,
  356. q__1.i = temp1.r * b[i__4].i + temp1.i * b[i__4]
  357. .r;
  358. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  359. /* L110: */
  360. }
  361. } else {
  362. i__2 = *m;
  363. for (i__ = 1; i__ <= i__2; ++i__) {
  364. i__3 = i__ + j * c_dim1;
  365. i__4 = i__ + j * c_dim1;
  366. q__2.r = beta->r * c__[i__4].r - beta->i * c__[i__4].i,
  367. q__2.i = beta->r * c__[i__4].i + beta->i * c__[
  368. i__4].r;
  369. i__5 = i__ + j * b_dim1;
  370. q__3.r = temp1.r * b[i__5].r - temp1.i * b[i__5].i,
  371. q__3.i = temp1.r * b[i__5].i + temp1.i * b[i__5]
  372. .r;
  373. q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
  374. c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
  375. /* L120: */
  376. }
  377. }
  378. i__2 = j - 1;
  379. for (k = 1; k <= i__2; ++k) {
  380. if (upper) {
  381. i__3 = k + j * a_dim1;
  382. q__1.r = alpha->r * a[i__3].r - alpha->i * a[i__3].i,
  383. q__1.i = alpha->r * a[i__3].i + alpha->i * a[i__3]
  384. .r;
  385. temp1.r = q__1.r, temp1.i = q__1.i;
  386. } else {
  387. r_cnjg(&q__2, &a[j + k * a_dim1]);
  388. q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i =
  389. alpha->r * q__2.i + alpha->i * q__2.r;
  390. temp1.r = q__1.r, temp1.i = q__1.i;
  391. }
  392. i__3 = *m;
  393. for (i__ = 1; i__ <= i__3; ++i__) {
  394. i__4 = i__ + j * c_dim1;
  395. i__5 = i__ + j * c_dim1;
  396. i__6 = i__ + k * b_dim1;
  397. q__2.r = temp1.r * b[i__6].r - temp1.i * b[i__6].i,
  398. q__2.i = temp1.r * b[i__6].i + temp1.i * b[i__6]
  399. .r;
  400. q__1.r = c__[i__5].r + q__2.r, q__1.i = c__[i__5].i +
  401. q__2.i;
  402. c__[i__4].r = q__1.r, c__[i__4].i = q__1.i;
  403. /* L130: */
  404. }
  405. /* L140: */
  406. }
  407. i__2 = *n;
  408. for (k = j + 1; k <= i__2; ++k) {
  409. if (upper) {
  410. r_cnjg(&q__2, &a[j + k * a_dim1]);
  411. q__1.r = alpha->r * q__2.r - alpha->i * q__2.i, q__1.i =
  412. alpha->r * q__2.i + alpha->i * q__2.r;
  413. temp1.r = q__1.r, temp1.i = q__1.i;
  414. } else {
  415. i__3 = k + j * a_dim1;
  416. q__1.r = alpha->r * a[i__3].r - alpha->i * a[i__3].i,
  417. q__1.i = alpha->r * a[i__3].i + alpha->i * a[i__3]
  418. .r;
  419. temp1.r = q__1.r, temp1.i = q__1.i;
  420. }
  421. i__3 = *m;
  422. for (i__ = 1; i__ <= i__3; ++i__) {
  423. i__4 = i__ + j * c_dim1;
  424. i__5 = i__ + j * c_dim1;
  425. i__6 = i__ + k * b_dim1;
  426. q__2.r = temp1.r * b[i__6].r - temp1.i * b[i__6].i,
  427. q__2.i = temp1.r * b[i__6].i + temp1.i * b[i__6]
  428. .r;
  429. q__1.r = c__[i__5].r + q__2.r, q__1.i = c__[i__5].i +
  430. q__2.i;
  431. c__[i__4].r = q__1.r, c__[i__4].i = q__1.i;
  432. /* L150: */
  433. }
  434. /* L160: */
  435. }
  436. /* L170: */
  437. }
  438. }
  439. return 0;
  440. /* End of CHEMM . */
  441. } /* chemm_ */