I've followed this example: http://codejourneys.blogspot.it/2008...of-use-of.html that shows how to use QtConcurrent to execute a function in a secondary thread.
Googling around, I've read somewhere that the QtConcurrent class would actually "balance" and span the workload on all available cores automatically. But after trying and reading some more, I think I understood that it's not really the case.
QtConcurrent::run() will actually run a function in a secondary thread, and you have to use it multiple times to enable more threads. Is this correct?
If so, say you have a myFunction performing n square roots, would you do something like this:
for (int i=0; i< QThreadPool::globalInstance()->maxThreadCount(); i++)
{
itemsPerThread=n/QThreadPool::globalInstance()->maxThreadCount();
itemStart=i*itemsPerThread;
itemEnd=(i+1)*itemsPerThread;
QtConcurrent::run(myFunction(itemStart,itemEnd));
}
for (int i=0; i< QThreadPool::globalInstance()->maxThreadCount(); i++)
{
itemsPerThread=n/QThreadPool::globalInstance()->maxThreadCount();
itemStart=i*itemsPerThread;
itemEnd=(i+1)*itemsPerThread;
QtConcurrent::run(myFunction(itemStart,itemEnd));
}
To copy to clipboard, switch view to plain text mode
i.e., assigning a range of values to process for each thread?
Thanks for any help.
Bookmarks