Merge branch 'islandmodel'

This commit is contained in:
quemy 2013-01-21 10:31:40 +01:00
commit 953b4377e9
77 changed files with 4960 additions and 408 deletions

View file

@ -44,6 +44,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-Wunknown-pragmas -O2" CACHE STRING "" FORCE)
if(SMP)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -pthread" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -pthread" CACHE STRING "" FORCE)
add_definitions(-D_GLIBCXX_USE_NANOSLEEP)
endif(SMP)
######################################################################################

View file

@ -47,6 +47,10 @@ if(PROFILING)
COMMAND lcov -r output.info '*/tutorial*' -o output.info
COMMAND lcov -r output.info '/usr*' -o output.info
COMMAND lcov -r output.info '*/test*' -o output.info
COMMAND lcov -r output.info '*/eo*' -o output.info
COMMAND lcov -r output.info '*/mo*' -o output.info
COMMAND lcov -r output.info '*/moeo*' -o output.info
COMMAND lcov -r output.info '*/problems*' -o output.info
COMMAND genhtml output.info -o coverage/ --highlight --legend
)
else(LCOV)

View file

@ -0,0 +1,62 @@
/*
<eoInvertedContinue.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef _eoInvertedContinue_h
#define _eoInvertedContinue_h
#include <eoContinue.h>
/**
* Return the opposite of the wrapped continuator
*
* @ingroup Continuators
*/
template< class EOT>
class eoInvertedContinue: public eoContinue<EOT>
{
public:
/// Ctor
eoInvertedContinue(eoContinue<EOT>& _cont)
: cont(_cont) {};
/** Returns the opposite of the wrapped continuator
*/
virtual bool operator() ( const eoPop<EOT>& _pop )
{
return !cont(_pop);
}
virtual std::string className(void) const { return "eoInvertedContinue"; }
private:
eoContinue<EOT> &eval;
};
#endif

View file

