Clean commit after name changes

This commit is contained in:
lasnier 2012-11-21 18:48:46 +01:00
commit 95b7b80f19
21 changed files with 192 additions and 106 deletions

View file

@ -29,19 +29,21 @@ Contact: paradiseo-help@lists.gforge.inria.fr
template<template <class> class EOAlgo, class EOT, class Policy>
template<class... Args>
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel (unsigned workersNb, Args&... args) :
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(unsigned workersNb, Args&... args) :
EOAlgo<EOT>(args...),
scheduler(workersNb)
{ assert(workersNb > 0); }
{
assert(workersNb > 0);
}
template<template <class> class EOAlgo, class EOT, class Policy>
template<class... Args>
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel (Args&... args) :
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(Args&... args) :
MWModel(Thread::hardware_concurrency(), args...)
{}
template<template <class> class EOAlgo, class EOT, class Policy>
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::~MWModel ()
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::~MWModel()
{}
template<template <class> class EOAlgo, class EOT, class Policy>

View file

@ -1,5 +1,5 @@
/*
<PPE.h>
<PPExpander.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
@ -31,7 +31,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#define PPE_H_
/** Parameter Pack Expansion: Utility file to expand parameter pack
/* Utility file to expand parameter pack with the recursive method
Utility file to expand parameter pack with the recursive method
**/
template<class... Arg> class Loop;

View file

@ -46,6 +46,8 @@ class IslandModel;
/** AbstractIsland: An abstract island.
The abstract island is used to manipulate island pointers wihout the knowledge of the algorithm.
@see smp::Island
*/
@ -77,6 +79,10 @@ public:
*/
virtual void check(void) = 0;
/**
* Check if the algorithm is stopped.
* @return true if stopped
*/
virtual bool isStopped(void) = 0;
};

View file

