0

I use Eigen 3.3 and Intel MKL 2017, and write and run program in Visual Studio 2012 with Win-7 64-bit system and Intel Xeon(R) CPU E5-1620 v2@3.70GHZ CPU.

I belive that my configuration for MKL is correct, because I can succesfully run MKL examlpe codes. The configuraton for using Intel MKL from Eigen follows from https://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html. For Visiual Studio 2012, I complie codes via Intel C++ Complier in Release x64 model.

However, the following code always takes about 400 seconds, no matter if I set #define EIGEN_USE_MKL_ALL or not (i.e., if use Intel MKL). It seems that MKL does not work in Eigen.

Could anyone give some suggestion? Thanks.

#define EIGEN_USE_MKL_ALL // Determine if use MKL
#define EIGEN_VECTORIZE_SSE4_2

#include "stdafx.h"
#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(30000, 3000);  
    MatrixXd b = MatrixXd::Random(3000, 30000);

    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;
}
olivia
  • 381
  • 3
  • 14
  • [Related](http://stackoverflow.com/questions/32092971/performance-of-coefficient-wise-array-operations-of-the-eigen-library-with-mkl-b/) – Avi Ginsburg Nov 29 '16 at 14:36
  • `clock()` returns user time, so that's not what you should use to measure the actual running time of a multi-threaded application. Moreover, to get the the best of Eigen on this kind of huge dense product don't forget to enable AVX or FMA (if supported), and OpenMP. Here it takes 61s, and 55s with MKL. – ggael Nov 29 '16 at 22:28
  • @ggael Thanks, but run code with/without #define EIGEN_USE_MKL_ALL has the same time cost....so MKL here does not work... – olivia Nov 30 '16 at 03:20
  • Stupid me. #define EIGEN_USE_MKL_ALL after #include "stdafx.h" or removing #include "stdafx.h" sloves the problem........ – olivia Nov 30 '16 at 03:53
  • @gaael BTW,could you please show me the timer function to measure my running time? just like tic and toc in Matlab. – olivia Nov 30 '16 at 04:00
  • 2
    @ggael, `clock` under MSVC returns wall time, so for OP, this should be OK. @olivia, when measuring time with OMP you can use `omp_get_wtime()` or in the more general case of a multithreaded program you can use `std::chrono::system_clock` – Avi Ginsburg Nov 30 '16 at 06:58
  • It is certainly related to computer but @ggael timing sounds odd. MATALB runs this easily in less than 20 [Sec]. Why would it take Eigen almost a minute? – Royi May 05 '19 at 20:31
  • I ran it on a more than 5 years old quadcore laptop @ 2.6GHz. The timing I gave are very close to the theoretical peak for my CPU. Nothing odd. For this product, 20sec means a performance of 270 GFlops, so you definitely have a much more powerful CPU. Also, beware that for this example, Matlab is only a thin layer on top of the MKL, so you're effectively timing the MKL. – ggael May 08 '19 at 13:48

0 Answers0