public static void Main()
    {
        /* Create object */
        SparseLinearAlgebra sparse = new SparseLinearAlgebra(1000, 1000, 4);
        sparse.initalization();
        //sparse.print_array();
        sparse.fill_arrays();
        //sparse.print_vectors();

        sparse.fill_row_ptr();
        //sparse.print_row_ptr();

        /* Create the workers */
        Thread worker1 = new Thread(new ThreadStart(() => sparse.computation(0)));
        worker1.Name = "worker1";

        Thread worker2 = new Thread(new ThreadStart(() => sparse.computation(1)));
        worker2.Name = "worker2";

        Thread worker3 = new Thread(new ThreadStart(() => sparse.computation(2)));
        worker3.Name = "worker3";

        Thread worker4 = new Thread(new ThreadStart(() => sparse.computation(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();

        /* Perform the main computation */
        //sparse.computation(0);

        /* 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");
    }
Example #2
0
    public static void Main()
    {
        /* Create object */
        SparseLinearAlgebra sparse = new SparseLinearAlgebra(1000, 1000, 4);

        sparse.initalization();
        //sparse.print_array();
        sparse.fill_arrays();
        //sparse.print_vectors();

        sparse.fill_row_ptr();
        //sparse.print_row_ptr();

        /* Create the workers */
        Thread worker1 = new Thread(new ThreadStart(() => sparse.computation(0)));

        worker1.Name = "worker1";

        Thread worker2 = new Thread(new ThreadStart(() => sparse.computation(1)));

        worker2.Name = "worker2";

        Thread worker3 = new Thread(new ThreadStart(() => sparse.computation(2)));

        worker3.Name = "worker3";

        Thread worker4 = new Thread(new ThreadStart(() => sparse.computation(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();


        /* Perform the main computation */
        //sparse.computation(0);


        /* 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");
    }