cpp, mkl 加速 eigen 实例

编程入门 行业动态 更新时间:2024-10-08 06:17:10

cpp, mkl 加速 eigen <a href=https://www.elefans.com/category/jswz/34/1771375.html style=实例"/>

cpp, mkl 加速 eigen 实例

安装mkl

把eigen放到代码文件平行目录

使用mkl编译:
mkl_test.cpp

#define EIGEN_USE_MKL_ALL#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <time.h>using namespace std;
using namespace Eigen;// 使用Eigen+Intel MKL
int main(int argc, char *argv[])
{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;//system("PAUSE");return 0;
}

编译指令:
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

然后运行./a.out
打印 0.23

对比不编译mkl:
mkl_test2.cpp

#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <time.h>using namespace std;
using namespace Eigen;int main(int argc, char *argv[])
{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;//system("PAUSE");return 0;
}

编译指令:g++ mkl_test2.cpp -o b.out -Ieigen
运行./b.out
打印11.94

更多推荐

cpp, mkl 加速 eigen 实例

本文发布于:2024-02-13 15:18:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759250.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实例   cpp   mkl   eigen

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!