这是一个小程序,其中包含对英特尔MKL
库函数和DLIB
优化例程find_min_using_approximate_derivatives
的调用。
使用intel C++
编译器编译代码时运行完美:icpc
使用调用:
icpc main.cpp -I /Users/Username/Code/dlib-18.16 -DDLIB_USE_BLAS -I$MKLROOT/include -L$MKLROOT/lib/ -lmkl_core -lmkl_intel_thread -lpthread -lm -lmkl_intel_lp64 -DENABLE_DLIB -DDLIB_USE_BLAS
或通过以下方式禁用代码的DLIB
相关部分:
clang++ main.cpp -I$MKLROOT/include -L$MKLROOT/lib/ -lmkl_core -lmkl_intel_thread -lpthread -lm -lmkl_intel_lp64
C ++代码
// #define ENABLE_DLIB
#ifdef ENABLE_DLIB
#include "dlib/optimization.h"
#endif
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include "mkl.h"
using namespace std;
#ifdef ENABLE_DLIB
using namespace dlib;
#endif
template<typename T>
void printArray(T *data, string name, int len){
cout << name << "\n";
for(int i=0;i<len;i++){
cout << data[i] << " ";
}
cout << "\n";
}
#ifdef ENABLE_DLIB
typedef matrix<double,0,1> column_vector;
double rosen (const column_vector& m)
{
const double x = m(0);
const double y = m(1);
return 100.0*pow(y - x*x,2) + pow(1 - x,2);
}
#endif
int main()
{
#ifdef ENABLE_DLIB
column_vector starting_point(2);
starting_point = 4, 8;
find_min_using_approximate_derivatives(bfgs_search_strategy(),
objective_delta_stop_strategy(1e-7),
rosen, starting_point, -1);
cout << "\nBFGS rosen minimum lies at:\n";
cout << "x = " << starting_point(0) << endl;
cout << "y = " << starting_point(1) << endl;
#endif
int len=10;
double *x=new double[len];
double *y=new double[len];
for(int i=0;i<len;i++){
x[i]=(double)std::rand()/RAND_MAX;
y[i]=(double)std::rand()/RAND_MAX;
}
printArray<double>(x, "x", len);
printArray<double>(y, "y", len);
//sum(x)
double x_sum=cblas_dasum(len,x,1);
cout<< "sum(x): "<< x_sum <<"\n";
}
尽管如此,它仍然无法将icpc
替换为clang++
以上的多个错误:
错误
In file included from /opt/intel/composer_xe_2015.3.187/mkl/include/mkl.h:48:
/opt/intel/composer_xe_2015.3.187/mkl/include/mkl_cblas.h:584:6: error: conflicting types for 'cblas_cgemm'
void cblas_cgemm(const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
^
/Users/Username/Code/dlib-18.16/dlib/matrix/matrix_blas_bindings.h:75:18: note: previous declaration is here
void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
...表明cblas_*
中镜像的MKL
例程之间存在冲突。 DLIB
的文档建议使用DLIB_USE_BLAS
预处理程序指令,以便与MKL
链接,但显然它似乎无法帮助使用clang++
。
我如何使这项工作?