Browse Source

LA: managed provider no longer parallelizes simple addition loops (complex)

spatial
Christoph Ruegg 9 years ago
parent
commit
f42efc5550
  1. 48
      src/Benchmark/LinearAlgebra/DenseVectorAdd.cs
  2. 29
      src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex.cs
  3. 29
      src/Numerics/Providers/LinearAlgebra/Managed/ManagedLinearAlgebraProvider.Complex32.cs

48
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<double> _av;
Vector<double> _bv;
//Complex[] _ac;
//Complex[] _bc;
//Vector<double> _av;
//Vector<double> _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<double>.Build.Dense(_a);
_bv = Vector<double>.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<double>.Build.Dense(_a);
//_bv = Vector<double>.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<double> 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;
//}
}
}

29
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];
}
}
/// <summary>
@ -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];
}
}
/// <summary>

29
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];
}
}
/// <summary>
@ -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];
}
}
/// <summary>

Loading…
Cancel
Save