diff --git a/src/NativeWrappers/MKL/lapack.cpp b/src/NativeWrappers/MKL/lapack.cpp index cb1fc691..1ae473c2 100644 --- a/src/NativeWrappers/MKL/lapack.cpp +++ b/src/NativeWrappers/MKL/lapack.cpp @@ -8,6 +8,8 @@ #include "lapack_common.h" #include "wrapper_common.h" #include "mkl_lapacke.h" +#include "mkl.h" +#include "mkl_trans.h" template inline MKL_INT lu_factor(MKL_INT m, T a[], MKL_INT ipiv[], @@ -748,4 +750,11 @@ extern "C" { return eigen_complex_factor(n, a, vectors, values, d, LAPACKE_zgees, LAPACKE_ztrevc); } } + + DLLEXPORT void SetImprovedConsistency(void) + { + // set improved consistency for mkl and vector functions + mkl_cbwr_set(MKL_CBWR_COMPATIBLE); + vmlSetMode(VML_HA|VML_DOUBLE_CONSISTENT); + } } \ No newline at end of file diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 161cacb3..383a230d 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -156,6 +156,7 @@ + diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs index 031a55e5..bef5bc34 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex.cs @@ -41,7 +41,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Intel's Math Kernel Library (MKL) linear algebra provider. /// - public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider + public partial class MklLinearAlgebraProvider { /// /// Computes the requested of the matrix. diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs index 982e9700..fffdbfd8 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Complex32.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Intel's Math Kernel Library (MKL) linear algebra provider. /// - public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider + public partial class MklLinearAlgebraProvider { /// /// Computes the requested of the matrix. diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs index 01118ece..02991cdb 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.Single.cs @@ -41,7 +41,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Intel's Math Kernel Library (MKL) linear algebra provider. /// - public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider + public partial class MklLinearAlgebraProvider { /// /// Computes the requested of the matrix. diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs new file mode 100644 index 00000000..3541b4f5 --- /dev/null +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs @@ -0,0 +1,51 @@ +// +// Math.NET Numerics, part of the Math.NET Project +// http://numerics.mathdotnet.com +// http://github.com/mathnet/mathnet-numerics +// http://mathnetnumerics.codeplex.com +// +// Copyright (c) 2009-2013 Math.NET +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +#if NATIVEMKL + +namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl +{ + /// + /// Intel's Math Kernel Library (MKL) linear algebra provider. + /// + public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider + { + /// If true improves MKL Consistency to get bit consistent results on repeated identical calculations + public MklLinearAlgebraProvider(bool bitConsistent = false) + { + if (bitConsistent) + { + SafeNativeMethods.SetImprovedConsistency(); + } + } + } +} + +#endif diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs index 5994ff75..673fdd74 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/MklLinearAlgebraProvider.double.cs @@ -41,7 +41,7 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl /// /// Intel's Math Kernel Library (MKL) linear algebra provider. /// - public partial class MklLinearAlgebraProvider : ManagedLinearAlgebraProvider + public partial class MklLinearAlgebraProvider { /// /// Computes the requested of the matrix. diff --git a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs index 78fc835b..768f3527 100644 --- a/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs +++ b/src/Numerics/Providers/LinearAlgebra/Mkl/SafeNativeMethods.cs @@ -100,6 +100,9 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Mkl #region LAPACK + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] + internal static extern void SetImprovedConsistency(); + [DllImport(DllName, ExactSpelling = true, SetLastError = false, CallingConvention = CallingConvention.Cdecl)] internal static extern float s_matrix_norm(byte norm, int rows, int columns, [In] float[] a, [In, Out] float[] work);