public static void ParallelUnsafeMatrixDemo() { Console.WriteLine("-------PARALLEL MATRIX MULTIPLICATION DEMO-------"); ParallelMatrixMultiplicator multiplicator = new ParallelMatrixMultiplicator(); UnsafeMatrix <long> A = Utils.RandomMatrix(500, 750); UnsafeMatrix <long> B = Utils.RandomMatrix(750, 500); Console.WriteLine("Multiplying two matrices {0}x{1} and {2}x{3}", A.Rows, A.Columns, B.Rows, B.Columns); Stopwatch stopWatch = new Stopwatch(); Console.WriteLine("Starting parallel..."); stopWatch.Start(); UnsafeMatrix <long> parallelResult = multiplicator.Multiply(A, B, 250); stopWatch.Stop(); Console.WriteLine($"Parallel: {stopWatch.Elapsed}"); stopWatch.Restart(); Console.WriteLine("Starting serial..."); stopWatch.Start(); UnsafeMatrix <long> serialResult = A * B; stopWatch.Stop(); Console.WriteLine($"Serial: {stopWatch.Elapsed}"); Console.WriteLine($"Verify results are equal: {parallelResult == serialResult}"); }
public void TestMultiplyNonSquare() { // Arrange UnsafeMatrix <long> A = Utils.RandomMatrix(50, 75); UnsafeMatrix <long> B = Utils.RandomMatrix(75, 50); // Act UnsafeMatrix <long> actual = new ParallelMatrixMultiplicator() .Multiply <long>(A, B, 25); // Assert Assert.AreEqual(actual, A * B); }