2

I successfully parallelized some work with non-static member function in QtConcurrent::run(). I am now trying to implement parallelized work with a static member function. I have a Random class, and I want to call rand(double,double) static function on one precise instance: it is a random number generator, and I want to run the thread calling runif on a newly seeded generator. I tried this here (class solveParallel is a simple class where I have a runRandom() and resultRandom() function, calling QtConcurent::run and Qfuture::result() respectively):

void solverParallelData::runRandom(const double& d1, const double& d2) 
{
    futureRandom = QtConcurrent::run(Random::rand,this->m_generator, d1, d2);
 }

and compilation error is "cannot deduce template argument as function argument is ambiguous": : any clue?

Thanks and regards.

kiriloff
  • 25,609
  • 37
  • 148
  • 229
  • What is the signature of `Random::rand` ? (If the function is static, trying to call it on a precise instance has no sense). – alexisdm Apr 05 '12 at 17:23
  • Thanks. signature is rand(double,double) – kiriloff Apr 06 '12 at 03:42
  • @alexisdm This makes sense. However, I want to re-seed the random number generator for each thread. How to do that? – kiriloff Apr 06 '12 at 06:42
  • I don't think you can reseed for each thread easily: QtConcurrent uses QThreadPool, and threads from a pool that aren't active for 30 seconds are deleted, so you would "lose the seed" for that thread. And you can't choose on which thread you will call the re-seeding, it would run it on the first available thread from the pool. – alexisdm Apr 06 '12 at 12:53

0 Answers0