Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

mkl, matmult.py in windows w/ mkl_rt.dll

Jonathan_H_1
Beginner
1,527 Views

I am trying to give examples to my students for directly calling mkl from python (using intel/anaconda python 2.7 dist) in a Windows 10 environment.; simple examples first, then moving on to paradiso, etc. (Yes, everything works fine in python with auto linking of mkl for standard scipy and scipy.sparse functions.) The students will need ctypes for specialty routines like paradiso and for their own needed c++ code snippets.

MKL 2018.3 is installed and successfully accessed via c++ from VS2017. So all the various mkl_rt.dll etc are present in the appropriate redist dirs. I am afraid I am not that familiar with ctypes in a windows environment. In python, trying to start by running the matmult.py example posted here: (https://software.intel.com/en-us/articles/using-intel-mkl-in-your-python-programs) but python chokes on cdll statement. How do I edit the cdll line 

from ctypes import *
# Load the share library
mkl = cdll.LoadLibrary("./libmkl_rt.so")

for a Windows environment? So far, none of the following work :

mkl=cdll.LoadLibrary(“.\mkl_rt.dll”)  #with mkl_rt.dll in current directory
mkl=cdll.LoadLibrary(“MKLPATH\mkl_rt.dll”) 
 
mkl=windll.LoadLibrary(“.\mkl_rt.dll”) #with mkl_rt.dll in current directory
mkl=windll.LoadLibrary(“MKLPATH\mkl_rt.dll”)  
mkl=windll.LoadLibrary(“MKLPATH\mkl_rt”)  

How do I edit the cdll line for a Windows environment?

OR is there a new version of matmult.py needed specific to  Windows installation?

Given that we're using the Intel Python distribution - is there a better way to access things like paradiso than using ctypes + the independent MKL install?

 

 

0 Kudos
1 Solution
Jing_Xu
Employee
1,527 Views

If the error message looks like "OSError: [WinError 126] The specified module could not be found", please use '/' instead of '\'. For instance, change “.\mkl_rt.dll” to “./mkl_rt.dll”, and try again.

By the way, please don't forget to call mklvars.bat to set required environment variables prior to running the python scripts.

Please feel free to get back any time you have further problems. It will be helpful if we can know the error message as well.

View solution in original post

0 Kudos
3 Replies
Jing_Xu
Employee
1,528 Views

If the error message looks like "OSError: [WinError 126] The specified module could not be found", please use '/' instead of '\'. For instance, change “.\mkl_rt.dll” to “./mkl_rt.dll”, and try again.

By the way, please don't forget to call mklvars.bat to set required environment variables prior to running the python scripts.

Please feel free to get back any time you have further problems. It will be helpful if we can know the error message as well.

0 Kudos
Jonathan_H_1
Beginner
1,527 Views

Jing: Yes, thank you - that was it.  I think rotating among windows/Linux, c++/python/matlab and spyder/vs2017 will be the death of me.

BTW: re mklvars.bat.  I think that you might have this script echo to the console to remind people to run devenv.exe from the vs2017 directory after it sets up the local variables.  The point is discussed very clearly in the Installation pdf, but old time intel compiler users who are familiar with the various _ _ _ _vars.sh scripts for setting environment variables might not think to run devenv.exe.  This delayed me a bit with getting mkl setup for vs2017 until I dug into the installation pdf.

Any other advice on getting the students setup to run paradiso from python.  Current plan is to use the paradiso examples from the mkl examples directory, having them port over to python using ctypes for the variables conversions.

Thanks again.

0 Kudos
Jing_Xu
Employee
1,527 Views

Good to hear that this problem's resovled.

Thank you for your advice about mklvars.bat and vs2017, I'll report to our engineer team. Besides, actually, you may choose "Use Intel(R) MKL" in the project's property window ("Configuration Properties -> Intel Performance Library -> Intel(R) Math Kernel Library -> Use Intel(R) MKL") to set environment variables automatically without running mklvars.bat, if MKL is integrated into VS2017 successfully.

One advice when porting MKL to Python might be that if there're MKL-specific structure types involved, you need to define them in your Python scipts. Their definitions can be found in header files.

0 Kudos
Reply