Browse Source

Alter parallelisation of matrix multiplication

I empirically noticed that matrix multiplication was extremely slow for
the matrices I was using i.e. multiplications were taking minutes rather
than seconds. After tracking down the root of the problem, I found it
was in the CacheObliviousMatrixMultiply() implementation, specifically,
where the sum of the column/row dimensions were compared with the
Control.ParallelizeOrder variable.

For significantly skewed matrix multiplication (wide * tall), the
parallelised redistribution greatly reduces performance. By removing the
'k' parameter from the comparison (where k is the number of columns in
the left matrix and the number of rows in the right) the performance is
improved drastically.

For perfectly square matrices, this change reduces performance slightly.
v2
Iain McDonald 14 years ago
committed by Christoph Ruegg
parent
commit
8e1cd36027
  1. 2
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs
  2. 2
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs
  3. 2
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs
  4. 2
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

2
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex.cs

@ -680,7 +680,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <param name="first">Indicates if this is the first recursion.</param>
private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, Complex alpha, Complex[] matrixA, int shiftArow, int shiftAcol, Complex[] matrixB, int shiftBrow, int shiftBcol, Complex[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first)
{
if (m + n + k <= Control.ParallelizeOrder)
if (m + n <= Control.ParallelizeOrder)
{
if ((int)transposeA > 111 && (int)transposeB > 111)
{

2
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Complex32.cs

@ -677,7 +677,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <param name="first">Indicates if this is the first recursion.</param>
private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, Complex32 alpha, Complex32[] matrixA, int shiftArow, int shiftAcol, Complex32[] matrixB, int shiftBrow, int shiftBcol, Complex32[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first)
{
if (m + n + k <= Control.ParallelizeOrder)
if (m + n <= Control.ParallelizeOrder)
{
if ((int)transposeA > 111 && (int)transposeB > 111)
{

2
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Double.cs

@ -674,7 +674,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <param name="first">Indicates if this is the first recursion.</param>
private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, double alpha, double[] matrixA, int shiftArow, int shiftAcol, double[] matrixB, int shiftBrow, int shiftBcol, double[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first)
{
if (m + n + k <= Control.ParallelizeOrder)
if (m + n <= Control.ParallelizeOrder)
{
if ((int)transposeA > 111 && (int)transposeB > 111)
{

2
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.Single.cs

@ -675,7 +675,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <param name="first">Indicates if this is the first recursion.</param>
private static void CacheObliviousMatrixMultiply(Transpose transposeA, Transpose transposeB, float alpha, float[] matrixA, int shiftArow, int shiftAcol, float[] matrixB, int shiftBrow, int shiftBcol, float[] result, int shiftCrow, int shiftCcol, int m, int n, int k, int constM, int constN, int constK, bool first)
{
if (m + n + k <= Control.ParallelizeOrder)
if (m + n <= Control.ParallelizeOrder)
{
if ((int)transposeA > 111 && (int)transposeB > 111)
{

Loading…
Cancel
Save