This project has moved and is read-only. For the latest updates, please go here.

Problem using Native Linear Algebra Provider

Feb 18, 2013 at 4:02 PM
Hello,

I'm having trouble getting the native linear algebra providers to work using the documentation here :
http://mathnetnumerics.codeplex.com/wikipage?title=Native%20Providers&referringTitle=Documentation
I'm using MKL, and while I was able to build the MKLWrapper project and grab the resulting MathNET.Numerics.MKL.dll, when I try to run my program and it hits a line that does any matrix operations (in my case, a .Divide) I get the following error :
An unhandled exception of type "System.DllNotFoundException' occurred in MathNet.Numerics.dll

Additional information: Unable to load DLL 'MathNET.Numerics.MKL.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
The MathNET.Numerics.MKL.dll is in the same directory as the MathNet.Numerics.dll I'm using in "References" (and out of frustration, I copied it to every other folder that any copy of MathNet.Numerics.dll happens to be in). The DLL was built in Release and x64 just like the MathNet.Numerics.dll, and the program I'm calling from.

Lots of googling has so far not given me much to go on. I'm not at all familiar with using unmanaged DLLs in a .NET project so it's very possible I'm missing something simple. Has anyone had experience with using MKL and have any suggestions on where I can look next?

Thanks,
Brian
Feb 18, 2013 at 4:27 PM
Feb 18, 2013 at 4:28 PM
In the MKL provider output directory, there should also be libiomp5md.dll (the Intel openmp rumtime). That also needs to be copied to the same directory as your executable. I find it useful to add both the provider and openmp runtime to the project solution and then set copy on build to always. This way the both DLLs are copied to your to output directory.
Feb 18, 2013 at 4:41 PM
Thanks very much for the quick replies! Sorry I should have mentioned that I'm also copying the libiomp5md.dll file along with the MathNET.Numerics.MKL.dll file, and I'm running 2.3 right now, developing in VS2010. Also, apparently our system/network config makes NuGet tricky, so unfortunately that's not an option.

Cuda, you mentioned adding the provider and the openmp runtime to my project solution - do you mean my solution (i.e., the software I'm developing, not any of the Math.NET Numerics solutions)? I tried adding the MKL dll as a Reference just to see what would happen, but as expected it didn't work. Is there another way to point Visual Studio to these files (aside from just dropping them in the folder with MathNet.Numerics.dll manually)? Maybe that's what I'm missing?

Thanks,
Brian
Feb 18, 2013 at 5:13 PM
In your project, click add existing item and then select the two DLLs. Then select those two items in
the solution explorer and click properties. From there set copy to always.

But I wonder if the problem is the visual c++ runtime. Could you try installing the VC++ 2012 runtime?
http://www.microsoft.com/en-us/download/details.aspx?id=30679
Feb 18, 2013 at 5:14 PM
But you are building it yourself so the runtime probably isn't the problem.
Feb 18, 2013 at 6:18 PM
I just checked the MKL provider DLL with dependency walker (http://www.dependencywalker.com/) and it only shows libiomp5md.dll and kernel32.dll as dependencies (as expected). If both your executable and the two DLLs are all in the same directory, I'm stumped.

The only thing I can think of is adding the directory that contains the two DLLs to your PATH and then launch your exe via the command line. If that works, then we know the problem is loading the DLLs locally.

Another option, is try it with mono. Mono has a great log facility.
From the mono command line prompt:
set MONO_LOG_LEVEL=debug
set MONO_LOG_MASK=dll
mono your.exe

Then mono will log all DLL errors and calls.
Marked as answer by cdrnet on 10/3/2013 at 5:48 PM
Feb 19, 2013 at 2:51 PM
That did the trick - for some reason VS didn't like the DLLs unless it put them there itself. Adding them manually to the project and selecting copy always worked on my test project and looks like it's working on the main project as well. Thanks very much for the help and the very quick responses!