public static void Main() { /* Create object */ DenseLinearAlgebra dense = new DenseLinearAlgebra(1000, 1000, 4); /* Fill tha arrays with inital values */ dense.array_initialization(); dense.vector_initialize(); dense.fill_with_zeros(); /* Create the workers */ Thread worker1 = new Thread(new ThreadStart(() => dense.multiplication(0))); worker1.Name = "worker1"; /* Create the workers */ Thread worker2 = new Thread(new ThreadStart(() => dense.multiplication(1))); worker2.Name = "worker2"; /* Create the workers */ Thread worker3 = new Thread(new ThreadStart(() => dense.multiplication(2))); worker3.Name = "worker3"; /* Create the workers */ Thread worker4 = new Thread(new ThreadStart(() => dense.multiplication(3))); worker4.Name = "worker4"; /* Count the time that has elapsed */ Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); /* Threads start their work */ worker1.Start(); worker2.Start(); worker3.Start(); worker4.Start(); /* Threads have finished their work */ worker1.Join(); worker2.Join(); worker3.Join(); worker4.Join(); /* Stop the clock */ stopWatch.Stop(); /* Get the elapsed time as a TimeSpan value. */ TimeSpan ts = stopWatch.Elapsed; Console.WriteLine(); Console.WriteLine("Elapsed time:"); /* Format and display the TimeSpan value. */ string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(elapsedTime, "RunTime"); }
public static void Main() { /* Create object */ DenseLinearAlgebra dense = new DenseLinearAlgebra(1000, 1000, 4); /* Fill tha arrays with inital values */ dense.array_initialization(); dense.vector_initialize(); dense.fill_with_zeros(); /* Create the workers */ Thread worker1 = new Thread(new ThreadStart(() => dense.multiplication(0))); worker1.Name = "worker1"; /* Create the workers */ Thread worker2 = new Thread(new ThreadStart(() => dense.multiplication(1))); worker2.Name = "worker2"; /* Create the workers */ Thread worker3 = new Thread(new ThreadStart(() => dense.multiplication(2))); worker3.Name = "worker3"; /* Create the workers */ Thread worker4 = new Thread(new ThreadStart(() => dense.multiplication(3))); worker4.Name = "worker4"; /* Count the time that has elapsed */ Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); /* Threads start their work */ worker1.Start(); worker2.Start(); worker3.Start(); worker4.Start(); /* Threads have finished their work */ worker1.Join(); worker2.Join(); worker3.Join(); worker4.Join(); /* Stop the clock */ stopWatch.Stop(); /* Get the elapsed time as a TimeSpan value. */ TimeSpan ts = stopWatch.Elapsed; Console.WriteLine(); Console.WriteLine("Elapsed time:"); /* Format and display the TimeSpan value. */ string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine(elapsedTime, "RunTime"); }