Migration from SVN

This commit is contained in:
quemy 2012-08-30 11:30:11 +02:00
commit 8cd56f37db
29069 changed files with 0 additions and 4096888 deletions

42
smp/src/CMakeLists.txt Normal file
View file

@ -0,0 +1,42 @@
######################################################################################
### 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 local/${LIB} COMPONENT libraries)
######################################################################################
### 3) Look for headers
######################################################################################
file(GLOB HDRS smp *.h)
install(FILES ${HDRS} DESTINATION local/include${INSTALL_SUB_DIR}/smp COMPONENT headers)
######################################################################################
### 4) Install directories
######################################################################################
install(DIRECTORY MWAlgo
DESTINATION local/include${INSTALL_SUB_DIR}/smp
COMPONENT headers
FILES_MATCHING PATTERN "*.h"
)

37
smp/src/MWAlgo/MWAlgo.h Normal file
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, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::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, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::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, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::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
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, class Policy>
template<class... Args>
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel (unsigned workersNb, Args&... args) :
EOAlgo<EOT>(args...),
scheduler(workersNb)
{ 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...)
{}
template<template <class> class EOAlgo, class EOT, class Policy>
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::~MWModel ()
{}
template<template <class> class EOAlgo, class EOT, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::apply(eoUF<EOT&, void>& func, eoPop<EOT>& pop)
{
scheduler(func, pop);
}
template<template <class> class EOAlgo, class EOT, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::evaluate(eoPop<EOT>& pop)
{
scheduler(this->eval, pop);
}
template<template <class> class EOAlgo, class EOT, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::operator()(eoPop<EOT>& pop)
{
// Call the tag dispatcher
operator()(pop,typename traits<EOAlgo,EOT>::type());
}
template<template <class> class EOAlgo, class EOT, class Policy>
void paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::operator()(eoPop<EOT>& pop, const error_tag&)
{
throw std::runtime_error("This is not a valid algorithm");
}

127
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 <algoDispatching.h>
#include <policiesDispatching.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 Policy = LinearPolicy>
class MWModel : public EOAlgo<EOT>
{
public:
/**
* Constructor
* @param workersNb the number of workers
* @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,Policy> scheduler;
};
#include <MWModel.cpp>
#include <MWAlgo/MWAlgo.h>
}
}
#endif

73
smp/src/algoDispatching.h Normal file
View file

@ -0,0 +1,73 @@
/*
<algoDispatching.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 ALGO_D_H_
#define ALGO_D_H_
#include <eo>
namespace paradiseo
{
namespace smp
{
/** Algo Dispatching
* The Algo Dispatching enable to choose the algorithm to call at compile time by tag-dispatching method
**/
// Main algorithms tags
struct error_tag {};
struct eoEasyEA_tag {};
struct eoEasyPSO_tag {};
struct eoSyncEasyPSO_tag {};
template<template <class> class A, class B>
struct traits {
typedef error_tag type;
};
template<class B>
struct traits<eoEasyEA,B> {
typedef eoEasyEA_tag type;
};
template<class B>
struct traits<eoEasyPSO,B> {
typedef eoEasyPSO_tag type;
};
template<class B>
struct traits<eoSyncEasyPSO,B> {
typedef eoSyncEasyPSO_tag type;
};
}
}
#endif

View file

@ -0,0 +1,61 @@
/*
<policiesDispatching.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 POLICIES_D_H_
#define POLICIES_D_H_
#include <eo>
namespace paradiseo
{
namespace smp
{
/** Policies Dispatching
* The Policies Dispatching enable to choose the policy to call at compile time by tag-dispatching method
**/
struct LinearPolicy {};
struct ProgressivePolicy {};
template<class B>
struct policyTraits {
typedef LinearPolicy type;
};
template<>
struct policyTraits<ProgressivePolicy> {
typedef ProgressivePolicy type;
};
}
}
#endif

148
smp/src/scheduler.cpp Normal file
View file

