From f42efc5550462c2c1aa70f1c701ba4cdcc37b529 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sun, 25 Feb 2018 10:47:12 +0100 Subject: [PATCH] LA: managed provider no longer parallelizes simple addition loops (complex) --- src/Benchmark/LinearAlgebra/DenseVectorAdd.cs | 48 ++++++++++++------- .../ManagedLinearAlgebraProvider.Complex.cs | 29 ++++------- .../ManagedLinearAlgebraProvider.Complex32.cs | 29 ++++------- 3 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/Benchmark/LinearAlgebra/DenseVectorAdd.cs b/src/Benchmark/LinearAlgebra/DenseVectorAdd.cs index c556441f..74e909dd 100644 --- a/src/Benchmark/LinearAlgebra/DenseVectorAdd.cs +++ b/src/Benchmark/LinearAlgebra/DenseVectorAdd.cs @@ -7,6 +7,8 @@ using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.Providers.Common.Mkl; using MathNet.Numerics.Providers.LinearAlgebra; +using Complex = System.Numerics.Complex; + namespace Benchmark.LinearAlgebra { [Config(typeof(Config))] @@ -47,12 +49,12 @@ namespace Benchmark.LinearAlgebra [Params(ProviderId.Managed, ProviderId.ManagedReference, ProviderId.NativeMKL)] public ProviderId Provider { get; set; } - //const int Rounds = 1024; - double[] _a; double[] _b; - Vector _av; - Vector _bv; + //Complex[] _ac; + //Complex[] _bc; + //Vector _av; + //Vector _bv; [GlobalSetup] public void Setup() @@ -72,22 +74,12 @@ namespace Benchmark.LinearAlgebra _a = Generate.Normal(N, 2.0, 10.0); _b = Generate.Normal(N, 200.0, 10.0); - _av = Vector.Build.Dense(_a); - _bv = Vector.Build.Dense(_b); + //_ac = Generate.Map2(_a, Generate.Normal(N, 2.0, 10.0), (a, i) => new Complex(a, i)); + //_bc = Generate.Map2(_b, Generate.Normal(N, 200.0, 10.0), (b, i) => new Complex(b, i)); + //_av = Vector.Build.Dense(_a); + //_bv = Vector.Build.Dense(_b); } - //[Benchmark(OperationsPerInvoke = 1, Baseline = true)] - //public double[] ForLoop() - //{ - // double[] r = new double[_a.Length]; - // for (int i = 0; i < r.Length; i++) - // { - // r[i] = _a[i] + _b[i]; - // } - - // return r; - //} - [Benchmark(OperationsPerInvoke = 1)] public double[] ProviderAddArrays() { @@ -96,10 +88,30 @@ namespace Benchmark.LinearAlgebra return r; } + //[Benchmark(OperationsPerInvoke = 1)] + //public Complex[] ProviderAddArraysComplex() + //{ + // Complex[] r = new Complex[_a.Length]; + // LinearAlgebraControl.Provider.AddArrays(_ac, _bc, r); + // return r; + //} + //[Benchmark(OperationsPerInvoke = 1)] //public Vector VectorAddOp() //{ // return _av + _bv; //} + + //[Benchmark(OperationsPerInvoke = 1, Baseline = true)] + //public double[] ForLoop() + //{ + // double[] r = new double[_a.Length]; + // for (int i = 0; i < r.Length; i++) + // { + // r[i] = _a[i] + _b[i]; + // } + + // return r; + //} } } diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs index 525d75ee..ae0489d4 100644 --- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs +++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2015 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -72,13 +72,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed } else if (alpha.IsOne()) { - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = y[i] + x[i]; - } - }); + result[i] = y[i] + x[i]; + } } else { @@ -212,13 +209,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed throw new ArgumentException(Resources.ArgumentVectorsSameLength); } - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = x[i] + y[i]; - } - }); + result[i] = x[i] + y[i]; + } } /// @@ -253,13 +247,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed throw new ArgumentException(Resources.ArgumentVectorsSameLength); } - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = x[i] - y[i]; - } - }); + result[i] = x[i] - y[i]; + } } /// diff --git a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs index 6a8d7603..8cb0d202 100644 --- a/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs +++ b/src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs @@ -3,7 +3,7 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // -// Copyright (c) 2009-2015 Math.NET +// Copyright (c) 2009-2018 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation @@ -73,13 +73,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed } else if (alpha.IsOne()) { - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = y[i] + x[i]; - } - }); + result[i] = y[i] + x[i]; + } } else { @@ -215,13 +212,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed throw new ArgumentException(Resources.ArgumentVectorsSameLength); } - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = x[i] + y[i]; - } - }); + result[i] = x[i] + y[i]; + } } /// @@ -256,13 +250,10 @@ namespace MathNet.Numerics.Providers.LinearAlgebra.Managed throw new ArgumentException(Resources.ArgumentVectorsSameLength); } - CommonParallel.For(0, y.Length, 4096, (a, b) => + for (int i = 0; i < result.Length; i++) { - for (int i = a; i < b; i++) - { - result[i] = x[i] - y[i]; - } - }); + result[i] = x[i] - y[i]; + } } ///