Reputation: 31
I created a matrix multiplicity code for an assignment but could not get the function working, so I suspect it is the BLAS lib not linked properly.
In OS X, the BLAS has been built into the Accelerate Framework, so in makefile I linked the lib by -framework Accelerate
and in cpp I also include the header by #include<Accelerate/Accelerate.h>
During compilation, my error is:
Undefined symbols for architecture x86_64:
"dgemm_(char*, char*, int*, int*, int*, double*, double*, int*, double*, int*, double*, double*, int*)"
So I created a simple test code but I still get the error during compilation:
test_2.cpp:35:3: error: use of undeclared identifier 'dgemm_'
dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, ...
^
1 error generated.
My simple test code is compiled with
clang++ -o test_2.exe test_2.cpp -framework Accelerate
My simple code is :
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cfloat>
#include <cmath>
#include <sys/time.h>
#ifdef __APPLE__
#include <Accelerate/Accelerate.h>
#else
#include <cblas.h>
#endif
using namespace std;
int main( int argc, char **argv )
{
int n=10;
int N=n;
double *A = (double*) malloc( n * n * sizeof(double) );
double *B = (double*) malloc( n * n * sizeof(double) );
double *C = (double*) malloc( n * n * sizeof(double) );
char TRANSA = 'N';
char TRANSB = 'N';
int M = N;
int K = N;
double ALPHA = 1.;
double BETA = 0.;
int LDA = N;
int LDB = N;
int LDC = N;
dgemm_(&TRANSA, &TRANSB, &M, &N, &K, &ALPHA, A, &LDA, B, &LDB, &BETA, C, &LDC);
return 0;
}
Upvotes: 3
Views: 3024
Reputation: 179452
Per the documentation, Accelerate.framework prefixes all BLAS functions with cblas_
. For example, the dgemm
function is declared as
void cblas_dgemm(const enum CBLAS_ORDER ORDER, const enum CBLAS_TRANSPOSE TRANSA, const enum CBLAS_TRANSPOSE TRANSB, const __LAPACK_int M, const __LAPACK_int N, const __LAPACK_int K, const double ALPHA, const double *A, const __LAPACK_int LDA, const double *B, const __LAPACK_int LDB, const double BETA, double *C, const __LAPACK_int LDC);
Upvotes: 2