Add notifier and delete Thread class
This commit is contained in:
parent
23a0b8f77b
commit
3196ba2bcf
10 changed files with 8 additions and 256 deletions
|
|
@ -17,7 +17,6 @@ set(LIBRARY_OUTPUT_PATH ${SMP_LIB_OUTPUT_PATH})
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
set (SMP_FILE
|
set (SMP_FILE
|
||||||
thread.cpp
|
|
||||||
MWModel.h
|
MWModel.h
|
||||||
scheduler.h
|
scheduler.h
|
||||||
island.h
|
island.h
|
||||||
|
|
@ -28,6 +27,7 @@ set (SMP_FILE
|
||||||
topology/star.cpp
|
topology/star.cpp
|
||||||
topology/ring.cpp
|
topology/ring.cpp
|
||||||
topology/hypercubic.cpp
|
topology/hypercubic.cpp
|
||||||
|
notifier.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(smp STATIC ${SMP_FILE})
|
add_library(smp STATIC ${SMP_FILE})
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(unsigned workersNb, Args&...
|
||||||
template<template <class> class EOAlgo, class EOT, class Policy>
|
template<template <class> class EOAlgo, class EOT, class Policy>
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(Args&... args) :
|
paradiseo::smp::MWModel<EOAlgo,EOT,Policy>::MWModel(Args&... args) :
|
||||||
MWModel(Thread::hardware_concurrency(), args...)
|
MWModel(std::thread::hardware_concurrency(), args...)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<template <class> class EOAlgo, class EOT, class Policy>
|
template<template <class> class EOAlgo, class EOT, class Policy>
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#define MWMODEL_H_
|
#define MWMODEL_H_
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <algoDispatching.h>
|
#include <algoDispatching.h>
|
||||||
|
|
@ -113,7 +114,7 @@ protected:
|
||||||
*/
|
*/
|
||||||
void operator()(eoPop<EOT>& pop,const error_tag&);
|
void operator()(eoPop<EOT>& pop,const error_tag&);
|
||||||
|
|
||||||
std::vector<Thread*> workers;
|
std::vector<std::thread*> workers;
|
||||||
Scheduler<EOT,Policy> scheduler;
|
Scheduler<EOT,Policy> scheduler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
Contact: paradiseo-help@lists.gforge.inria.fr
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
template<class EOT, class Policy>
|
template<class EOT, class Policy>
|
||||||
paradiseo::smp::Scheduler<EOT,Policy>::Scheduler(unsigned workersNb) :
|
paradiseo::smp::Scheduler<EOT,Policy>::Scheduler(unsigned workersNb) :
|
||||||
workers(workersNb),
|
workers(workersNb),
|
||||||
|
|
@ -75,7 +73,7 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
||||||
|
|
||||||
// Starting threads
|
// Starting threads
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
workers[i].start(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyLinearPolicy, this, std::ref(func), std::ref(popPackages[i]));
|
||||||
|
|
||||||
// Wait the end of tasks
|
// Wait the end of tasks
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
|
|
@ -90,7 +88,7 @@ void paradiseo::smp::Scheduler<EOT,Policy>::operator()(eoUF<EOT&, void>& func, e
|
||||||
for(unsigned i = 0; i < workers.size(); i++)
|
for(unsigned i = 0; i < workers.size(); i++)
|
||||||
{
|
{
|
||||||
planning[i] = 2;
|
planning[i] = 2;
|
||||||
workers[i].start(&Scheduler<EOT,Policy>::applyProgressivePolicy, this, std::ref(func), std::ref(popPackages[i]), i);
|
workers[i] = std::thread(&Scheduler<EOT,Policy>::applyProgressivePolicy, this, std::ref(func), std::ref(popPackages[i]), i);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned counter = 0;
|
unsigned counter = 0;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include <thread.h>
|
|
||||||
#include <policiesDispatching.h>
|
#include <policiesDispatching.h>
|
||||||
|
|
||||||
#include <eoEvalFunc.h>
|
#include <eoEvalFunc.h>
|
||||||
|
|
@ -106,7 +105,7 @@ protected:
|
||||||
*/
|
*/
|
||||||
std::vector<std::vector<EOT*>> subGroups(eoPop<EOT>& pop);
|
std::vector<std::vector<EOT*>> subGroups(eoPop<EOT>& pop);
|
||||||
|
|
||||||
std::vector<Thread> workers;
|
std::vector<std::thread> workers;
|
||||||
std::vector<std::vector<EOT*>> popPackages;
|
std::vector<std::vector<EOT*>> popPackages;
|
||||||
|
|
||||||
std::atomic<bool> done;
|
std::atomic<bool> done;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#ifndef SMP_H
|
#ifndef SMP_H
|
||||||
#define SMP_H
|
#define SMP_H
|
||||||
|
|
||||||
#include <thread.h>
|
|
||||||
#include <MWModel.h>
|
#include <MWModel.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <islandModel.h>
|
#include <islandModel.h>
|
||||||
|
|
@ -40,6 +39,7 @@ Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
#include <intPolicy.h>
|
#include <intPolicy.h>
|
||||||
#include <policyElement.h>
|
#include <policyElement.h>
|
||||||
#include <islandNotifier.h>
|
#include <islandNotifier.h>
|
||||||
|
#include <notifier.h>
|
||||||
|
|
||||||
// Topologies
|
// Topologies
|
||||||
#include <topology/topology.h>
|
#include <topology/topology.h>
|
||||||
|
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
<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
112
smp/src/thread.h
|
|
@ -1,112 +0,0 @@
|
||||||
/*
|
|
||||||
<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_*/
|
|
||||||
|
|
@ -11,7 +11,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
|
||||||
set (TEST_LIST
|
set (TEST_LIST
|
||||||
t-smpThread
|
|
||||||
t-smpScheduler
|
t-smpScheduler
|
||||||
t-smpMW_eoEasyEA
|
t-smpMW_eoEasyEA
|
||||||
t-smpMW_eoEasyPSO
|
t-smpMW_eoEasyPSO
|
||||||
|
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
#include <cassert>
|
|
||||||
#include <vector>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
#include <smp>
|
|
||||||
|
|
||||||
#include "smpTestClass.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace paradiseo::smp;
|
|
||||||
|
|
||||||
void f(std::atomic<int> &x)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < 100; i++) {
|
|
||||||
cout << x << endl;
|
|
||||||
x++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void g(std::atomic<int> &x)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < 100; i++)
|
|
||||||
x--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void foo()
|
|
||||||
{
|
|
||||||
std::cout << "Foo" << std::endl;
|
|
||||||
//std::this_thread::sleep_for(std::chrono::seconds(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
//---------------------------------------------------
|
|
||||||
std::atomic<int> nb(0);
|
|
||||||
|
|
||||||
Thread t1(&f,std::ref(nb));
|
|
||||||
Thread t2(&g,std::ref(nb));
|
|
||||||
|
|
||||||
t1.join();
|
|
||||||
t2.join();
|
|
||||||
|
|
||||||
assert(nb == 0); // Test atomic_barrier
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
try
|
|
||||||
{
|
|
||||||
t1.start(foo);
|
|
||||||
|
|
||||||
t1.join();
|
|
||||||
}
|
|
||||||
catch(exception& e)
|
|
||||||
{
|
|
||||||
cout << "Exception: " << e.what() << '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue