Fix a bug in SMP Master / Worker model when the population size is lower than the number of workers.
This commit is contained in:
parent
e71dea0c5a
commit
b0479a15e9
1 changed files with 11 additions and 7 deletions
|
|
@ -68,15 +68,19 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
|||
}
|
||||
}
|
||||
|
||||
if(nbIndi != 0) // Handle the offset if there is less individuals than workers
|
||||
indice++;
|
||||
for(unsigned i = 0; i < remaining; i++)
|
||||
popPackages[i].push_back(&pop[indice+i+1]);
|
||||
popPackages[i].push_back(&pop[indice+i]);
|
||||
|
||||
// Starting threads
|
||||
for(unsigned i = 0; i < workers.size(); i++)
|
||||
if(!popPackages[i].empty())
|
||||
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
||||
|
||||
// Wait the end of tasks
|
||||
for(unsigned i = 0; i < workers.size(); i++)
|
||||
if(!popPackages[i].empty() && workers[i].joinable())
|
||||
workers[i].join();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue