[Qt-interest] Using QThreads for parallel diffusion

Samuel Rødal sroedal at trolltech.com
Fri Oct 23 11:48:56 CEST 2009


quasilister wrote:
> Dear QtUsers,
> 
> I am trying use QThreads for a numerical calculations in addition to 
> normal threading of an application.  Specifically, I am using QThreads 
> for a parallel implementation of solving a basic diffusion equation.  Do 
> QThreads take a particularly long time to spawn?  I know that hardware 
> will play a big importance on timing, but has anyone ever made such a 
> measurement?  I may be doing something terribly wrong but when I 
> compared serial to threaded code the times to completion were nearly 
> identical for a lattice size of 1024x1024.  This remained true for 2,4 
> and 8 threads.  (I am running on a mac pro with dual quad core 
> processors 6GB RAM).  I was expecting a 40%-50% improvement on time.  
> After increasing the size to 2048x2048 I finally saw the improvement I 
> was expecting.  To me, this seems like QThreads take quite a bit of time 
> to spawn. 
> 
> 
> I should note that I am restarting threads in the following manner:
>     for(int i = 0; i < num_threads; i++) {
>             Thread_Array[i].start();
>         }
>         for(int i = 0; i < num_threads; i++) {
>             Thread_Array[i].wait();
>         }
> 
> 
> And looping over both those loops.
> 
> Any help would be greatly appreciate!

I would suggest that you use QtConcurrent instead of manually spawning 
threads.

See http://doc.trolltech.com/4.5/threads.html#qtconcurrent

--
Samuel



More information about the Qt-interest-old mailing list