diff --git a/smp/src/scheduler.cpp b/smp/src/scheduler.cpp index 68b366c08..9a5210e0a 100644 --- a/smp/src/scheduler.cpp +++ b/smp/src/scheduler.cpp @@ -67,17 +67,21 @@ void paradiseo::smp::Scheduler::operator()(eoUF& func, e indice = i*nbIndi+j; } } - - for(unsigned i = 0; i < remaining; i++) - popPackages[i].push_back(&pop[indice+i+1]); + + 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]); // Starting threads for(unsigned i = 0; i < workers.size(); i++) - workers[i] = std::thread(&Scheduler::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i])); - + if(!popPackages[i].empty()) + workers[i] = std::thread(&Scheduler::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i])); + // Wait the end of tasks for(unsigned i = 0; i < workers.size(); i++) - workers[i].join(); + if(!popPackages[i].empty() && workers[i].joinable()) + workers[i].join(); } template @@ -117,7 +121,7 @@ void paradiseo::smp::Scheduler::operator()(eoUF& func, e } done = true; - + for(unsigned i = 0; i < workers.size(); i++) workers[i].join(); }