@ -11,7 +11,7 @@ if(DOXYGEN_FOUND)
# Creating the custom target
if(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
add_custom_target(doc-smp
COMMAND ${DOXYGEN_EXECUTABLE} ${SMP_DOC_CONFIG_FILE} 2> /dev/null > /dev/null
COMMAND ${DOXYGEN_EXECUTABLE} ${SMP_DOC_CONFIG_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
add_custom_target(doc-smp

View file

@ -4,7 +4,7 @@
ParadisEO-SMP for Symmetric MultiProcessing or Shared Memory Parallelism is a module for multicores computations on several algorithms proposed by ParadiseEO. By simply wrapping the algorithms, it allows you to refer only to the API of your algorithm instead of learning a new one.
Different parallelism models are avaiable such as the Master / Slaves model or the Island Model.
Different parallelism models are available such as the Master / Slaves Model or the Island Model.
@section tutorials Tutorials

View file

@ -1296,7 +1296,7 @@ SKIP_FUNCTION_MACROS = YES
# If a tag file is not located in the directory in which doxygen
# is run, you must also specify the path to the tagfile here.
TAGFILES = @SMP_BIN_DIR@/doc/eo.doxytag=http://eodev.sourceforge.net/smp/doc/html
TAGFILES = @SMP_BIN_DIR@/doc/smp.doxytag=http://paradiseo.gforge.inria.fr/addon/smp/doc/index.html
# When a file name is specified after GENERATE_TAGFILE, doxygen will create
# a tag file that is based on the input files it reads.

View file

@ -2,6 +2,7 @@
### 0) Include directories
######################################################################################
include_directories(${EO_SRC_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
######################################################################################
@ -16,9 +17,22 @@ set(LIBRARY_OUTPUT_PATH ${SMP_LIB_OUTPUT_PATH})
######################################################################################
set (SMP_FILE
thread.cpp
MWModel.h
scheduler.h)
scheduler.h
island.h
topology/abstractTopology.h
topology/topology.h
topology/topologyBuilder.h
topology/complete.cpp
topology/star.cpp
topology/ring.cpp
topology/hypercubic.cpp
topology/mesh.cpp
topology/customBooleanTopology.cpp
topology/customStochasticTopology.cpp
notifier.cpp
islandModelWrapper.h
)
add_library(smp STATIC ${SMP_FILE})
@ -28,15 +42,16 @@ install(TARGETS smp ARCHIVE DESTINATION ${LIB} COMPONENT libraries)
### 3) Look for headers
######################################################################################
file(GLOB HDRS smp *.h)
file(GLOB HDRS smp *.h *.cpp)
install(FILES ${HDRS} DESTINATION include${INSTALL_SUB_DIR}/smp COMPONENT headers)
######################################################################################
### 4) Install directories
######################################################################################
install(DIRECTORY MWAlgo
install(DIRECTORY MWAlgo topology
DESTINATION include${INSTALL_SUB_DIR}/smp
COMPONENT headers
FILES_MATCHING PATTERN "*.h"
PATTERN "*.cpp"
)

View file

@ -32,12 +32,14 @@ template<class... 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) :
MWModel(Thread::hardware_concurrency(), args...)
MWModel(std::thread::hardware_concurrency(), args...)
{}
template<template <class> class EOAlgo, class EOT, class Policy>

View file

@ -27,16 +27,16 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef MWMODEL_H_
#define MWMODEL_H_
#ifndef SMP_MWMODEL_H_
#define SMP_MWMODEL_H_
#include <cassert>
#include <thread>
#include <scheduler.h>
#include <algoDispatching.h>
#include <policiesDispatching.h>
#include <eo>
@ -47,7 +47,7 @@ namespace smp
/** MWModel: Master / Worker Model for multicore computation
The MW Model wraps any algorithm in order to apply it on several populations.
The MW Model wraps any algorithm in order to dispatch load between threads.
@see smp::Worker, smp::Thread
*/
@ -99,7 +99,7 @@ protected:
void operator()(eoPop<EOT>& pop, const eoEasyEA_tag&);
/**
* Specifid algorithm for EasyPSO
* Specific algorithm for EasyPSO
*/
void operator()(eoPop<EOT>& pop, const eoEasyPSO_tag&);
@ -113,7 +113,7 @@ protected:
*/
void operator()(eoPop<EOT>& pop,const error_tag&);
std::vector<Thread*> workers;
std::vector<std::thread*> workers;
Scheduler<EOT,Policy> scheduler;
};

74
smp/src/PPExpander.h Normal file
View file

@ -0,0 +1,74 @@
/*
<PPExpander.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_PPE_H_
#define SMP_PPE_H_
namespace paradiseo
{
namespace smp
{
/** Parameter Pack Expansion: Utility file to expand parameter pack
Utility file to expand parameter pack with the recursive method
**/
template<class... Arg> class Loop;
template<class T, class... Arg>
class Loop<T,Arg...>
{
template<class U>
U& findValueImpl(T&, Arg&... arg, std::false_type)
{
return Loop<Arg...>().template findValue<U>(arg...);
}
template<class U>
U& findValueImpl(T& t, Arg&... arg, std::true_type)
{
return t;
}
public:
template<class U>
U& findValue(T& t, Arg&... arg)
{
typedef typename std::is_base_of<U,T>::type tag;
return findValueImpl<U>(t,arg...,tag());
}
};
}
}
#endif

98
smp/src/abstractIsland.h Normal file
View file

@ -0,0 +1,98 @@
/*
<abstractIsland.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_ABSTRACT_ISLAND_H_
#define SMP_ABSTRACT_ISLAND_H_
#include <atomic>
#include <eoPop.h>
#include <migPolicy.h>
namespace paradiseo
{
namespace smp
{
// Forward declaration
template<class bEOT>
class IslandModel;
/** AbstractIsland: An abstract island.
The abstract island is used to manipulate island pointers wihout the knowledge of the algorithm.
The template is the base type for individuals.
@see smp::Island smp::IslandModel
*/
template<class bEOT>
class AIsland
{
public:
virtual void operator()() = 0;
/**
* Set the Island Model.
* @param _model The model which manipulate the island.
*/
virtual void setModel(IslandModel<bEOT>* _model) = 0;
/**
* Check if there is population to receive or to emigrate.
*/
virtual void check(void) = 0;
/**
* Update the island by adding population to send in the imigrants list.
* @param _data Population to integrate.
*/
virtual void update(eoPop<bEOT> _data) = 0;
/**
* Check if the algorithm is stopped.
* @return true if stopped.
*/
virtual bool isStopped(void) const = 0;
/**
* Receive population by integrate individuals.
*/
virtual void receive(void) = 0;
protected:
std::mutex m;
};
}
}
#endif