@ -37,7 +37,9 @@ namespace paradiseo
namespace smp
{
/** Algo Dispatching
* The Algo Dispatching enable to choose the algorithm to call at compile time by tag-dispatching method
The Algo Dispatching enable to choose the algorithm to call at compile time by tag-dispatching method
**/
// Main algorithms tags

View file

@ -37,12 +37,22 @@ namespace paradiseo
{
namespace smp
{
/** Bimap
Bidirectional map in order to create a bijection between islands and vertices.
A and B objects are stocked in two std::set, then if you would avoid instances duplications,
template A and B with pointers.
**/
template<class A, class B>
class Bimap
{
public:
/**
* Add a relation
* @param workersNb the number of workers
* @param args... list of parameters according to the constructor of your algorithm
*/
void add(A a, B b)
{
ASet.insert(a);
@ -51,6 +61,7 @@ public:
leftAssociation[&b] = &a;
}
B& getRight(A const a)
{
return *rightAssociation[&a];

View file

@ -31,27 +31,33 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#define CONT_D_H_
/** Continuator Dispatching
* The Continuator Dispatching enable to wrap continuator in Island constructor for a better user interface
The Continuator Dispatching enable to wrap continuators in Island constructor for a better user interface
**/
template<class T, class U>
U& wrap_pp_impl(T&, U& u, std::false_type)
{ return u; }
{
return u;
}
template<class T, class U>
T& wrap_pp_impl(T& t, U&, std::true_type)
{ return t; }
{
return t;
}
template<class T, class U>
struct result_of_wrap_pp :
std::conditional<std::is_base_of<T,U>::value,T&,U&>
struct result_of_wrap_pp :
std::conditional<std::is_base_of<T,U>::value,T&,U&>
{};
template<class T, class U>
typename result_of_wrap_pp<T,U>::type wrap_pp(T& t, U& u)
{
typedef typename std::is_base_of<T,U>::type tag;
return wrap_pp_impl(t,u,tag());
typedef typename std::is_base_of<T,U>::type tag;
return wrap_pp_impl(t,u,tag());
}
#endif

View file

@ -46,6 +46,8 @@ namespace smp
/** ContWrapper: Utility class to wrap the algorithm continuators with island notifier.
Utility class to wrap the algorithm continuators with island notifier during the island construction.
By using the wrapper, we do not have to modify original continuators inside the IslandModel and then,
it avoids some side effects.
*/
template<class EOT>

View file

@ -45,21 +45,7 @@ The island model will check its policy to know how to integrate population sent
*/
template <class EOT>
class IntPolicy
{
public:
/**
* Constructor
* @param _eval Method to evaluate the population to integrate.
* @param _replace Method to replace elements in the island.
*/
IntPolicy(eoEvalFunc<EOT>& _eval, eoReplacement<EOT>& _replace);
eoEvalFunc<EOT>& eval;
eoReplacement<EOT>& replace;
};
#include<intPolicy.cpp>
using IntPolicy = eoReplacement<EOT>;
}

View file

@ -29,6 +29,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <type_traits>
template<template <class> class EOAlgo, class EOT>
template<class... Args>
paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
@ -37,6 +38,8 @@ paradiseo::smp::Island<EOAlgo,EOT>::Island(unsigned _popSize, eoInit<EOT>& _chro
ContWrapper<EOT>(Loop<Args...>().template findValue<eoContinue<EOT>>(args...), this),
// We inject the wrapped continuator by tag dispatching method during the algorithm construction.
algo(EOAlgo<EOT>(wrap_pp<eoContinue<EOT>>(this->ck,args)...)),
// With the PPE we look for the eval function in order to evaluate EOT to integrate
eval(Loop<Args...>().template findValue<eoEvalFunc<EOT>>(args...)),
pop(_popSize, _chromInit),
intPolicy(_intPolicy),
migPolicy(_migPolicy),
@ -51,6 +54,9 @@ void paradiseo::smp::Island<EOAlgo,EOT>::operator()()
{
stopped = false;
algo(pop);
// Let's wait the end of communications with the island model
for(auto& message : sentMessages)
message.join();
stopped = true;
}
@ -100,6 +106,14 @@ void paradiseo::smp::Island<EOAlgo,EOT>::send(eoSelect<EOT>& _select)
eoPop<EOT> migPop;
_select(pop, migPop);
//std::cout << " La population migrante est :" << std::endl << migPop << std::endl;
// Delete delivered messages
for(auto it = sentMessages.begin(); it != sentMessages.end(); it++)
if(!it->joinable())
sentMessages.erase(it);
sentMessages.push_back(std::thread(&IslandModel<EOT>::update, model, migPop, this));
}
template<template <class> class EOAlgo, class EOT>
@ -108,9 +122,12 @@ void paradiseo::smp::Island<EOAlgo,EOT>::receive(void)
while (!listImigrants.empty())
{
eoPop<EOT> offspring = *(listImigrants.front());
for(auto indi : offspring)
intPolicy.replace(pop, offspring);
// Evaluate objects to integrate
for(auto& indi : offspring)
eval(indi);
intPolicy(pop, offspring);
listImigrants.pop();
}

View file

@ -48,6 +48,12 @@ namespace paradiseo
{
namespace smp
{
/** Island: Concrete island that wraps an algorithm
The island wraps an algorithm and provide mecanism for emigration and integration of populations.
@see smp::AbstractIsland, smp::MigPolicy
*/
template<template <class> class EOAlgo, class EOT>
class Island : private ContWrapper<EOT>, public AIsland<EOT>
@ -59,7 +65,7 @@ public:
* @param _chromInit Population initializer.
* @param _intPolicy Integration policy
* @param _migPolicy Migration policy
* @param args Parameters to construct the algorithm of the island.
* @param args Parameters to construct the algorithm.
*/
template<class... Args>
Island(unsigned _popSize, eoInit<EOT>& _chromInit, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
@ -92,7 +98,11 @@ public:
*/
virtual void check(void);
virtual bool isStopped(void);
/**
* Check if the algorithm is stopped.
* @return true if stopped
*/
virtual bool isStopped(void);
protected:
@ -107,13 +117,16 @@ protected:
*/
virtual void receive(void);
IslandModel<EOT>* model;
IslandModel<EOT>* model;
eoEvalFunc<EOT>& eval;
eoPop<EOT> pop;
EOAlgo<EOT> algo;
std::queue<eoPop<EOT>*> listImigrants;
IntPolicy<EOT>& intPolicy;
MigPolicy<EOT>& migPolicy;
std::atomic<bool> stopped;
std::vector<std::thread> sentMessages;
};
#include <island.cpp>

View file

@ -1,5 +1,5 @@
/*
<intPolicy.cpp>
<islandModel.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
@ -27,9 +27,51 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
template <class EOT>
paradiseo::smp::IntPolicy<EOT>::IntPolicy(eoEvalFunc<EOT>& _eval, eoReplacement<EOT>& _replace) :
eval(_eval),
replace(_replace)
{}
template<class EOT>
void paradiseo::smp::IslandModel<EOT>::add(AIsland<EOT>& _island)
{
static unsigned i = 0;
islands[i] = &_island;
islands[i]->setModel(this);
i++;
}
template<class EOT>
void paradiseo::smp::IslandModel<EOT>::operator()()
{
std::vector<Thread> threads(islands.size());
unsigned i = 0;
for(auto it : islands)
{
threads[i].start(&AIsland<EOT>::operator(), it.second);
i++;
}
unsigned workingThread = islands.size();
while(workingThread > 0)
{
workingThread = islands.size();
for(auto& it : islands)
if(it.second->isStopped())
workingThread--;
std::this_thread::sleep_for(std::chrono::nanoseconds(10));
}
for(auto& thread : threads)
thread.join();
}
template<class EOT>
void paradiseo::smp::IslandModel<EOT>::update(eoPop<EOT> _data, AIsland<EOT>* _island)
{
std::cout << "Pop reçue par le médiateur" << std::endl;
std::lock_guard<std::mutex> lock(this->m);
std::cout << _data << std::endl;
listEmigrants.push(std::pair<eoPop<EOT>,AIsland<EOT>*>(_data, _island));
}

View file

@ -1,5 +1,5 @@
/*
<IslandModel.h>
<islandModel.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
@ -45,57 +45,41 @@ namespace smp
/** IslandModel
The IslandModel object is an island container that provides mecanism in order to perform a
island model pattern according to a topology.
@see smp::Island, smp::MigPolicy
*/
template<class EOT>
class IslandModel
{
public:
void add(AIsland<EOT>& _island)
{
static unsigned i = 0;
islands[i] = &_island;
islands[i]->setModel(this);
i++;
}
/**
* Add an island to the model.
* @param _island Island to add.
*/
void add(AIsland<EOT>& _island);
void operator()()
{
std::vector<Thread> threads(islands.size());
unsigned i = 0;
for(auto it : islands)
{
threads[i].start(&AIsland<EOT>::operator(), it.second);
i++;
}
unsigned workingThread = islands.size();
while(workingThread > 0)
{
workingThread = islands.size();
for(auto& it : islands)
if(it.second->isStopped())
workingThread--;
std::this_thread::sleep_for(std::chrono::nanoseconds(10));
}
for(auto& thread : threads)
thread.join();
}
/**
* Launch the island model by starting islands on their population.
*/
void operator()();
void update(eoPop<EOT>* _data, AIsland<EOT>* _island)
{
listEmigrants.insert(std::pair<eoPop<EOT>*,AIsland<EOT>*>(_data, _island));
}
/**
* Update the island model by adding population to send in the emigrants list.
*/
void update(eoPop<EOT> _data, AIsland<EOT>* _island);
protected:
std::queue<std::pair<eoPop<EOT>*,AIsland<EOT>*>> listEmigrants;
std::queue<std::pair<eoPop<EOT>,AIsland<EOT>*>> listEmigrants;
Bimap<unsigned, unsigned> table;
std::map<unsigned, AIsland<EOT>*> islands;
std::mutex m;
};
#include <islandModel.cpp>
}
}

View file

@ -36,8 +36,8 @@ Contact: paradiseo-help@lists.gforge.inria.fr
/** IslandNotifier: The notifier will perform the binded task each generation.
The island notifier makes the binded task executed by the island which observes.
We can imagine that a continuator check is we have to execute the binded task.
At the moment the task is perfermed each generation.
We can imagine that a continuator checks if we have to execute the binded task.
At the moment, the task is performed each generation.
*/

View file

@ -1,5 +1,5 @@
/*
<policy.h>
<migPolicy.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
@ -37,7 +37,7 @@ namespace paradiseo
{
namespace smp
{
/** MigPolicy: Migration policy
/** MigPolicy: Migration policy is a vector of PolicyElement.
*/
template <class EOT>

View file

@ -37,7 +37,9 @@ namespace paradiseo
namespace smp
{
/** Policies Dispatching
* The Policies Dispatching enable to choose the policy to call at compile time by tag-dispatching method
The Policies Dispatching enable to choose the policy to call at compile time by tag-dispatching method
**/
struct LinearPolicy {};

View file

@ -31,9 +31,9 @@ Contact: paradiseo-help@lists.gforge.inria.fr
#include <eo>
template <class EOT>
paradiseo::smp::PolicyElement<EOT>::PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria) :
paradiseo::smp::PolicyElement<EOT>::PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criterion) :
selection(_selection),
criteria(_criteria)
criterion(_criterion)
{ }
template <class EOT>
@ -45,13 +45,13 @@ bool paradiseo::smp::PolicyElement<EOT>::operator()(const eoPop<EOT>& _pop)
//i++;
// END DEBUG
return criteria(_pop);
return criterion(_pop);
}
template <class EOT>
void paradiseo::smp::PolicyElement<EOT>::addCriteria(eoContinue<EOT>& _criteria)
void paradiseo::smp::PolicyElement<EOT>::addCriterion(eoContinue<EOT>& _criterion)
{
criteria.add(_criteria);
criterion.add(_criterion);
}
template <class EOT>

View file

@ -36,6 +36,11 @@ namespace paradiseo
{
namespace smp
{
/** PolicyElement: PolicyElement is an element of a migration policy.
The policy element is a pair of a selection method and a criterion to apply the selection.
*/
template <class EOT>
class PolicyElement : public eoContinue<EOT>
@ -44,22 +49,22 @@ public :
/**
* Constructor
* @param _selection How to select elements for migration
* @param _criteria When notifying the island
* @param _criterion When notifying the island
*/
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criteria);
PolicyElement(eoSelect<EOT>& _selection, eoContinue<EOT>& _criterion);
/**
* Check is the criteria is reach
* Check is the criterion is reach
* @param _pop Population which is checked by the criteria.
* @return false if the criteria is reached.
* @return false if the criterion is reached.
*/
bool operator()(const eoPop<EOT>& _pop);
/**
* Add criteria for the same selection method.
* @param _criteria New criteria.
* @param _criterion New criterion.
*/
void addCriteria(eoContinue<EOT>& _criteria);
void addCriterion(eoContinue<EOT>& _criterion);
/**
* Access to the selection method.
@ -69,7 +74,7 @@ public :
protected :
eoSelect<EOT>& selection;
eoContinue<EOT>& criteria;
eoContinue<EOT>& criterion;
};
#include <policyElement.cpp>

View file

@ -46,9 +46,12 @@ namespace paradiseo
{
namespace smp
{
/**
A scheduler class
/** Scheduler : Dispatch load between workers according to a policy.
Dispatch load between the specified number of workers according to a policy.
*/
template<class EOT, class Policy = LinearPolicy>
class Scheduler
{

View file

@ -27,6 +27,8 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef ABSTRACT_TOPO_H_
#define ABSTRACT_TOPO_H_
#include <vector>
@ -62,3 +64,5 @@ public :
}
}
#endif

View file

@ -17,7 +17,8 @@ set (TEST_LIST
t-smpMW_eoEasyPSO
t-smpMW_eoSyncEasyPSO
t-smpIsland
t-smpTopo)
t-smpTopo
)
######################################################################################
### 3) Create each test

View file

@ -9,11 +9,11 @@ using namespace std;
int main(void)
{
typedef struct {
unsigned popSize = 10;
unsigned popSize = 100;
unsigned tSize = 2;
double pCross = 0.8;
double pMut = 0.7;
unsigned maxGen = 10;
unsigned maxGen = 10000;
} Param;
Param param;
@ -61,8 +61,7 @@ int main(void)
migPolicy.push_back(PolicyElement<Indi>(who, criteria));
// // Integration policy
eoPlusReplacement<Indi> replace_1;
IntPolicy<Indi> intPolicy(plainEval,replace_1);
eoPlusReplacement<Indi> intPolicy;
Island<eoEasyEA,Indi> test(param.popSize, chromInit, intPolicy, migPolicy, genCont, plainEval, select, transform, replace);
@ -77,8 +76,7 @@ int main(void)
migPolicy_2.push_back(PolicyElement<Indi>(who_2, criteria_2));
// // Integration policy
eoPlusReplacement<Indi> replace_2;
IntPolicy<Indi> intPolicy_2(plainEval,replace_2);
eoPlusReplacement<Indi> intPolicy_2;
Island<eoEasyEA,Indi> test2(param.popSize, chromInit, intPolicy_2, migPolicy_2, genCont_2, plainEval, select, transform, replace);