user1706918
user1706918

Reputation:

DGEMM and Numerical Constants as Arguments

While using BLAS DGEMM matrix-multiply function, I noticed that for an uninitialized result matrix C, I get NaNs in the resultwhen I call it like so:

DGEMM('N', 'N', M, N, K, 1.0, A, LDA, B, LDB, 0.0, C, LDC)

However, if I declare ALPHA and BETA before-hand:

REAL*8 ALPHA, BETA
PARAMETER (ALPHA=1.0)
PARAMETER (BETA=0.0)

DGEMM('N', 'N', M, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)

then the multiplication works okay. Does anyone have any ideas as to why declaring the arguments works?

Note that I'm using the Intel Fortran compiler along with it's MKL library.

Upvotes: 1

Views: 2035

Answers (1)

Jonathan Dursi
Jonathan Dursi

Reputation: 50937

It would work if you passed alpha and beta as double precision numerical constants (eg, 1.d0), but you're passing it single precision constants, and Fortran 77 has no way of knowing dgemm's argument list and promoting the reals to double precision. (It might work with the single precision constants if you used MKL's Fortran 95 interface, but I'm not sure).

Because you're only passing pointers 4-byte arguments and the library subroutine is looking up 8-byte values, the rest of the calculation gets messed up.

Upvotes: 4

Related Questions