Mecanism to isolate stopped island in topology

This commit is contained in:
quemy 2012-11-24 16:23:01 +01:00
commit cf93d6aeb4
5 changed files with 32 additions and 37 deletions

View file

@ -57,13 +57,6 @@ public:
{ {
rightAssociation[a] = b; rightAssociation[a] = b;
leftAssociation[b] = a; leftAssociation[b] = a;
std::cout << "DUMP" << std::endl;
for(auto i : rightAssociation)
std::cout << i.first << "------" << i.second << std::endl;
for(auto i : leftAssociation)
std::cout << i.first << "------" << i.second << std::endl;
std::cout << "END DUMP" << std::endl;
} }
std::map<A,B> getRight() const std::map<A,B> getRight() const

View file

@ -43,7 +43,8 @@ paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chro
pop(_popSize, _chromInit), pop(_popSize, _chromInit),
intPolicy(_intPolicy), intPolicy(_intPolicy),
migPolicy(_migPolicy), migPolicy(_migPolicy),
stopped(false) stopped(false),
model(nullptr)
{ {
// Check in compile time the inheritance thanks to type_trait. // Check in compile time the inheritance thanks to type_trait.
static_assert(std::is_base_of<eoAlgo<EOT>,EOAlgo<EOT>>::value, "Algorithm must inherit from eoAlgo<EOT>"); static_assert(std::is_base_of<eoAlgo<EOT>,EOAlgo<EOT>>::value, "Algorithm must inherit from eoAlgo<EOT>");
@ -58,6 +59,7 @@ void paradiseo::smp::Island<EOAlgo,EOT>::operator()()
for(auto& message : sentMessages) for(auto& message : sentMessages)
message.join(); message.join();
stopped = true; stopped = true;
//std::cout << "Fin de l'île " << this << std::endl;
} }
template<template <class> class EOAlgo, class EOT> template<template <class> class EOAlgo, class EOT>
@ -96,39 +98,37 @@ bool paradiseo::smp::Island<EOAlgo,EOT>::isStopped(void) const
template<template <class> class EOAlgo, class EOT> template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select) void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select)
{ {
//std::cout << "Ile lance la migration" << std::endl; if(model != nullptr)
eoPop<EOT> migPop; {
_select(pop, migPop); //std::cout << "Ile lance la migration" << std::endl;
//std::cout << " La population migrante est :" << std::endl << migPop << std::endl; eoPop<EOT> migPop;
_select(pop, migPop);
//std::cout << " La population migrante est :" << std::endl << migPop << std::endl;
// Delete delivered messages // Delete delivered messages
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++) for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
if(!it->joinable()) if(!it->joinable())
sentMessages.erase(it); sentMessages.erase(it);
sentMessages.push_back(std::thread(&IslandModel<EOT>::update, model, migPop, this));
sentMessages.push_back(std::thread(&IslandModel<EOT>::update, model, migPop, this));
}
} }
template<template <class> class EOAlgo, class EOT> template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::Island<EOAlgo,EOT>::receive(void) void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
{ {
std::lock_guard<std::mutex> lock(this->m); std::lock_guard<std::mutex> lock(this->m);
if(!listImigrants.empty()) {
std::cout << "______________________________________________" << std::endl;
std::cout << "Ile : " << this << std::endl;
std::cout << "Pop avant : " << std::endl << pop << std::endl;
while (!listImigrants.empty()) while (!listImigrants.empty())
{ {
eoPop<EOT> offspring = listImigrants.front(); eoPop<EOT> offspring = listImigrants.front();
// Evaluate objects to integrate // Evaluate objects to integrate
std::cout << "Evaluation des individus : " << std::endl; //std::cout << "Evaluation des individus : " << std::endl;
for(auto& indi : offspring) for(auto& indi : offspring)
{ {
eval(indi); eval(indi);
std::cout << indi << std::endl; //std::cout << indi << std::endl;
} }
//std::cout << "Ile " << this << " recoit : " << std::endl; //std::cout << "Ile " << this << " recoit : " << std::endl;
//std::cout << offspring << std::endl; //std::cout << offspring << std::endl;
@ -137,9 +137,6 @@ void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
listImigrants.pop(); listImigrants.pop();
} }
std::cout << "Pop après : " << std::endl << pop << std::endl;
std::cout << "______________________________________________" << std::endl;
}
} }
template<template <class> class EOAlgo, class EOT> template<template <class> class EOAlgo, class EOT>

