Hi all, I am facing problems when I try to parallelize some parts of my code using QtConcurrent. I am writting an optimization routine, and parallelization occurs in several places. First, I parallelize random generation of points and function evaluation at these points. Then, I parallelize calls to optimization algorithm, let's call it Algo() method, in a mainOptim() routine. Finally, I parallelize operations needed for a function evaluation at one given point. I can sum up with pseudo-C++-code my problem's architecture this way
void mainOptim()
{
QList<Point> points_ = randomPoint(); // create M random points and their function evaluations
// I parallelize this N calls to Algo
for (int i=0;i<N;i++)
{
initPt = points_[i].point;
Algo();
}
}
QList<Point> randomPoint()
{
QList<Point> points = new QList<Point>;
for (int i=0;i<M;i++)
{
for(int j=0;j<ndim;j++)
{
Point.point[j] = rand();
}
Point.eval = funcEval(Point.point);
points.append(Point);
}
return points;
}
double funcEval(double* point)
{
double d;
/*
some parallelized calls to an interpreter here
*/
return d;
}
funcEval is called many times successively in Algo(), so that both mainOptim and randomPoint are using 'nested' parallelization.
Now that I have set the stage, I have a lot of unanswered questions I would like to add:
1/ USING QtConcurrent for non-QObject classe:
is QtConcurrent only working when the class 'launching' parallelized work is QObject?
2/ HOW could presence or absence of a QTime object have some impact on parallelization success?
I wrapped parallelized code on evalFunc() method with the commands QTime t.start() and t.elapsed() to account for the time spent in parallelized code. I then commented the lines concerning QTime object, and it seems that parallelization is working only when QTime linked commands are present. This can all sound preposterous, but QTime is related to QCoreApplication, and I suspect presence of QTime object operates some refresh operation in threads or the like. Is it possible?
3/ WHAT could hinder parallelization? Is nested parallelization forbidden?
4/ IS nested parallelization of any use? When I parallelize calls to one method, I actually run up to 8 such calls in parallel, then wait for available threads and so on. I have doubt that nested parallelization can improve execution time. If I am running three threads for three main method calls, and then again 200 parallelized calls in each main method call, I am using 3 threads, that are then calling the 5 remaining threads upon avaibility. In theory, this won't help go faster. What do you think of it?
5/ PARALLELIZATION for random points generation uses QtConcurrent::run() on a static member function of class Random. Also, I want to 'reseed' random number generator at each thread creation. Thus, I create an instance of Random class at each thread creation, and call a static method newSeed() on this instance. I don't know whether I am working properly: methods are static, and I am afraid I am changing the seed not only for the Random instance I created in my new thread, but for all Random instances in running threads.
I thank you for help on some or all of these items. Please warn if code/more info needed. I am stuck there.
Regards.
Bookmarks