public void ParallelEfficiencyTest() { var parallelMultiplier = new MatricesMultiplierParallel(); var regularMultiplier = new MatricesMultiplier(); Stopwatch watch = new Stopwatch(); TimeSpan regularTime = default; TimeSpan parallelTime = default; var matrixSize = 1; while (parallelTime >= regularTime) { var matrix1 = new Matrix(matrixSize, matrixSize, true); var matrix2 = new Matrix(matrixSize, matrixSize, true); watch.Start(); regularMultiplier.Multiply(matrix1, matrix2); regularTime = watch.Elapsed; watch.Restart(); parallelMultiplier.Multiply(matrix1, matrix2); parallelTime = watch.Elapsed; watch.Reset(); matrixSize++; } Console.WriteLine($"Parallel algorithm is more efficient then regular when square matrices has [ {matrixSize} x {matrixSize} ] size."); }
public void ParallelEfficiencyTest() { var matricesMultiplier = new MatricesMultiplier(); var matricesMultiplierParallel = new MatricesMultiplierParallel(); int firstSize = Environment.ProcessorCount; for (var secondSize = 1; secondSize < 256; secondSize++) { var matrix1 = new Matrix(firstSize, secondSize, true); var matrix2 = new Matrix(secondSize, firstSize, true); Stopwatch sw = new Stopwatch(); sw.Start(); matricesMultiplier.Multiply(matrix1, matrix2); sw.Stop(); var nonParallelElapsed = sw.Elapsed; sw.Restart(); matricesMultiplierParallel.Multiply(matrix1, matrix2); sw.Stop(); var parallelElapsed = sw.Elapsed; if (parallelElapsed < nonParallelElapsed) { Assert.IsTrue(true, $"Performance in multithreading mode is better with sizes: {firstSize}x{secondSize}"); return; } } Assert.IsTrue(false); }
private Multipliers WhoIsBetter(int capacity) { var m1 = new Matrix(capacity, capacity); var m2 = new Matrix(capacity, capacity); SetupValues(m1); SetupValues(m2); var multiplier = new MatricesMultiplier(); var multiplierParallel = new MatricesMultiplierParallel(); var milliseconds = Time(() => multiplier.Multiply(m1, m2)); var millisecondsParallel = Time(() => multiplierParallel.Multiply(m1, m2)); return(millisecondsParallel < milliseconds ? Multipliers.Parallel : Multipliers.Usual); }
public void ParallelEfficiencyTest() { var matricesMultiplier = new MatricesMultiplier(); var matricesMultiplierParallel = new MatricesMultiplierParallel(); for (var i = 1; i < 100; i++) { var singleMultiplicationimeTime = GetTimeSpentOnMatrixMultiplication(matricesMultiplier, i); var parallelMultiplicationimeTime = GetTimeSpentOnMatrixMultiplication(matricesMultiplierParallel, i); if (parallelMultiplicationimeTime < singleMultiplicationimeTime) { Console.WriteLine($"Matrice size : {i};"); } } }
private static void CreateAndProcessMatrices(byte sizeOfMatrix) { Console.WriteLine("Multiplying..."); var firstMatrix = new Matrix(sizeOfMatrix, sizeOfMatrix); var secondMatrix = new Matrix(sizeOfMatrix, sizeOfMatrix); SetupMatrix(firstMatrix); SetupMatrix(secondMatrix); IMatrix resultMatrix = new MatricesMultiplierParallel().Multiply(firstMatrix, secondMatrix); Console.WriteLine("firstMatrix:"); firstMatrix.Print(); Console.WriteLine("secondMatrix:"); secondMatrix.Print(); Console.WriteLine("resultMatrix:"); resultMatrix.Print(); }
public void ParallelEfficiencyTest() { var sw = new Stopwatch(); var multiplier = new MatricesMultiplier(); var parallelMultiplier = new MatricesMultiplierParallel(); for (var i = 1; i < 100; i++) { var firstMatrix = new Matrix(i, i, true); var secondMatrix = new Matrix(i, i, true); sw.Start(); var sequentialMatrixResult = multiplier.Multiply(firstMatrix, secondMatrix); sw.Stop(); var sequentialElapsed = sw.Elapsed.TotalMilliseconds; sw.Reset(); sw.Start(); var parallelMatrixResult = parallelMultiplier.Multiply(firstMatrix, secondMatrix); var parallelElapsed = sw.Elapsed.TotalMilliseconds; sw.Stop(); sw.Reset(); if (sequentialElapsed > parallelElapsed) { Logger.LogMessage( $"Parallel multiplication is more effective than sequential for matrices size: [{i}, {i}]. Sequential multiplication elapsed time: {sequentialElapsed} ms. Parallel multiplication elapsed time: {parallelElapsed} ms"); } for (int j = 0; j < sequentialMatrixResult.RowCount; j++) { for (int k = 0; k < sequentialMatrixResult.ColCount; k++) { Assert.AreEqual(sequentialMatrixResult.GetElement(j, k), parallelMatrixResult.GetElement(j, k)); } } } }