Add the SMP module

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2714 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
quemy 2012-08-17 11:52:14 +00:00
commit 0890c67d31
43 changed files with 4030 additions and 41 deletions

View file

@ -18,7 +18,7 @@ enable_language(CXX)
## Test the presence of a compiler
if("${CMAKE_CXX_COMPILER}" STREQUAL "" OR "${CMAKE_C_COMPILER}" STREQUAL "")
message(FATAL_ERROR "No compiler founded !")
message(FATAL_ERROR "No compiler found !")
endif()
## Versioning
@ -54,11 +54,14 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Target.cmake)
set(EO_SRC_DIR "${CMAKE_SOURCE_DIR}/eo" CACHE PATH "ParadisEO-EO source directory" FORCE)
set(EO_BIN_DIR "${CMAKE_BINARY_DIR}/eo" CACHE PATH "ParadisEO-EO binary directory" FORCE)
set(MO_SRC_DIR "${CMAKE_SOURCE_DIR}/mo" CACHE PATH "ParadisMO-MO source directory" FORCE)
set(MO_BIN_DIR "${CMAKE_BINARY_DIR}/mo" CACHE PATH "ParadisMO-MO binary directory" FORCE)
set(MO_SRC_DIR "${CMAKE_SOURCE_DIR}/mo" CACHE PATH "ParadisEO-MO source directory" FORCE)
set(MO_BIN_DIR "${CMAKE_BINARY_DIR}/mo" CACHE PATH "ParadisEO-MO binary directory" FORCE)
set(MOEO_SRC_DIR "${CMAKE_SOURCE_DIR}/moeo" CACHE PATH "ParadisMOEO-MOEO source directory" FORCE)
set(MOEO_BIN_DIR "${CMAKE_BINARY_DIR}/moeo" CACHE PATH "ParadisMOEO-MOEO binary directory" FORCE)
set(MOEO_SRC_DIR "${CMAKE_SOURCE_DIR}/moeo" CACHE PATH "ParadisEO-MOEO source directory" FORCE)
set(MOEO_BIN_DIR "${CMAKE_BINARY_DIR}/moeo" CACHE PATH "ParadisEO-MOEO binary directory" FORCE)
set(SMP_SRC_DIR "${CMAKE_SOURCE_DIR}/smp" CACHE PATH "ParadisEO-SMP source directory" FORCE)
set(SMP_BIN_DIR "${CMAKE_BINARY_DIR}/smp" CACHE PATH "ParadisEO-SMP binary directory" FORCE)
set(PROBLEMS_SRC_DIR "${CMAKE_SOURCE_DIR}/problems" CACHE PATH "Problems dependant source directory" FORCE)
@ -79,12 +82,19 @@ if(NOT EO_ONLY)
set(MOEO_MODULE_NAME "ParadisEO-MOEO")
set(CMAKE_SOURCE_DIR ${MOEO_SRC_DIR})
add_subdirectory(${MOEO_SRC_DIR})
## SMP Module
if(SMP)
set(SMP_MODULE_NAME "ParadisEO-SMP")
set(CMAKE_SOURCE_DIR ${SMP_SRC_DIR})
add_subdirectory(${SMP_SRC_DIR})
endif()
endif()
######################################################################################
### 5) Packaging : only in release !
######################################################################################
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Package.cmake)
endif()

View file

