Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
202 Views

Setting the MKL dist dlls path, for the single dynamic library

Hi,

In Windows, the mkl_rt.dll searches for the MKL dlls it needs in the PATH env variable. Is there other way besides setting the PATH to tell the  mkl_rt.dll  where the MKL dlls resides.

The motivation for this is to prevent dll hell i.e. if we deliver a software that was developed against MKL version X.XX and we deliver the corresponding dist dlls, but on  a user machine, exists another version of MKL, which is defined in the PATH before ours , the wrong version will be used. What is the solution for this scenario.

(Loading the correct mkl_rt.dll is not a problem using the SetDllDirectory windows API , but its not good for telling the mkl_rt.dll where to look).

Thanks

Eran 

0 Kudos
8 Replies
Employee
202 Views

Hi Eran:

You will required to link with mkl_rt.dll while you choose the linking model with Single-dynamic library. By using this way it really make your linking simpler that it loads dependent libraries dynamically at runtime depending on runtime CPU detection. But if you release an application and would like to run in other system with different path of MKL lib or without MKL lib. Please select to use Static linking model, so that you do not need to worry about the linking path of mkl lib. 

Please use MKL Link Line Advisor to help you understand which dll you are required to link with different linking model. If you would like to compiler in command line, please refer:
>icl sample.cpp -Qmkl
or you could specify static linking lib
>icl sample.cpp mkl_intel_lp64.lib mkl_core.lib mkl_sequential.lib
*replace "mkl_sequential.lib" to "mkl_thread.lib" if you would like to use OpenMP threading

And you could also see article Compiling and Linking Intel® Math Kernel Library with Microsoft* Visual C++* to learn how to add MKL lib in IDE manually. Hope it would be useful to you.

Regards,
Fiona

0 Kudos
Beginner
202 Views

Thanks for the reply.

I didn't understand the following -  "But if you release an application and would like to run in other system with different path of MKL lib" ?

The mkl_rt.dll resides within the 'redist' direcotry with the other MKL dlls . but it doesn't know to load them unless I give it the path in the PATH env variable (am I wrong ?). I was expecting it to try to load from the same directory it resides in.

So the PATH env is the only way to tell the mkl_rt.dll where the MKL redist path ?

Thanks

Eran

 

0 Kudos
Employee
202 Views

Hi Eran:

Sorry for my unclear explanation. The mkl_rt.lib depends on other lib files. If you set path for mkl_rt.dll, you should ensure other dll files also refer to same path as mkl_rt.dll; the mkl_rt.dll will look for other dll files in current location first. Thus, you have to release your app always with dll files and make sure the path is always current. This method might cause a mess of your MKL dll path, other user might change or delete dll files. I recommend to use static linking with your application while you plan to release this project and run this application in different system. Using static linking is the simplest and best way to overcome the limitation of dynamic linking.

Best regards,
Fiona

0 Kudos
Beginner
202 Views

Thanks again for the quick reply. 

I'm still not getting something you write that "the mkl_rt.dll will look for other dll files in current location first." what do you mean by  current location ? for example our app resides at c::\\ourapp\\ourapp.exe and it loads explicitly the mkl_rt.dll from c::\\mkl\\redist\\ . all the other mkl dlls also found in c::\\mkl\\redist\\ but when using the MKL functionalliy . our app crashes since mkl_rt.dll  can't find the MKL dlls. it doesn't look at the same directory where it resides. only if I set the PATH env to include c::\\mkl\\redist\\ , the mkl_rt.dll  founds the MKL dlls and works. we want to avoid static linking we prefer to find a solution for the dynamic linking.

Thanks again!

 

 

 

 

 

0 Kudos
Employee
202 Views

Hi Eran,

Because mkl_rt.dll depends on other dll file, if you set code to load mkl_rt.dll from c::\\mkl\\redist\\ , you should also ask code to load other dll from c::\\mkl\\redist\\ .

The quickest way is, do not set to load particular path for mkl_rt.dll, copy all dll file from MKL redist folder to the location of your app exe file.
For instance, your app is locate in C:\Myapp\sample.exe ,please copy all MKL dll file to C:\Myapp. Here's an image could help you to understand.

mkl_dll.png

 

I have tested that the sample.exe could find all dll in this case.

Best regards,

Fiona

0 Kudos
Beginner
202 Views

Hi Fiona,

The problem is that our app runs as a plugin within another process, so we are not located at the same place as the exe. putting all the mkl dlls within the same directory of the plugin dll causing a crash because the mkl_rt.dll can't find the mkl dlls. the only way I could satisfy the mkl_rt.dll is to set the PATH env variable ,which is not good enough because there is a risk to load a different  mkl version which its path was defined first. Static link is not good enough also because then we need to static link each of our plugins , it will increase our installer size significantly. I must find a way to tell the mkl_rt.dll to load a specific version of mkl or to load from the same directory it's located (but not from the PATH env).

Thanks 

Eran

 

0 Kudos
Employee
202 Views

Hi Eran,

Here's another way I can find out is to build your own customer lib and dll file, and link this customer dll with your application. Please follow this article Using the Custom Dynamic-link Library Builder in the Command-line Mode to generate customer lib and dll. And then, put the dll and lib file under your application folder, and refer it in your project. So that, the customer dll could replace mkl_rt.dll. This method won't increase your installer size, you could just specify functions you need in function_list file. Hope it could help you.

Regards,

Fiona

0 Kudos
Beginner
202 Views

Hi Fiona,

The custom method worked very well !

Is there a way to create custom dll for MacOS ?

Thanks

Eran

0 Kudos