using System; using System.Diagnostics; using System.Threading; class Program { #if DEBUG const int SIZE = 200; #else const int SIZE = 768; #endif static int[,] m1 = new int[SIZE, SIZE]; static int[,] m2 = new int[SIZE, SIZE]; static int[,] res1 = new int[SIZE, SIZE]; // seq static int[,] res2 = new int[SIZE, SIZE]; // pfor static int[,] res3 = new int[SIZE, SIZE]; // tasks static int[,] res4 = new int[SIZE, SIZE]; // pool static void Main() { // Populate arrays Random rgen = new Random(69); for (int i = 0; i < SIZE; i++) for (int j = 0; j < SIZE; j++) m1[i, j] = rgen.Next(); for (int i = 0; i < SIZE; i++) for (int j = 0; j < SIZE; j++) m2[i, j] = rgen.Next(); Stopwatch sw; #region Sequential Console.Write("Sequential: "); sw = Stopwatch.StartNew(); MM.MulSeq(SIZE, m1, m2, res1); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); Thread.Sleep(2000); #endregion #region ParalleFor Console.Write("ParalleFor: "); sw = Stopwatch.StartNew(); MM.MulPFor(SIZE, m1, m2, res2); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); Thread.Sleep(2000); #endregion #region Tasks Console.Write("Tasks : "); sw = Stopwatch.StartNew(); MM.MulTask(SIZE, m1, m2, res3); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); Thread.Sleep(2000); #endregion #region ThreadPool Console.Write("ThreadPool: "); sw = Stopwatch.StartNew(); MM.MulPool(SIZE, m1, m2, res4); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); Thread.Sleep(2000); #endregion Console.ReadLine(); } } //public static void VerifyArrays(double[,] r1, double[,] r2, double[,] r3, double[,] r4) //{ // bool result = true; // for (int i = 0; i < SIZE; i++) // for (int j = 0; j < SIZE; j++) // if (r1[i, j] != r2[i, j]) // result = false; // for (int i = 0; i < SIZE; i++) // for (int j = 0; j < SIZE; j++) // if (r2[i, j] != r3[i, j]) // result = false; // for (int i = 0; i < SIZE; i++) // for (int j = 0; j < SIZE; j++) // if (r3[i, j] != r4[i, j]) // result = false; // if (!result) // Console.WriteLine("...Done, but different results :-( "); // else // Console.WriteLine("...Done :-) "); //}