View file

@ -117,7 +117,6 @@ protected:
*/ */
virtual void receive(void); virtual void receive(void);
IslandModel<EOT>* model;
eoEvalFunc<EOT>& eval; eoEvalFunc<EOT>& eval;
eoPop<EOT> pop; eoPop<EOT> pop;
EOAlgo<EOT> algo; EOAlgo<EOT> algo;
@ -126,7 +125,7 @@ protected:
MigPolicy<EOT>& migPolicy; MigPolicy<EOT>& migPolicy;
std::atomic<bool> stopped; std::atomic<bool> stopped;
std::vector<std::thread> sentMessages; std::vector<std::thread> sentMessages;
IslandModel<EOT>* model;
}; };
#include <island.cpp> #include <island.cpp>

View file

@ -64,9 +64,14 @@ void paradiseo::smp::IslandModel<EOT>::operator()()
// Count working islands // Count working islands
workingThread = islands.size(); workingThread = islands.size();
for(auto& it : islands) for(auto& it : islands)
{
// If an island is stopped we need to isolate its node in the topology
if(it->isStopped()) if(it->isStopped())
{
workingThread--; workingThread--;
topo.isolateNode(table.getLeft()[it]);
}
}
// Check reception // Check reception
send(); send();
@ -95,14 +100,14 @@ void paradiseo::smp::IslandModel<EOT>::send(void)
std::lock_guard<std::mutex> lock(m); std::lock_guard<std::mutex> lock(m);
while (!listEmigrants.empty()) while (!listEmigrants.empty())
{ {
std::cout << "Le mediateur va envoyer de " << listEmigrants.front().second << " qui est " << table.getLeft()[listEmigrants.front().second] << std::endl; //std::cout << "Le mediateur va envoyer de " << listEmigrants.front().second << " qui est " << table.getLeft()[listEmigrants.front().second] << std::endl;
unsigned id = table.getLeft()[listEmigrants.front().second]; unsigned id = table.getLeft()[listEmigrants.front().second];
std::vector<unsigned> neighbors = topo.getIdNeighbors(id); std::vector<unsigned> neighbors = topo.getIdNeighbors(id);
eoPop<EOT> migPop = listEmigrants.front().first; eoPop<EOT> migPop = listEmigrants.front().first;
for (unsigned neighbor : neighbors) for (unsigned neighbor : neighbors)
{ {
std::cout << "On envoie à " << neighbor << std::endl; //std::cout << "On envoie à " << neighbor << std::endl;
sentMessages.push_back(std::thread(&AIsland<EOT>::update, table.getRight()[neighbor], migPop)); sentMessages.push_back(std::thread(&AIsland<EOT>::update, table.getRight()[neighbor], migPop));
} }
listEmigrants.pop(); listEmigrants.pop();

View file

@ -9,7 +9,7 @@ using namespace std;
int main(void) int main(void)
{ {
typedef struct { typedef struct {
unsigned popSize = 3; unsigned popSize = 1000;
unsigned tSize = 2; unsigned tSize = 2;
double pCross = 0.8; double pCross = 0.8;
double pMut = 0.7; double pMut = 0.7;
@ -87,8 +87,9 @@ int main(void)
model.add(test); model.add(test);
model.add(test2); model.add(test2);
model(); //model();
test();
test2();
cout << test.getPop() << endl; cout << test.getPop() << endl;
cout << test2.getPop() << endl; cout << test2.getPop() << endl;
} }