Calling (BLAS subroutine) DGEMM from C++

493 views
Skip to first unread message

Olumide

unread,
Apr 5, 2011, 7:43:35 PM4/5/11
to matrixprogramming
I'm trying to call the Matrix-Matrix computation subroutine DGEMM from
C++ as follows:

double* dgemm( int _numRowA , int _numColA , double* _A , int
_numRowB , int _numColB , double* _B , int& _numRowC , int& _numColC )
{
if( _numColA != _numRowB )
{
std::cout << "number of columns of Matrix A is NOT equal to num of
rows of Matrix B" << std::endl;
return NULL;
}

_numRowC = _numRowA;
_numColC = _numColB;

char trans = 'N';
double alpha = 1.0 , beta = 1.0;
double *C = new double [ _numRowC * _numColC ];
int lda = ( _numRowA >= _numColA ) ? _numRowA : _numColA;
int ldb = ( _numRowB >= _numColB ) ? _numRowB : _numColB;
int ldc = ( _numRowC >= _numColC ) ? _numRowC : _numColC;
DGEMM( &trans , &trans , &_numRowA , &_numColB , &_numColA , &alpha ,
_A , &lda , _B , &ldb , &beta , C , &ldc );

return C;
}

where _A and _B are the matrices I'd like to multiply, and _dim* are
their dimensions. Unfortunately I'm getting gibberish results. What am
I doing wrong?

Thanks.

Olumide

unread,
Apr 5, 2011, 9:34:15 PM4/5/11
to matrixprogramming
Problem solved. beta had to be zero.
Reply all
Reply to author
Forward
0 new messages