View file

@ -27,8 +27,8 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef ALGO_D_H_
#define ALGO_D_H_
#ifndef SMP_ALGO_DISPATCHING_H_
#define SMP_ALGO_DISPATCHING_H_
#include <eo>
@ -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 enables to choose the algorithm to call at compile time by tag-dispatching method
**/
// Main algorithms tags

79
smp/src/bimap.cpp Normal file
View file

@ -0,0 +1,79 @@
/*
<bimap.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
template<class A, class B>
void paradiseo::smp::Bimap<A,B>::add(A& a, B& b)
{
rightAssociation[a] = b;
leftAssociation[b] = a;
}
template<class A, class B>
std::map<A,B> paradiseo::smp::Bimap<A,B>::getRight() const
{
return rightAssociation;
}
template<class A, class B>
std::map<B,A> paradiseo::smp::Bimap<A,B>::getLeft() const
{
return leftAssociation;
}
template<class A, class B>
void paradiseo::smp::Bimap<A,B>::removeFromRight(const A& a)
{
for(auto& it : leftAssociation)
if(it->second == a)
leftAssociation.erase(it);
rightAssociation.erase(a);
}
template<class A, class B>
void paradiseo::smp::Bimap<A,B>::removeFromLeft(const B& b)
{
for(auto& it : rightAssociation)
if(it->second == b)
rightAssociation.erase(it);
leftAssociation.erase(b);
}
template<class A, class B>
unsigned paradiseo::smp::Bimap<A,B>::size() const
{
return leftAssociation.size();
}
template<class A, class B>
bool paradiseo::smp::Bimap<A,B>::empty() const
{
return leftAssociation.empty();
}

105
smp/src/bimap.h Normal file
View file

@ -0,0 +1,105 @@
/*
<bimap.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_BIMAP_MODEL_H_
#define SMP_BIMAP_MODEL_H_
#include <map>
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::map, then if you would like to avoid instances duplications,
template A and B with pointers.
**/
template<class A, class B>
class Bimap
{
public:
/**
* Add a relation
* @param A right key
* @param B left key
*/
void add(A& a, B& b);
/**
* Return a map which represents the right association.
* @return rightAssociation
*/
std::map<A,B> getRight() const;
/**
* Return a map which represents the left association.
* @return leftAssociation
*/
std::map<B,A> getLeft() const;
/**
* Remove an association from a right key.
* @param Right key of the association to be removed.
*/
void removeFromRight(const A& a);
/**
* Remove an association from a left key.
* @param Left key of the association to be removed.
*/
void removeFromLeft(const B& b);
/**
* Return the number of associations.
* @return Size of bimap
*/
unsigned size() const;
/**
* Check if the bimap is empty
* @return true if the bimap is empty
*/
bool empty() const;
protected:
std::map<A,B> rightAssociation;
std::map<B,A> leftAssociation;
};
#include <bimap.cpp>
}
}
#endif

63
smp/src/contDispatching.h Normal file
View file

@ -0,0 +1,63 @@
/*
<contDispatching.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_CONT_DISPATCHING_H_
#define SMP_CONT_DISPATCHING_H_
/** Continuator Dispatching
The Continuator Dispatching enables to wrap continuators in the Island constructor for a better user interface and, moreover, avoiding side effect.
**/
template<class T, class U>
U& wrap_pp_impl(T&, U& u, std::false_type)
{
return u;
}
template<class T, class U>
T& wrap_pp_impl(T& t, U&, std::true_type)
{
return t;
}
template<class T, class 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());
}
#endif

36
smp/src/contWrapper.cpp Normal file
View file

