Chris@202: /* dgemm.f -- translated by f2c (version 20061008). Chris@202: You must link the resulting object file with libf2c: Chris@202: on Microsoft Windows system, link with libf2c.lib; Chris@202: on Linux or Unix systems, link with .../path/to/libf2c.a -lm Chris@202: or, if you install libf2c.a in a standard place, with -lf2c -lm Chris@202: -- in that order, at the end of the command line, as in Chris@202: cc *.o -lf2c -lm Chris@202: Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., Chris@202: Chris@202: http://www.netlib.org/f2c/libf2c.zip Chris@202: */ Chris@202: Chris@202: #include "f2c.h" Chris@202: #include "blaswrap.h" Chris@202: Chris@202: /* Subroutine */ int dgemm_(char *transa, char *transb, integer *m, integer * Chris@202: n, integer *k, doublereal *alpha, doublereal *a, integer *lda, Chris@202: doublereal *b, integer *ldb, doublereal *beta, doublereal *c__, Chris@202: integer *ldc) Chris@202: { Chris@202: /* System generated locals */ Chris@202: integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2, Chris@202: i__3; Chris@202: Chris@202: /* Local variables */ Chris@202: integer i__, j, l, info; Chris@202: logical nota, notb; Chris@202: doublereal temp; Chris@202: integer ncola; Chris@202: extern logical lsame_(char *, char *); Chris@202: integer nrowa, nrowb; Chris@202: extern /* Subroutine */ int xerbla_(char *, integer *); Chris@202: Chris@202: /* .. Scalar Arguments .. */ Chris@202: /* .. */ Chris@202: /* .. Array Arguments .. */ Chris@202: /* .. */ Chris@202: Chris@202: /* Purpose */ Chris@202: /* ======= */ Chris@202: Chris@202: /* DGEMM performs one of the matrix-matrix operations */ Chris@202: Chris@202: /* C := alpha*op( A )*op( B ) + beta*C, */ Chris@202: Chris@202: /* where op( X ) is one of */ Chris@202: Chris@202: /* op( X ) = X or op( X ) = X', */ Chris@202: Chris@202: /* alpha and beta are scalars, and A, B and C are matrices, with op( A ) */ Chris@202: /* an m by k matrix, op( B ) a k by n matrix and C an m by n matrix. */ Chris@202: Chris@202: /* Arguments */ Chris@202: /* ========== */ Chris@202: Chris@202: /* TRANSA - CHARACTER*1. */ Chris@202: /* On entry, TRANSA specifies the form of op( A ) to be used in */ Chris@202: /* the matrix multiplication as follows: */ Chris@202: Chris@202: /* TRANSA = 'N' or 'n', op( A ) = A. */ Chris@202: Chris@202: /* TRANSA = 'T' or 't', op( A ) = A'. */ Chris@202: Chris@202: /* TRANSA = 'C' or 'c', op( A ) = A'. */ Chris@202: Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* TRANSB - CHARACTER*1. */ Chris@202: /* On entry, TRANSB specifies the form of op( B ) to be used in */ Chris@202: /* the matrix multiplication as follows: */ Chris@202: Chris@202: /* TRANSB = 'N' or 'n', op( B ) = B. */ Chris@202: Chris@202: /* TRANSB = 'T' or 't', op( B ) = B'. */ Chris@202: Chris@202: /* TRANSB = 'C' or 'c', op( B ) = B'. */ Chris@202: Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* M - INTEGER. */ Chris@202: /* On entry, M specifies the number of rows of the matrix */ Chris@202: /* op( A ) and of the matrix C. M must be at least zero. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* N - INTEGER. */ Chris@202: /* On entry, N specifies the number of columns of the matrix */ Chris@202: /* op( B ) and the number of columns of the matrix C. N must be */ Chris@202: /* at least zero. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* K - INTEGER. */ Chris@202: /* On entry, K specifies the number of columns of the matrix */ Chris@202: /* op( A ) and the number of rows of the matrix op( B ). K must */ Chris@202: /* be at least zero. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* ALPHA - DOUBLE PRECISION. */ Chris@202: /* On entry, ALPHA specifies the scalar alpha. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* A - DOUBLE PRECISION array of DIMENSION ( LDA, ka ), where ka is */ Chris@202: /* k when TRANSA = 'N' or 'n', and is m otherwise. */ Chris@202: /* Before entry with TRANSA = 'N' or 'n', the leading m by k */ Chris@202: /* part of the array A must contain the matrix A, otherwise */ Chris@202: /* the leading k by m part of the array A must contain the */ Chris@202: /* matrix A. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* LDA - INTEGER. */ Chris@202: /* On entry, LDA specifies the first dimension of A as declared */ Chris@202: /* in the calling (sub) program. When TRANSA = 'N' or 'n' then */ Chris@202: /* LDA must be at least max( 1, m ), otherwise LDA must be at */ Chris@202: /* least max( 1, k ). */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* B - DOUBLE PRECISION array of DIMENSION ( LDB, kb ), where kb is */ Chris@202: /* n when TRANSB = 'N' or 'n', and is k otherwise. */ Chris@202: /* Before entry with TRANSB = 'N' or 'n', the leading k by n */ Chris@202: /* part of the array B must contain the matrix B, otherwise */ Chris@202: /* the leading n by k part of the array B must contain the */ Chris@202: /* matrix B. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* LDB - INTEGER. */ Chris@202: /* On entry, LDB specifies the first dimension of B as declared */ Chris@202: /* in the calling (sub) program. When TRANSB = 'N' or 'n' then */ Chris@202: /* LDB must be at least max( 1, k ), otherwise LDB must be at */ Chris@202: /* least max( 1, n ). */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* BETA - DOUBLE PRECISION. */ Chris@202: /* On entry, BETA specifies the scalar beta. When BETA is */ Chris@202: /* supplied as zero then C need not be set on input. */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: /* C - DOUBLE PRECISION array of DIMENSION ( LDC, n ). */ Chris@202: /* Before entry, the leading m by n part of the array C must */ Chris@202: /* contain the matrix C, except when beta is zero, in which */ Chris@202: /* case C need not be set on entry. */ Chris@202: /* On exit, the array C is overwritten by the m by n matrix */ Chris@202: /* ( alpha*op( A )*op( B ) + beta*C ). */ Chris@202: Chris@202: /* LDC - INTEGER. */ Chris@202: /* On entry, LDC specifies the first dimension of C as declared */ Chris@202: /* in the calling (sub) program. LDC must be at least */ Chris@202: /* max( 1, m ). */ Chris@202: /* Unchanged on exit. */ Chris@202: Chris@202: Chris@202: /* Level 3 Blas routine. */ Chris@202: Chris@202: /* -- Written on 8-February-1989. */ Chris@202: /* Jack Dongarra, Argonne National Laboratory. */ Chris@202: /* Iain Duff, AERE Harwell. */ Chris@202: /* Jeremy Du Croz, Numerical Algorithms Group Ltd. */ Chris@202: /* Sven Hammarling, Numerical Algorithms Group Ltd. */ Chris@202: Chris@202: Chris@202: /* .. External Functions .. */ Chris@202: /* .. */ Chris@202: /* .. External Subroutines .. */ Chris@202: /* .. */ Chris@202: /* .. Intrinsic Functions .. */ Chris@202: /* .. */ Chris@202: /* .. Local Scalars .. */ Chris@202: /* .. */ Chris@202: /* .. Parameters .. */ Chris@202: /* .. */ Chris@202: Chris@202: /* Set NOTA and NOTB as true if A and B respectively are not */ Chris@202: /* transposed and set NROWA, NCOLA and NROWB as the number of rows */ Chris@202: /* and columns of A and the number of rows of B respectively. */ Chris@202: Chris@202: /* Parameter adjustments */ Chris@202: a_dim1 = *lda; Chris@202: a_offset = 1 + a_dim1; Chris@202: a -= a_offset; Chris@202: b_dim1 = *ldb; Chris@202: b_offset = 1 + b_dim1; Chris@202: b -= b_offset; Chris@202: c_dim1 = *ldc; Chris@202: c_offset = 1 + c_dim1; Chris@202: c__ -= c_offset; Chris@202: Chris@202: /* Function Body */ Chris@202: nota = lsame_(transa, "N"); Chris@202: notb = lsame_(transb, "N"); Chris@202: if (nota) { Chris@202: nrowa = *m; Chris@202: ncola = *k; Chris@202: } else { Chris@202: nrowa = *k; Chris@202: ncola = *m; Chris@202: } Chris@202: if (notb) { Chris@202: nrowb = *k; Chris@202: } else { Chris@202: nrowb = *n; Chris@202: } Chris@202: Chris@202: /* Test the input parameters. */ Chris@202: Chris@202: info = 0; Chris@202: if (! nota && ! lsame_(transa, "C") && ! lsame_( Chris@202: transa, "T")) { Chris@202: info = 1; Chris@202: } else if (! notb && ! lsame_(transb, "C") && ! Chris@202: lsame_(transb, "T")) { Chris@202: info = 2; Chris@202: } else if (*m < 0) { Chris@202: info = 3; Chris@202: } else if (*n < 0) { Chris@202: info = 4; Chris@202: } else if (*k < 0) { Chris@202: info = 5; Chris@202: } else if (*lda < max(1,nrowa)) { Chris@202: info = 8; Chris@202: } else if (*ldb < max(1,nrowb)) { Chris@202: info = 10; Chris@202: } else if (*ldc < max(1,*m)) { Chris@202: info = 13; Chris@202: } Chris@202: if (info != 0) { Chris@202: xerbla_("DGEMM ", &info); Chris@202: return 0; Chris@202: } Chris@202: Chris@202: /* Quick return if possible. */ Chris@202: Chris@202: if (*m == 0 || *n == 0 || (*alpha == 0. || *k == 0) && *beta == 1.) { Chris@202: return 0; Chris@202: } Chris@202: Chris@202: /* And if alpha.eq.zero. */ Chris@202: Chris@202: if (*alpha == 0.) { Chris@202: if (*beta == 0.) { Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = 0.; Chris@202: /* L10: */ Chris@202: } Chris@202: /* L20: */ Chris@202: } Chris@202: } else { Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]; Chris@202: /* L30: */ Chris@202: } Chris@202: /* L40: */ Chris@202: } Chris@202: } Chris@202: return 0; Chris@202: } Chris@202: Chris@202: /* Start the operations. */ Chris@202: Chris@202: if (notb) { Chris@202: if (nota) { Chris@202: Chris@202: /* Form C := alpha*A*B + beta*C. */ Chris@202: Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: if (*beta == 0.) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = 0.; Chris@202: /* L50: */ Chris@202: } Chris@202: } else if (*beta != 1.) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]; Chris@202: /* L60: */ Chris@202: } Chris@202: } Chris@202: i__2 = *k; Chris@202: for (l = 1; l <= i__2; ++l) { Chris@202: if (b[l + j * b_dim1] != 0.) { Chris@202: temp = *alpha * b[l + j * b_dim1]; Chris@202: i__3 = *m; Chris@202: for (i__ = 1; i__ <= i__3; ++i__) { Chris@202: c__[i__ + j * c_dim1] += temp * a[i__ + l * Chris@202: a_dim1]; Chris@202: /* L70: */ Chris@202: } Chris@202: } Chris@202: /* L80: */ Chris@202: } Chris@202: /* L90: */ Chris@202: } Chris@202: } else { Chris@202: Chris@202: /* Form C := alpha*A'*B + beta*C */ Chris@202: Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: temp = 0.; Chris@202: i__3 = *k; Chris@202: for (l = 1; l <= i__3; ++l) { Chris@202: temp += a[l + i__ * a_dim1] * b[l + j * b_dim1]; Chris@202: /* L100: */ Chris@202: } Chris@202: if (*beta == 0.) { Chris@202: c__[i__ + j * c_dim1] = *alpha * temp; Chris@202: } else { Chris@202: c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[ Chris@202: i__ + j * c_dim1]; Chris@202: } Chris@202: /* L110: */ Chris@202: } Chris@202: /* L120: */ Chris@202: } Chris@202: } Chris@202: } else { Chris@202: if (nota) { Chris@202: Chris@202: /* Form C := alpha*A*B' + beta*C */ Chris@202: Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: if (*beta == 0.) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = 0.; Chris@202: /* L130: */ Chris@202: } Chris@202: } else if (*beta != 1.) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: c__[i__ + j * c_dim1] = *beta * c__[i__ + j * c_dim1]; Chris@202: /* L140: */ Chris@202: } Chris@202: } Chris@202: i__2 = *k; Chris@202: for (l = 1; l <= i__2; ++l) { Chris@202: if (b[j + l * b_dim1] != 0.) { Chris@202: temp = *alpha * b[j + l * b_dim1]; Chris@202: i__3 = *m; Chris@202: for (i__ = 1; i__ <= i__3; ++i__) { Chris@202: c__[i__ + j * c_dim1] += temp * a[i__ + l * Chris@202: a_dim1]; Chris@202: /* L150: */ Chris@202: } Chris@202: } Chris@202: /* L160: */ Chris@202: } Chris@202: /* L170: */ Chris@202: } Chris@202: } else { Chris@202: Chris@202: /* Form C := alpha*A'*B' + beta*C */ Chris@202: Chris@202: i__1 = *n; Chris@202: for (j = 1; j <= i__1; ++j) { Chris@202: i__2 = *m; Chris@202: for (i__ = 1; i__ <= i__2; ++i__) { Chris@202: temp = 0.; Chris@202: i__3 = *k; Chris@202: for (l = 1; l <= i__3; ++l) { Chris@202: temp += a[l + i__ * a_dim1] * b[j + l * b_dim1]; Chris@202: /* L180: */ Chris@202: } Chris@202: if (*beta == 0.) { Chris@202: c__[i__ + j * c_dim1] = *alpha * temp; Chris@202: } else { Chris@202: c__[i__ + j * c_dim1] = *alpha * temp + *beta * c__[ Chris@202: i__ + j * c_dim1]; Chris@202: } Chris@202: /* L190: */ Chris@202: } Chris@202: /* L200: */ Chris@202: } Chris@202: } Chris@202: } Chris@202: Chris@202: return 0; Chris@202: Chris@202: /* End of DGEMM . */ Chris@202: Chris@202: } /* dgemm_ */