Linking MKL with Eigen

This is a post summarizing my experience trying to get Eigen to work with the MKL library. It turns out linking with MKL radically accelerates the application.

I was trying to use MKL backend for Eigen, which is used in my code for ALS in ligra in this repository

https://github.com/yunmingzhang17/ligra

I first followed the directions here and added the flag

-DEIGEN_USE_MKL_ALL

http://eigen.tuxfamily.org/dox/TopicUsingIntelMKL.html

I got the problem that I can’t find mkl.h, so I added the flag

-DMKL_LP64 to the compile flag,

But then Eigen can’t find its own header, I realized I didn’t include the current directory in the include path

-I.

Then error start to show up unable to find MKL. I chose to dynamically link MKL, so I had to add (1)  -L link flags , (2) I also need to add MKL to LD_LIBRARY_PATH

For (1), I used the tool here

https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor

I was using Linux, but for Eigen, one thing to note is that it only works with LP64 (32 bit integers), it doesn’t work with the ILP64 interface in MKL. I only use sequential MKL for now

mkl_link_advisor (the pdf file, screenshot of how I used the advisor to show me the dynamic flag)

Furthermore, to get the tool to work and since I am doing dynamic linking (which grabs the relevant code during runtime), I had to add MKL to the LD_LIBRARY_PATH.

The quickies way to do that is go to icc/mkl/bin and run mklvars.sh

source /data/scratch/yunming/icc/install/mkl/bin/mklvars.sh intel64 (this is my command to set up the variables easily).

Once I did that, I was able to run Eigen with MKL

Hope this helps!

Advertisements
This entry was posted in Tools and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s