@ -38,9 +38,6 @@ Then, follow UNIX instructions.
------------------------------------------------------------------------------------------
1.0 DEPENDENCIES
------------------------------------------------------------------------------------------
Required
- Compiler with OpenMP implementation (hence, Clang isn't supported atm).
Optionnal
- Doxygen for documentation
- lcov for coverage
@ -74,7 +71,7 @@ To compile ParadisEO simply compile sources using your generator. For instance,
------------------------------------------------------------------------------------------
There are 2 types of build : Release or Debug.
To explicitly change the type, add -DCMAKE_BUILD_TYPE=Debug for instance.
To explicitly change the type, add -DDEBUG=true, otherwise, it will be the Release type.
------------------------------------------------------------------------------------------
1.3 INSTALLATION
@ -97,6 +94,7 @@ doc for all documentations
doc-eo for building EO documentation
doc-mo for MO
doc-moeo for MOEO
doc-smp for SMP
Each documentation are generated separatly in the module build folder.
For instance, after the generation of the MO documentation, you will find it in build/paradise-mo/doc.

View file

@ -34,8 +34,13 @@ endif()
######################################################################################
add_definitions(-DDEPRECATED_MESSAGES)
set(CMAKE_CXX_FLAGS_DEBUG "-Wunknown-pragmas -O0 -g -Wall -Wextra -ansi -pedantic -fopenmp -std=c++0x" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "-Wunknown-pragmas -O2 -fopenmp -std=c++0x" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-Wunknown-pragmas -O0 -g -Wall -Wextra -ansi -pedantic" CACHE STRING "" FORCE)
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)
endif(SMP)
######################################################################################
### 1) Define installation type
@ -55,6 +60,7 @@ endif()
if(PROFILING)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pg --coverage" CACHE STRING "" FORCE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
set(ENABLE_CMAKE_TESTING "true" CACHE STRING "" FORCE)
endif(PROFILING)
@ -67,16 +73,6 @@ if(ENABLE_CMAKE_TESTING)
include(CTest REQUIRED)
endif(ENABLE_CMAKE_TESTING)
######################################################################################
### 4) Set DEBUG or RELEASE build type depending testing and profiling
######################################################################################
if(NOT DEFINED DEBUG)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
else( NOT DEFINED DEBUG)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif(NOT DEFINED DEBUG)
######################################################################################
### 5) Build examples ?
######################################################################################

View file

@ -27,6 +27,8 @@ macro(add_lesson module target files)
target_link_libraries(${i} eoutils ga eo)
elseif(${module} MATCHES moeo)
target_link_libraries(${i} moeo flowshop eo eoutils)
elseif(${module} MATCHES smp)
target_link_libraries(${i} smp eo eoutils)
endif()
install(TARGETS ${i} RUNTIME DESTINATION share${INSTALL_SUB_DIR}/${module}/tutorial/${target} COMPONENT examples)
endforeach(i)

View file

@ -11,11 +11,20 @@ endif(UNIX)
######################################################################################
if(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
add_custom_target(doc
COMMAND make doc-eo
COMMAND make doc-mo
COMMAND make doc-moeo
)
if(SMP)
add_custom_target(doc
COMMAND make doc-eo
COMMAND make doc-mo
COMMAND make doc-moeo
COMMAND make doc-smp
)
else()
add_custom_target(doc
COMMAND make doc-eo
COMMAND make doc-mo
COMMAND make doc-moeo
)
endif()
endif(DOXYGEN_FOUND AND DOXYGEN_EXECUTABLE)
######################################################################################

View file

@ -81,13 +81,6 @@ ENDIF (WIN32)
######################################################################################
#####################################################################################
### 3) Manage the build type
#####################################################################################
INCLUDE(BuildConfig.cmake)
######################################################################################

View file

@ -216,7 +216,7 @@ public:
}
private:
protected:
eoInitializerBase <POT> &init;
eoContinue < POT > &continuator;

View file

@ -6,12 +6,6 @@ include_directories(${EO_SRC_DIR}/src)
include_directories(${MOEO_SRC_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
######################################################################################
### 1) Link EO library
######################################################################################
link_directories(${EO_BIN_DIR}/lib)
######################################################################################
### 2) Define output paths
######################################################################################

18
trunk/smp/CMakeLists.txt Normal file
View file

@ -0,0 +1,18 @@
######################################################################################
### 0) Include subdirectories
######################################################################################
add_subdirectory(doc)
add_subdirectory(src)
if(ENABLE_CMAKE_TESTING)
add_subdirectory(test)
endif(ENABLE_CMAKE_TESTING)
if(ENABLE_CMAKE_EXAMPLE)
if(${CMAKE_VERBOSE_MAKEFILE})
message("PEO Examples :")
endif(${CMAKE_VERBOSE_MAKEFILE})
add_subdirectory(tutorial)
endif(ENABLE_CMAKE_EXAMPLE)

View file

@ -0,0 +1,37 @@
######################################################################################
### 0) Documentation
######################################################################################
if(DOXYGEN_FOUND)
# Directory where the generation will be launched
set(SMP_DOC_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Documentation directory")
# Name of the doxygene configuration file
set(SMP_DOC_CONFIG_FILE "smp.doxyfile" CACHE PATH "Documentation configuration file")
if(DOXYGEN_EXECUTABLE)
# 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
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
else(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
add_custom_target(doc-smp
COMMAND ${DOXYGEN_EXECUTABLE} ${SMP_DOC_CONFIG_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif(UNIX AND NOT ${CMAKE_VERBOSE_MAKEFILE})
endif(DOXYGEN_EXECUTABLE)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${SMP_DOC_CONFIG_FILE}.cmake"
"${SMP_DOC_DIR}/${SMP_DOC_CONFIG_FILE}")
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DESTINATION share${INSTALL_SUB_DIR}/smp COMPONENT doc
PATTERN "CMakeFiles" EXCLUDE
PATTERN "cmake_install.cmake" EXCLUDE
PATTERN "CTestTestfile.cmake" EXCLUDE
PATTERN "Makefile" EXCLUDE
PATTERN "smp.cfg" EXCLUDE
PATTERN "smp.doxytag" EXCLUDE
)
else(DOXYGEN_FOUND)
message(STATUS "Unable to generate the documentation, Doxygen package not found")
endif(DOXYGEN_FOUND)

47
trunk/smp/doc/index.h Normal file
View file

@ -0,0 +1,47 @@
/** @mainpage Welcome to ParadisEO-SMP
@section Introduction
ParadisEO-SMP for Symmetric MultiProcessing 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.
@section tutorials Tutorials
Tutorials for ParadisEO-SMP are available in the "Tutorials section" of the <a href="http://paradiseo.gforge.inria.fr">ParadisEO website</a>.
@section LICENSE
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
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".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited liability.
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
*/
/** @page webpages Related webpages
- ParadisEO <a href="http://paradiseo.gforge.inria.fr">homepage</a>
- INRIA GForge <a href="http://gforge.inria.fr/projects/paradiseo/">project page</a>
- <a href="../../README">README</a>
*/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,43 @@
######################################################################################
### 0) Include directories
######################################################################################
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
######################################################################################
### 1) Set paths
######################################################################################
set(SMP_LIB_OUTPUT_PATH ${SMP_BIN_DIR}/lib)
set(LIBRARY_OUTPUT_PATH ${SMP_LIB_OUTPUT_PATH})
######################################################################################
### 2) Build lib
######################################################################################
set (SMP_FILE
thread.cpp
MWModel.h
scheduler.h)
add_library(smp STATIC ${SMP_FILE})
install(TARGETS smp ARCHIVE DESTINATION ${LIB} COMPONENT libraries)
######################################################################################
### 3) Look for headers
######################################################################################
file(GLOB HDRS SMP)
install(FILES ${HDRS} DESTINATION include${INSTALL_SUB_DIR}/smp COMPONENT headers)
######################################################################################
### 4) Install directories
######################################################################################
install(DIRECTORY algo
DESTINATION include${INSTALL_SUB_DIR}/smp
COMPONENT headers
FILES_MATCHING PATTERN "*.h"
)

View file

@ -0,0 +1,37 @@
/*
<MWAlgo.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 MWAlGO_H
#define MWAlGO_H
#include <MWAlgo/eoEasyEA.cpp>
#include <MWAlgo/eoEasyPSO.cpp>
#include <MWAlgo/eoSyncEasyPSO.cpp>
#endif

View file

@ -0,0 +1,43 @@
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::operator()(eoPop<EOT>& _pop, const eoEasyEA_tag&)
{
if (this->isFirstCall)
{
size_t total_capacity = _pop.capacity() + this->offspring.capacity();
_pop.reserve(total_capacity);
this->offspring.reserve(total_capacity);
this->isFirstCall = false;
}
eoPop<EOT> empty_pop;
this->popEval(empty_pop, _pop); // A first eval of pop.
do
{
try
{
unsigned pSize = _pop.size();
this->offspring.clear(); // new offspring
this->breed(_pop, this->offspring);
scheduler(EOAlgo<EOT>::eval, this->offspring); // eval of parents + offspring if necessary
this->replace(_pop, this->offspring); // after replace, the new pop. is in _pop
if (pSize > _pop.size())
throw std::runtime_error("Population shrinking!");
else if (pSize < _pop.size())
throw std::runtime_error("Population growing!");
}
catch (std::exception& e)
{
std::string s = e.what();
s.append( " in eoEasyEA");
throw std::runtime_error( s );
}
}
while (this->continuator( _pop ) );
}

View file

@ -0,0 +1,35 @@
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::operator()(eoPop<EOT>& _pop, const eoEasyPSO_tag&)
{
try
{
// initializes the topology, velocity, best particle(s)
this->init();
do
{
// loop over all the particles for the current iteration
for (unsigned idx = 0; idx < _pop.size (); idx++)
{
// perform velocity evaluation
this->velocity (_pop[idx],idx);
// apply the flight
this->flight (_pop[idx]);
}
// evaluate the position
scheduler(EOAlgo<EOT>::eval, _pop);
for (unsigned idx = 0; idx < _pop.size (); idx++)
// update the topology (particle and local/global best(s))
this->velocity.updateNeighborhood(_pop[idx],idx);
} while (this->continuator (_pop));
}
catch (std::exception & e)
{
std::string s = e.what ();
s.append (" in eoEasyPSO");
throw std::runtime_error (s);
}
}

View file

@ -0,0 +1,36 @@
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::operator()(eoPop<EOT>& _pop, const eoSyncEasyPSO_tag&)
{
try
{
// initializes the topology, velocity, best particle(s)
this->init();
// just to use a loop eval
eoPop<EOT> empty_pop;
do
{
// perform velocity evaluation
//scheduler(this->velocity, _pop);
this->velocity.apply(_pop);
// apply the flight
this->flight.apply(_pop);
// evaluate the position (with a loop eval, empty_swarm IS USELESS)
scheduler(EOAlgo<EOT>::eval, _pop);
// update the topology (particle and local/global best(s))
this->velocity.updateNeighborhood(_pop);
} while (this->continuator(_pop));
}
catch (std::exception & e)
{
std::string s = e.what ();
s.append (" in eoSyncEasyPSO");
throw std::runtime_error (s);
}
}

71
trunk/smp/src/MWModel.cpp Normal file
View file

@ -0,0 +1,71 @@
/*
<MWModel.cpp>
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
*/
template<template <class> class EOAlgo, class EOT>
template<class... Args>
paradiseo::smp::MWModel<EOAlgo,EOT>::MWModel (unsigned workersNb, Args&... args) :
EOAlgo<EOT>(args...),
scheduler(workersNb-1)
{ assert(workersNb > 0); }
template<template <class> class EOAlgo, class EOT>
template<class... Args>
paradiseo::smp::MWModel<EOAlgo,EOT>::MWModel (Args&... args) :
MWModel(Thread::hardware_concurrency(), args...)
{}
template<template <class> class EOAlgo, class EOT>
paradiseo::smp::MWModel<EOAlgo,EOT>::~MWModel ()
{}
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::apply(eoUF<EOT&, void>& func, eoPop<EOT>& pop)
{
scheduler(func, pop);
}
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::evaluate(eoPop<EOT>& pop)
{
scheduler(this->eval, pop);
}
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::operator()(eoPop<EOT>& pop)
{
// Call the tag dispatcher
operator()(pop,typename traits<EOAlgo,EOT>::type());
}
template<template <class> class EOAlgo, class EOT>
void paradiseo::smp::MWModel<EOAlgo,EOT>::operator()(eoPop<EOT>& pop, const error_tag&)
{
throw std::runtime_error("This is not a valid algorithm");
}

127
trunk/smp/src/MWModel.h Normal file
View file

@ -0,0 +1,127 @@
/*
<MWModel.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 MWMODEL_H_
#define MWMODEL_H_
#include <cassert>
#include <scheduler.h>
#include <tagDispatching.h>
#include <eo>
namespace paradiseo
{
namespace smp
{
/** MWModel: Master / Worker Model for multicore computation
The MW Model wraps any algorithm in order to apply it on several populations.
@see smp::Worker, smp::Thread
*/
template<template <class> class EOAlgo, class EOT>
class MWModel : public EOAlgo<EOT>
{
public:
/**
* Constructor
* @param workersNb the number of workers including the master
* @param args... list of parameters according to the constructor of your algorithm
*/
template<class... Args>
MWModel(unsigned workersNb, Args&... args);
/**
* Constructor
* @param args... list of parameters according to the constructor of your algorithm
*/
template<class... Args>
MWModel(Args&... args);
~MWModel();
/**
* Apply an unary functor to the population
* @param func unary functor
* @param pop population
*/
void apply(eoUF<EOT&, void>& func, eoPop<EOT>& pop);
/**
* Evaluate the population
* @param pop population to evaluate
*/
void evaluate(eoPop<EOT>& pop);
/**
* Run the algorithm on population
* @param pop population to run the algorithm
*/
void operator()(eoPop<EOT>& pop);
protected:
/**
* Specific algorithm for eoEasyEA
*/
void operator()(eoPop<EOT>& pop, const eoEasyEA_tag&);
/**
* Specifid algorithm for EasyPSO
*/
void operator()(eoPop<EOT>& pop, const eoEasyPSO_tag&);
/**
* Specific algorithm for eoSyncEasyPSO
*/
void operator()(eoPop<EOT>& pop, const eoSyncEasyPSO_tag&);
/**
* If we don't know the algorithm type
*/
void operator()(eoPop<EOT>& pop,const error_tag&);
std::vector<Thread*> workers;
Scheduler<EOT> scheduler;
};
#include <MWModel.cpp>
#include <MWAlgo/MWAlgo.h>
}
}
#endif

View file

@ -0,0 +1,97 @@
/*
<scheduler.cpp>
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
*/
template<class EOT>
paradiseo::smp::Scheduler<EOT>::Scheduler(unsigned workersNb) :
workers(workersNb),
popPackages(workersNb),
done(false),
planning(workersNb),
idWaitingThread(-1)
{ }
template<class EOT>
paradiseo::smp::Scheduler<EOT>::~Scheduler()
{ }
template<class EOT>
void paradiseo::smp::Scheduler<EOT>::operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop)
{
done = false;
idWaitingThread = -1;
for(unsigned i = 0; i < workers.size(); i++)
{
planning[i] = 2;
workers[i].start(&Scheduler<EOT>::apply, this, std::ref(func), std::ref(popPackages[i]), i);
}
unsigned counter = 0;
unsigned j = 0;
while(counter < pop.size())
{
std::unique_lock<std::mutex> lock(m);
cvt.wait(lock, [this]() -> bool {return (int)idWaitingThread != -1;});
j = 0;
while (j < planning[idWaitingThread] && counter < pop.size())
{
popPackages[idWaitingThread].push_back(&pop[counter]);
counter++;
j++;
}
planning[idWaitingThread] *= 2;
idWaitingThread = -1;
cv.notify_one();
}
done = true;
idWaitingThread = -1;
cv.notify_all();
for(unsigned i = 0; i < workers.size(); i++)
workers[i].join();
}
template<class EOT>
void paradiseo::smp::Scheduler<EOT>::apply(eoUF<EOT&, void>& func, std::vector<EOT*>& pop, int id)
{
while(!done || !pop.empty())
{
for(unsigned i = 0; i < pop.size(); i++)
func(*pop[i]);
pop.clear();
std::unique_lock<std::mutex> lock(m);
idWaitingThread = id;
// We notify the scheduler we finished the package
cvt.notify_one();
// We wait for a new package
cv.wait(lock, [this]() -> bool {return (int)idWaitingThread == -1 || (bool)done;});
}
}

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