我正在试验英特尔MKL库使用它们提供的Boost :: uBLAS接口(包括mkl_boost_ublas_matrix_prod.hpp)执行矩阵乘法。我的数据只是整数,所以我尝试将矩阵模板类型更改为int,并且性能下降了,主要原因似乎是由于代码只使用一个CPU内核而不是我已有的12个内核。我找不到MKL文档中的任何内容来解释为什么整数不使用MKL的OpenMP多线程功能(我猜他们根本不使用MKL?)。英特尔MKL矩阵产品性能与双数据,浮点数和整型数据类型
此外,与浮动相比,我看到50%的双打表现受到双打打击。
问题:
- 为什么和双精度浮点数之间的差距呢?
- 为什么我不能使用整数?
下面是从下面的代码我的结果:
matrix<float>(10000x10000): 13 seconds (12 threads used)
matrix<double>(10000x10000): 26 seconds (12 threads used)
matrix<int>(10000x10000): >1000 seconds (1 thread used, stopped early)
matrix<float>(25000x25000): 187 seconds (12 threads used)
matrix<double>(25000x25000): 401 seconds (12 threads used)
代码中使用(根据需要更换两个矩阵<类型>行):
g++ Flags: -std=c++0x -O3 -DNDEBUG -DMKL_ILP64 -m64 -msse4.2 -march=native -mtune=native
ld Flags: -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm
:
#include <boost/numeric/ublas/matrix.hpp>
#include <mkl_boost_ublas_matrix_prod.hpp>
using namespace boost::numeric::ublas;
void benchmark() {
int size = 10000;
matrix<float> m(size, size);
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
m(i,j) = 2*i-j;
}
}
matrix<float> r(size, size);
r = prod(m,m);
}
int main(int argc, char *argv[]) {
benchmark();
return 0;
}
编译时
处理器:
Intel Xeon E7530 with 6 Cores (x2) with HT.
,因为他们说,这不会有任何帮助,所以我有12个线程可用的MKL不使用超线程,而不是24
太棒了,谢谢! – 2012-08-01 13:56:45