2

I'm trying to use the Mkl native provider from mathdotnet with mono in Linux.

I'm using monodevelop and installed MathNet.Numerics and both MathNet.Numerics.MKL.Linux-x64 and -x86 packages via the build in NuGet package manager.

When I try this code, i get System.NotSupportedException: MKL Native Provider Not Found.

using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics;

namespace mdeveloptest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Control.UseNativeMKL ();

            Matrix<double> a = DenseMatrix.OfArray(new double[,] { {1,2,3}, {4,5,6}, {7,8,9}});
            Matrix<double> b = DenseMatrix.OfArray(new double[,] { {1,2,3}, {4,5,6}, {7,8,9}});

            Console.WriteLine (a*b);

        }
    }
}

The MKL-packages provide a libiomp5.so and a MathNet.Numerics.MKL.dll file. In windows it was enough to copy these files to the output directory but it doesn't seem to be enough in Linux.

I'm also not sure if I need the x64 or x86 package or if mono somehow can choose the right one by itself.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Robert
  • 101
  • 7

2 Answers2

1

Linux's ldconfig needs to know where to find the shared libraries (*.so) even if they are in the current directory of the executable. If you where running this mono app from the cmd and all your files (exe, dlls and SOs) are in the current directory, you would:

export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH
mono mdeveloptest.exe

In MonoDevelop / Xamarin Studio:

  1. Open the Project options
  2. Goto the Run / General panel
  3. Add an Environment Variable

.

Variable        | Value
LD_LIBRARY_PATH | ./

FYI: I have used ${PWD} as XS/MonoDevelop env vars and they get shell expanded correctly, it might be the way they are quoting the strings. As the poster had to use "./", I updated the answer.

FYI: OS-X's dyld includes the current directory by default and thus the DYLD_LIBRARY_PATH would not need to be set in this case.

Additional info:

Native assembly resolving is very different on Linux than on Windows, simply putting the native libraries into the same folder as the executable is not enough. The safe way is to edit /etc/ld.so.conf and use ldconfig to tell where to look for the libraries. Alternatively you could add the path to LD_LIBRARY_PATH or even just copy them to /usr/lib.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • thx a lot, setting LD_LIBRARY_PATH variable finaly worked for me. in monodevelop the value doesn't seem to get interpreted, the variable there just gets set to the string "${PWD}". setting it to "./" then worked. also somehow using ldconfig didn't work for me – Robert Jul 14 '15 at 11:11
  • 1
    No problem, I updated the answer with the "./" reply so hopefully the next person finds the answer. – SushiHangover Jul 14 '15 at 18:37
0

What version of Math.NET Numerics are you using? Since v3.6 it is supposed to look explicitly also in the output folder, even on Linux. You can also set Control.NativeProviderPath to make it look at another path as well. And yes, if you put both into an x64 and x86 subfolder, it will pick the right one automatically. See our documentation for Intel MKL for details.

Of course you can also set it up as shared library the Linux way with ldconfig, see Linux Interop with Native Libraries.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34
  • 1
    hi, thx for the help. i'm using mathnet v3.7. I tried Control.NativeProvierPath, ldconfig with putting everything to /lib and just copying ibiomp5.soand MathNet.Numerics.MKL.dll to the folder containing the .exe file. Nothing worked except setting the LD_LIBRARY_PATH-variable. – Robert Jul 14 '15 at 11:16