@ -0,0 +1,36 @@
/*
<contWrapper.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
template<class EOT, class bEOT>
paradiseo::smp::ContWrapper<EOT, bEOT>::ContWrapper(eoContinue<EOT>& _cont, AIsland<bEOT>* island) :
ck(_cont),
islandNotifier(island, &AIsland<bEOT>::check)
{
ck.add(islandNotifier);
}

72
smp/src/contWrapper.h Normal file
View file

@ -0,0 +1,72 @@
/*
<contWrapper.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_CONT_WRAPPER_H_
#define SMP_CONT_WRAPPER_H_
#include <utils/eoCheckPoint.h>
#include <eoContinue.h>
#include <migPolicy.h>
#include <islandNotifier.h>
namespace paradiseo
{
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, class bEOT>
class ContWrapper
{
public:
/**
* Constructor
* @param _cont Original continuators
* @param _island Pointer on the island used by the notifier
*/
ContWrapper(eoContinue<EOT>& _cont, AIsland<bEOT>* _island);
protected:
eoCheckPoint<EOT> ck;
IslandNotifier<bEOT> islandNotifier;
};
#include <contWrapper.cpp>
}
}
#endif

54
smp/src/intPolicy.h Normal file
View file

@ -0,0 +1,54 @@
/*
<intPolicy.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_INT_POLICY_H_
#define SMP_INT_POLICY_H_
#include <eoReplacement.h>
namespace paradiseo
{
namespace smp
{
/** IntPolicy: Integration policy for island.
The island model will check its policy to know how to integrate populations sent by other islands.
@see smp::Island, smp::MigPolicy
*/
template <class EOT>
using IntPolicy = eoReplacement<EOT>;
}
}
#endif

158
smp/src/island.cpp Normal file
View file

