Results 1 to 7 of 7

Thread: qt thread question for different algorithm thread

  1. #1

    Default qt thread question for different algorithm thread

    Hi, guys,

    I am new the the qt thread, most of the example I found online is about multithread for one algorithm.

    I have a problem to multithread 4 different algorithm at the same time to speed things up.

    for example I have 3 thread totally different Thread class,

    class ThreadA: public QThread
    {}
    class ThreadB: public QThread
    {}
    class ThreadC ublic QThread
    {}


    void main()
    {
    ThreadA a;
    ThreadB b;
    ThreadC c;

    a.start();
    b.start();
    c.start();

    }


    my program is sorta like the above structure, however when I run it, it doesnt look like it was multithreading running .

    I am just wondering if anyone ever try to run different algorithm at the same time using the qt thread.

    thank you

  2. #2
    Join Date
    Jul 2010
    Posts
    21
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qt thread question for different algorithm thread

    however when I run it, it doesnt look like it was multithreading running
    How do you arrive at this conclusion?

    The structure of your code seems more or less correct. But before returning from main(), it might be a good idea to wait for all threads to finish (for example, add a.wait(), b.wait(), and c.wait() in the end of your main()). Moreover, it is always a good practice to instantiate either QCoreApplication (console app) or QApplication (gui app) in the beginning of main().

  3. #3

    Default Re: qt thread question for different algorithm thread

    I put the wait() at the end for sure, and the cpu usage is 75% for the whole time, and it seems like a multithread.

    but the memory usage doesnt increase and the running time is as same as I running the three algorithm in sequence.


    I am just wondering if there something I did wrong

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: qt thread question for different algorithm thread

    If You are on Windows try SysinternalsSuite, more precisely ProcessExplorer. It has tab Threads that shows how many threads are running at the present time etc.

  5. #5

    Default Re: qt thread question for different algorithm thread

    I use the software, it shows actually 3 thread is running at the same time.

    but the running time is too long. even longer than the sequence running

    is the multithread supposed to speed up the program ?

  6. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: qt thread question for different algorithm thread

    Multithreading is used basically in one of the two conditions.
    - to "unfreeze" GUI thread (main window, this don't speedup Your program, It only keep your GUI responsive IF YOU HAVE 1CORE CPU, on multi core speedup )
    - to speed up calculations
    Depending on the task speedup very from few % to around 95%. Good example of that is CPU intense tasks like 3D rendering (programs like 3D studio Max, Maya, XSI, LightWave etc..., for example 1Core CPU render around 90-95% slower then 2Core CPU).
    Please remember that not all algorithms are parallel scalable, so that means not always gain is as significant as the one in 3D Rendering (like global illumination, ambient occlusion etc..)

    Please also note that when You have 1Core CPU Your task are divide into (in Your case) 3 threads that are running ON THE SAME CPU/CORE so maybe that's why You don't see the difference. Basically nowadays Threads should be run on the Multi Core CPU (or to "unfreeze" GUI), that way task can be assigned to individual CORE so You program utilize 100% of the CPU power.
    Also the way task is assigned to the specific CORE is controlled by Your Operating System. If you have 2Cores and 3 threads it's obvious that 1Core will process 2threads, so maybe that's why speedup is not so significant in Your case.

    As of qt threads I use it, and many other people here, for example in task like parallel image thumbnails downloading (up to N threads, when N < image thumbnails count), and it works like a charm, so probably You do something wrong or Your program logic is wrong.
    Regards

  7. #7

    Default Re: qt thread question for different algorithm thread

    Quote Originally Posted by Talei View Post
    Multithreading is used basically in one of the two conditions.
    - to "unfreeze" GUI thread (main window, this don't speedup Your program, It only keep your GUI responsive IF YOU HAVE 1CORE CPU, on multi core speedup )
    - to speed up calculations
    Depending on the task speedup very from few % to around 95%. Good example of that is CPU intense tasks like 3D rendering (programs like 3D studio Max, Maya, XSI, LightWave etc..., for example 1Core CPU render around 90-95% slower then 2Core CPU).
    Please remember that not all algorithms are parallel scalable, so that means not always gain is as significant as the one in 3D Rendering (like global illumination, ambient occlusion etc..)

    Please also note that when You have 1Core CPU Your task are divide into (in Your case) 3 threads that are running ON THE SAME CPU/CORE so maybe that's why You don't see the difference. Basically nowadays Threads should be run on the Multi Core CPU (or to "unfreeze" GUI), that way task can be assigned to individual CORE so You program utilize 100% of the CPU power.
    Also the way task is assigned to the specific CORE is controlled by Your Operating System. If you have 2Cores and 3 threads it's obvious that 1Core will process 2threads, so maybe that's why speedup is not so significant in Your case.

    As of qt threads I use it, and many other people here, for example in task like parallel image thumbnails downloading (up to N threads, when N < image thumbnails count), and it works like a charm, so probably You do something wrong or Your program logic is wrong.
    Regards


    well, thank you for your reply,


    basically my algorithm is a big while() loop which loops for 3million times.

    class A: QThread
    {
    void run()
    {
    while()
    {}
    }
    }


    and in the main funciton

    main()
    {
    A a1;
    A a2;

    a1.start()
    a2.start()

    a1.wait()
    a2.wait()
    }


    I run it on a four core cpu, but the time is still like I run them in sequece.

Similar Threads

  1. Replies: 9
    Last Post: 28th November 2009, 20:31
  2. Replies: 16
    Last Post: 7th October 2009, 08:17
  3. Replies: 6
    Last Post: 29th April 2009, 18:17
  4. thread question
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 15th March 2009, 01:34
  5. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.