diff --git a/docs/content/MKL.fsx b/docs/content/MKL.fsx index 084972cb..f71d0547 100644 --- a/docs/content/MKL.fsx +++ b/docs/content/MKL.fsx @@ -37,6 +37,72 @@ You can also explicitly disable the MKL provider by forcing it to use the manage Control.UseManaged(); +Using Intel MKL on Linux with Mono +---------------------------------- + +We no longer provide new MKL NuGet packages for Linux since we no longer have an license to do so +(only Windows for now), but it is still possible to use the older Linux MKL NuGet packages if you +don't want to build it yourself. Assuming you have Mono and NuGet installed (here v3.2.8), you can +fetch the MKL package of the right architecture (x64 or x86, `uname -m` if you don't know) as usual: + + [lang=sh] + mono nuget.exe install MathNet.Numerics -Pre -OutputDirectory packages + mono nuget.exe install MathNet.Numerics.MKL.Linux-x64 -Pre -OutputDirectory packages + +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, but for now we'll just copy them to `usr/lib`: + + [lang=sh] + sudo cp packages/MathNet.Numerics.MKL.Linux-x64.1.3.0/content/libiomp5.so /usr/lib/ + sudo cp packages/MathNet.Numerics.MKL.Linux-x64.1.3.0/content/MathNet.Numerics.MKL.dll /usr/lib/ + +Then we're all set and can just call `Control.UseNativeMKL()` if we want to use the native provider. +Let's create the following C# file `Example.cs`: + + [lang=csharp] + using System; + using System.Diagnostics; + using MathNet.Numerics; + using MathNet.Numerics.LinearAlgebra; + + class Program + { + static void Main(string[] args) + { + // Using managed code only + Control.UseManaged(); + Console.WriteLine(Control.LinearAlgebraProvider); + + var m = Matrix.Build.Random(500, 500); + var v = Vector.Build.Random(500); + + var w = Stopwatch.StartNew(); + var y1 = m.Solve(v); + Console.WriteLine(w.Elapsed); + Console.WriteLine(y1); + + // Using the Intel MKL native provider + Control.UseNativeMKL(); + Console.WriteLine(Control.LinearAlgebraProvider); + + w.Restart(); + var y2 = m.Solve(v); + Console.WriteLine(w.Elapsed); + Console.WriteLine(y2); + } + } + +Compile and run: + + [lang=sh] + // single line: + mcs -optimize -lib:packages/MathNet.Numerics.3.0.0-alpha8/lib/net40/ + -r:MathNet.Numerics.dll Example.cs -out:Example + // launch: + mono Example + + Licensing Restrictions ---------------------- diff --git a/docs/content/index.fsx b/docs/content/index.fsx index 30c80d20..f85b4134 100644 --- a/docs/content/index.fsx +++ b/docs/content/index.fsx @@ -7,8 +7,8 @@ Getting Started =============== -Installation Instructions -------------------------- +NuGet Packages +-------------- The recommended way to get Math.NET Numerics is to use NuGet. The following packages are provided and maintained in the public [NuGet Gallery](https://nuget.org/profiles/mathnet/): @@ -21,16 +21,121 @@ The recommended way to get Math.NET Numerics is to use NuGet. The following pack - **MathNet.Numerics.Signed** - strong-named version of the core package *(not recommended)*. - **MathNet.Numerics.FSharp.Signed** - strong-named version of the F# package *(not recommended)*. +Supported Platforms: + +- .Net 4.0, .Net 3.5 and Mono: Windows, Linux and Mac. +- PCL Portable Profiles 47 and 136: Silverlight 5, Windows Phone 8, .NET for Windows Store apps (Metro). +- PCL/Xamarin: Android, iOS *(not verified due to lack of license and devices)* + Alternatively you can also download the binaries in Zip packages, available on [CodePlex](http://mathnetnumerics.codeplex.com/releases): - Binaries - core package and F# extensions, including .Net 4, .Net 3.5 and portable/PCL builds. - Signed Binaries - strong-named version of the core package *(not recommended)*. -Supported Platforms: -- .Net 4.0, .Net 3.5 and Mono: Windows, Linux and Mac. -- PCL Portable Profiles 47 and 136: Silverlight 5, Windows Phone 8, .NET for Windows Store apps (Metro). -- PCL/Xamarin: Android, iOS *(not verified due to lack of license and devices)* +Using Math.NET Numerics with F# +------------------------------- + +Even though the core of Math.NET Numerics is written in C#, it aims to support F# +just as well. In order to achieve this we recommend to reference the `MathNet.Numerics.FSharp` +package as well (in addition to `MathNet.Numerics`) which adds a few modules to make it more +idiomatic and includes arbitrary precision types (BigInteger, BigRational). + +It also works well in the interactive F# environment (REPL) which can be launched with +`fsharpi` on all platforms (including Linux). As a start let's enter the following lines +into F# interactive. Each `;;` will cause the preceding lines to be executed immediately, +use the `Tab` key for auto-completion or `#help;;` for help. + + [lang=fsharp] + #r "MathNet.Numerics.dll" + #r "MathNet.Numerics.FSharp.dll";; + + open MathNet.Numerics;; + SpecialFunctions.Gamma(0.5);; + + open MathNet.Numerics.LinearAlgebra;; + let m : Matrix = DenseMatrix.randomStandard 50 50;; + (m * m.Transpose()).Determinant();; + + +Using Math.NET Numerics on Linux with Mono +------------------------------------------ + +You need a recent version of Mono in order to use Math.NET Numerics on anything other than Windows. +Luckily there has been great progress lately to make both Mono and F# available as proper Debian packages. +In Debian *testing* and Ubuntu *14.04 (trusty/universe)* you can install both of them with APT: + + [lang=sh] + sudo apt-get update + sudo apt-get install mono-complete + sudo apt-get install fsharp + +If you don't have NuGet yet: + + [lang=sh] + sudo mozroots --import --sync + curl -L http://nuget.org/nuget.exe -o nuget.exe + +Then you can use NuGet to fetch the latest binaries in your working directory. +The `-Pre` argument causes it to include pre-releases, omit it if you want stable releases only. + + [lang=sh] + mono nuget.exe install MathNet.Numerics -Pre -OutputDirectory packages + # or if you intend to use F#: + mono nuget.exe install MathNet.Numerics.FSharp -Pre -OutputDirectory packages + +In practice you'd probably use the Monodevelop IDE instead which can take care of fetching and updating +NuGet packages and maintain assembly references. But for completeness let's use the compiler directly this time. +Let's create a C# file `Start.cs`: + + [lang=csharp] + using System; + using MathNet.Numerics; + using MathNet.Numerics.LinearAlgebra; + + class Program + { + static void Main(string[] args) + { + // Evaluate a special function + Console.WriteLine(SpecialFunctions.Erf(0.5)); + + // Solve a random linear equation system with 500 unknowns + var m = Matrix.Build.Random(500, 500); + var v = Vector.Build.Random(500); + var y = m.Solve(v); + Console.WriteLine(y); + } + } + +Since we want to use the compiler directly, let's copy all references to the working directory +as well to keep the command line more compact (normally you'd use the -lib argument instead) and compile: + + [lang=sh] + cp packages/MathNet.Numerics.3.0.0-alpha8/lib/net40/* . + mcs -optimize -r:MathNet.Numerics.dll Start.cs -out:Start + +Run: + + [lang=sh] + mono Start + +Which will print something like the following to the output: + + [lang=text] + 0.520499877813047 + DenseVector 500-Double + -0.181414 -1.25024 -0.607136 1.12975 -3.31201 0.344146 + 0.934095 -2.96364 1.84499 1.20752 0.753055 1.56942 + 0.472414 6.10418 -0.359401 0.613927 -0.140105 2.6079 + 0.163564 -3.04402 -0.350791 2.37228 -1.65218 -0.84056 + 1.51311 -2.17326 -0.220243 -0.0368934 -0.970052 0.580543 + 0.755483 -1.01755 -0.904162 -1.21824 -2.24888 1.42923 + -0.971345 -3.16723 -0.822723 1.85148 -1.12235 -0.547885 + -2.01044 4.06481 -0.128382 0.51167 -1.70276 ... + +See [Intel MKL](MKL.html) for details how to use native providers on Linux. + Building Math.NET Numerics --------------------------