我为分配创建了矩阵多重性代码,但是无法使函数正常工作,因此我怀疑这是BLAS库未正确链接。
在OS X中,BLAS已内置到Accelerate Framework中,因此在makefile中,我通过-framework Accelerate链接了lib,在cpp中,我还通过#include<Accelerate/Accelerate.h>包括了标题

在编译期间,我的错误是:

Undefined symbols for architecture x86_64:
"dgemm_(char*, char*, int*, int*, int*, double*, double*, int*, double*, int*, double*, double*, int*)"

所以我创建了一个简单的测试代码,但是在编译过程中仍然出现错误:
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.

我的简单测试代码是用
 clang++  -o test_2.exe test_2.cpp -framework Accelerate

我的简单代码是:
#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;
}

最佳答案

对于the documentation,Accelerate.framework在所有BLAS函数之前加上cblas_前缀。例如,dgemm函数声明为

 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 );

08-24 14:05