c++ - 特征中的向量加法和点不通过 mkl 加速
问题描述
这是我使用的代码:
#define EIGEN_USE_MKL_ALL
#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <time.h>
using namespace std;
using namespace Eigen;
int main(int argc, char *argv[])
{
VectorXf a = VectorXf::Random(100000000);
VectorXf b = VectorXf::Random(100000000);
double start = clock();
VectorXf c = a+b;
float d = a.dot(b);
double endd = clock();
double thisTime = (double)(endd - start) / CLOCKS_PER_SEC;
cout << thisTime << endl;
return 0;
}
使用 mkl 编译:
g++ mkl_test.cpp /home/tong.guo/intel/mkl/lib/intel64/libmkl_rt.so -Ieigen -Wl,--no-as-needed -lpthread -lm -ldl -m64 -I/home/tong.guo/intel/mkl/include
去掉第一行代码,不用mkl编译:
g++ mkl_test.cpp -Ieigen
时间几乎一样。
但是可以加速矩阵计算。将代码更改为下面我可以看到速度。
MatrixXd a = MatrixXd::Random(1000, 1000);
MatrixXd b = MatrixXd::Random(1000, 1000);
double start = clock();
MatrixXd c = a * b;
double endd = clock();
double thisTime = (double)(endd - start) / CLOCKS_PER_SEC;
cout << thisTime << endl;
解决方案
推荐阅读
- wpf - 在 WPF 中打开模式对话框以获取 CefSharp 的凭据
- linux - 多线程`select`不返回数据准备好
- php - Magento2:更新核心文件中的一行代码
- android - 如何启用后退按钮 wen setCancelable 在进度对话框中设置为 false
- dc.js - 根据 dc.js 中的国家/地区创建组
- reporting-services - 使用参数时SSRS只显示一行
- html - 菜单栏 - 不同宽度的链接填充菜单栏的流体宽度
- hierarchical-data - 如何比较分层模型中的两个超参数?
- multithreading - 有没有办法强制一个进程与另一个进程共享地址空间?
- flutter - 设置颤振