我想测试Intel MKL
矩阵乘法,所以我包括我只是使用cblas_dgemm函数,但它总是说
undefined reference to `cblas_dgemm'
我还链接了-lmkl_core -lmkl_blas95_lp64 -lmkl_lapack95_lp64
,但是我在$MKLROOT/lib/intel64/
目录中的库中测试了许多组合,错误仍然存在。 有人可以给我一些建议吗? 谢谢。
也许这是一个正确的答案,我们可以使用cblas_
:
在QT Creator的项目文件中:
unix { INCLUDEPATH += /opt/intel/mkl/include LIBS += -L/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -L/opt/intel/lib/intel64 -liomp5 -lpthread -dl -lm }
以下是MKL
测试cblas_*
的main.cpp
:
#include using namespace std; #include #include #include #include #include #include #include #include template void printArray(T *data, char *name, int len){ cout << name << "n"; for(int i=0;i void printMatrix(T *data, char *name, int m, int n){ cout << name << "n"; for(int i=0;i(x, "x", len); printArray(y, "y", len); //sum(x) double x_sum=cblas_dasum(len,x,1); cout<< "sum(x): "<< x_sum <<"n"; //y=a*x+y double alpha=1; cblas_daxpy(len,alpha,x,1,y,1); printArray (y,"y=a*x+y",len); //y=x cblas_dcopy(len,x,1,y,1); printArray (y,"y=x",len); //x*y'; double xy_dot=cblas_ddot(len,x,1,y,1); cout <<"x*y': "<(x,"x:",len); printArray (y,"y:",len); //LEVEL 2 BLAS //matrix and vector manipulation int m=len; int n=len; double *A=new double[m*n]; for(int i=0;i(A,"A",m,n); //matrix and vector multiplication double alpha_dgemv=1.0; double beta_dgemv=1.0; //y=alpha*A*x+beta*y, if A is a mxn band matrix, then use cblas_dgbmv cblas_dgemv(CblasRowMajor,CblasNoTrans,m,n,alpha_dgemv,A,m,x,1,beta_dgemv,y,1); printArray (x,"x:",len); printArray (y,"y=alpha*A*x+beta*y",len); //y=alpha*A'*x+beta*y cblas_dgemv(CblasRowMajor,CblasTrans,m,n,alpha_dgemv,A,m,x,1,beta_dgemv,y,1); printArray (x,"x:",len); printArray (y,"y=alpha*A'*x+beta*y",len); //A=alpha*x*y'+A; double alpha_dger=1.0; cblas_dger(CblasRowMajor,m,n,alpha_dger,x,1,y,1,A,m); printArray (x,"x:",len); printArray (y,"y:",len); printMatrix (A,"A=alpha1*x*y'+A",m,n); delete[] x;x=NULL; delete[] y;y=NULL; delete[] A;A=NULL; // m=10; n=5; int k=3; double *Amxk=new double[m*k]; double *Bkxn=new double[k*n]; double *Cmxn=new double[m*n]; for(int i=0;i(Amxk,"Amxk",m,k); printMatrix (Bkxn,"Bkxn",k,n); printMatrix (Cmxn,"Cmxn",m,n); double alpha_dgemm=1.0; double beta_dgemm=1.0; cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha_dgemm, Amxk, k, Bkxn, n, beta_dgemm, Cmxn, n); printMatrix (Cmxn,"Cmxn",m,n); delete[] Amxk; delete[] Bkxn; delete[] Cmxn; //general symmetric matrix eigenvalue decomposition /* Locals */ const MKL_INT N=5; const MKL_INT LDA=5; MKL_INT lda = LDA, info; n=N; /* Local arrays */ double w[N]; double a[LDA*N] = { 6.39, 0.13, -8.23, 5.71, -3.18, 0.00, 8.37, -4.46, -6.10, 7.21, 0.00, 0.00, -9.58, -9.25, -7.42, 0.00, 0.00, 0.00, 3.72, 8.54, 0.00, 0.00, 0.00, 0.00, 2.51 }; /* Executable statements */ printf( "LAPACKE_dsyevd (row-major, high-level) Example Program Resultsn" ); /* Solve eigenproblem */ info = LAPACKE_dsyevd( LAPACK_ROW_MAJOR, 'V', 'U', n, a, lda, w ); /* Check for convergence */ if( info > 0 ) { printf( "The algorithm failed to compute eigenvalues.n" ); exit( 1 ); } printArray (w,"w:",N); printMatrix (a,"a:",N,N); int N1=10; int d=3; double *A1=new double[N1*d]; for(int j=0;j(A1,"A:",d,N1); double *A_mean=new double[1*d]; for(int i=0;i(A_mean,"A_mean",d); delete[] A1;A1=NULL; delete[] A_mean;A_mean=NULL; return 0; }
然后,在终端中,键入以下代码以加载环境设置:
source /opt/intel/bin/compilervars.sh intel64
英特尔®数学核心库Link Line Advisor正是您所需要的。 它可以为您生成适当的编译/链接选项。
以上就是c/c++开发分享如何链接英特尔MKL库,只使用cblas_dgemm函数相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/544819.html