Parallel execution of Functions

Hi !

I have 3 functions, which executes sequentially so take much time (about 10 minutes). i want to reduce time, by executing those by parallel. Those functions don't depend on each other.

how can i do that, plz suggestion and code.....


Answer this question

Parallel execution of Functions

  • Goye

    I don't know of any tools that will automatically tune your code. Can you post your code here, maybe there's something obvious...

    Spreading the load across the net can get quite complex, and is a type of architecture your whole program should be designed for. I wouldn't try and implement that before ruling out the easy solutions.

  • FinallyInSeattle

    With just one processor, you can't get faster execution time. In fact, because the context has to switch between each thread it will take longer.

    You would either need an Intel HyperThreading or real dual core processor. Or somehow spread the workload across the network.

    Of course, tuning the performance of the code itself would be best.

  • Marian Todorov

    You could use the BackgroundWorker Class for this. there is an example in MSDN:

    http://msdn2.microsoft.com/en-us/library/4852et58(en-us,vs.80).aspx





  • ahr

    Hi Daniel !

    ya i m agree with u.
    but have u any idea how i can spread the workload across the network. or how i can tume the performance of the code... (there is any tool for that)..

    plz give suggestion.........


  • Bob Brown

    hi rgerbig !

    i know threading,
    by using threading we can get parallel execution , But there is no difference in execution time.

    i want execution in less time.

    have u any suggestion..........

  • Endocare

    Hi,

    look at this:


    void Button2Click(object sender, System.EventArgs e)

    {

    Thread t1 = new Thread(new ThreadStart (thread1));

    Thread t2 = new Thread(new ThreadStart (thread2));

    Thread t3 = new Thread(new ThreadStart (thread3));

    t1.Start();

    t2.Start();

    t3.Start();

    t1.Join();

    t2.Join();

    t3.Join();

    MessageBox.Show("Threads are done");

    }

    void thread1 ()

    {

    for (int i = 0; i < 150000000; i++)

    {

    }

    MessageBox.Show("Thread1 executet");

    }

    void thread2 ()

    {

    for (int i = 0; i < 50; i++)

    {

    }

    MessageBox.Show("Thread2 executet");

    }

    void thread3()

    {

    for (int i = 0; i < 230; i++)

    {

    }

    MessageBox.Show("Thread3 executet");

    }


     


  • Parallel execution of Functions