2

I have an F# project that uses MathNet.Numerics for Linear Algebra routines.

I have placed the following code in an F# module:

module LinearAlgebra

open MathNet.Numerics
open MathNet.Numerics.LinearAlgebra.Double
open MathNet.Numerics.LinearAlgebra.Generic

Control.LinearAlgebraProvider <- new Algorithms.LinearAlgebra.Mkl.MklLinearAlgebraProvider()

But the times I am seeing for matrix multiplication remain the same whether I have this line of code enabled or commented out.

I have installed the Mkl provider NuGet package as described here: http://christoph.ruegg.name/blog/mathnet-numerics-with-native-linear-algebra.html

and have ensured that these two dlls are copied to the bin directory: libiomp5md.dll MathNet.Numerics.MKL.dll

Any ideas about how I can detect if the native provider is actually being used?

TylerH
  • 20,799
  • 66
  • 75
  • 101
JTS
  • 33
  • 5

1 Answers1

2

The docs are a bit more up to date than the mentioned blog post, but it seems all the required steps have been done.

  • How large are your matrices?
  • Are all the involved matrices dense?
  • Is this module the module where your linear algebra code is in? If not, have you made sure that this module is actually executed - before the linear algebra code?

You can verify the native provider is enabled by checking Control.LinearAlgebraProvider right before the linear algebra code is executed. In v3, calling ToString on it will provide some additional info like platform and revision as well.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34
  • Matrices are 4000x430 and 430x430. I am using only dense matrix types, even though some are sparse in terms of structure. As I understood, sparse is not working yet with native providers. So if I set the MklProvider in the module where the calculations are made, it works. But if I set it in another module and import that module, it does not work. So I wrapped the call to set the provider in an init function and call that after opening the module, and that also works. Must be something about F# modules that I am not aware of. – JTS Jun 01 '14 at 04:58
  • Thanks for the update. Yes, adding sparse support to the MKL native provider has been delayed to a minor release after v3.0. – Christoph Rüegg Jun 01 '14 at 13:17
  • Found the reason why the top level statement in the opened module was not working. I had only inline functions in the module so it was never truly being opened prior to using the linear algebra provider. – JTS Jun 01 '14 at 15:35
  • By the way, a big "thanks" to the MathNet team for this library. – JTS Jun 01 '14 at 16:58