Difficulty of compiling fortran code while linking with mkl

Difficulty of compiling fortran code while linking with mkl


I have been trying to compile my fortran code, where I am using a couple of mkl functions such as dss solver, MKL_DCSRMULTCSR, MKL_DCSRGEMV, etc. Previously I had a similar code, from which I was compiling a dll. I was calling then the created dll from matlab using loadlibrary function. This has worked in the past, because my code did not use any of the mkl functions I mentioned above.

Now when I try the loadlibrary command, it complains that it does not recognize the mkl functions. I have been searching for solutions here in forum, on the web, etc. Unfortunately, all the things I have tried so far failed. This is where I need your help.

So far I have tried two approaches: 

- I tried to link the mkl libraries while I am compiling the code. For example I have tried commands such as:

ifort -shared -fpic -o Engine.so -O3 -L/usr/local/intel/composer_xe_2013.5.192/mkl/lib/intel64/ -I/usr/local/intel/composer_xe_2013.5.192/mkl/include/ -lmkl_intel_lp64.so -lmkl_sequential -lmkl_core SourceCode/*.f90

Although it does not return any error and creates the Engine.so successfully, when I load it in matlab, it tells me that it cant find "lmkl_intel_lp64.so" library (even if I copy it to the same directory). My question here is: do you think there is something wrong the way I compile it or do I need to define something on matlab side?

- the second thing I tried was just to compile it without linking to mkl libraries as:

ifort -shared -fpic -o Engine.so -O3 SourceCode/*.f90

where included the "mkl_dss.f90" file in my fortran code. This again returns no error and created the dll successfully. And when I load it in matlab, it actually does NOT complain about dss functions (so I assume that I managed to include the dss solver). However it still complains about the remaining two MKL_DCSRMULTCSR, MKL_DCSRGEMV functions. I know that they are part of mkl_spblas however there is no .f90 file for this, but only an .fi file (I think the difference is still not clear to me, i.e. why there is f90 file for dss but an fi file for spblas). As a result, I could not do the same trick for these two functions.

Sorry for the long post, I tried to summarize it as short as possible while describing the important parts.

I would be glad for any suggestions how I could make this thing work 

Thank you very much in advance,

best regards,





2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Under current linux, current working directory is not included in default paths, in the hope of stopping some of the simple trojan horse exploits.  The normal way of adding MKL shared objects directory to LD_LIBRARY_PATH is by sourcing the mklvars (perhaps via compilervars) script as is done when setting up to compile.  If you prefer to use current working directory, you can add that to LD_LIBRARY_PATH if it doesn't conflict with your local system policy.

You should be able to check your shared object paths by ldd.

Leave a Comment

Please sign in to add a comment. Not a member? Join today