@ -0,0 +1,158 @@
/*
<island.cpp>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
template<template <class> class EOAlgo, class EOT, class bEOT>
template<class... Args>
paradiseo::smp::Island<EOAlgo,EOT,bEOT>::Island(std::function<EOT(bEOT&)> _convertFromBase, std::function<bEOT(EOT&)> _convertToBase, eoPop<EOT>& _pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
// The PPExpander looks for the continuator in the parameters pack.
// The private inheritance of ContWrapper wraps the continuator and add islandNotifier.
ContWrapper<EOT, bEOT>(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(_pop),
intPolicy(_intPolicy),
migPolicy(_migPolicy),
stopped(false),
model(nullptr),
convertFromBase(_convertFromBase),
convertToBase(_convertToBase)
{
// 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>");
}
template<template <class> class EOAlgo, class EOT, class bEOT>
template<class... Args>
paradiseo::smp::Island<EOAlgo,EOT,bEOT>::Island(eoPop<EOT>& _pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args) :
Island(
// Default conversion functions for homogeneous islands
[](bEOT& i) -> EOT { return std::forward<EOT>(i); },
[](EOT& i) -> bEOT { return std::forward<bEOT>(i); },
_pop, _intPolicy, _migPolicy, args...)
{ }
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::operator()()
{
stopped = false;
algo(pop);
stopped = true;
// Let's wait the end of communications with the island model
for(auto& message : sentMessages)
message.join();
}
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::setModel(IslandModel<bEOT>* _model)
{
model = _model;
}
template<template <class> class EOAlgo, class EOT, class bEOT>
eoPop<EOT>& paradiseo::smp::Island<EOAlgo,EOT,bEOT>::getPop() const
{
return pop;
}
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::check()
{
// Sending
for(PolicyElement<EOT>& elem : migPolicy)
if(!elem(pop))
send(elem.getSelect());
// Receiving
receive();
}
template<template <class> class EOAlgo, class EOT, class bEOT>
bool paradiseo::smp::Island<EOAlgo,EOT,bEOT>::isStopped(void) const
{
return (bool)stopped;
}
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::send(eoSelect<EOT>& _select)
{
// Allow island to work alone
if(model != nullptr)
{
eoPop<EOT> migPop;
_select(pop, migPop);
// Convert pop to base pop
eoPop<bEOT> baseMigPop;
for(auto& indi : migPop)
baseMigPop.push_back(std::move(convertToBase(indi)));
//std::cout << "On envoie de l'île : " << 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<bEOT>::update, model, std::move(baseMigPop), this));
}
}
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::receive(void)
{
std::lock_guard<std::mutex> lock(this->m);
while (!listImigrants.empty())
{
//std::cout << "On reçoit dans l'île : " << listImigrants.size() << std::endl;
eoPop<bEOT> base_offspring = std::move(listImigrants.front());
// Convert objects from base to our objects type
eoPop<EOT> offspring;
for(auto& indi : base_offspring)
offspring.push_back(std::move(convertFromBase(indi)));
// Evaluate objects to integrate
for(auto& indi : offspring)
eval(indi);
intPolicy(pop, offspring);
listImigrants.pop();
}
}
template<template <class> class EOAlgo, class EOT, class bEOT>
void paradiseo::smp::Island<EOAlgo,EOT,bEOT>::update(eoPop<bEOT> _data)
{
//std::cout << "On update dans l'île" << std::endl;
std::lock_guard<std::mutex> lock(this->m);
listImigrants.push(_data);
}

157
smp/src/island.h Normal file
View file

@ -0,0 +1,157 @@
/*
<island.h>
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2012
Alexandre Quemy, Thibault Lasnier - INSA Rouen
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can ue,
modify and/ or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
Contact: paradiseo-help@lists.gforge.inria.fr
*/
#ifndef SMP_ISLAND_H_
#define SMP_ISLAND_H_
#include <queue>
#include <vector>
#include <utility>
#include <atomic>
#include <type_traits>
#include <eoEvalFunc.h>
#include <eoSelect.h>
#include <eoAlgo.h>
#include <eoPop.h>
#include <abstractIsland.h>
#include <islandModel.h>
#include <migPolicy.h>
#include <intPolicy.h>
#include <PPExpander.h>
#include <contWrapper.h>
#include <contDispatching.h>
namespace paradiseo
{
namespace smp
{
/** Island: Concrete island that wraps an algorithm
The island wraps an algorithm and provide mecanisms for emigration and integration of populations.
An island also have a base type which represents the type of individuals of the Island Model.
@see smp::AbstractIsland, smp::MigPolicy
*/
template<template <class> class EOAlgo, class EOT, class bEOT = EOT>
class Island : private ContWrapper<EOT, bEOT>, public AIsland<bEOT>
{
public:
/**
* Constructor
* @param _convertFromBase Function to convert EOT from base EOT
* @param _convertToBase Function to convert base EOT to EOT
* @param _pop Population of the island
* @param _intPolicy Integration policy
* @param _migPolicy Migration policy
* @param args Parameters to construct the algorithm.
*/
template<class... Args>
Island(std::function<EOT(bEOT&)> _convertFromBase, std::function<bEOT(EOT&)> _convertToBase, eoPop<EOT>& pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
/**
* Constructor
* @param _pop Population of the island
* @param _intPolicy Integration policy
* @param _migPolicy Migration policy
* @param args Parameters to construct the algorithm.
*/
template<class... Args>
Island(eoPop<EOT>& pop, IntPolicy<EOT>& _intPolicy, MigPolicy<EOT>& _migPolicy, Args&... args);
/**
* Start the island.
*/
void operator()(void);
/**
* Set model
* @param _model Pointer to the Island Model corresponding
*/
virtual void setModel(IslandModel<bEOT>* _model);
/**
* Return a reference to the island population.
* @return Reference to the island population
*/
eoPop<EOT>& getPop() const;
/**
* Check if there is population to receive or to migrate
*/
virtual void check(void);
/**
* Update the list of imigrants.
* @param _data Elements to integrate in the main population.
*/
void update(eoPop<bEOT> _data);
/**
* Check if the algorithm is stopped.
* @return true if stopped
*/
virtual bool isStopped(void) const;
/**
* Check if there is population to receive
*/
virtual void receive(void);
AIsland<bEOT> clone() const;
protected:
/**
* Send population to mediator
* @param _select Method to select EOT to send
*/
virtual void send(eoSelect<EOT>& _select);
EOAlgo<EOT> algo;
eoEvalFunc<EOT>& eval;
eoPop<EOT>& pop;
std::queue<eoPop<bEOT>> listImigrants;
IntPolicy<EOT>& intPolicy;
MigPolicy<EOT>& migPolicy;
std::atomic<bool> stopped;
std::vector<std::thread> sentMessages;
IslandModel<bEOT>* model;
std::function<EOT(bEOT&)> convertFromBase;
std::function<bEOT(EOT&)> convertToBase;
};
#include <island.cpp>
}
}
#endif

Some files were not shown because too many files have changed in this diff Show more