@ -0,0 +1,148 @@
/*
<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
*/
#include <typeinfo>
template<class EOT, class Policy>
paradiseo::smp::Scheduler<EOT,Policy>::Scheduler(unsigned workersNb) :
workers(workersNb),
popPackages(workersNb),
done(false),
planning(workersNb),
m(workersNb)
{ }
template<class EOT, class Policy>
paradiseo::smp::Scheduler<EOT,Policy>::~Scheduler()
{ }
template<class EOT, class Policy>
void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop)
{
// Call the tag dispatcher
operator()(func, pop,typename policyTraits<Policy>::type());
}
template<class EOT, class Policy>
void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop, const LinearPolicy&)
{
// Determine number of packages according to the number of workers
unsigned nbPackages = workers.size();
// Fill packages
unsigned nbIndi = pop.size() / nbPackages;
unsigned remaining = pop.size() % nbPackages;
unsigned indice = 0;
for(unsigned i = 0; i < nbPackages; i++)
{
popPackages[i].clear();
for(unsigned j = 0; j < nbIndi; j++)
{
popPackages[i].push_back(&pop[i*nbIndi+j]);
indice = i*nbIndi+j;
}
}
for(unsigned i = 0; i < remaining; i++)
popPackages[i].push_back(&pop[indice+i+1]);
// Starting threads
for(unsigned i = 0; i < workers.size(); i++)
workers[i].start(&Scheduler<EOT,Policy>::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();
}
template<class EOT, class Policy>
void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop, const ProgressivePolicy&)
{
done = false;
for(unsigned i = 0; i < workers.size(); i++)
{
planning[i] = 2;
workers[i].start(&Scheduler<EOT,Policy>::applyProgressivePolicy, this, std::ref(func), std::ref(popPackages[i]), i);
}
unsigned counter = 0;
unsigned j = 0;
while(counter < pop.size())
{
for(unsigned i = 0; i < workers.size(); i++)
{
if(popPackages[i].empty() && counter < pop.size())
{
j = 0;
std::unique_lock<std::mutex> lock(m[i]);
while (j < planning[i] && counter < pop.size())
{
//std::cout << counter << std::endl;
popPackages[i].push_back(&pop[counter]);
counter++;
j++;
}
planning[i] *= 2;
}
}
/* A nanosleep can increase performances by 10% but
as it is not supported by Fedora atm, I deactivate it. */
//std::this_thread::sleep_for(std::chrono::nanoseconds(10));
}
done = true;
for(unsigned i = 0; i < workers.size(); i++)
workers[i].join();
}
template<class EOT, class Policy>
void paradiseo::smp::Scheduler<EOT,Policy>::applyLinearPolicy(eoUF<EOT&, void>& func, std::vector<EOT*>& pop)
{
for(unsigned i = 0; i < pop.size(); i++)
func(*pop[i]);
}
template<class EOT, class Policy>
void paradiseo::smp::Scheduler<EOT,Policy>::applyProgressivePolicy(eoUF<EOT&, void>& func, std::vector<EOT*>& pop, int id)
{
while(!done || !pop.empty())
{
std::unique_lock<std::mutex> lock(m[id]);
for(unsigned i = 0; i < pop.size(); i++) {
//std::cout << "." << id << "." << std::endl;
func(*pop[i]);
}
pop.clear();
lock.unlock();
}
}

121
smp/src/scheduler.h Normal file
View file

