2

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 Accelerateand 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;
}
Lotte Wang
  • 21
  • 1
  • 5

1 Answers1

1

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 int __ M , const int __ N , const int __ K , const double __ alpha , const double *__ A , const int __ lda , const double *__ B , const int __ ldb , const double __ beta , double *__ C , const int __ ldc ); 
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • Thank you! I was reading the documentation but I found a previous thread which makes me though the call is same: http://stackoverflow.com/questions/10112135/understanding-lapack-calls-in-c-with-a-simple-example – Lotte Wang Oct 26 '15 at 08:25