@ -0,0 +1,121 @@
/*
<scheduler.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 SCHEDULER_H_
#define SCHEDULER_H_
#include <iostream>
#include <vector>
#include <atomic>
#include <mutex>
#include <thread.h>
#include <policiesDispatching.h>
#include <eoEvalFunc.h>
#include <eoPop.h>
namespace paradiseo
{
namespace smp
{
/**
A scheduler class
*/
template<class EOT, class Policy = LinearPolicy>
class Scheduler
{
public:
/**
* Constructor
* @param workersNb number of workers to perform tasks
*/
Scheduler(unsigned workersNb);
/**
* Destructor
*/
~Scheduler();
/**
* Start an unary functor on workers on all the pop
* @param func unary functor
* @param pop reference to the population
*/
void operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop);
protected:
/**
* Perform scheduling with a linear policy
*/
void operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop, const LinearPolicy&);
/**
* Perform scheduling with a linear policy
*/
void operator()(eoUF<EOT&, void>& func, eoPop<EOT>& pop, const ProgressivePolicy&);
/**
* Apply an unary functor on a sub-group of population
* @param func unary functor
* @param pop reference to the sub-group
*/
void applyLinearPolicy(eoUF<EOT&, void>& func, std::vector<EOT*>& pop);
/**
* Apply an unary functor on a sub-group of population
* @param func unary functor
* @param pop reference to the sub-group
* @param id id of the thread
*/
void applyProgressivePolicy(eoUF<EOT&, void>& func, std::vector<EOT*>& pop, int id);
/**
* Create sub-groups with similar size from a population.
* @param pop reference to the pop
*/
std::vector<std::vector<EOT*>> subGroups(eoPop<EOT>& pop);
std::vector<Thread> workers;
std::vector<std::vector<EOT*>> popPackages;
std::atomic<bool> done;
std::vector<unsigned> planning;
std::vector<std::atomic<int>> isWorking;
std::vector<std::mutex> m;
};
#include <scheduler.cpp>
}
}
#endif /*SCHEDULER_H_*/

35
smp/src/smp Normal file
View file

@ -0,0 +1,35 @@
/*
<smp>
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 SMP_INCLUDE
#define SMP_INCLUDE
#include <smp.h>
#endif

37
smp/src/smp.h Normal file
View file

@ -0,0 +1,37 @@
/*
<smp.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 SMP_H
#define SMP_H
#include <thread.h>
#include <MWModel.h>
#include <scheduler.h>
#endif

73
smp/src/thread.cpp Normal file
View file

@ -0,0 +1,73 @@
/*
<thread.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
*/
#include <algorithm>
#include <utility>
#include <thread.h>
namespace paradiseo
{
namespace smp
{
Thread::Thread(Thread&& other)
{
t = std::move(other.t);
}
Thread& Thread::operator=(Thread&& other)
{
t = std::move(other.t);
return *this;
}
const std::thread::id paradiseo::smp::Thread::getId() const
{
return t.get_id();
}
bool paradiseo::smp::Thread::joinable() const
{
return t.joinable();
}
void paradiseo::smp::Thread::join()
{
t.join();
}
int paradiseo::smp::Thread::hardware_concurrency()
{
return std::thread::hardware_concurrency();
}
}
}

112
smp/src/thread.h Normal file
View file

@ -0,0 +1,112 @@
/*
<thread.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 THREAD_H_
#define THREAD_H_
#include <iostream>
#include <thread>
#include <vector>
namespace paradiseo
{
namespace smp
{
/**
A thread class which encapsulate the std::thread behaviour for more flexibility
@see smp::Worker, smp::MWModel
*/
class Thread
{
public:
/**
* Default constructor
*/
Thread() = default;
/**
* Constructor that will immediatly start the thread
* @param f represente any callable object such as function or class method
* @param args... reference object and parameters for f
*/
template< class Callable, class... Args >
explicit Thread(Callable&& f, Args&&... args) : t(std::thread(std::forward<Callable>(f), std::forward<Args>(args)...)) {}
Thread(Thread&& other);
Thread(const Thread&) = delete;
Thread& operator=(const Thread&) = delete;
virtual ~Thread() = default;
Thread& operator=(Thread&& other);
/**
* Start the thread according to parameters
* If the thread is running, it will wait until the end of its task
* @param f represente any callable object such as function or class method
* @param args... reference object and parameters for f
*/
template<class Callable,class... Args>
void start(Callable&& f,Args&&... args);
/**
* Get the id of the thread
* @return id of the thread
*/
const std::thread::id getId() const;
/**
* Get the state of the thread
* @return true if the thread is running, false otherwise
*/
bool joinable() const;
/**
* Wait until the end of the task
*/
void join();
static int hardware_concurrency();
protected:
std::thread t;
};
template<class Callable,class... Args>
void paradiseo::smp::Thread::start(Callable&& f,Args&&... args)
{
t = std::thread(std::forward<Callable>(f), std::forward<Args>(args)...);
}
}
}
#endif /*THREAD_H_*/