Style for PEO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@906 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f4740e571c
commit
b74a446baa
82 changed files with 1946 additions and 1663 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <communicable.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,7 +47,8 @@ static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of regist
|
|||
unsigned Communicable :: num_comm = 0;
|
||||
|
||||
|
||||
Communicable :: Communicable () {
|
||||
Communicable :: Communicable ()
|
||||
{
|
||||
|
||||
comm_to_key [this] = key = ++ num_comm;
|
||||
key_to_comm.push_back (this);
|
||||
|
|
@ -55,46 +56,54 @@ Communicable :: Communicable () {
|
|||
sem_init (& sem_stop, 0, 0);
|
||||
}
|
||||
|
||||
Communicable :: ~ Communicable () {
|
||||
|
||||
Communicable :: ~ Communicable ()
|
||||
{
|
||||
}
|
||||
|
||||
COMM_ID Communicable :: getKey () {
|
||||
COMM_ID Communicable :: getKey ()
|
||||
{
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
Communicable * getCommunicable (COMM_ID __key) {
|
||||
Communicable * getCommunicable (COMM_ID __key)
|
||||
{
|
||||
|
||||
assert (__key < key_to_comm.size ());
|
||||
return key_to_comm [__key];
|
||||
return key_to_comm [__key];
|
||||
}
|
||||
|
||||
COMM_ID getKey (const Communicable * __comm) {
|
||||
COMM_ID getKey (const Communicable * __comm)
|
||||
{
|
||||
|
||||
return comm_to_key [__comm];
|
||||
}
|
||||
|
||||
void Communicable :: lock () {
|
||||
void Communicable :: lock ()
|
||||
{
|
||||
|
||||
sem_wait (& sem_lock);
|
||||
}
|
||||
sem_wait (& sem_lock);
|
||||
}
|
||||
|
||||
void Communicable :: unlock () {
|
||||
void Communicable :: unlock ()
|
||||
{
|
||||
|
||||
sem_post (& sem_lock);
|
||||
}
|
||||
|
||||
void Communicable :: stop () {
|
||||
void Communicable :: stop ()
|
||||
{
|
||||
sem_wait (& sem_stop);
|
||||
}
|
||||
|
||||
void Communicable :: resume () {
|
||||
void Communicable :: resume ()
|
||||
{
|
||||
|
||||
sem_post (& sem_stop);
|
||||
}
|
||||
|
||||
void initCommunicableEnv () {
|
||||
void initCommunicableEnv ()
|
||||
{
|
||||
|
||||
key_to_comm.resize (1);
|
||||
comm_to_key.clear ();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <communicable.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,37 +42,38 @@
|
|||
|
||||
typedef unsigned COMM_ID;
|
||||
|
||||
class Communicable {
|
||||
class Communicable
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
Communicable ();
|
||||
Communicable ();
|
||||
|
||||
virtual ~ Communicable ();
|
||||
virtual ~ Communicable ();
|
||||
|
||||
COMM_ID getKey ();
|
||||
COMM_ID getKey ();
|
||||
|
||||
void lock (); /* It suspends the current process if the semaphore is locked */
|
||||
void unlock (); /* It unlocks the shared semaphore */
|
||||
void lock (); /* It suspends the current process if the semaphore is locked */
|
||||
void unlock (); /* It unlocks the shared semaphore */
|
||||
|
||||
void stop (); /* It suspends the current process */
|
||||
void resume (); /* It resumes ___________ */
|
||||
void stop (); /* It suspends the current process */
|
||||
void resume (); /* It resumes ___________ */
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
static unsigned num_comm;
|
||||
static unsigned num_comm;
|
||||
|
||||
protected :
|
||||
protected :
|
||||
|
||||
COMM_ID key;
|
||||
COMM_ID key;
|
||||
|
||||
sem_t sem_lock;
|
||||
sem_t sem_lock;
|
||||
|
||||
sem_t sem_stop;
|
||||
};
|
||||
sem_t sem_stop;
|
||||
};
|
||||
|
||||
extern void initCommunicableEnv ();
|
||||
|
||||
extern Communicable * getCommunicable (COMM_ID __key);
|
||||
extern Communicable * getCommunicable (COMM_ID __key);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <cooperative.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,38 +43,39 @@
|
|||
|
||||
typedef unsigned COOP_ID;
|
||||
|
||||
class Cooperative : public Communicable {
|
||||
class Cooperative : public Communicable
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
Runner * getOwner ();
|
||||
Runner * getOwner ();
|
||||
|
||||
void setOwner (Runner & __runner);
|
||||
void setOwner (Runner & __runner);
|
||||
|
||||
virtual void pack () = 0;
|
||||
virtual void pack () = 0;
|
||||
|
||||
virtual void unpack () = 0;
|
||||
virtual void unpack () = 0;
|
||||
|
||||
virtual void packSynchronizeReq () = 0;
|
||||
virtual void packSynchronizeReq () = 0;
|
||||
|
||||
void send (Cooperative * __coop);
|
||||
void send (Cooperative * __coop);
|
||||
|
||||
void synchronizeCoopEx ();
|
||||
void synchronizeCoopEx ();
|
||||
|
||||
virtual void notifySending ();
|
||||
virtual void notifySending ();
|
||||
|
||||
virtual void notifyReceiving ();
|
||||
virtual void notifyReceiving ();
|
||||
|
||||
virtual void notifySendingSyncReq ();
|
||||
virtual void notifySendingSyncReq ();
|
||||
|
||||
virtual void notifySynchronized ();
|
||||
virtual void notifySynchronized ();
|
||||
|
||||
private :
|
||||
private :
|
||||
|
||||
Runner * owner;
|
||||
Runner * owner;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
extern Cooperative * getCooperative (COOP_ID __key);
|
||||
extern Cooperative * getCooperative (COOP_ID __key);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <eoPop_comm.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,14 +42,16 @@
|
|||
#include "messaging.h"
|
||||
|
||||
|
||||
template <class EOT> void pack (const eoPop <EOT> & __pop) {
|
||||
template <class EOT> void pack (const eoPop <EOT> & __pop)
|
||||
{
|
||||
|
||||
pack ((unsigned) __pop.size ());
|
||||
for (unsigned i = 0; i < __pop.size (); i ++)
|
||||
pack (__pop [i]);
|
||||
}
|
||||
|
||||
template <class EOT> void unpack (eoPop <EOT> & __pop) {
|
||||
template <class EOT> void unpack (eoPop <EOT> & __pop)
|
||||
{
|
||||
|
||||
unsigned n;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <eoVector_comm.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,34 +43,41 @@
|
|||
#include "messaging.h"
|
||||
|
||||
|
||||
template <class F, class T> void pack (const eoVector <F, T> & __v) {
|
||||
template <class F, class T> void pack (const eoVector <F, T> & __v)
|
||||
{
|
||||
|
||||
if (__v.invalid()) {
|
||||
pack((unsigned)0);
|
||||
}
|
||||
else {
|
||||
pack((unsigned)1);
|
||||
pack (__v.fitness ());
|
||||
}
|
||||
if (__v.invalid())
|
||||
{
|
||||
pack((unsigned)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
pack((unsigned)1);
|
||||
pack (__v.fitness ());
|
||||
}
|
||||
|
||||
unsigned len = __v.size ();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (__v [i]);
|
||||
pack (__v [i]);
|
||||
}
|
||||
|
||||
template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
||||
template <class F, class T> void unpack (eoVector <F, T> & __v)
|
||||
{
|
||||
|
||||
unsigned valid; unpack(valid);
|
||||
unsigned valid;
|
||||
unpack(valid);
|
||||
|
||||
if (! valid) {
|
||||
__v.invalidate();
|
||||
}
|
||||
else {
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
}
|
||||
if (! valid)
|
||||
{
|
||||
__v.invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
}
|
||||
|
||||
unsigned len;
|
||||
unpack (len);
|
||||
|
|
@ -79,125 +86,132 @@ template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
|||
unpack (__v [i]);
|
||||
}
|
||||
|
||||
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) {
|
||||
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v)
|
||||
{
|
||||
|
||||
if (__v.invalid()) {
|
||||
pack((unsigned)0);
|
||||
}
|
||||
else {
|
||||
pack((unsigned)1);
|
||||
pack (__v.fitness ());
|
||||
pack (__v.best());
|
||||
}
|
||||
if (__v.invalid())
|
||||
{
|
||||
pack((unsigned)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
pack((unsigned)1);
|
||||
pack (__v.fitness ());
|
||||
pack (__v.best());
|
||||
}
|
||||
|
||||
unsigned len = __v.size ();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (__v [i]);
|
||||
pack (__v [i]);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (__v.bestPositions[i]);
|
||||
pack (__v.bestPositions[i]);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (__v.velocities[i]);
|
||||
pack (__v.velocities[i]);
|
||||
}
|
||||
|
||||
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v) {
|
||||
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v)
|
||||
{
|
||||
|
||||
unsigned valid; unpack(valid);
|
||||
unsigned valid;
|
||||
unpack(valid);
|
||||
|
||||
if (! valid) {
|
||||
__v.invalidate();
|
||||
}
|
||||
else {
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
if (! valid)
|
||||
{
|
||||
__v.invalidate();
|
||||
}
|
||||
else
|
||||
{
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
unpack(fit);
|
||||
__v.best(fit);
|
||||
|
||||
}
|
||||
__v.best(fit);
|
||||
|
||||
}
|
||||
unsigned len;
|
||||
unpack (len);
|
||||
__v.resize (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (__v [i]);
|
||||
unpack (__v [i]);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (__v.bestPositions[i]);
|
||||
unpack (__v.bestPositions[i]);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (__v.velocities[i]);
|
||||
unpack (__v.velocities[i]);
|
||||
}
|
||||
|
||||
template <class F, class T, class V, class W> void unpack (moeoVector <F,T,V,W> &_v)
|
||||
template <class F, class T, class V, class W> void unpack (moeoVector <F,T,V,W> &_v)
|
||||
{
|
||||
unsigned valid;
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidate();
|
||||
else
|
||||
unsigned valid;
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidate();
|
||||
else
|
||||
{
|
||||
T fit;
|
||||
unpack (fit);
|
||||
_v.fitness (fit);
|
||||
}
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidateDiversity();
|
||||
else
|
||||
{
|
||||
V diver;
|
||||
unpack(diver);
|
||||
_v.diversity(diver);
|
||||
T fit;
|
||||
unpack (fit);
|
||||
_v.fitness (fit);
|
||||
}
|
||||
unsigned len;
|
||||
unpack (len);
|
||||
_v.resize (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (_v [i]);
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidateObjectiveVector();
|
||||
else
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidateDiversity();
|
||||
else
|
||||
{
|
||||
F object;
|
||||
unpack (len);
|
||||
object.resize(len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (object[i]);
|
||||
_v.objectiveVector(object);
|
||||
V diver;
|
||||
unpack(diver);
|
||||
_v.diversity(diver);
|
||||
}
|
||||
unsigned len;
|
||||
unpack (len);
|
||||
_v.resize (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (_v [i]);
|
||||
unpack(valid);
|
||||
if (! valid)
|
||||
_v.invalidateObjectiveVector();
|
||||
else
|
||||
{
|
||||
F object;
|
||||
unpack (len);
|
||||
object.resize(len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (object[i]);
|
||||
_v.objectiveVector(object);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <class F, class T, class V, class W> void pack (moeoVector <F,T,V,W> &_v)
|
||||
template <class F, class T, class V, class W> void pack (moeoVector <F,T,V,W> &_v)
|
||||
{
|
||||
if (_v.invalid())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
if (_v.invalid())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
{
|
||||
pack((unsigned)1);
|
||||
pack (_v.fitness ());
|
||||
pack((unsigned)1);
|
||||
pack (_v.fitness ());
|
||||
}
|
||||
if (_v.invalidDiversity())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
if (_v.invalidDiversity())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
{
|
||||
pack((unsigned)1);
|
||||
pack(_v.diversity());
|
||||
pack((unsigned)1);
|
||||
pack(_v.diversity());
|
||||
}
|
||||
unsigned len = _v.size ();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (_v[i]);
|
||||
if (_v.invalidObjectiveVector())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
unsigned len = _v.size ();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (_v[i]);
|
||||
if (_v.invalidObjectiveVector())
|
||||
pack((unsigned)0);
|
||||
else
|
||||
{
|
||||
pack((unsigned)1);
|
||||
F object;
|
||||
object=_v.objectiveVector();
|
||||
len=object.nObjectives();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (object[i]);
|
||||
pack((unsigned)1);
|
||||
F object;
|
||||
object=_v.objectiveVector();
|
||||
len=object.nObjectives();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (object[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <messaging.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -47,41 +47,43 @@ extern void pack (const char & __c);
|
|||
extern void pack (const bool & __b, int __nitem = 1);
|
||||
|
||||
/* Float */
|
||||
extern void pack (const float & __f, int __nitem = 1);
|
||||
extern void pack (const float & __f, int __nitem = 1);
|
||||
|
||||
/* Double */
|
||||
extern void pack (const double & __d, int __nitem = 1);
|
||||
extern void pack (const double & __d, int __nitem = 1);
|
||||
|
||||
/* Integer */
|
||||
extern void pack (const int & __i, int __nitem = 1);
|
||||
extern void pack (const int & __i, int __nitem = 1);
|
||||
|
||||
/* Unsigned int. */
|
||||
extern void pack (const unsigned int & __ui, int __nitem = 1);
|
||||
extern void pack (const unsigned int & __ui, int __nitem = 1);
|
||||
|
||||
/* Short int. */
|
||||
extern void pack (const short & __sh, int __nitem = 1);
|
||||
extern void pack (const short & __sh, int __nitem = 1);
|
||||
|
||||
/* Unsigned short */
|
||||
extern void pack (const unsigned short & __ush, int __nitem = 1);
|
||||
|
||||
/* Long */
|
||||
extern void pack (const long & __l, int __nitem = 1);
|
||||
extern void pack (const long & __l, int __nitem = 1);
|
||||
|
||||
/* Unsigned long */
|
||||
extern void pack (const unsigned long & __ul, int __nitem = 1);
|
||||
extern void pack (const unsigned long & __ul, int __nitem = 1);
|
||||
|
||||
/* String */
|
||||
extern void pack (const char * __str);
|
||||
extern void pack (const std::string & __str);
|
||||
|
||||
/* Pointer */
|
||||
template <class T> void pack (const T * __ptr) {
|
||||
template <class T> void pack (const T * __ptr)
|
||||
{
|
||||
|
||||
pack ((unsigned long) __ptr);
|
||||
pack ((unsigned long) __ptr);
|
||||
}
|
||||
|
||||
/* Pair */
|
||||
template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
|
||||
template <class U, class V> void pack (const std :: pair <U, V> & __pair)
|
||||
{
|
||||
|
||||
pack (__pair.first);
|
||||
pack (__pair.second);
|
||||
|
|
@ -90,41 +92,42 @@ template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
|
|||
|
||||
|
||||
/* Char */
|
||||
extern void unpack (char & __c);
|
||||
extern void unpack (char & __c);
|
||||
|
||||
/* Boolean */
|
||||
extern void unpack (bool & __b, int __nitem = 1);
|
||||
|
||||
/* Float */
|
||||
extern void unpack (float & __f, int __nitem = 1);
|
||||
extern void unpack (float & __f, int __nitem = 1);
|
||||
|
||||
/* Double */
|
||||
extern void unpack (double & __d, int __nitem = 1);
|
||||
extern void unpack (double & __d, int __nitem = 1);
|
||||
|
||||
/* Integer */
|
||||
extern void unpack (int & __i, int __nitem = 1);
|
||||
extern void unpack (int & __i, int __nitem = 1);
|
||||
|
||||
/* Unsigned int. */
|
||||
extern void unpack (unsigned int & __ui, int __nitem = 1);
|
||||
extern void unpack (unsigned int & __ui, int __nitem = 1);
|
||||
|
||||
/* Short int. */
|
||||
extern void unpack (short & __sh, int __nitem = 1);
|
||||
extern void unpack (short & __sh, int __nitem = 1);
|
||||
|
||||
/* Unsigned short */
|
||||
extern void unpack (unsigned short & __ush, int __nitem = 1);
|
||||
|
||||
/* Long */
|
||||
extern void unpack (long & __l, int __nitem = 1);
|
||||
extern void unpack (long & __l, int __nitem = 1);
|
||||
|
||||
/* Unsigned long */
|
||||
extern void unpack (unsigned long & __ul, int __nitem = 1);
|
||||
extern void unpack (unsigned long & __ul, int __nitem = 1);
|
||||
|
||||
/* String */
|
||||
extern void unpack (char * __str);
|
||||
extern void unpack (char * __str);
|
||||
extern void unpack (std::string & __str);
|
||||
|
||||
/* Pointer */
|
||||
template <class T> void unpack (T * & __ptr) {
|
||||
template <class T> void unpack (T * & __ptr)
|
||||
{
|
||||
|
||||
unsigned long p;
|
||||
unpack (p);
|
||||
|
|
@ -132,7 +135,8 @@ template <class T> void unpack (T * & __ptr) {
|
|||
}
|
||||
|
||||
/* Pair */
|
||||
template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
|
||||
template <class U, class V> void unpack (std :: pair <U, V> & __pair)
|
||||
{
|
||||
|
||||
unpack (__pair.first);
|
||||
unpack (__pair.second);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_debug.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -58,7 +58,8 @@ static char host [MAX_BUFF_SIZE];
|
|||
std :: vector <FILE *> files;
|
||||
|
||||
|
||||
void setDebugMode (bool __dbg) {
|
||||
void setDebugMode (bool __dbg)
|
||||
{
|
||||
|
||||
debug = __dbg;
|
||||
gethostname (host, MAX_BUFF_SIZE);
|
||||
|
|
@ -66,7 +67,8 @@ void setDebugMode (bool __dbg) {
|
|||
|
||||
extern int getNodeRank ();
|
||||
|
||||
void initDebugging () {
|
||||
void initDebugging ()
|
||||
{
|
||||
|
||||
mkdir (DEBUG_PATH, S_IRWXU);
|
||||
// files.push_back (stdout);
|
||||
|
|
@ -75,7 +77,8 @@ void initDebugging () {
|
|||
files.push_back (fopen (buff, "w"));
|
||||
}
|
||||
|
||||
void endDebugging () {
|
||||
void endDebugging ()
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < files.size (); i ++)
|
||||
if (files [i] != stdout)
|
||||
|
|
@ -83,29 +86,32 @@ void endDebugging () {
|
|||
files.clear();
|
||||
}
|
||||
|
||||
void printDebugMessage (const char * __mess) {
|
||||
void printDebugMessage (const char * __mess)
|
||||
{
|
||||
|
||||
if (debug) {
|
||||
if (debug)
|
||||
{
|
||||
|
||||
char buff [MAX_BUFF_SIZE];
|
||||
char localTime [MAX_BUFF_SIZE];
|
||||
time_t t = time (0);
|
||||
char buff [MAX_BUFF_SIZE];
|
||||
char localTime [MAX_BUFF_SIZE];
|
||||
time_t t = time (0);
|
||||
|
||||
/* Date */
|
||||
strcpy( localTime, ctime (& t) );
|
||||
localTime[ strlen( localTime )-1 ] = ']';
|
||||
sprintf (buff, "[%s][%s: ", host, localTime );
|
||||
/* Date */
|
||||
strcpy( localTime, ctime (& t) );
|
||||
localTime[ strlen( localTime )-1 ] = ']';
|
||||
sprintf (buff, "[%s][%s: ", host, localTime );
|
||||
|
||||
for (unsigned i = 0; i < files.size (); i ++)
|
||||
fprintf (files [i], buff);
|
||||
for (unsigned i = 0; i < files.size (); i ++)
|
||||
fprintf (files [i], buff);
|
||||
|
||||
/* Message */
|
||||
sprintf (buff, "%s", __mess);
|
||||
/* Message */
|
||||
sprintf (buff, "%s", __mess);
|
||||
|
||||
for (unsigned i = 0; i < files.size (); i ++) {
|
||||
fputs (buff, files [i]);
|
||||
fputs ("\n", files [i]);
|
||||
fflush (files [i]);
|
||||
for (unsigned i = 0; i < files.size (); i ++)
|
||||
{
|
||||
fputs (buff, files [i]);
|
||||
fputs ("\n", files [i]);
|
||||
fflush (files [i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_debug.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_fin.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,7 +39,8 @@
|
|||
#include "runner.h"
|
||||
#include "rmc.h"
|
||||
|
||||
void peo :: finalize () {
|
||||
void peo :: finalize ()
|
||||
{
|
||||
|
||||
printDebugMessage ("waiting for the termination of all threads");
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_fin.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,7 +37,8 @@
|
|||
#ifndef __peo_finalize_h
|
||||
#define __peo_finalize_h
|
||||
|
||||
namespace peo {
|
||||
namespace peo
|
||||
{
|
||||
|
||||
extern void finalize ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -57,7 +57,8 @@ extern void initScheduler ();
|
|||
extern void initSynchron ();
|
||||
|
||||
|
||||
static void initExecutionEnv() {
|
||||
static void initExecutionEnv()
|
||||
{
|
||||
|
||||
initCommunicableEnv ();
|
||||
initBuffers ();
|
||||
|
|
@ -72,13 +73,15 @@ static void initExecutionEnv() {
|
|||
}
|
||||
|
||||
|
||||
namespace peo {
|
||||
namespace peo
|
||||
{
|
||||
|
||||
int * argc;
|
||||
|
||||
char * * * argv;
|
||||
|
||||
void init (int & __argc, char * * & __argv) {
|
||||
void init (int & __argc, char * * & __argv)
|
||||
{
|
||||
|
||||
argc = & __argc;
|
||||
|
||||
|
|
@ -87,7 +90,7 @@ namespace peo {
|
|||
/* Initializing the execution environment */
|
||||
initExecutionEnv();
|
||||
|
||||
/* Loading the common parameters */
|
||||
/* Loading the common parameters */
|
||||
loadParameters (__argc, __argv);
|
||||
|
||||
/* Initializing the the Resource Management and Communication */
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,7 +37,8 @@
|
|||
#ifndef __peo_init_h
|
||||
#define __peo_init_h
|
||||
|
||||
namespace peo {
|
||||
namespace peo
|
||||
{
|
||||
|
||||
extern int * argc;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_param.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,7 +40,8 @@
|
|||
#include "peo_debug.h"
|
||||
|
||||
|
||||
void peo :: loadParameters (int & __argc, char * * & __argv) {
|
||||
void peo :: loadParameters (int & __argc, char * * & __argv)
|
||||
{
|
||||
|
||||
eoParser parser (__argc, __argv);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_param.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,7 +37,8 @@
|
|||
#ifndef __peo_param_h
|
||||
#define __peo_param_h
|
||||
|
||||
namespace peo {
|
||||
namespace peo
|
||||
{
|
||||
|
||||
extern void loadParameters (int & __argc, char * * & __argv);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_run.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,7 +39,8 @@
|
|||
#include "runner.h"
|
||||
|
||||
|
||||
void peo :: run () {
|
||||
void peo :: run ()
|
||||
{
|
||||
|
||||
startRunners ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <peo_run.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,7 +37,8 @@
|
|||
#ifndef __peo_run_h
|
||||
#define __peo_run_h
|
||||
|
||||
namespace peo {
|
||||
namespace peo
|
||||
{
|
||||
|
||||
extern void run ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <reac_thread.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,29 +41,34 @@ static bool the_end = false;
|
|||
static std :: vector <ReactiveThread *> reac_threads;
|
||||
|
||||
|
||||
ReactiveThread :: ReactiveThread () {
|
||||
ReactiveThread :: ReactiveThread ()
|
||||
{
|
||||
|
||||
reac_threads.push_back (this);
|
||||
sem_init (& sem, 0, 0);
|
||||
}
|
||||
|
||||
void ReactiveThread :: sleep () {
|
||||
void ReactiveThread :: sleep ()
|
||||
{
|
||||
|
||||
sem_wait (& sem);
|
||||
sem_wait (& sem);
|
||||
}
|
||||
|
||||
void ReactiveThread :: wakeUp () {
|
||||
void ReactiveThread :: wakeUp ()
|
||||
{
|
||||
|
||||
sem_post (& sem);
|
||||
sem_post (& sem);
|
||||
}
|
||||
|
||||
void initReactiveThreadsEnv () {
|
||||
void initReactiveThreadsEnv ()
|
||||
{
|
||||
|
||||
the_end = false;
|
||||
reac_threads.clear ();
|
||||
}
|
||||
|
||||
void stopReactiveThreads () {
|
||||
void stopReactiveThreads ()
|
||||
{
|
||||
|
||||
the_end = true;
|
||||
for (unsigned i = 0; i < reac_threads.size (); i ++)
|
||||
|
|
@ -71,4 +76,7 @@ void stopReactiveThreads () {
|
|||
reac_threads.clear ();
|
||||
}
|
||||
|
||||
bool theEnd () { return the_end; }
|
||||
bool theEnd ()
|
||||
{
|
||||
return the_end;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <reac_thread.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,21 +42,22 @@
|
|||
#include "thread.h"
|
||||
|
||||
|
||||
class ReactiveThread : public Thread {
|
||||
class ReactiveThread : public Thread
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/* Ctor */
|
||||
ReactiveThread ();
|
||||
/* Ctor */
|
||||
ReactiveThread ();
|
||||
|
||||
void sleep ();
|
||||
void sleep ();
|
||||
|
||||
void wakeUp ();
|
||||
void wakeUp ();
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
sem_t sem;
|
||||
};
|
||||
sem_t sem;
|
||||
};
|
||||
|
||||
extern void initReactiveThreadsEnv ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <ring_topo.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,17 +37,19 @@
|
|||
#include "ring_topo.h"
|
||||
|
||||
void RingTopology :: setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to) {
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to)
|
||||
{
|
||||
__from.clear () ;
|
||||
__to.clear () ;
|
||||
|
||||
int len = mig.size () ;
|
||||
int len = mig.size () ;
|
||||
|
||||
for (int i = 0 ; i < len ; i ++)
|
||||
if (mig [i] == __mig) {
|
||||
__from.push_back (mig [(i - 1 + len) % len]) ;
|
||||
__to.push_back (mig [(i + 1) % len]) ;
|
||||
break;
|
||||
for (int i = 0 ; i < len ; i ++)
|
||||
if (mig [i] == __mig)
|
||||
{
|
||||
__from.push_back (mig [(i - 1 + len) % len]) ;
|
||||
__to.push_back (mig [(i + 1) % len]) ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <ring_topo.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,14 +39,15 @@
|
|||
|
||||
#include "topology.h"
|
||||
|
||||
class RingTopology : public Topology {
|
||||
class RingTopology : public Topology
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
void setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to);
|
||||
|
||||
};
|
||||
void setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <rmc.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
extern void initRMC (int & __argc, char * * & __argv);
|
||||
|
||||
extern void runRMC (); /* Resource Management and Communication */
|
||||
extern void runRMC (); /* Resource Management and Communication */
|
||||
|
||||
extern void finalizeRMC ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <runner.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,7 +48,7 @@
|
|||
#include "../rmc/mpi/schema.h"
|
||||
|
||||
|
||||
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
|
||||
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
|
||||
|
||||
static std :: vector <Runner *> the_runners;
|
||||
|
||||
|
|
@ -66,7 +66,8 @@ extern int getNumberOfNodes ();
|
|||
extern void wakeUpCommunicator ();
|
||||
|
||||
|
||||
Runner :: Runner () {
|
||||
Runner :: Runner ()
|
||||
{
|
||||
|
||||
exec_id = 0;
|
||||
def_id = ++ num_def_runners;
|
||||
|
|
@ -77,35 +78,41 @@ Runner :: Runner () {
|
|||
sem_init (& sem_cntxt, 0, 0);
|
||||
}
|
||||
|
||||
RUNNER_ID Runner :: getDefinitionID () {
|
||||
RUNNER_ID Runner :: getDefinitionID ()
|
||||
{
|
||||
|
||||
return def_id;
|
||||
}
|
||||
|
||||
RUNNER_ID Runner :: getExecutionID () {
|
||||
RUNNER_ID Runner :: getExecutionID ()
|
||||
{
|
||||
|
||||
return exec_id;
|
||||
}
|
||||
|
||||
void Runner :: setExecutionID (const RUNNER_ID& execution_id) {
|
||||
void Runner :: setExecutionID (const RUNNER_ID& execution_id)
|
||||
{
|
||||
|
||||
exec_id = execution_id;
|
||||
}
|
||||
|
||||
Runner * getRunner (RUNNER_ID __key) {
|
||||
Runner * getRunner (RUNNER_ID __key)
|
||||
{
|
||||
|
||||
return dynamic_cast <Runner *> (getCommunicable (__key));
|
||||
}
|
||||
|
||||
void initializeContext () {
|
||||
void initializeContext ()
|
||||
{
|
||||
|
||||
num_local_exec_runners = 0;
|
||||
|
||||
// setting up the execution IDs & counting the number of local exec. runners
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++) {
|
||||
the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] );
|
||||
if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++;
|
||||
}
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||
{
|
||||
the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] );
|
||||
if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++;
|
||||
}
|
||||
|
||||
collectiveCountOfRunners( &num_local_exec_runners, &num_exec_runners );
|
||||
|
||||
|
|
@ -115,17 +122,20 @@ void initializeContext () {
|
|||
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
|
||||
}
|
||||
|
||||
void Runner :: waitStarting () {
|
||||
void Runner :: waitStarting ()
|
||||
{
|
||||
|
||||
sem_wait (& sem_start);
|
||||
}
|
||||
|
||||
void Runner :: waitContextInitialization () {
|
||||
void Runner :: waitContextInitialization ()
|
||||
{
|
||||
|
||||
sem_wait (& sem_cntxt);
|
||||
}
|
||||
|
||||
void Runner :: start () {
|
||||
void Runner :: start ()
|
||||
{
|
||||
|
||||
setActive ();
|
||||
|
||||
|
|
@ -136,46 +146,54 @@ void Runner :: start () {
|
|||
terminate ();
|
||||
}
|
||||
|
||||
void startRunners () {
|
||||
void startRunners ()
|
||||
{
|
||||
|
||||
/* Runners */
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||
if (the_runners [i] -> isAssignedLocally ()) {
|
||||
addThread (the_runners [i], ll_threads);
|
||||
the_runners [i] -> waitStarting ();
|
||||
}
|
||||
if (the_runners [i] -> isAssignedLocally ())
|
||||
{
|
||||
addThread (the_runners [i], ll_threads);
|
||||
the_runners [i] -> waitStarting ();
|
||||
}
|
||||
|
||||
printDebugMessage ("launched the parallel runners");
|
||||
}
|
||||
|
||||
void joinRunners () {
|
||||
void joinRunners ()
|
||||
{
|
||||
|
||||
joinThreads (ll_threads);
|
||||
the_runners.clear();
|
||||
}
|
||||
|
||||
bool atLeastOneActiveRunner () {
|
||||
bool atLeastOneActiveRunner ()
|
||||
{
|
||||
|
||||
return num_exec_runners;
|
||||
}
|
||||
|
||||
unsigned numberOfActiveRunners () {
|
||||
unsigned numberOfActiveRunners ()
|
||||
{
|
||||
|
||||
return num_exec_runners;
|
||||
}
|
||||
|
||||
void Runner :: notifyContextInitialized () {
|
||||
void Runner :: notifyContextInitialized ()
|
||||
{
|
||||
|
||||
sem_post (& sem_cntxt);
|
||||
}
|
||||
|
||||
void Runner :: notifySendingTermination () {
|
||||
void Runner :: notifySendingTermination ()
|
||||
{
|
||||
|
||||
printDebugMessage ("I am informed that everyone received my termination notification.");
|
||||
setPassive ();
|
||||
}
|
||||
|
||||
void unpackTerminationOfRunner () {
|
||||
void unpackTerminationOfRunner ()
|
||||
{
|
||||
|
||||
RUNNER_ID finished_id;
|
||||
unpack (finished_id);
|
||||
|
|
@ -184,17 +202,19 @@ void unpackTerminationOfRunner () {
|
|||
|
||||
printDebugMessage ("I'm noticed of the termination of a runner");
|
||||
|
||||
if (!num_exec_runners) {
|
||||
if (!num_exec_runners)
|
||||
{
|
||||
|
||||
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
|
||||
stopReactiveThreads ();
|
||||
printDebugMessage ("Reactive threads stopped!");
|
||||
}
|
||||
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
|
||||
stopReactiveThreads ();
|
||||
printDebugMessage ("Reactive threads stopped!");
|
||||
}
|
||||
|
||||
wakeUpCommunicator ();
|
||||
}
|
||||
|
||||
void initRunnersEnv () {
|
||||
void initRunnersEnv ()
|
||||
{
|
||||
|
||||
ll_threads.clear ();
|
||||
the_runners.clear ();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <runner.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,49 +46,50 @@
|
|||
typedef unsigned RUNNER_ID;
|
||||
|
||||
|
||||
class Runner : public Communicable, public Thread {
|
||||
class Runner : public Communicable, public Thread
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
Runner ();
|
||||
Runner ();
|
||||
|
||||
RUNNER_ID getDefinitionID ();
|
||||
RUNNER_ID getDefinitionID ();
|
||||
|
||||
RUNNER_ID getExecutionID ();
|
||||
RUNNER_ID getExecutionID ();
|
||||
|
||||
void setExecutionID (const RUNNER_ID& execution_id);
|
||||
void setExecutionID (const RUNNER_ID& execution_id);
|
||||
|
||||
bool isAssignedLocally ();
|
||||
bool isAssignedLocally ();
|
||||
|
||||
void waitStarting ();
|
||||
void waitStarting ();
|
||||
|
||||
void waitContextInitialization ();
|
||||
void waitContextInitialization ();
|
||||
|
||||
void start ();
|
||||
void start ();
|
||||
|
||||
virtual void run () = 0;
|
||||
virtual void run () = 0;
|
||||
|
||||
void terminate ();
|
||||
void terminate ();
|
||||
|
||||
void notifyContextInitialized ();
|
||||
void notifyContextInitialized ();
|
||||
|
||||
void notifySendingTermination ();
|
||||
void notifySendingTermination ();
|
||||
|
||||
void packTermination ();
|
||||
void packTermination ();
|
||||
|
||||
private :
|
||||
private :
|
||||
|
||||
sem_t sem_start;
|
||||
sem_t sem_cntxt;
|
||||
sem_t sem_start;
|
||||
sem_t sem_cntxt;
|
||||
|
||||
unsigned def_id;
|
||||
unsigned exec_id;
|
||||
};
|
||||
unsigned def_id;
|
||||
unsigned exec_id;
|
||||
};
|
||||
|
||||
|
||||
extern void initRunnersEnv ();
|
||||
|
||||
extern Runner * getRunner (RUNNER_ID __key);
|
||||
extern Runner * getRunner (RUNNER_ID __key);
|
||||
|
||||
extern void initializeContext ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <service.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,38 +36,49 @@
|
|||
|
||||
#include "service.h"
|
||||
|
||||
void Service :: setOwner (Thread & __owner) {
|
||||
void Service :: setOwner (Thread & __owner)
|
||||
{
|
||||
|
||||
owner = & __owner;
|
||||
}
|
||||
|
||||
Thread * Service :: getOwner () {
|
||||
Thread * Service :: getOwner ()
|
||||
{
|
||||
|
||||
return owner;
|
||||
}
|
||||
|
||||
Service * getService (SERVICE_ID __key) {
|
||||
Service * getService (SERVICE_ID __key)
|
||||
{
|
||||
|
||||
return dynamic_cast <Service *> (getCommunicable (__key));
|
||||
}
|
||||
|
||||
void Service :: notifySendingData () { }
|
||||
void Service :: notifySendingData ()
|
||||
{ }
|
||||
|
||||
void Service :: notifySendingResourceRequest () {
|
||||
void Service :: notifySendingResourceRequest ()
|
||||
{
|
||||
|
||||
num_sent_rr --;
|
||||
if (! num_sent_rr)
|
||||
notifySendingAllResourceRequests ();
|
||||
}
|
||||
|
||||
void Service :: notifySendingAllResourceRequests () { }
|
||||
void Service :: notifySendingAllResourceRequests ()
|
||||
{ }
|
||||
|
||||
void Service :: packData () {}
|
||||
void Service :: packData ()
|
||||
{}
|
||||
|
||||
void Service :: unpackData () {}
|
||||
void Service :: unpackData ()
|
||||
{}
|
||||
|
||||
void Service :: execute () {}
|
||||
void Service :: execute ()
|
||||
{}
|
||||
|
||||
void Service :: packResult () {}
|
||||
void Service :: packResult ()
|
||||
{}
|
||||
|
||||
void Service :: unpackResult () {}
|
||||
void Service :: unpackResult ()
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <service.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,37 +43,38 @@
|
|||
|
||||
typedef unsigned SERVICE_ID;
|
||||
|
||||
class Service : public Communicable {
|
||||
class Service : public Communicable
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
void setOwner (Thread & __owner);
|
||||
void setOwner (Thread & __owner);
|
||||
|
||||
Thread * getOwner ();
|
||||
Thread * getOwner ();
|
||||
|
||||
void requestResourceRequest (unsigned __how_many = 1);
|
||||
void packResourceRequest ();
|
||||
void requestResourceRequest (unsigned __how_many = 1);
|
||||
void packResourceRequest ();
|
||||
|
||||
virtual void packData ();
|
||||
virtual void unpackData ();
|
||||
virtual void packData ();
|
||||
virtual void unpackData ();
|
||||
|
||||
virtual void execute ();
|
||||
virtual void execute ();
|
||||
|
||||
virtual void packResult ();
|
||||
virtual void unpackResult ();
|
||||
virtual void packResult ();
|
||||
virtual void unpackResult ();
|
||||
|
||||
virtual void notifySendingData ();
|
||||
virtual void notifySendingResourceRequest ();
|
||||
virtual void notifySendingAllResourceRequests ();
|
||||
virtual void notifySendingData ();
|
||||
virtual void notifySendingResourceRequest ();
|
||||
virtual void notifySendingAllResourceRequests ();
|
||||
|
||||
private :
|
||||
private :
|
||||
|
||||
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
|
||||
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
|
||||
|
||||
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
|
||||
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
extern Service * getService (SERVICE_ID __key);
|
||||
extern Service * getService (SERVICE_ID __key);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <thread.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,66 +43,78 @@ static std :: vector <Thread *> threads;
|
|||
unsigned num_act = 0;
|
||||
|
||||
|
||||
Thread :: Thread () {
|
||||
Thread :: Thread ()
|
||||
{
|
||||
|
||||
threads.push_back (this);
|
||||
act = false;
|
||||
}
|
||||
|
||||
Thread :: ~ Thread () {
|
||||
Thread :: ~ Thread ()
|
||||
{
|
||||
|
||||
/* Nothing ! */
|
||||
}
|
||||
|
||||
void Thread :: setActive () {
|
||||
void Thread :: setActive ()
|
||||
{
|
||||
|
||||
if (! act) {
|
||||
if (! act)
|
||||
{
|
||||
|
||||
act = true;
|
||||
num_act ++;
|
||||
}
|
||||
act = true;
|
||||
num_act ++;
|
||||
}
|
||||
}
|
||||
|
||||
void Thread :: setPassive () {
|
||||
void Thread :: setPassive ()
|
||||
{
|
||||
|
||||
if (act) {
|
||||
if (act)
|
||||
{
|
||||
|
||||
act = false;
|
||||
num_act --;
|
||||
}
|
||||
act = false;
|
||||
num_act --;
|
||||
}
|
||||
}
|
||||
|
||||
void initThreadsEnv () {
|
||||
void initThreadsEnv ()
|
||||
{
|
||||
|
||||
threads.clear ();
|
||||
num_act = 0;
|
||||
}
|
||||
|
||||
bool atLeastOneActiveThread () {
|
||||
bool atLeastOneActiveThread ()
|
||||
{
|
||||
|
||||
return num_act;
|
||||
}
|
||||
|
||||
static void * launch (void * __arg) {
|
||||
static void * launch (void * __arg)
|
||||
{
|
||||
|
||||
Thread * thr = (Thread *) __arg;
|
||||
Thread * thr = (Thread *) __arg;
|
||||
thr -> start ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
|
||||
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads)
|
||||
{
|
||||
|
||||
pthread_t * ll_thr = new pthread_t;
|
||||
__ll_threads.push_back (ll_thr);
|
||||
pthread_create (ll_thr, 0, launch, __hl_thread);
|
||||
pthread_create (ll_thr, 0, launch, __hl_thread);
|
||||
}
|
||||
|
||||
void joinThreads (std :: vector <pthread_t *> & __threads) {
|
||||
void joinThreads (std :: vector <pthread_t *> & __threads)
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < __threads.size (); i ++) {
|
||||
pthread_join (* __threads [i], 0);
|
||||
delete __threads [i];
|
||||
}
|
||||
for (unsigned i = 0; i < __threads.size (); i ++)
|
||||
{
|
||||
pthread_join (* __threads [i], 0);
|
||||
delete __threads [i];
|
||||
}
|
||||
__threads.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <thread.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,27 +41,28 @@
|
|||
|
||||
|
||||
/* A high-level thread */
|
||||
class Thread {
|
||||
class Thread
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
/* Ctor */
|
||||
Thread ();
|
||||
/* Ctor */
|
||||
Thread ();
|
||||
|
||||
/* Dtor */
|
||||
virtual ~ Thread ();
|
||||
/* Dtor */
|
||||
virtual ~ Thread ();
|
||||
|
||||
/* Go ! */
|
||||
virtual void start () = 0;
|
||||
/* Go ! */
|
||||
virtual void start () = 0;
|
||||
|
||||
void setActive ();/* It means the current process is going to send messages soon */
|
||||
void setPassive ();/* The current process is not going to perform send operations
|
||||
(but it may receive messages) */
|
||||
void setActive ();/* It means the current process is going to send messages soon */
|
||||
void setPassive ();/* The current process is not going to perform send operations
|
||||
(but it may receive messages) */
|
||||
|
||||
private :
|
||||
private :
|
||||
|
||||
bool act;
|
||||
};
|
||||
bool act;
|
||||
};
|
||||
|
||||
extern void initThreadsEnv ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <topology.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,17 +36,20 @@
|
|||
|
||||
#include "topology.h"
|
||||
|
||||
Topology :: ~ Topology () {
|
||||
Topology :: ~ Topology ()
|
||||
{
|
||||
|
||||
/* Nothing ! */
|
||||
}
|
||||
|
||||
void Topology :: add (Cooperative & __mig) {
|
||||
void Topology :: add (Cooperative & __mig)
|
||||
{
|
||||
|
||||
mig.push_back (& __mig) ;
|
||||
}
|
||||
mig.push_back (& __mig) ;
|
||||
}
|
||||
|
||||
Topology :: operator std :: vector <Cooperative *>& () {
|
||||
Topology :: operator std :: vector <Cooperative *>& ()
|
||||
{
|
||||
|
||||
return mig;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <topology.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,23 +41,24 @@
|
|||
|
||||
#include "cooperative.h"
|
||||
|
||||
class Topology {
|
||||
class Topology
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
virtual ~Topology ();
|
||||
virtual ~Topology ();
|
||||
|
||||
void add (Cooperative & __mig);
|
||||
void add (Cooperative & __mig);
|
||||
|
||||
virtual void setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to) = 0;
|
||||
virtual void setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to) = 0;
|
||||
|
||||
operator std :: vector <Cooperative *>& ();
|
||||
operator std :: vector <Cooperative *>& ();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
|
||||
std :: vector <Cooperative *> mig;
|
||||
};
|
||||
std :: vector <Cooperative *> mig;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative,
|
|||
peoData & __source,
|
||||
peoData & __destination
|
||||
);
|
||||
|
||||
|
||||
|
||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
||||
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
||||
|
|
@ -234,20 +234,20 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack(
|
|||
unlock();
|
||||
}
|
||||
|
||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq() {
|
||||
}
|
||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq()
|
||||
{}
|
||||
|
||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrate()
|
||||
{
|
||||
std :: vector< Cooperative* >in, out;
|
||||
topology.setNeighbors( this, in, out );
|
||||
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i++ )
|
||||
{
|
||||
|
||||
TYPE mig;
|
||||
select(mig);
|
||||
em.push( mig );
|
||||
em.push( mig );
|
||||
coop_em.push( out[i] );
|
||||
send( out[i] );
|
||||
printDebugMessage( "sending some emigrants." );
|
||||
|
|
@ -257,13 +257,13 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrat
|
|||
|
||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigrate()
|
||||
{
|
||||
|
||||
|
||||
lock ();
|
||||
{
|
||||
|
||||
while ( !imm.empty() )
|
||||
{
|
||||
replace(imm.front() );
|
||||
replace(imm.front() );
|
||||
imm.pop();
|
||||
printDebugMessage( "receiving some immigrants." );
|
||||
}
|
||||
|
|
@ -274,8 +274,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
|
|||
|
||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
|
||||
{
|
||||
|
||||
if (cont.check())
|
||||
|
||||
if (cont.check())
|
||||
{
|
||||
|
||||
emigrate(); // sending emigrants
|
||||
|
|
|
|||
|
|
@ -44,39 +44,42 @@
|
|||
/************************** DEFINE A DATA ******************************************/
|
||||
/**************************************************************************************/
|
||||
|
||||
class peoData {
|
||||
public:
|
||||
class peoData
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void pack () {}
|
||||
virtual void unpack () {}
|
||||
|
||||
};
|
||||
virtual void pack ()
|
||||
{}
|
||||
virtual void unpack ()
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Specific implementation : migration of a population
|
||||
|
||||
template<class EOT>
|
||||
class peoPop: public eoPop<EOT>, public peoData
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void pack ()
|
||||
{
|
||||
::pack ((unsigned) this->size ());
|
||||
for (unsigned i = 0; i < this->size (); i ++)
|
||||
::pack ((*this)[i]);
|
||||
}
|
||||
public:
|
||||
|
||||
virtual void unpack ()
|
||||
{
|
||||
unsigned n;
|
||||
::unpack (n);
|
||||
this->resize (n);
|
||||
for (unsigned i = 0; i < n; i ++)
|
||||
::unpack ((*this)[i]);
|
||||
}
|
||||
virtual void pack ()
|
||||
{
|
||||
::pack ((unsigned) this->size ());
|
||||
for (unsigned i = 0; i < this->size (); i ++)
|
||||
::pack ((*this)[i]);
|
||||
}
|
||||
|
||||
};
|
||||
virtual void unpack ()
|
||||
{
|
||||
unsigned n;
|
||||
::unpack (n);
|
||||
this->resize (n);
|
||||
for (unsigned i = 0; i < n; i ++)
|
||||
::unpack ((*this)[i]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************************************/
|
||||
|
|
@ -84,27 +87,30 @@ public:
|
|||
/**************************************************************************************/
|
||||
|
||||
class continuator
|
||||
{
|
||||
public:
|
||||
virtual bool check()=0;
|
||||
};
|
||||
{
|
||||
public:
|
||||
virtual bool check()=0;
|
||||
};
|
||||
|
||||
|
||||
// Specific implementation : migration of a population
|
||||
|
||||
template < class EOT> class eoContinuator : public continuator{
|
||||
public:
|
||||
|
||||
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop){}
|
||||
|
||||
virtual bool check(){
|
||||
return cont(pop);
|
||||
}
|
||||
template < class EOT> class eoContinuator : public continuator
|
||||
{
|
||||
public:
|
||||
|
||||
protected:
|
||||
eoContinue<EOT> & cont ;
|
||||
const eoPop<EOT> & pop;
|
||||
};
|
||||
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop)
|
||||
{}
|
||||
|
||||
virtual bool check()
|
||||
{
|
||||
return cont(pop);
|
||||
}
|
||||
|
||||
protected:
|
||||
eoContinue<EOT> & cont ;
|
||||
const eoPop<EOT> & pop;
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************************************/
|
||||
|
|
@ -112,32 +118,34 @@ protected:
|
|||
/**************************************************************************************/
|
||||
|
||||
template < class TYPE> class selector
|
||||
{
|
||||
public:
|
||||
virtual void operator()(TYPE &)=0;
|
||||
};
|
||||
{
|
||||
public:
|
||||
virtual void operator()(TYPE &)=0;
|
||||
};
|
||||
|
||||
|
||||
// Specific implementation : migration of a population
|
||||
|
||||
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >{
|
||||
public:
|
||||
|
||||
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source){}
|
||||
|
||||
virtual void operator()(TYPE & _dest)
|
||||
{
|
||||
size_t target = static_cast<size_t>(nb_select);
|
||||
_dest.resize(target);
|
||||
for (size_t i = 0; i < _dest.size(); ++i)
|
||||
_dest[i] = selector(source);
|
||||
}
|
||||
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
|
||||
{
|
||||
public:
|
||||
|
||||
protected:
|
||||
eoSelectOne<EOT> & selector ;
|
||||
unsigned nb_select;
|
||||
const TYPE & source;
|
||||
};
|
||||
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source)
|
||||
{}
|
||||
|
||||
virtual void operator()(TYPE & _dest)
|
||||
{
|
||||
size_t target = static_cast<size_t>(nb_select);
|
||||
_dest.resize(target);
|
||||
for (size_t i = 0; i < _dest.size(); ++i)
|
||||
_dest[i] = selector(source);
|
||||
}
|
||||
|
||||
protected:
|
||||
eoSelectOne<EOT> & selector ;
|
||||
unsigned nb_select;
|
||||
const TYPE & source;
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************************************/
|
||||
|
|
@ -145,27 +153,29 @@ protected:
|
|||
/**************************************************************************************/
|
||||
|
||||
template < class TYPE> class replacement
|
||||
{
|
||||
public:
|
||||
virtual void operator()(TYPE &)=0;
|
||||
};
|
||||
{
|
||||
public:
|
||||
virtual void operator()(TYPE &)=0;
|
||||
};
|
||||
|
||||
|
||||
// Specific implementation : migration of a population
|
||||
|
||||
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >{
|
||||
public:
|
||||
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination){}
|
||||
|
||||
virtual void operator()(TYPE & _source)
|
||||
{
|
||||
replace(destination, _source);
|
||||
}
|
||||
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
|
||||
{
|
||||
public:
|
||||
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination)
|
||||
{}
|
||||
|
||||
protected:
|
||||
eoReplacement<EOT> & replace;
|
||||
TYPE & destination;
|
||||
};
|
||||
virtual void operator()(TYPE & _source)
|
||||
{
|
||||
replace(destination, _source);
|
||||
}
|
||||
|
||||
protected:
|
||||
eoReplacement<EOT> & replace;
|
||||
TYPE & destination;
|
||||
};
|
||||
|
||||
|
||||
/**************************************************************************************/
|
||||
|
|
@ -173,25 +183,26 @@ protected:
|
|||
/**************************************************************************************/
|
||||
|
||||
class eoSyncContinue: public continuator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) {}
|
||||
|
||||
virtual bool check()
|
||||
{
|
||||
return ((++ counter) % period) != 0 ;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
unsigned period;
|
||||
|
||||
unsigned counter;
|
||||
public:
|
||||
|
||||
};
|
||||
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter)
|
||||
{}
|
||||
|
||||
virtual bool check()
|
||||
{
|
||||
return ((++ counter) % period) != 0 ;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
unsigned period;
|
||||
|
||||
unsigned counter;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -43,20 +43,20 @@ template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& >
|
|||
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
||||
#endif
|
||||
struct peoEvalFunc: public eoEvalFunc<EOT>
|
||||
{
|
||||
|
||||
peoEvalFunc( FitT (* _eval)( FunctionArg ) )
|
||||
: eoEvalFunc<EOT>(), evalFunc( _eval )
|
||||
{};
|
||||
|
||||
virtual void operator() ( EOT & _peo )
|
||||
{
|
||||
_peo.fitness((*evalFunc)( _peo ));
|
||||
};
|
||||
|
||||
peoEvalFunc( FitT (* _eval)( FunctionArg ) )
|
||||
: eoEvalFunc<EOT>(), evalFunc( _eval )
|
||||
{};
|
||||
|
||||
virtual void operator() ( EOT & _peo )
|
||||
{
|
||||
_peo.fitness((*evalFunc)( _peo ));
|
||||
};
|
||||
|
||||
private:
|
||||
FitT (* evalFunc )( FunctionArg );
|
||||
};
|
||||
FitT (* evalFunc )( FunctionArg );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class peoGlobalBestVelocity : public eoReplacement<POT>
|
|||
typedef typename POT::ParticleVelocityType VelocityType;
|
||||
|
||||
peoGlobalBestVelocity( const double & _c3,
|
||||
eoVelocity < POT > &_velocity):
|
||||
eoVelocity < POT > &_velocity):
|
||||
c3 (_c3),
|
||||
velocity (_velocity)
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ template< class EOT > peoMoeoPopEval< EOT > :: peoMoeoPopEval(
|
|||
|
||||
template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
|
||||
{
|
||||
this->operator()(__pop);
|
||||
this->operator()(__pop);
|
||||
}
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
||||
|
|
@ -166,7 +166,7 @@ template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __pop
|
|||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: packData()
|
||||
{
|
||||
{
|
||||
// printDebugMessage ("debut pakc data");
|
||||
pack( progression[ tasks.front() ].first-- );
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ template< class EOT > void peoMoeoPopEval< EOT > :: packData()
|
|||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: unpackData()
|
||||
{
|
||||
{
|
||||
unpack( num_func );
|
||||
/* Unpacking the solution */
|
||||
unpack( sol );
|
||||
|
|
@ -191,28 +191,28 @@ template< class EOT > void peoMoeoPopEval< EOT > :: unpackData()
|
|||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: execute()
|
||||
{
|
||||
|
||||
|
||||
/* Computing the fitness of the solution */
|
||||
funcs[ num_func ]->operator()( sol );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: packResult()
|
||||
{
|
||||
{
|
||||
// std::cout<<"\nD";
|
||||
/* Packing the fitness of the solution */
|
||||
/* typedef typename PO < F >::Fitness Fitness;
|
||||
MOEOObjectiveVector ObjectiveVector;*/
|
||||
/* typedef typename PO < F >::Fitness Fitness;
|
||||
MOEOObjectiveVector ObjectiveVector;*/
|
||||
std::vector < double > object;
|
||||
unsigned len;
|
||||
object=sol.objectiveVector();
|
||||
len=object.size();
|
||||
pack (len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
pack (object[i]);
|
||||
|
||||
|
||||
|
||||
pack (object[i]);
|
||||
|
||||
|
||||
|
||||
// pack( sol.fitness() );
|
||||
/* Packing the @ of the individual */
|
||||
pack( ad_sol );
|
||||
|
|
@ -221,25 +221,25 @@ template< class EOT > void peoMoeoPopEval< EOT > :: packResult()
|
|||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: unpackResult()
|
||||
{
|
||||
{
|
||||
// typename EOT :: Fitness fit;
|
||||
|
||||
/* Unpacking the computed fitness */
|
||||
// unpack( fit );
|
||||
unsigned len;
|
||||
std::vector < double > object;
|
||||
unsigned len;
|
||||
std::vector < double > object;
|
||||
|
||||
unpack(len);
|
||||
object.resize(len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (object[i]);
|
||||
unpack(len);
|
||||
object.resize(len);
|
||||
for (unsigned i = 0 ; i < len; i ++)
|
||||
unpack (object[i]);
|
||||
/* Unpacking the @ of the associated individual */
|
||||
unpack( ad_sol );
|
||||
|
||||
|
||||
/* Associating the fitness the local solution */
|
||||
// merge_eval( *ad_sol, object );
|
||||
ad_sol->objectiveVector(object);
|
||||
ad_sol->objectiveVector(object);
|
||||
progression[ ad_sol ].second--;
|
||||
|
||||
/* Notifying the container of the termination of the evaluation */
|
||||
|
|
@ -265,7 +265,7 @@ template< class EOT > void peoMoeoPopEval< EOT > :: notifySendingData()
|
|||
|
||||
|
||||
template< class EOT > void peoMoeoPopEval< EOT > :: notifySendingAllResourceRequests()
|
||||
{
|
||||
{
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,227 +43,227 @@
|
|||
|
||||
|
||||
template < typename EntityType > class peoMultiStart : public Service
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm )
|
||||
{
|
||||
|
||||
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
||||
algorithms.push_back( singularAlgorithm );
|
||||
public:
|
||||
|
||||
aggregationFunction = new NoAggregationFunction();
|
||||
}
|
||||
template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm )
|
||||
{
|
||||
|
||||
template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) )
|
||||
{
|
||||
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
||||
algorithms.push_back( singularAlgorithm );
|
||||
|
||||
singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm );
|
||||
algorithms.push_back( singularAlgorithm );
|
||||
aggregationFunction = new NoAggregationFunction();
|
||||
}
|
||||
|
||||
aggregationFunction = new NoAggregationFunction();
|
||||
}
|
||||
template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) )
|
||||
{
|
||||
|
||||
template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
|
||||
{
|
||||
singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm );
|
||||
algorithms.push_back( singularAlgorithm );
|
||||
|
||||
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
||||
aggregationFunction = new NoAggregationFunction();
|
||||
}
|
||||
|
||||
template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
|
||||
{
|
||||
|
||||
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
||||
{
|
||||
|
||||
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
||||
}
|
||||
|
||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||
}
|
||||
|
||||
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType >
|
||||
peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms,
|
||||
AggregationFunctionType& externalAggregationFunction )
|
||||
{
|
||||
|
||||
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
||||
{
|
||||
|
||||
algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) );
|
||||
}
|
||||
|
||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||
}
|
||||
|
||||
~peoMultiStart()
|
||||
{
|
||||
|
||||
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
|
||||
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
|
||||
|
||||
delete aggregationFunction;
|
||||
}
|
||||
|
||||
|
||||
template < typename Type > void operator()( Type& externalData )
|
||||
{
|
||||
|
||||
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ )
|
||||
{
|
||||
|
||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||
}
|
||||
|
||||
functionIndex = dataIndex = idx = num_term = 0;
|
||||
requestResourceRequest( data.size() * algorithms.size() );
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd )
|
||||
{
|
||||
|
||||
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ )
|
||||
{
|
||||
|
||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||
}
|
||||
|
||||
functionIndex = dataIndex = idx = num_term = 0;
|
||||
requestResourceRequest( data.size() * algorithms.size() );
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
void packData();
|
||||
|
||||
void unpackData();
|
||||
|
||||
void execute();
|
||||
|
||||
void packResult();
|
||||
|
||||
void unpackResult();
|
||||
|
||||
void notifySendingData();
|
||||
|
||||
void notifySendingAllResourceRequests();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template < typename Type > struct DataType;
|
||||
|
||||
struct AbstractDataType
|
||||
{
|
||||
|
||||
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
||||
}
|
||||
virtual ~AbstractDataType()
|
||||
{ }
|
||||
|
||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||
}
|
||||
template < typename Type > operator Type& ()
|
||||
{
|
||||
|
||||
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType >
|
||||
peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms,
|
||||
AggregationFunctionType& externalAggregationFunction )
|
||||
{
|
||||
|
||||
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
||||
{
|
||||
|
||||
algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) );
|
||||
}
|
||||
|
||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
||||
}
|
||||
|
||||
~peoMultiStart()
|
||||
{
|
||||
|
||||
for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ];
|
||||
for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ];
|
||||
|
||||
delete aggregationFunction;
|
||||
}
|
||||
|
||||
|
||||
template < typename Type > void operator()( Type& externalData )
|
||||
{
|
||||
|
||||
for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ )
|
||||
{
|
||||
|
||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||
}
|
||||
|
||||
functionIndex = dataIndex = idx = num_term = 0;
|
||||
requestResourceRequest( data.size() * algorithms.size() );
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd )
|
||||
{
|
||||
|
||||
for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ )
|
||||
{
|
||||
|
||||
data.push_back( new DataType< EntityType >( *externalDataIterator ) );
|
||||
}
|
||||
|
||||
functionIndex = dataIndex = idx = num_term = 0;
|
||||
requestResourceRequest( data.size() * algorithms.size() );
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
void packData();
|
||||
|
||||
void unpackData();
|
||||
|
||||
void execute();
|
||||
|
||||
void packResult();
|
||||
|
||||
void unpackResult();
|
||||
|
||||
void notifySendingData();
|
||||
|
||||
void notifySendingAllResourceRequests();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
template < typename Type > struct DataType;
|
||||
|
||||
struct AbstractDataType
|
||||
{
|
||||
|
||||
virtual ~AbstractDataType()
|
||||
{ }
|
||||
|
||||
template < typename Type > operator Type& ()
|
||||
{
|
||||
|
||||
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
||||
}
|
||||
};
|
||||
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
||||
}
|
||||
};
|
||||
|
||||
template < typename Type > struct DataType : public AbstractDataType
|
||||
{
|
||||
{
|
||||
|
||||
DataType( Type& externalData ) : data( externalData )
|
||||
{ }
|
||||
DataType( Type& externalData ) : data( externalData )
|
||||
{ }
|
||||
|
||||
Type& data;
|
||||
};
|
||||
Type& data;
|
||||
};
|
||||
|
||||
struct AbstractAlgorithm
|
||||
{
|
||||
struct AbstractAlgorithm
|
||||
{
|
||||
|
||||
virtual ~AbstractAlgorithm()
|
||||
{ }
|
||||
virtual ~AbstractAlgorithm()
|
||||
{ }
|
||||
|
||||
virtual void operator()( AbstractDataType& dataTypeInstance )
|
||||
{}
|
||||
};
|
||||
virtual void operator()( AbstractDataType& dataTypeInstance )
|
||||
{}
|
||||
};
|
||||
|
||||
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||
{ }
|
||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||
{ }
|
||||
|
||||
void operator()( AbstractDataType& dataTypeInstance )
|
||||
{
|
||||
algorithm( dataTypeInstance );
|
||||
}
|
||||
void operator()( AbstractDataType& dataTypeInstance )
|
||||
{
|
||||
algorithm( dataTypeInstance );
|
||||
}
|
||||
|
||||
AlgorithmType& algorithm;
|
||||
};
|
||||
AlgorithmType& algorithm;
|
||||
};
|
||||
|
||||
|
||||
template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm )
|
||||
{ }
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm )
|
||||
{ }
|
||||
|
||||
void operator()( AbstractDataType& dataTypeInstance )
|
||||
{
|
||||
algorithm( dataTypeInstance );
|
||||
}
|
||||
void operator()( AbstractDataType& dataTypeInstance )
|
||||
{
|
||||
algorithm( dataTypeInstance );
|
||||
}
|
||||
|
||||
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
||||
};
|
||||
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
||||
};
|
||||
|
||||
struct AbstractAggregationAlgorithm
|
||||
{
|
||||
struct AbstractAggregationAlgorithm
|
||||
{
|
||||
|
||||
virtual ~AbstractAggregationAlgorithm()
|
||||
{ }
|
||||
virtual ~AbstractAggregationAlgorithm()
|
||||
{ }
|
||||
|
||||
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{};
|
||||
};
|
||||
virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{};
|
||||
};
|
||||
|
||||
template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm )
|
||||
{ }
|
||||
AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm )
|
||||
{ }
|
||||
|
||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{
|
||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{
|
||||
|
||||
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
|
||||
}
|
||||
aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB );
|
||||
}
|
||||
|
||||
AggregationAlgorithmType& aggregationAlgorithm;
|
||||
};
|
||||
AggregationAlgorithmType& aggregationAlgorithm;
|
||||
};
|
||||
|
||||
struct NoAggregationFunction : public AbstractAggregationAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{
|
||||
void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB )
|
||||
{
|
||||
|
||||
static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB );
|
||||
}
|
||||
static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
AbstractAlgorithm* singularAlgorithm;
|
||||
|
||||
std::vector< AbstractAlgorithm* > algorithms;
|
||||
AbstractAggregationAlgorithm* aggregationFunction;
|
||||
|
||||
|
||||
EntityType entityTypeInstance;
|
||||
std::vector< AbstractDataType* > data;
|
||||
|
||||
unsigned idx;
|
||||
unsigned num_term;
|
||||
unsigned dataIndex;
|
||||
unsigned functionIndex;
|
||||
};
|
||||
|
||||
|
||||
|
||||
AbstractAlgorithm* singularAlgorithm;
|
||||
|
||||
std::vector< AbstractAlgorithm* > algorithms;
|
||||
AbstractAggregationAlgorithm* aggregationFunction;
|
||||
|
||||
|
||||
EntityType entityTypeInstance;
|
||||
std::vector< AbstractDataType* > data;
|
||||
|
||||
unsigned idx;
|
||||
unsigned num_term;
|
||||
unsigned dataIndex;
|
||||
unsigned functionIndex;
|
||||
};
|
||||
|
||||
|
||||
template < typename EntityType > void peoMultiStart< EntityType >::packData()
|
||||
{
|
||||
|
||||
|
|
@ -274,11 +274,11 @@ template < typename EntityType > void peoMultiStart< EntityType >::packData()
|
|||
// done with functionIndex for the entire data set - moving to another
|
||||
// function/algorithm starting all over with the entire data set ( idx is set to 0 )
|
||||
if ( idx == data.size() )
|
||||
{
|
||||
{
|
||||
|
||||
++functionIndex;
|
||||
idx = 0;
|
||||
}
|
||||
++functionIndex;
|
||||
idx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template < typename EntityType > void peoMultiStart< EntityType >::unpackData()
|
||||
|
|
@ -322,11 +322,11 @@ template < typename EntityType > void peoMultiStart< EntityType >::unpackResult(
|
|||
num_term++;
|
||||
|
||||
if ( num_term == data.size() * algorithms.size() )
|
||||
{
|
||||
{
|
||||
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
}
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
template < typename EntityType > void peoMultiStart< EntityType >::notifySendingData()
|
||||
|
|
|
|||
|
|
@ -45,13 +45,13 @@
|
|||
//! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness
|
||||
//! value is explicitly specified.
|
||||
template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT >
|
||||
{
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
|
||||
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
|
||||
};
|
||||
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
|
||||
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
|
||||
};
|
||||
|
||||
|
||||
template< class EOT > void peoNoAggEvalFunc< EOT > :: operator()( EOT& __sol, const typename EOT :: Fitness& __fit )
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ template< class EOT > peoPopEval< EOT > :: peoPopEval(
|
|||
|
||||
template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop )
|
||||
{
|
||||
this->operator()(__pop);
|
||||
this->operator()(__pop);
|
||||
}
|
||||
|
||||
template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
||||
|
|
@ -166,7 +166,7 @@ template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
|||
|
||||
|
||||
template< class EOT > void peoPopEval< EOT > :: packData()
|
||||
{
|
||||
{
|
||||
// printDebugMessage ("debut pakc data");
|
||||
pack( progression[ tasks.front() ].first-- );
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ template< class EOT > void peoPopEval< EOT > :: packData()
|
|||
|
||||
|
||||
template< class EOT > void peoPopEval< EOT > :: unpackData()
|
||||
{
|
||||
{
|
||||
unpack( num_func );
|
||||
/* Unpacking the solution */
|
||||
unpack( sol );
|
||||
|
|
@ -191,14 +191,14 @@ template< class EOT > void peoPopEval< EOT > :: unpackData()
|
|||
|
||||
template< class EOT > void peoPopEval< EOT > :: execute()
|
||||
{
|
||||
|
||||
|
||||
/* Computing the fitness of the solution */
|
||||
funcs[ num_func ]->operator()( sol );
|
||||
}
|
||||
|
||||
|
||||
template< class EOT > void peoPopEval< EOT > :: packResult()
|
||||
{
|
||||
{
|
||||
/* Packing the fitness of the solution */
|
||||
pack( sol.fitness() );
|
||||
/* Packing the @ of the individual */
|
||||
|
|
@ -207,7 +207,7 @@ template< class EOT > void peoPopEval< EOT > :: packResult()
|
|||
|
||||
|
||||
template< class EOT > void peoPopEval< EOT > :: unpackResult()
|
||||
{
|
||||
{
|
||||
typename EOT :: Fitness fit;
|
||||
|
||||
/* Unpacking the computed fitness */
|
||||
|
|
@ -244,7 +244,7 @@ template< class EOT > void peoPopEval< EOT > :: notifySendingData()
|
|||
|
||||
|
||||
template< class EOT > void peoPopEval< EOT > :: notifySendingAllResourceRequests()
|
||||
{
|
||||
{
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -147,61 +147,61 @@
|
|||
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
||||
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
|
||||
template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater
|
||||
{
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
|
||||
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
||||
//!
|
||||
//! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically;
|
||||
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
||||
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
||||
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
||||
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
||||
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
||||
peoSyncIslandMig(
|
||||
unsigned __frequency,
|
||||
selector <TYPE> & __select,
|
||||
replacement <TYPE> & __replace,
|
||||
Topology& __topology,
|
||||
peoData & __source,
|
||||
peoData & __destination
|
||||
);
|
||||
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
|
||||
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
|
||||
//!
|
||||
//! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically;
|
||||
//! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population;
|
||||
//! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population;
|
||||
//! @param Topology& __topology - topological model to be followed when performing migrations;
|
||||
//! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected;
|
||||
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
||||
peoSyncIslandMig(
|
||||
unsigned __frequency,
|
||||
selector <TYPE> & __select,
|
||||
replacement <TYPE> & __replace,
|
||||
Topology& __topology,
|
||||
peoData & __source,
|
||||
peoData & __destination
|
||||
);
|
||||
|
||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
||||
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
||||
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
||||
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
||||
void operator()();
|
||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
||||
//! from the source population and sent to the next island (defined by the topology object) while the immigrant
|
||||
//! individuals are integrated in the destination population. There is no need to explicitly call the function - the
|
||||
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
||||
void operator()();
|
||||
|
||||
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
||||
void pack();
|
||||
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
||||
void unpack();
|
||||
//! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function.
|
||||
void packSynchronizeReq();
|
||||
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
||||
void pack();
|
||||
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
||||
void unpack();
|
||||
//! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function.
|
||||
void packSynchronizeReq();
|
||||
|
||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||
void notifySending();
|
||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||
void notifySending();
|
||||
|
||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||
void notifyReceiving();
|
||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||
void notifyReceiving();
|
||||
|
||||
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
|
||||
void notifySendingSyncReq();
|
||||
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
|
||||
void notifySendingSyncReq();
|
||||
|
||||
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
|
||||
void notifySynchronized();
|
||||
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
|
||||
void notifySynchronized();
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
void emigrate();
|
||||
void immigrate();
|
||||
void emigrate();
|
||||
void immigrate();
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
eoSyncContinue cont; // continuator
|
||||
selector <TYPE> & select; // the selection strategy
|
||||
|
|
@ -213,14 +213,14 @@ private:
|
|||
std :: queue< TYPE > em;
|
||||
std :: queue< Cooperative* > coop_em;
|
||||
|
||||
sem_t sync;
|
||||
sem_t sync;
|
||||
|
||||
bool explicitPassive;
|
||||
bool standbyMigration;
|
||||
bool explicitPassive;
|
||||
bool standbyMigration;
|
||||
|
||||
std :: vector< Cooperative* > in, out, all;
|
||||
unsigned nbMigrations;
|
||||
};
|
||||
std :: vector< Cooperative* > in, out, all;
|
||||
unsigned nbMigrations;
|
||||
};
|
||||
|
||||
|
||||
template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandMig(
|
||||
|
|
@ -243,7 +243,7 @@ template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandM
|
|||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: pack()
|
||||
{
|
||||
::pack( coop_em.front()->getKey() );
|
||||
em.front().pack();
|
||||
em.front().pack();
|
||||
coop_em.pop();
|
||||
em.pop();
|
||||
}
|
||||
|
|
@ -256,7 +256,8 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: unpack()
|
|||
explicitPassive = true;
|
||||
}
|
||||
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq() {
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq()
|
||||
{
|
||||
|
||||
packSynchronRequest( all );
|
||||
}
|
||||
|
|
@ -265,25 +266,26 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: emigrat
|
|||
{
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i ++ )
|
||||
{
|
||||
{
|
||||
|
||||
TYPE mig;
|
||||
select( mig );
|
||||
em.push( mig );
|
||||
coop_em.push( out[ i ] );
|
||||
send( out[ i ] );
|
||||
printDebugMessage( "peoSyncIslandMig: sending some emigrants." );
|
||||
}
|
||||
TYPE mig;
|
||||
select( mig );
|
||||
em.push( mig );
|
||||
coop_em.push( out[ i ] );
|
||||
send( out[ i ] );
|
||||
printDebugMessage( "peoSyncIslandMig: sending some emigrants." );
|
||||
}
|
||||
}
|
||||
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: immigrate()
|
||||
{
|
||||
assert( imm.size() );
|
||||
|
||||
while ( imm.size() ) {
|
||||
replace( imm.front() ) ;
|
||||
imm.pop();
|
||||
}
|
||||
while ( imm.size() )
|
||||
{
|
||||
replace( imm.front() ) ;
|
||||
imm.pop();
|
||||
}
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: receiving some immigrants." );
|
||||
}
|
||||
|
|
@ -292,19 +294,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: operato
|
|||
{
|
||||
|
||||
if ( cont.check() )
|
||||
{
|
||||
explicitPassive = standbyMigration = false;
|
||||
topology.setNeighbors( this, in, out ); all = topology;
|
||||
nbMigrations = 0;
|
||||
synchronizeCoopEx(); stop();
|
||||
// sending emigrants
|
||||
emigrate();
|
||||
// synchronizing
|
||||
sem_wait( &sync );
|
||||
// receiving immigrants
|
||||
immigrate();
|
||||
synchronizeCoopEx(); stop();
|
||||
}
|
||||
{
|
||||
explicitPassive = standbyMigration = false;
|
||||
topology.setNeighbors( this, in, out );
|
||||
all = topology;
|
||||
nbMigrations = 0;
|
||||
synchronizeCoopEx();
|
||||
stop();
|
||||
// sending emigrants
|
||||
emigrate();
|
||||
// synchronizing
|
||||
sem_wait( &sync );
|
||||
// receiving immigrants
|
||||
immigrate();
|
||||
synchronizeCoopEx();
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifySending()
|
||||
|
|
@ -316,19 +321,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifyR
|
|||
{
|
||||
nbMigrations++;
|
||||
|
||||
if ( nbMigrations == in.size() ) {
|
||||
if ( nbMigrations == in.size() )
|
||||
{
|
||||
|
||||
if ( standbyMigration ) getOwner()->setActive();
|
||||
sem_post( &sync );
|
||||
}
|
||||
if ( standbyMigration ) getOwner()->setActive();
|
||||
sem_post( &sync );
|
||||
}
|
||||
}
|
||||
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq () {
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq ()
|
||||
{
|
||||
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized () {
|
||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized ()
|
||||
{
|
||||
|
||||
standbyMigration = true;
|
||||
getOwner()->setActive();
|
||||
|
|
|
|||
|
|
@ -47,49 +47,49 @@ extern int getNodeRank();
|
|||
|
||||
|
||||
template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
|
||||
{
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
peoTransform(
|
||||
peoTransform(
|
||||
|
||||
eoQuadOp< EOT >& __cross,
|
||||
double __cross_rate,
|
||||
eoMonOp< EOT >& __mut,
|
||||
double __mut_rate
|
||||
);
|
||||
eoQuadOp< EOT >& __cross,
|
||||
double __cross_rate,
|
||||
eoMonOp< EOT >& __mut,
|
||||
double __mut_rate
|
||||
);
|
||||
|
||||
void operator()( eoPop< EOT >& __pop );
|
||||
void operator()( eoPop< EOT >& __pop );
|
||||
|
||||
void packData();
|
||||
void packData();
|
||||
|
||||
void unpackData();
|
||||
void unpackData();
|
||||
|
||||
void execute();
|
||||
void execute();
|
||||
|
||||
void packResult();
|
||||
void packResult();
|
||||
|
||||
void unpackResult();
|
||||
void unpackResult();
|
||||
|
||||
void notifySendingData();
|
||||
void notifySendingAllResourceRequests();
|
||||
void notifySendingData();
|
||||
void notifySendingAllResourceRequests();
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
eoQuadOp< EOT >& cross;
|
||||
double cross_rate;
|
||||
eoQuadOp< EOT >& cross;
|
||||
double cross_rate;
|
||||
|
||||
eoMonOp< EOT >& mut;
|
||||
double mut_rate;
|
||||
eoMonOp< EOT >& mut;
|
||||
double mut_rate;
|
||||
|
||||
unsigned idx;
|
||||
unsigned idx;
|
||||
|
||||
eoPop< EOT >* pop;
|
||||
eoPop< EOT >* pop;
|
||||
|
||||
EOT father, mother;
|
||||
EOT father, mother;
|
||||
|
||||
unsigned num_term;
|
||||
};
|
||||
unsigned num_term;
|
||||
};
|
||||
|
||||
template< class EOT > peoTransform< EOT > :: peoTransform(
|
||||
|
||||
|
|
@ -151,11 +151,11 @@ template< class EOT > void peoTransform< EOT > :: unpackResult()
|
|||
|
||||
// Can be used with an odd size
|
||||
if ( num_term == 2*(pop->size()/2) )
|
||||
{
|
||||
{
|
||||
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
}
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -45,117 +45,117 @@
|
|||
|
||||
|
||||
class peoWrapper : public Runner
|
||||
{
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
|
||||
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
|
||||
template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
|
||||
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
|
||||
{}
|
||||
|
||||
template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||
template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||
{}
|
||||
|
||||
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
|
||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
|
||||
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
|
||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
|
||||
{}
|
||||
|
||||
template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||
template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||
{}
|
||||
|
||||
~peoWrapper()
|
||||
~peoWrapper()
|
||||
{
|
||||
|
||||
delete algorithm;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
algorithm->operator()();
|
||||
}
|
||||
void run()
|
||||
{
|
||||
algorithm->operator()();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
struct AbstractAlgorithm
|
||||
{
|
||||
struct AbstractAlgorithm
|
||||
{
|
||||
|
||||
// virtual destructor as we will be using inheritance and polymorphism
|
||||
virtual ~AbstractAlgorithm()
|
||||
{ }
|
||||
// virtual destructor as we will be using inheritance and polymorphism
|
||||
virtual ~AbstractAlgorithm()
|
||||
{ }
|
||||
|
||||
// operator to be called for executing the algorithm
|
||||
virtual void operator()()
|
||||
{ }
|
||||
};
|
||||
// operator to be called for executing the algorithm
|
||||
virtual void operator()()
|
||||
{ }
|
||||
};
|
||||
|
||||
template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||
{}
|
||||
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||
{}
|
||||
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm( algorithmData );
|
||||
}
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm( algorithmData );
|
||||
}
|
||||
|
||||
AlgorithmType& algorithm;
|
||||
AlgorithmDataType& algorithmData;
|
||||
};
|
||||
AlgorithmType& algorithm;
|
||||
AlgorithmDataType& algorithmData;
|
||||
};
|
||||
|
||||
template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||
{}
|
||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||
{}
|
||||
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm();
|
||||
}
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm();
|
||||
}
|
||||
|
||||
AlgorithmType& algorithm;
|
||||
};
|
||||
AlgorithmType& algorithm;
|
||||
};
|
||||
|
||||
template< typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||
{}
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||
{}
|
||||
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm( algorithmData );
|
||||
}
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm( algorithmData );
|
||||
}
|
||||
|
||||
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
||||
AlgorithmDataType& algorithmData;
|
||||
};
|
||||
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
||||
AlgorithmDataType& algorithmData;
|
||||
};
|
||||
|
||||
template< typename AlgorithmReturnType > struct FunctionAlgorithm< AlgorithmReturnType, void > : public AbstractAlgorithm
|
||||
{
|
||||
{
|
||||
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() )
|
||||
: algorithm( externalAlgorithm )
|
||||
{}
|
||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() )
|
||||
: algorithm( externalAlgorithm )
|
||||
{}
|
||||
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm();
|
||||
}
|
||||
virtual void operator()()
|
||||
{
|
||||
algorithm();
|
||||
}
|
||||
|
||||
AlgorithmReturnType (*algorithm)();
|
||||
AlgorithmReturnType (*algorithm)();
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
AbstractAlgorithm* algorithm;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
AbstractAlgorithm* algorithm;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <comm.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -52,29 +52,32 @@ static sem_t sem_comm_init;
|
|||
static Communicator * the_thread;
|
||||
|
||||
|
||||
Communicator :: Communicator (int * __argc, char * * * __argv) {
|
||||
Communicator :: Communicator (int * __argc, char * * * __argv)
|
||||
{
|
||||
|
||||
the_thread = this;
|
||||
the_thread = this;
|
||||
initNode (__argc, __argv);
|
||||
loadRMCParameters (* __argc, * __argv);
|
||||
|
||||
sem_post (& sem_comm_init);
|
||||
}
|
||||
|
||||
void Communicator :: start () {
|
||||
void Communicator :: start ()
|
||||
{
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
|
||||
/* Zzz Zzz Zzz :-))) */
|
||||
sleep ();
|
||||
/* Zzz Zzz Zzz :-))) */
|
||||
sleep ();
|
||||
|
||||
sendMessages ();
|
||||
sendMessages ();
|
||||
|
||||
if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ())
|
||||
break;
|
||||
if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ())
|
||||
break;
|
||||
|
||||
receiveMessages ();
|
||||
}
|
||||
receiveMessages ();
|
||||
}
|
||||
|
||||
waitBuffers ();
|
||||
printDebugMessage ("finalizing");
|
||||
|
|
@ -82,24 +85,28 @@ void Communicator :: start () {
|
|||
//synchronizeNodes ();
|
||||
}
|
||||
|
||||
void initCommunication () {
|
||||
void initCommunication ()
|
||||
{
|
||||
|
||||
static bool initializedSemaphore = false;
|
||||
|
||||
if (initializedSemaphore) {
|
||||
sem_destroy(& sem_comm_init);
|
||||
}
|
||||
if (initializedSemaphore)
|
||||
{
|
||||
sem_destroy(& sem_comm_init);
|
||||
}
|
||||
|
||||
sem_init (& sem_comm_init, 0, 0);
|
||||
initializedSemaphore = true;
|
||||
}
|
||||
|
||||
void waitNodeInitialization () {
|
||||
void waitNodeInitialization ()
|
||||
{
|
||||
|
||||
sem_wait (& sem_comm_init);
|
||||
}
|
||||
|
||||
void wakeUpCommunicator () {
|
||||
void wakeUpCommunicator ()
|
||||
{
|
||||
|
||||
the_thread -> wakeUp ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <comm.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,15 +40,16 @@
|
|||
#include "../../core/communicable.h"
|
||||
#include "../../core/reac_thread.h"
|
||||
|
||||
class Communicator : public ReactiveThread {
|
||||
class Communicator : public ReactiveThread
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
/* Ctor */
|
||||
Communicator (int * __argc, char * * * __argv);
|
||||
/* Ctor */
|
||||
Communicator (int * __argc, char * * * __argv);
|
||||
|
||||
void start ();
|
||||
};
|
||||
void start ();
|
||||
};
|
||||
|
||||
extern void initCommunication ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <coop.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,42 +41,48 @@
|
|||
#include "mess.h"
|
||||
#include "../../core/peo_debug.h"
|
||||
|
||||
Runner * Cooperative :: getOwner () {
|
||||
Runner * Cooperative :: getOwner ()
|
||||
{
|
||||
|
||||
return owner;
|
||||
}
|
||||
|
||||
void Cooperative :: setOwner (Runner & __runner) {
|
||||
void Cooperative :: setOwner (Runner & __runner)
|
||||
{
|
||||
|
||||
owner = & __runner;
|
||||
}
|
||||
|
||||
void Cooperative :: send (Cooperative * __coop) {
|
||||
void Cooperative :: send (Cooperative * __coop)
|
||||
{
|
||||
|
||||
:: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG);
|
||||
// stop ();
|
||||
}
|
||||
|
||||
void Cooperative :: synchronizeCoopEx () {
|
||||
void Cooperative :: synchronizeCoopEx ()
|
||||
{
|
||||
:: send (this, my_node -> rk_sched, SYNCHRONIZE_REQ_TAG);
|
||||
}
|
||||
|
||||
Cooperative * getCooperative (COOP_ID __key) {
|
||||
Cooperative * getCooperative (COOP_ID __key)
|
||||
{
|
||||
|
||||
return dynamic_cast <Cooperative *> (getCommunicable (__key));
|
||||
}
|
||||
|
||||
void Cooperative :: notifySending () {
|
||||
void Cooperative :: notifySending ()
|
||||
{
|
||||
|
||||
//getOwner -> setPassive ();
|
||||
// resume ();
|
||||
}
|
||||
|
||||
void Cooperative :: notifyReceiving () {
|
||||
}
|
||||
void Cooperative :: notifyReceiving ()
|
||||
{}
|
||||
|
||||
void Cooperative :: notifySendingSyncReq () {
|
||||
}
|
||||
void Cooperative :: notifySendingSyncReq ()
|
||||
{}
|
||||
|
||||
void Cooperative :: notifySynchronized () {
|
||||
}
|
||||
void Cooperative :: notifySynchronized ()
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <mess.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,62 +42,69 @@
|
|||
#include "node.h"
|
||||
|
||||
#define MPI_BUF_SIZE 1024*64
|
||||
|
||||
|
||||
static char mpi_buf [MPI_BUF_SIZE];
|
||||
|
||||
|
||||
static int pos_buf;
|
||||
|
||||
static std :: vector <char *> act_buf; /* Active buffers */
|
||||
|
||||
static std :: vector <MPI_Request *> act_req; /* Active requests */
|
||||
|
||||
void initBuffers () {
|
||||
void initBuffers ()
|
||||
{
|
||||
|
||||
pos_buf = 0;
|
||||
act_buf.clear ();
|
||||
act_req.clear ();
|
||||
}
|
||||
|
||||
void cleanBuffers () {
|
||||
void cleanBuffers ()
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < act_req.size ();) {
|
||||
for (unsigned i = 0; i < act_req.size ();)
|
||||
{
|
||||
|
||||
MPI_Status stat ;
|
||||
int flag ;
|
||||
MPI_Status stat ;
|
||||
int flag ;
|
||||
|
||||
MPI_Test (act_req [i], & flag, & stat) ;
|
||||
if (flag) {
|
||||
MPI_Test (act_req [i], & flag, & stat) ;
|
||||
if (flag)
|
||||
{
|
||||
|
||||
delete[] act_buf [i] ;
|
||||
delete act_req [i] ;
|
||||
|
||||
act_buf [i] = act_buf.back () ;
|
||||
act_buf.pop_back () ;
|
||||
delete[] act_buf [i] ;
|
||||
delete act_req [i] ;
|
||||
|
||||
act_req [i] = act_req.back () ;
|
||||
act_req.pop_back () ;
|
||||
act_buf [i] = act_buf.back () ;
|
||||
act_buf.pop_back () ;
|
||||
|
||||
act_req [i] = act_req.back () ;
|
||||
act_req.pop_back () ;
|
||||
}
|
||||
else
|
||||
i ++;
|
||||
}
|
||||
else
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
void waitBuffers () {
|
||||
void waitBuffers ()
|
||||
{
|
||||
|
||||
printDebugMessage ("waiting the termination of the asynchronous operations to complete");
|
||||
|
||||
for (unsigned i = 0; i < act_req.size (); i ++) {
|
||||
for (unsigned i = 0; i < act_req.size (); i ++)
|
||||
{
|
||||
|
||||
MPI_Status stat ;
|
||||
MPI_Status stat ;
|
||||
|
||||
MPI_Wait (act_req [i], & stat) ;
|
||||
MPI_Wait (act_req [i], & stat) ;
|
||||
|
||||
delete[] act_buf [i] ;
|
||||
delete act_req [i] ;
|
||||
}
|
||||
delete[] act_buf [i] ;
|
||||
delete act_req [i] ;
|
||||
}
|
||||
}
|
||||
|
||||
bool probeMessage (int & __src, int & __tag) {
|
||||
bool probeMessage (int & __src, int & __tag)
|
||||
{
|
||||
|
||||
int flag;
|
||||
|
||||
|
|
@ -111,19 +118,22 @@ bool probeMessage (int & __src, int & __tag) {
|
|||
return flag;
|
||||
}
|
||||
|
||||
void waitMessage () {
|
||||
void waitMessage ()
|
||||
{
|
||||
|
||||
MPI_Status stat;
|
||||
MPI_Status stat;
|
||||
|
||||
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
|
||||
}
|
||||
|
||||
void initMessage () {
|
||||
void initMessage ()
|
||||
{
|
||||
|
||||
pos_buf = 0;
|
||||
}
|
||||
|
||||
void sendMessage (int __to, int __tag) {
|
||||
void sendMessage (int __to, int __tag)
|
||||
{
|
||||
|
||||
cleanBuffers ();
|
||||
act_buf.push_back (new char [pos_buf]);
|
||||
|
|
@ -132,13 +142,15 @@ void sendMessage (int __to, int __tag) {
|
|||
MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ());
|
||||
}
|
||||
|
||||
void sendMessageToAll (int __tag) {
|
||||
void sendMessageToAll (int __tag)
|
||||
{
|
||||
|
||||
for (int i = 0; i < getNumberOfNodes (); i ++)
|
||||
sendMessage (i, __tag);
|
||||
}
|
||||
|
||||
void receiveMessage (int __from, int __tag) {
|
||||
void receiveMessage (int __from, int __tag)
|
||||
{
|
||||
|
||||
MPI_Status stat;
|
||||
MPI_Request req;
|
||||
|
|
@ -147,80 +159,93 @@ void receiveMessage (int __from, int __tag) {
|
|||
MPI_Wait (& req, & stat);
|
||||
}
|
||||
|
||||
void synchronizeNodes () {
|
||||
void synchronizeNodes ()
|
||||
{
|
||||
|
||||
MPI_Barrier ( MPI_COMM_WORLD );
|
||||
}
|
||||
|
||||
/* Char */
|
||||
void pack (const char & __c) {
|
||||
void pack (const char & __c)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Boolean */
|
||||
void pack (const bool & __b, int __nitem){
|
||||
void pack (const bool & __b, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __b, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Float */
|
||||
void pack (const float & __f, int __nitem) {
|
||||
void pack (const float & __f, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Double */
|
||||
void pack (const double & __d, int __nitem) {
|
||||
void pack (const double & __d, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Integer */
|
||||
void pack (const int & __i, int __nitem) {
|
||||
void pack (const int & __i, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned int. */
|
||||
void pack (const unsigned int & __ui, int __nitem) {
|
||||
void pack (const unsigned int & __ui, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Short int. */
|
||||
void pack (const short & __sh, int __nitem) {
|
||||
void pack (const short & __sh, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned short */
|
||||
void pack (const unsigned short & __ush, int __nitem) {
|
||||
void pack (const unsigned short & __ush, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Long */
|
||||
void pack (const long & __l, int __nitem) {
|
||||
void pack (const long & __l, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned long */
|
||||
void pack (const unsigned long & __ul, int __nitem) {
|
||||
void pack (const unsigned long & __ul, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* String */
|
||||
void pack (const char * __str) {
|
||||
void pack (const char * __str)
|
||||
{
|
||||
|
||||
int len = strlen (__str) + 1;
|
||||
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
void pack (const std::string & __str) {
|
||||
void pack (const std::string & __str)
|
||||
{
|
||||
|
||||
size_t size = __str.size() + 1;
|
||||
char * buffer = new char[ size ];
|
||||
|
|
@ -230,79 +255,91 @@ void pack (const std::string & __str) {
|
|||
}
|
||||
|
||||
/* Char */
|
||||
void unpack (char & __c) {
|
||||
void unpack (char & __c)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Boolean */
|
||||
extern void unpack (bool & __b, int __nitem ){
|
||||
extern void unpack (bool & __b, int __nitem )
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD);
|
||||
}
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Float */
|
||||
void unpack (float & __f, int __nitem) {
|
||||
void unpack (float & __f, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Double */
|
||||
void unpack (double & __d, int __nitem) {
|
||||
void unpack (double & __d, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Integer */
|
||||
void unpack (int & __i, int __nitem) {
|
||||
void unpack (int & __i, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned int. */
|
||||
void unpack (unsigned int & __ui, int __nitem) {
|
||||
void unpack (unsigned int & __ui, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Short int. */
|
||||
void unpack (short & __sh, int __nitem) {
|
||||
void unpack (short & __sh, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned short */
|
||||
void unpack (unsigned short & __ush, int __nitem) {
|
||||
void unpack (unsigned short & __ush, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Long */
|
||||
void unpack (long & __l, int __nitem) {
|
||||
void unpack (long & __l, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* Unsigned long */
|
||||
void unpack (unsigned long & __ul, int __nitem) {
|
||||
void unpack (unsigned long & __ul, int __nitem)
|
||||
{
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
/* String */
|
||||
void unpack (char * __str) {
|
||||
void unpack (char * __str)
|
||||
{
|
||||
|
||||
int len;
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
|
||||
}
|
||||
void unpack (std::string & __str) {
|
||||
|
||||
void unpack (std::string & __str)
|
||||
{
|
||||
|
||||
char * buffer;
|
||||
int len;
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, buffer, len, MPI_CHAR, MPI_COMM_WORLD);
|
||||
__str.assign( buffer );
|
||||
|
||||
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, buffer, len, MPI_CHAR, MPI_COMM_WORLD);
|
||||
__str.assign( buffer );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <mess.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <node.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,50 +43,57 @@
|
|||
#include "mess.h"
|
||||
|
||||
|
||||
class MPIThreadedEnv {
|
||||
class MPIThreadedEnv
|
||||
{
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
static void init ( int * __argc, char * * * __argv ) {
|
||||
static void init ( int * __argc, char * * * __argv )
|
||||
{
|
||||
|
||||
static MPIThreadedEnv mpiThreadedEnv( __argc, __argv );
|
||||
}
|
||||
|
||||
static void finalize () {
|
||||
|
||||
static bool finalizedEnvironment = false;
|
||||
|
||||
if (! finalizedEnvironment ) {
|
||||
|
||||
MPI_Finalize ();
|
||||
finalizedEnvironment = true;
|
||||
static MPIThreadedEnv mpiThreadedEnv( __argc, __argv );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static void finalize ()
|
||||
{
|
||||
|
||||
/* No instance of this class can be created outside its domain! */
|
||||
MPIThreadedEnv ( int * __argc, char * * * __argv ) {
|
||||
static bool finalizedEnvironment = false;
|
||||
|
||||
static bool MPIThreadedEnvInitialized = false;
|
||||
int provided = 1;
|
||||
if (! finalizedEnvironment )
|
||||
{
|
||||
|
||||
if (! MPIThreadedEnvInitialized) {
|
||||
|
||||
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
|
||||
|
||||
assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
|
||||
Yet, only one thread performs the comm.
|
||||
operations */
|
||||
MPIThreadedEnvInitialized = true;
|
||||
MPI_Finalize ();
|
||||
finalizedEnvironment = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~MPIThreadedEnv() {
|
||||
private:
|
||||
|
||||
finalize ();
|
||||
}
|
||||
};
|
||||
/* No instance of this class can be created outside its domain! */
|
||||
MPIThreadedEnv ( int * __argc, char * * * __argv )
|
||||
{
|
||||
|
||||
static bool MPIThreadedEnvInitialized = false;
|
||||
int provided = 1;
|
||||
|
||||
if (! MPIThreadedEnvInitialized)
|
||||
{
|
||||
|
||||
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
|
||||
|
||||
assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
|
||||
Yet, only one thread performs the comm.
|
||||
operations */
|
||||
MPIThreadedEnvInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
~MPIThreadedEnv()
|
||||
{
|
||||
|
||||
finalize ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static int rk, sz; /* Rank & size */
|
||||
|
|
@ -96,27 +103,32 @@ static std :: map <std :: string, int> name_to_rk;
|
|||
static std :: vector <std :: string> rk_to_name;
|
||||
|
||||
|
||||
int getNodeRank () {
|
||||
int getNodeRank ()
|
||||
{
|
||||
|
||||
return rk;
|
||||
}
|
||||
|
||||
int getNumberOfNodes () {
|
||||
int getNumberOfNodes ()
|
||||
{
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners ) {
|
||||
void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners )
|
||||
{
|
||||
|
||||
MPI_Allreduce( num_local_exec_runners, num_exec_runners, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD );
|
||||
}
|
||||
|
||||
int getRankFromName (const std :: string & __name) {
|
||||
int getRankFromName (const std :: string & __name)
|
||||
{
|
||||
|
||||
return atoi (__name.c_str ());
|
||||
return atoi (__name.c_str ());
|
||||
}
|
||||
|
||||
void initNode (int * __argc, char * * * __argv) {
|
||||
void initNode (int * __argc, char * * * __argv)
|
||||
{
|
||||
|
||||
rk_to_name.clear ();
|
||||
name_to_rk.clear ();
|
||||
|
|
@ -130,12 +142,13 @@ void initNode (int * __argc, char * * * __argv) {
|
|||
char names [sz] [MPI_MAX_PROCESSOR_NAME];
|
||||
int len;
|
||||
|
||||
/* Processor names */
|
||||
MPI_Get_processor_name (names [0], & len); /* Me */
|
||||
/* Processor names */
|
||||
MPI_Get_processor_name (names [0], & len); /* Me */
|
||||
MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
|
||||
|
||||
for (int i = 0; i < sz; i ++) {
|
||||
rk_to_name.push_back (names [i]);
|
||||
name_to_rk [names [i]] = i;
|
||||
}
|
||||
for (int i = 0; i < sz; i ++)
|
||||
{
|
||||
rk_to_name.push_back (names [i]);
|
||||
name_to_rk [names [i]] = i;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <node.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,15 +44,16 @@
|
|||
|
||||
typedef int RANK_ID;
|
||||
|
||||
struct Node {
|
||||
struct Node
|
||||
{
|
||||
|
||||
RANK_ID rk; /* Rank */
|
||||
std :: string name; /* Host name */
|
||||
unsigned num_workers; /* Number of parallel workers */
|
||||
int rk_sched; /* rank of the scheduler */
|
||||
std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
|
||||
std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
|
||||
};
|
||||
RANK_ID rk; /* Rank */
|
||||
std :: string name; /* Host name */
|
||||
unsigned num_workers; /* Number of parallel workers */
|
||||
int rk_sched; /* rank of the scheduler */
|
||||
std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
|
||||
std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
|
||||
};
|
||||
|
||||
extern Node * my_node;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <param.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,7 +38,8 @@
|
|||
|
||||
#include "schema.h"
|
||||
|
||||
void loadRMCParameters (int & __argc, char * * & __argv) {
|
||||
void loadRMCParameters (int & __argc, char * * & __argv)
|
||||
{
|
||||
|
||||
eoParser parser (__argc, __argv);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <param.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <recv.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,106 +45,112 @@
|
|||
#include "../../core/cooperative.h"
|
||||
#include "../../core/peo_debug.h"
|
||||
|
||||
void receiveMessages () {
|
||||
void receiveMessages ()
|
||||
{
|
||||
|
||||
cleanBuffers ();
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
|
||||
if (! atLeastOneActiveThread ()) {
|
||||
|
||||
waitMessage ();
|
||||
}
|
||||
|
||||
int src, tag;
|
||||
|
||||
while (probeMessage (src, tag)) {
|
||||
|
||||
receiveMessage (src, tag);
|
||||
initMessage ();
|
||||
|
||||
switch (tag) {
|
||||
|
||||
case RUNNER_STOP_TAG:
|
||||
unpackTerminationOfRunner ();
|
||||
break;
|
||||
|
||||
case SYNCHRONIZE_REQ_TAG:
|
||||
unpackSynchronRequest ();
|
||||
break;
|
||||
|
||||
case SYNCHRONIZED_TAG:
|
||||
if (! atLeastOneActiveThread ())
|
||||
{
|
||||
RUNNER_ID runner_id;
|
||||
unpack (runner_id);
|
||||
|
||||
COOP_ID coop_id;
|
||||
unpack (coop_id);
|
||||
|
||||
getCooperative (coop_id) -> notifySynchronized ();
|
||||
break;
|
||||
waitMessage ();
|
||||
}
|
||||
|
||||
case COOP_TAG:
|
||||
COOP_ID coop_id;
|
||||
unpack (coop_id);
|
||||
getCooperative (coop_id) -> unpack ();
|
||||
getCooperative (coop_id) -> notifyReceiving ();
|
||||
break;
|
||||
int src, tag;
|
||||
|
||||
case SCHED_REQUEST_TAG:
|
||||
unpackResourceRequest ();
|
||||
break;
|
||||
|
||||
case SCHED_RESULT_TAG:
|
||||
while (probeMessage (src, tag))
|
||||
{
|
||||
/* Unpacking the resource */
|
||||
SERVICE_ID serv_id;
|
||||
unpack (serv_id);
|
||||
Service * serv = getService (serv_id);
|
||||
int dest;
|
||||
unpack (dest);
|
||||
WORKER_ID worker_id;
|
||||
unpack (worker_id);
|
||||
|
||||
/* Going back ... */
|
||||
receiveMessage (src, tag);
|
||||
initMessage ();
|
||||
pack (worker_id);
|
||||
pack (serv_id);
|
||||
serv -> packData ();
|
||||
serv -> notifySendingData ();
|
||||
sendMessage (dest, TASK_DATA_TAG);
|
||||
break;
|
||||
|
||||
switch (tag)
|
||||
{
|
||||
|
||||
case RUNNER_STOP_TAG:
|
||||
unpackTerminationOfRunner ();
|
||||
break;
|
||||
|
||||
case SYNCHRONIZE_REQ_TAG:
|
||||
unpackSynchronRequest ();
|
||||
break;
|
||||
|
||||
case SYNCHRONIZED_TAG:
|
||||
{
|
||||
RUNNER_ID runner_id;
|
||||
unpack (runner_id);
|
||||
|
||||
COOP_ID coop_id;
|
||||
unpack (coop_id);
|
||||
|
||||
getCooperative (coop_id) -> notifySynchronized ();
|
||||
break;
|
||||
}
|
||||
|
||||
case COOP_TAG:
|
||||
COOP_ID coop_id;
|
||||
unpack (coop_id);
|
||||
getCooperative (coop_id) -> unpack ();
|
||||
getCooperative (coop_id) -> notifyReceiving ();
|
||||
break;
|
||||
|
||||
case SCHED_REQUEST_TAG:
|
||||
unpackResourceRequest ();
|
||||
break;
|
||||
|
||||
case SCHED_RESULT_TAG:
|
||||
{
|
||||
/* Unpacking the resource */
|
||||
SERVICE_ID serv_id;
|
||||
unpack (serv_id);
|
||||
Service * serv = getService (serv_id);
|
||||
int dest;
|
||||
unpack (dest);
|
||||
WORKER_ID worker_id;
|
||||
unpack (worker_id);
|
||||
|
||||
/* Going back ... */
|
||||
initMessage ();
|
||||
pack (worker_id);
|
||||
pack (serv_id);
|
||||
serv -> packData ();
|
||||
serv -> notifySendingData ();
|
||||
sendMessage (dest, TASK_DATA_TAG);
|
||||
break;
|
||||
}
|
||||
|
||||
case TASK_DATA_TAG:
|
||||
{
|
||||
WORKER_ID worker_id;
|
||||
unpack (worker_id);
|
||||
Worker * worker = getWorker (worker_id);
|
||||
worker -> setSource (src);
|
||||
worker -> unpackData ();
|
||||
worker -> wakeUp ();
|
||||
break;
|
||||
}
|
||||
|
||||
case TASK_RESULT_TAG:
|
||||
{
|
||||
SERVICE_ID serv_id;
|
||||
unpack (serv_id);
|
||||
Service * serv = getService (serv_id);
|
||||
serv -> unpackResult ();
|
||||
break;
|
||||
}
|
||||
|
||||
case TASK_DONE_TAG:
|
||||
unpackTaskDone ();
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
case TASK_DATA_TAG:
|
||||
{
|
||||
WORKER_ID worker_id;
|
||||
unpack (worker_id);
|
||||
Worker * worker = getWorker (worker_id);
|
||||
worker -> setSource (src);
|
||||
worker -> unpackData ();
|
||||
worker -> wakeUp ();
|
||||
break;
|
||||
}
|
||||
|
||||
case TASK_RESULT_TAG:
|
||||
{
|
||||
SERVICE_ID serv_id;
|
||||
unpack (serv_id);
|
||||
Service * serv = getService (serv_id);
|
||||
serv -> unpackResult ();
|
||||
break;
|
||||
}
|
||||
|
||||
case TASK_DONE_TAG:
|
||||
unpackTaskDone ();
|
||||
break;
|
||||
|
||||
default:
|
||||
;
|
||||
};
|
||||
}
|
||||
|
||||
} while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/ );
|
||||
while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/ );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <recv.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <rmc.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -46,18 +46,21 @@ static std :: vector <Worker *> worker_threads; /* Worker threads */
|
|||
static Communicator* communicator_thread = NULL; /* Communicator thread */
|
||||
|
||||
|
||||
void runRMC () {
|
||||
void runRMC ()
|
||||
{
|
||||
|
||||
/* Worker(s) ? */
|
||||
for (unsigned i = 0; i < my_node -> num_workers; i ++) {
|
||||
worker_threads.push_back (new Worker);
|
||||
addThread (worker_threads.back(), ll_threads);
|
||||
}
|
||||
for (unsigned i = 0; i < my_node -> num_workers; i ++)
|
||||
{
|
||||
worker_threads.push_back (new Worker);
|
||||
addThread (worker_threads.back(), ll_threads);
|
||||
}
|
||||
|
||||
wakeUpCommunicator ();
|
||||
}
|
||||
|
||||
void initRMC (int & __argc, char * * & __argv) {
|
||||
void initRMC (int & __argc, char * * & __argv)
|
||||
{
|
||||
|
||||
/* Communication */
|
||||
initCommunication ();
|
||||
|
|
@ -71,14 +74,16 @@ void initRMC (int & __argc, char * * & __argv) {
|
|||
initScheduler ();
|
||||
}
|
||||
|
||||
void finalizeRMC () {
|
||||
void finalizeRMC ()
|
||||
{
|
||||
|
||||
printDebugMessage ("before join threads RMC");
|
||||
|
||||
joinThreads (ll_threads);
|
||||
for (unsigned i = 0; i < worker_threads.size(); i++ ) {
|
||||
delete worker_threads [i];
|
||||
}
|
||||
for (unsigned i = 0; i < worker_threads.size(); i++ )
|
||||
{
|
||||
delete worker_threads [i];
|
||||
}
|
||||
worker_threads.clear ();
|
||||
delete communicator_thread;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <runner.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,7 +43,8 @@
|
|||
#include "schema.h"
|
||||
|
||||
|
||||
bool Runner :: isAssignedLocally () {
|
||||
bool Runner :: isAssignedLocally ()
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
||||
if (my_node -> id_run [i] == def_id)
|
||||
|
|
@ -51,12 +52,14 @@ bool Runner :: isAssignedLocally () {
|
|||
return false;
|
||||
}
|
||||
|
||||
void Runner :: terminate () {
|
||||
void Runner :: terminate ()
|
||||
{
|
||||
|
||||
sendToAll (this, RUNNER_STOP_TAG);
|
||||
}
|
||||
|
||||
void Runner :: packTermination () {
|
||||
void Runner :: packTermination ()
|
||||
{
|
||||
|
||||
pack (def_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <scheduler.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -49,52 +49,59 @@ static unsigned initNumberOfRes = 0;
|
|||
|
||||
extern void wakeUpCommunicator();
|
||||
|
||||
void initScheduler () {
|
||||
void initScheduler ()
|
||||
{
|
||||
|
||||
resources = std :: queue <SCHED_RESOURCE> ();
|
||||
requests = std :: queue <SCHED_REQUEST> ();
|
||||
initNumberOfRes = 0;
|
||||
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||
{
|
||||
|
||||
const Node & node = the_schema [i];
|
||||
const Node & node = the_schema [i];
|
||||
|
||||
if (node.rk_sched == my_node -> rk)
|
||||
for (unsigned j = 0; j < node.num_workers; j ++)
|
||||
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
||||
}
|
||||
if (node.rk_sched == my_node -> rk)
|
||||
for (unsigned j = 0; j < node.num_workers; j ++)
|
||||
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
||||
}
|
||||
initNumberOfRes = resources.size ();
|
||||
}
|
||||
|
||||
bool allResourcesFree () {
|
||||
bool allResourcesFree ()
|
||||
{
|
||||
return resources.size () == initNumberOfRes;
|
||||
}
|
||||
|
||||
unsigned numResourcesFree () {
|
||||
unsigned numResourcesFree ()
|
||||
{
|
||||
return resources.size ();
|
||||
}
|
||||
|
||||
static void update () {
|
||||
static void update ()
|
||||
{
|
||||
|
||||
unsigned num_alloc = std :: min (resources.size (), requests.size ());
|
||||
|
||||
for (unsigned i = 0; i < num_alloc; i ++) {
|
||||
for (unsigned i = 0; i < num_alloc; i ++)
|
||||
{
|
||||
|
||||
SCHED_REQUEST req = requests.front ();
|
||||
requests.pop ();
|
||||
SCHED_REQUEST req = requests.front ();
|
||||
requests.pop ();
|
||||
|
||||
SCHED_RESOURCE res = resources.front ();
|
||||
resources.pop ();
|
||||
SCHED_RESOURCE res = resources.front ();
|
||||
resources.pop ();
|
||||
|
||||
printDebugMessage ("allocating a resource.");
|
||||
initMessage ();
|
||||
pack (req.second);
|
||||
pack (res);
|
||||
sendMessage (req.first, SCHED_RESULT_TAG);
|
||||
}
|
||||
printDebugMessage ("allocating a resource.");
|
||||
initMessage ();
|
||||
pack (req.second);
|
||||
pack (res);
|
||||
sendMessage (req.first, SCHED_RESULT_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
void unpackResourceRequest () {
|
||||
void unpackResourceRequest ()
|
||||
{
|
||||
|
||||
printDebugMessage ("queuing a resource request.");
|
||||
SCHED_REQUEST req;
|
||||
|
|
@ -103,7 +110,8 @@ void unpackResourceRequest () {
|
|||
update ();
|
||||
}
|
||||
|
||||
void unpackTaskDone () {
|
||||
void unpackTaskDone ()
|
||||
{
|
||||
|
||||
printDebugMessage ("I'm notified a worker is now idle.");
|
||||
SCHED_RESOURCE res;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <scheduler.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -53,7 +53,7 @@ extern void initScheduler ();
|
|||
extern void unpackResourceRequest ();
|
||||
|
||||
/* Being known a worker is now idle :-) */
|
||||
extern void unpackTaskDone ();
|
||||
extern void unpackTaskDone ();
|
||||
|
||||
extern bool allResourcesFree ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <schema.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -51,17 +51,19 @@ Node * my_node;
|
|||
static unsigned maxSpecifiedRunnerID = 0;
|
||||
|
||||
|
||||
RANK_ID getRankOfRunner (RUNNER_ID __key) {
|
||||
RANK_ID getRankOfRunner (RUNNER_ID __key)
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
|
||||
if (the_schema [i].id_run [j] == __key)
|
||||
return the_schema [i].rk;
|
||||
assert (false);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void loadNode (int __rk_sched) {
|
||||
static void loadNode (int __rk_sched)
|
||||
{
|
||||
|
||||
Node node;
|
||||
|
||||
|
|
@ -72,55 +74,62 @@ static void loadNode (int __rk_sched) {
|
|||
/* ATT: num_workers */
|
||||
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
|
||||
/* TAG: <runner> | </node> */
|
||||
std :: string name = getNextNode ();
|
||||
assert (name == "runner" || name == "node");
|
||||
if (name == "runner") {
|
||||
/* TAG: </node> */
|
||||
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
||||
if ( node.id_run.back() > maxSpecifiedRunnerID )
|
||||
maxSpecifiedRunnerID = node.id_run.back();
|
||||
/* TAG: </runner> */
|
||||
assert (getNextNode () == "runner");
|
||||
/* TAG: <runner> | </node> */
|
||||
std :: string name = getNextNode ();
|
||||
assert (name == "runner" || name == "node");
|
||||
if (name == "runner")
|
||||
{
|
||||
/* TAG: </node> */
|
||||
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
||||
if ( node.id_run.back() > maxSpecifiedRunnerID )
|
||||
maxSpecifiedRunnerID = node.id_run.back();
|
||||
/* TAG: </runner> */
|
||||
assert (getNextNode () == "runner");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* TAG: </node> */
|
||||
node.execution_id_run = node.id_run;
|
||||
the_schema.push_back (node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* TAG: </node> */
|
||||
node.execution_id_run = node.id_run;
|
||||
the_schema.push_back (node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void loadGroup () {
|
||||
static void loadGroup ()
|
||||
{
|
||||
|
||||
std :: string name;
|
||||
|
||||
/* ATT: scheduler*/
|
||||
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
|
||||
/* TAG: <node> | </group> */
|
||||
name = getNextNode ();
|
||||
assert (name == "node" || name == "group");
|
||||
if (name == "node")
|
||||
/* TAG: <node> */
|
||||
loadNode (rk_sched);
|
||||
else
|
||||
/* TAG: </group> */
|
||||
break;
|
||||
}
|
||||
/* TAG: <node> | </group> */
|
||||
name = getNextNode ();
|
||||
assert (name == "node" || name == "group");
|
||||
if (name == "node")
|
||||
/* TAG: <node> */
|
||||
loadNode (rk_sched);
|
||||
else
|
||||
/* TAG: </group> */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool isScheduleNode () {
|
||||
bool isScheduleNode ()
|
||||
{
|
||||
|
||||
return my_node -> rk == my_node -> rk_sched;
|
||||
}
|
||||
|
||||
void loadSchema (const char * __filename) {
|
||||
void loadSchema (const char * __filename)
|
||||
{
|
||||
|
||||
openXMLDocument (__filename);
|
||||
|
||||
|
|
@ -133,37 +142,43 @@ void loadSchema (const char * __filename) {
|
|||
the_schema.clear();
|
||||
maxSpecifiedRunnerID = 0;
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
|
||||
/* TAG: <group> | </schema> */
|
||||
name = getNextNode ();
|
||||
assert (name == "group" || name == "schema");
|
||||
if (name == "group")
|
||||
/* TAG: <group> */
|
||||
loadGroup ();
|
||||
else
|
||||
/* TAG: </schema> */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
std :: set<unsigned> uniqueRunnerIDs; unsigned nbUniqueIDs = 0;
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
||||
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++) {
|
||||
uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
|
||||
/* In case a duplicate ID has been found */
|
||||
if ( uniqueRunnerIDs.size() == nbUniqueIDs ) {
|
||||
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
|
||||
}
|
||||
nbUniqueIDs = uniqueRunnerIDs.size();
|
||||
/* TAG: <group> | </schema> */
|
||||
name = getNextNode ();
|
||||
assert (name == "group" || name == "schema");
|
||||
if (name == "group")
|
||||
/* TAG: <group> */
|
||||
loadGroup ();
|
||||
else
|
||||
/* TAG: </schema> */
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
std :: set<unsigned> uniqueRunnerIDs;
|
||||
unsigned nbUniqueIDs = 0;
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||
{
|
||||
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++)
|
||||
{
|
||||
uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
|
||||
/* In case a duplicate ID has been found */
|
||||
if ( uniqueRunnerIDs.size() == nbUniqueIDs )
|
||||
{
|
||||
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
|
||||
}
|
||||
nbUniqueIDs = uniqueRunnerIDs.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Looking for my node */
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
||||
if (the_schema [i].rk == getNodeRank ())
|
||||
my_node = & (the_schema [i]);
|
||||
}
|
||||
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||
{
|
||||
if (the_schema [i].rk == getNodeRank ())
|
||||
my_node = & (the_schema [i]);
|
||||
}
|
||||
|
||||
|
||||
/* About me */
|
||||
|
|
@ -175,16 +190,18 @@ void loadSchema (const char * __filename) {
|
|||
if (isScheduleNode ())
|
||||
printDebugMessage ("I'am a scheduler");
|
||||
|
||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
|
||||
sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
|
||||
printDebugMessage (mess);
|
||||
}
|
||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
||||
{
|
||||
sprintf (mess, "I manage the runner %d", my_node -> id_run [i]);
|
||||
printDebugMessage (mess);
|
||||
}
|
||||
|
||||
if (my_node -> num_workers) {
|
||||
if (my_node -> num_workers)
|
||||
{
|
||||
|
||||
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
|
||||
printDebugMessage (mess);
|
||||
}
|
||||
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
|
||||
printDebugMessage (mess);
|
||||
}
|
||||
|
||||
closeXMLDocument ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <schema.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <send.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -50,13 +50,15 @@
|
|||
#define TO_ALL -1
|
||||
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
|
||||
Communicable * comm;
|
||||
int to;
|
||||
int tag;
|
||||
Communicable * comm;
|
||||
int to;
|
||||
int tag;
|
||||
|
||||
} SEND_REQUEST;
|
||||
}
|
||||
SEND_REQUEST;
|
||||
|
||||
|
||||
static std :: queue <SEND_REQUEST> mess;
|
||||
|
|
@ -66,15 +68,17 @@ static sem_t sem_send;
|
|||
static bool contextInitialized = false;
|
||||
|
||||
|
||||
void initSending () {
|
||||
void initSending ()
|
||||
{
|
||||
|
||||
static bool initializedSemaphore = false;
|
||||
|
||||
mess = std :: queue <SEND_REQUEST> ();
|
||||
|
||||
if (initializedSemaphore) {
|
||||
sem_destroy(& sem_send);
|
||||
}
|
||||
if (initializedSemaphore)
|
||||
{
|
||||
sem_destroy(& sem_send);
|
||||
}
|
||||
|
||||
sem_init (& sem_send, 0, 1);
|
||||
initializedSemaphore = true;
|
||||
|
|
@ -82,9 +86,10 @@ void initSending () {
|
|||
contextInitialized = false;
|
||||
}
|
||||
|
||||
void send (Communicable * __comm, int __to, int __tag) {
|
||||
void send (Communicable * __comm, int __to, int __tag)
|
||||
{
|
||||
|
||||
SEND_REQUEST req;
|
||||
SEND_REQUEST req;
|
||||
req.comm = __comm;
|
||||
req.to = __to;
|
||||
req.tag = __tag;
|
||||
|
|
@ -95,74 +100,79 @@ void send (Communicable * __comm, int __to, int __tag) {
|
|||
wakeUpCommunicator ();
|
||||
}
|
||||
|
||||
void sendToAll (Communicable * __comm, int __tag) {
|
||||
void sendToAll (Communicable * __comm, int __tag)
|
||||
{
|
||||
|
||||
send (__comm, TO_ALL, __tag);
|
||||
}
|
||||
|
||||
extern void initializeContext ();
|
||||
|
||||
void sendMessages () {
|
||||
void sendMessages ()
|
||||
{
|
||||
|
||||
if (! contextInitialized) {
|
||||
contextInitialized = true;
|
||||
initializeContext();
|
||||
}
|
||||
if (! contextInitialized)
|
||||
{
|
||||
contextInitialized = true;
|
||||
initializeContext();
|
||||
}
|
||||
|
||||
sem_wait (& sem_send);
|
||||
|
||||
while (! mess.empty ()) {
|
||||
while (! mess.empty ())
|
||||
{
|
||||
|
||||
SEND_REQUEST req = mess.front ();
|
||||
SEND_REQUEST req = mess.front ();
|
||||
|
||||
Communicable * comm = req.comm;
|
||||
Communicable * comm = req.comm;
|
||||
|
||||
initMessage ();
|
||||
initMessage ();
|
||||
|
||||
switch (req.tag) {
|
||||
switch (req.tag)
|
||||
{
|
||||
|
||||
case RUNNER_STOP_TAG:
|
||||
dynamic_cast <Runner *> (comm) -> packTermination ();
|
||||
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
||||
break;
|
||||
case RUNNER_STOP_TAG:
|
||||
dynamic_cast <Runner *> (comm) -> packTermination ();
|
||||
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
||||
break;
|
||||
|
||||
case COOP_TAG:
|
||||
dynamic_cast <Cooperative *> (comm) -> pack ();
|
||||
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
||||
break;
|
||||
case COOP_TAG:
|
||||
dynamic_cast <Cooperative *> (comm) -> pack ();
|
||||
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
||||
break;
|
||||
|
||||
case SYNCHRONIZE_REQ_TAG:
|
||||
dynamic_cast <Cooperative *> (comm) -> packSynchronizeReq ();
|
||||
dynamic_cast <Cooperative *> (comm) -> notifySendingSyncReq ();
|
||||
break;
|
||||
case SYNCHRONIZE_REQ_TAG:
|
||||
dynamic_cast <Cooperative *> (comm) -> packSynchronizeReq ();
|
||||
dynamic_cast <Cooperative *> (comm) -> notifySendingSyncReq ();
|
||||
break;
|
||||
|
||||
case SCHED_REQUEST_TAG:
|
||||
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
||||
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
||||
break;
|
||||
case SCHED_REQUEST_TAG:
|
||||
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
||||
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
||||
break;
|
||||
|
||||
case TASK_RESULT_TAG:
|
||||
dynamic_cast <Worker *> (comm) -> packResult ();
|
||||
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
||||
break;
|
||||
case TASK_RESULT_TAG:
|
||||
dynamic_cast <Worker *> (comm) -> packResult ();
|
||||
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
||||
break;
|
||||
|
||||
case TASK_DONE_TAG:
|
||||
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
||||
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
||||
break;
|
||||
case TASK_DONE_TAG:
|
||||
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
||||
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
if (req.to == TO_ALL)
|
||||
sendMessageToAll (req.tag);
|
||||
else
|
||||
sendMessage (req.to, req.tag);
|
||||
if (req.to == TO_ALL)
|
||||
sendMessageToAll (req.tag);
|
||||
else
|
||||
sendMessage (req.to, req.tag);
|
||||
|
||||
mess.pop ();
|
||||
}
|
||||
mess.pop ();
|
||||
}
|
||||
|
||||
sem_post (& sem_send);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <send.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <service.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,14 +41,16 @@
|
|||
#include "send.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
void Service :: requestResourceRequest (unsigned __how_many) {
|
||||
void Service :: requestResourceRequest (unsigned __how_many)
|
||||
{
|
||||
|
||||
num_sent_rr = __how_many;
|
||||
for (unsigned i = 0; i < __how_many; i ++)
|
||||
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
|
||||
}
|
||||
|
||||
void Service :: packResourceRequest () {
|
||||
void Service :: packResourceRequest ()
|
||||
{
|
||||
|
||||
SCHED_REQUEST req;
|
||||
req.first = getNodeRank ();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <scheduler.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -50,26 +50,30 @@ extern void wakeUpCommunicator();
|
|||
extern RANK_ID getRankOfRunner (RUNNER_ID __key);
|
||||
|
||||
/* Initializing the list of runners to be synchronized */
|
||||
void initSynchron () {
|
||||
void initSynchron ()
|
||||
{
|
||||
|
||||
syncRunners = SYNC();
|
||||
}
|
||||
|
||||
/* packing a synchronization request from a service */
|
||||
void packSynchronRequest ( const std :: vector <Cooperative *>& coops ) {
|
||||
void packSynchronRequest ( const std :: vector <Cooperative *>& coops )
|
||||
{
|
||||
|
||||
/* Number of coops to synchronize */
|
||||
pack( (unsigned)( coops.size() ) );
|
||||
|
||||
/* Coops to synchronize */
|
||||
for (unsigned i = 0; i < coops.size(); i ++) {
|
||||
pack( coops[ i ]->getOwner()->getDefinitionID() );
|
||||
pack( coops[ i ]->getKey() );
|
||||
}
|
||||
for (unsigned i = 0; i < coops.size(); i ++)
|
||||
{
|
||||
pack( coops[ i ]->getOwner()->getDefinitionID() );
|
||||
pack( coops[ i ]->getKey() );
|
||||
}
|
||||
}
|
||||
|
||||
/* Processing a synchronization request from a service */
|
||||
void unpackSynchronRequest () {
|
||||
void unpackSynchronRequest ()
|
||||
{
|
||||
|
||||
unsigned req_num_entries;
|
||||
unpack (req_num_entries);
|
||||
|
|
@ -79,45 +83,50 @@ void unpackSynchronRequest () {
|
|||
|
||||
/* Adding entries for each of the runners to be synchronized */
|
||||
SyncEntry req_entry;
|
||||
for (unsigned i = 0; i < req_num_entries; i ++) {
|
||||
for (unsigned i = 0; i < req_num_entries; i ++)
|
||||
{
|
||||
|
||||
unpack (req_entry.runner);
|
||||
unpack (req_entry.coop);
|
||||
unpack (req_entry.runner);
|
||||
unpack (req_entry.coop);
|
||||
|
||||
req_sync.first.push_back (req_entry);
|
||||
}
|
||||
req_sync.first.push_back (req_entry);
|
||||
}
|
||||
|
||||
/* Looking for the sync vector */
|
||||
SYNC::iterator sync_it = syncRunners.find (req_sync);
|
||||
|
||||
/* The vector does not exist - insert a new sync */
|
||||
if (sync_it == syncRunners.end ()) {
|
||||
req_sync.second = 1;
|
||||
syncRunners.insert (req_sync);
|
||||
}
|
||||
else {
|
||||
|
||||
/* The vector exists - updating the entry */
|
||||
std::pair< SYNC_RUNNERS, unsigned >& sync_req_entry = const_cast< std::pair< SYNC_RUNNERS, unsigned >& > (*sync_it);
|
||||
sync_req_entry.second ++;
|
||||
|
||||
/* All the runners to be synchronized sent the SYNC_REQUEST signal */
|
||||
if (sync_req_entry.second == sync_req_entry.first.size()) {
|
||||
|
||||
/* Remove the entry */
|
||||
syncRunners.erase (sync_it);
|
||||
|
||||
/* Send SYNCHRONIZED signals to all the coop objects */
|
||||
for (unsigned i = 0; i < req_sync.first.size(); i ++) {
|
||||
|
||||
initMessage ();
|
||||
|
||||
pack (req_sync.first [i].runner);
|
||||
pack (req_sync.first [i].coop);
|
||||
|
||||
RANK_ID dest_rank = getRankOfRunner (req_sync.first [i].runner);
|
||||
sendMessage (dest_rank, SYNCHRONIZED_TAG);
|
||||
}
|
||||
if (sync_it == syncRunners.end ())
|
||||
{
|
||||
req_sync.second = 1;
|
||||
syncRunners.insert (req_sync);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* The vector exists - updating the entry */
|
||||
std::pair< SYNC_RUNNERS, unsigned >& sync_req_entry = const_cast< std::pair< SYNC_RUNNERS, unsigned >& > (*sync_it);
|
||||
sync_req_entry.second ++;
|
||||
|
||||
/* All the runners to be synchronized sent the SYNC_REQUEST signal */
|
||||
if (sync_req_entry.second == sync_req_entry.first.size())
|
||||
{
|
||||
|
||||
/* Remove the entry */
|
||||
syncRunners.erase (sync_it);
|
||||
|
||||
/* Send SYNCHRONIZED signals to all the coop objects */
|
||||
for (unsigned i = 0; i < req_sync.first.size(); i ++)
|
||||
{
|
||||
|
||||
initMessage ();
|
||||
|
||||
pack (req_sync.first [i].runner);
|
||||
pack (req_sync.first [i].coop);
|
||||
|
||||
RANK_ID dest_rank = getRankOfRunner (req_sync.first [i].runner);
|
||||
sendMessage (dest_rank, SYNCHRONIZED_TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <synchron.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,31 +44,39 @@
|
|||
#include "../../core/runner.h"
|
||||
#include "../../core/cooperative.h"
|
||||
|
||||
struct SyncEntry {
|
||||
struct SyncEntry
|
||||
{
|
||||
|
||||
RUNNER_ID runner;
|
||||
COOP_ID coop;
|
||||
};
|
||||
RUNNER_ID runner;
|
||||
COOP_ID coop;
|
||||
};
|
||||
|
||||
struct SyncCompare {
|
||||
struct SyncCompare
|
||||
{
|
||||
|
||||
bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B ) {
|
||||
bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B )
|
||||
{
|
||||
|
||||
const std::vector< SyncEntry >& syncA = A.first;
|
||||
const std::vector< SyncEntry >& syncB = B.first;
|
||||
const std::vector< SyncEntry >& syncA = A.first;
|
||||
const std::vector< SyncEntry >& syncB = B.first;
|
||||
|
||||
if ( syncA.size() == syncB.size() ) {
|
||||
std::vector< SyncEntry >::const_iterator itA = syncA.begin();
|
||||
std::vector< SyncEntry >::const_iterator itB = syncB.begin();
|
||||
if ( syncA.size() == syncB.size() )
|
||||
{
|
||||
std::vector< SyncEntry >::const_iterator itA = syncA.begin();
|
||||
std::vector< SyncEntry >::const_iterator itB = syncB.begin();
|
||||
|
||||
while ( (*itA).runner < (*itB).runner && itA != syncA.end() ) { itA++; itB++; }
|
||||
while ( (*itA).runner < (*itB).runner && itA != syncA.end() )
|
||||
{
|
||||
itA++;
|
||||
itB++;
|
||||
}
|
||||
|
||||
return itA == syncA.end();
|
||||
return itA == syncA.end();
|
||||
}
|
||||
|
||||
return syncA.size() < syncB.size();
|
||||
}
|
||||
|
||||
return syncA.size() < syncB.size();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
typedef std::vector< SyncEntry > SYNC_RUNNERS;
|
||||
typedef std::set< std::pair< SYNC_RUNNERS, unsigned >, SyncCompare > SYNC;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <tags.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <worker.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -48,12 +48,14 @@ static std :: vector <Worker *> key_to_worker (1); /* Vector of registered worke
|
|||
|
||||
extern void wakeUpCommunicator ();
|
||||
|
||||
Worker * getWorker (WORKER_ID __key) {
|
||||
Worker * getWorker (WORKER_ID __key)
|
||||
{
|
||||
|
||||
return key_to_worker [__key];
|
||||
}
|
||||
|
||||
Worker :: Worker () {
|
||||
Worker :: Worker ()
|
||||
{
|
||||
|
||||
recvAndCompleted = false;
|
||||
taskAssigned = 0;
|
||||
|
|
@ -63,69 +65,79 @@ Worker :: Worker () {
|
|||
sem_init( &sem_task_done, 0, 0 );
|
||||
}
|
||||
|
||||
void Worker :: packResult () {
|
||||
void Worker :: packResult ()
|
||||
{
|
||||
|
||||
pack (serv_id);
|
||||
serv -> packResult ();
|
||||
}
|
||||
|
||||
void Worker :: unpackData () {
|
||||
void Worker :: unpackData ()
|
||||
{
|
||||
|
||||
taskAssigned ++;
|
||||
printDebugMessage ("unpacking the ID. of the service.");
|
||||
unpack (serv_id);
|
||||
serv = getService (serv_id);
|
||||
serv = getService (serv_id);
|
||||
printDebugMessage ("found the service.");
|
||||
serv -> unpackData ();
|
||||
serv -> unpackData ();
|
||||
printDebugMessage ("unpacking the data.");
|
||||
setActive ();
|
||||
}
|
||||
|
||||
void Worker :: packTaskDone () {
|
||||
void Worker :: packTaskDone ()
|
||||
{
|
||||
|
||||
pack (getNodeRank ());
|
||||
pack (id);
|
||||
}
|
||||
|
||||
void Worker :: notifySendingResult () {
|
||||
void Worker :: notifySendingResult ()
|
||||
{
|
||||
|
||||
/* Notifying the scheduler of the termination */
|
||||
recvAndCompleted = true;
|
||||
wakeUp ();
|
||||
}
|
||||
|
||||
void Worker :: notifySendingTaskDone () {
|
||||
void Worker :: notifySendingTaskDone ()
|
||||
{
|
||||
|
||||
sem_post(&sem_task_done);
|
||||
setPassive ();
|
||||
}
|
||||
|
||||
void Worker :: setSource (int __rank) {
|
||||
void Worker :: setSource (int __rank)
|
||||
{
|
||||
|
||||
src = __rank;
|
||||
}
|
||||
|
||||
void Worker :: start () {
|
||||
void Worker :: start ()
|
||||
{
|
||||
|
||||
while (true) {
|
||||
while (true)
|
||||
{
|
||||
|
||||
sleep ();
|
||||
sleep ();
|
||||
|
||||
if (! atLeastOneActiveRunner () && ! taskAssigned)
|
||||
break;
|
||||
if (! atLeastOneActiveRunner () && ! taskAssigned)
|
||||
break;
|
||||
|
||||
if (recvAndCompleted) {
|
||||
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
||||
recvAndCompleted = false;
|
||||
sem_wait(&sem_task_done);
|
||||
taskAssigned --;
|
||||
if (recvAndCompleted)
|
||||
{
|
||||
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
||||
recvAndCompleted = false;
|
||||
sem_wait(&sem_task_done);
|
||||
taskAssigned --;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
serv -> execute ();
|
||||
send (this, src, TASK_RESULT_TAG);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
serv -> execute ();
|
||||
send (this, src, TASK_RESULT_TAG);
|
||||
}
|
||||
}
|
||||
|
||||
printDebugMessage ("Worker finished execution.");
|
||||
setPassive ();
|
||||
|
|
@ -133,7 +145,8 @@ void Worker :: start () {
|
|||
wakeUpCommunicator();
|
||||
}
|
||||
|
||||
void initWorkersEnv () {
|
||||
void initWorkersEnv ()
|
||||
{
|
||||
|
||||
key_to_worker.resize (1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <worker.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,41 +42,42 @@
|
|||
#include "../../core/service.h"
|
||||
|
||||
|
||||
typedef unsigned WORKER_ID;
|
||||
typedef unsigned WORKER_ID;
|
||||
|
||||
class Worker : public Communicable, public ReactiveThread {
|
||||
class Worker : public Communicable, public ReactiveThread
|
||||
{
|
||||
|
||||
public :
|
||||
public :
|
||||
|
||||
Worker ();
|
||||
Worker ();
|
||||
|
||||
void start ();
|
||||
void start ();
|
||||
|
||||
void packResult ();
|
||||
void packResult ();
|
||||
|
||||
void unpackData ();
|
||||
void unpackData ();
|
||||
|
||||
void packTaskDone ();
|
||||
void packTaskDone ();
|
||||
|
||||
void notifySendingResult ();
|
||||
void notifySendingResult ();
|
||||
|
||||
void notifySendingTaskDone ();
|
||||
void notifySendingTaskDone ();
|
||||
|
||||
void setSource (int __rank);
|
||||
void setSource (int __rank);
|
||||
|
||||
private :
|
||||
private :
|
||||
|
||||
WORKER_ID id;
|
||||
SERVICE_ID serv_id;
|
||||
Service * serv;
|
||||
int src;
|
||||
WORKER_ID id;
|
||||
SERVICE_ID serv_id;
|
||||
Service * serv;
|
||||
int src;
|
||||
|
||||
bool recvAndCompleted;
|
||||
unsigned taskAssigned;
|
||||
bool recvAndCompleted;
|
||||
unsigned taskAssigned;
|
||||
|
||||
sem_t sem_task_done;
|
||||
sem_t sem_task_asgn;
|
||||
};
|
||||
sem_t sem_task_done;
|
||||
sem_t sem_task_asgn;
|
||||
};
|
||||
|
||||
extern void initWorkersEnv ();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <xml_parser.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,23 +40,27 @@
|
|||
|
||||
static xmlTextReaderPtr reader;
|
||||
|
||||
void openXMLDocument (const char * __filename) {
|
||||
void openXMLDocument (const char * __filename)
|
||||
{
|
||||
|
||||
reader = xmlNewTextReaderFilename (__filename);
|
||||
|
||||
if (! reader) {
|
||||
if (! reader)
|
||||
{
|
||||
|
||||
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
void closeXMLDocument () {
|
||||
void closeXMLDocument ()
|
||||
{
|
||||
|
||||
xmlFreeTextReader (reader);
|
||||
}
|
||||
|
||||
std :: string getAttributeValue (const std :: string & __attr) {
|
||||
std :: string getAttributeValue (const std :: string & __attr)
|
||||
{
|
||||
|
||||
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
|
||||
|
||||
|
|
@ -67,7 +71,8 @@ std :: string getAttributeValue (const std :: string & __attr) {
|
|||
return str;
|
||||
}
|
||||
|
||||
static bool isSep (const xmlChar * __text) {
|
||||
static bool isSep (const xmlChar * __text)
|
||||
{
|
||||
|
||||
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
|
||||
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
|
||||
|
|
@ -75,15 +80,18 @@ static bool isSep (const xmlChar * __text) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std :: string getNextNode () {
|
||||
std :: string getNextNode ()
|
||||
{
|
||||
|
||||
xmlChar * name, * value;
|
||||
|
||||
do {
|
||||
xmlTextReaderRead (reader);
|
||||
name = xmlTextReaderName (reader);
|
||||
value = xmlTextReaderValue (reader);
|
||||
} while (! strcmp ((char *) name, "#text") && isSep (value));
|
||||
do
|
||||
{
|
||||
xmlTextReaderRead (reader);
|
||||
name = xmlTextReaderName (reader);
|
||||
value = xmlTextReaderValue (reader);
|
||||
}
|
||||
while (! strcmp ((char *) name, "#text") && isSep (value));
|
||||
|
||||
std :: string str;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <xml_parser.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -71,48 +71,48 @@ template < class POT > class eoPrint : public eoContinue <POT>
|
|||
|
||||
void peoPSOSeq ()
|
||||
{
|
||||
/*
|
||||
const unsigned int VEC_SIZE = 4;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
const unsigned int MAX_GEN = 100;
|
||||
const double INIT_POSITION_MIN = -50.0;
|
||||
const double INIT_POSITION_MAX = 50.0;
|
||||
const double INIT_VELOCITY_MIN = -1;
|
||||
const double INIT_VELOCITY_MAX = 1;
|
||||
const double omega = 1.0;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2;
|
||||
rng.reseed (44);
|
||||
std::cout<<"\n\nWith one PSO\n\n";
|
||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > popSeq;
|
||||
popSeq.append (POP_SIZE, random);
|
||||
apply(evalSeq, popSeq);
|
||||
;
|
||||
apply < Indi > (veloRandom, popSeq);
|
||||
apply < Indi > (localInit, popSeq);
|
||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||
topologySeq.setup(popSeq);
|
||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq);
|
||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||
eoPrint <Indi> printSeq;
|
||||
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
||||
continuatorSeq.add(printSeq);
|
||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||
psaSeq (popSeq);
|
||||
popSeq.sort ();
|
||||
*/
|
||||
/*
|
||||
const unsigned int VEC_SIZE = 4;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
const unsigned int MAX_GEN = 100;
|
||||
const double INIT_POSITION_MIN = -50.0;
|
||||
const double INIT_POSITION_MAX = 50.0;
|
||||
const double INIT_VELOCITY_MIN = -1;
|
||||
const double INIT_VELOCITY_MAX = 1;
|
||||
const double omega = 1.0;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2;
|
||||
rng.reseed (44);
|
||||
std::cout<<"\n\nWith one PSO\n\n";
|
||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > popSeq;
|
||||
popSeq.append (POP_SIZE, random);
|
||||
apply(evalSeq, popSeq);
|
||||
;
|
||||
apply < Indi > (veloRandom, popSeq);
|
||||
apply < Indi > (localInit, popSeq);
|
||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||
topologySeq.setup(popSeq);
|
||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq);
|
||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||
eoPrint <Indi> printSeq;
|
||||
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
||||
continuatorSeq.add(printSeq);
|
||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||
psaSeq (popSeq);
|
||||
popSeq.sort ();
|
||||
*/
|
||||
}
|
||||
|
||||
void peoPSOPara()
|
||||
|
|
|
|||
|
|
@ -52,54 +52,54 @@ double f (const Indi & _indi)
|
|||
|
||||
double peoPSOSeq ()
|
||||
{
|
||||
/*
|
||||
clock_t beginSeq,endSeq;
|
||||
double timeSeq;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
const unsigned int MAX_GEN = 5000;
|
||||
const double FIT_CONT = -1e-6;
|
||||
const double INIT_POSITION_MIN = -5.0;
|
||||
const double INIT_POSITION_MAX = 5.0;
|
||||
const double INIT_VELOCITY_MIN = -1;
|
||||
const double INIT_VELOCITY_MAX = 1;
|
||||
const double C1 = 2;
|
||||
const double C2 = 2;
|
||||
rng.reseed (36);
|
||||
beginSeq=clock();
|
||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > popSeq;
|
||||
popSeq.append (POP_SIZE, random);
|
||||
apply(evalSeq, popSeq);
|
||||
;
|
||||
apply < Indi > (veloRandom, popSeq);
|
||||
apply < Indi > (localInit, popSeq);
|
||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||
topologySeq.setup(popSeq);
|
||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
||||
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
||||
continuatorSeq.add(fitContSeq);
|
||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||
//Sequential
|
||||
psaSeq (popSeq);
|
||||
popSeq.sort ();
|
||||
endSeq=clock();
|
||||
timeSeq = endSeq-beginSeq;
|
||||
return timeSeq;
|
||||
*/
|
||||
/*
|
||||
clock_t beginSeq,endSeq;
|
||||
double timeSeq;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 10;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||
const unsigned int MAX_GEN = 5000;
|
||||
const double FIT_CONT = -1e-6;
|
||||
const double INIT_POSITION_MIN = -5.0;
|
||||
const double INIT_POSITION_MAX = 5.0;
|
||||
const double INIT_VELOCITY_MIN = -1;
|
||||
const double INIT_VELOCITY_MAX = 1;
|
||||
const double C1 = 2;
|
||||
const double C2 = 2;
|
||||
rng.reseed (36);
|
||||
beginSeq=clock();
|
||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
eoPop < Indi > popSeq;
|
||||
popSeq.append (POP_SIZE, random);
|
||||
apply(evalSeq, popSeq);
|
||||
;
|
||||
apply < Indi > (veloRandom, popSeq);
|
||||
apply < Indi > (localInit, popSeq);
|
||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||
topologySeq.setup(popSeq);
|
||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
||||
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
||||
continuatorSeq.add(fitContSeq);
|
||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||
//Sequential
|
||||
psaSeq (popSeq);
|
||||
popSeq.sort ();
|
||||
endSeq=clock();
|
||||
timeSeq = endSeq-beginSeq;
|
||||
return timeSeq;
|
||||
*/
|
||||
}
|
||||
|
||||
void peoPSOPara(long int arg)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ int main (int __argc, char *__argv[])
|
|||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
||||
// For a parallel evaluation
|
||||
|
||||
|
||||
peoEvalFunc<Indi> plainEval(f);
|
||||
peoPopEval <Indi> eval(plainEval);
|
||||
|
||||
|
|
@ -95,26 +95,26 @@ int main (int __argc, char *__argv[])
|
|||
eoSegmentCrossover<Indi> crossover; // Crossover
|
||||
eoUniformMutation<Indi> mutation(EPSILON); // Mutation
|
||||
eoSGATransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
|
||||
|
||||
// Replacement
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
||||
// Creation of the population
|
||||
eoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
|
||||
|
||||
// Algorithm
|
||||
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
|
||||
//Parallel algorithm
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
eval.setOwner(parallelEA);
|
||||
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,11 +71,11 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
const double INIT_POSITION_MIN = -2.0; // For initialize x
|
||||
const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double weight = 1;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
rng.reseed (time(0));
|
||||
|
||||
// Stopping
|
||||
|
|
@ -92,14 +92,14 @@ int main (int __argc, char *__argv[])
|
|||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
|
||||
// Velocity
|
||||
// Velocity
|
||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||
|
||||
// Initializing the best
|
||||
// Initializing the best
|
||||
eoFirstIsBestInit < Indi > localInit;
|
||||
|
||||
// Flight
|
||||
// Flight
|
||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||
eoStandardFlight < Indi > flight(bndsFlight);
|
||||
|
||||
|
|
@ -111,20 +111,20 @@ int main (int __argc, char *__argv[])
|
|||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,weight,C1,C2,bnds);
|
||||
|
||||
|
||||
// Initialization
|
||||
eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop);
|
||||
|
||||
|
||||
//Parallel algorithm
|
||||
eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight);
|
||||
peoWrapper parallelPSO( psa, pop);
|
||||
eval.setOwner(parallelPSO);
|
||||
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,14 +52,14 @@ int main (int __argc, char *__argv[])
|
|||
{
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int MAX_GEN = 300;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int MAX_GEN = 300;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const float CROSS_RATE = 0.8;
|
||||
const double EPSILON = 0.01;
|
||||
const float MUT_RATE = 0.3;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const float CROSS_RATE = 0.8;
|
||||
const double EPSILON = 0.01;
|
||||
const float MUT_RATE = 0.3;
|
||||
rng.reseed (time(0));
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
|
|
@ -70,9 +70,9 @@ int main (int __argc, char *__argv[])
|
|||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
|
||||
|
||||
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
|
||||
eoPlusReplacement<Indi> replace;
|
||||
|
|
@ -81,14 +81,14 @@ int main (int __argc, char *__argv[])
|
|||
eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
eval.setOwner(parallelEA);
|
||||
|
||||
|
||||
transform.setOwner (parallelEA);
|
||||
|
||||
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
// First algorithm
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
eoCheckPoint<Indi> checkpoint(continuatorPara);
|
||||
|
|
@ -82,10 +82,10 @@ int main (int __argc, char *__argv[])
|
|||
eoRankingSelect<Indi> selectionStrategy;
|
||||
eoSelectNumber<Indi> select(selectionStrategy,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover;
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
eoUniformMutation<Indi> mutation(EPSILON);
|
||||
peoTransform<Indi> transform(crossover,CROSS_RATE,mutation,MUT_RATE);
|
||||
peoPop < Indi > pop;
|
||||
pop.append (POP_SIZE, random);
|
||||
pop.append (POP_SIZE, random);
|
||||
eoPlusReplacement<Indi> replace;
|
||||
eoRandomSelect<Indi> mig_select_one;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_select_one,MIG_SIZE,pop);
|
||||
|
|
@ -102,7 +102,7 @@ int main (int __argc, char *__argv[])
|
|||
|
||||
// Second algorithm (on the same model but with others names)
|
||||
/*****************************************************************************************/
|
||||
|
||||
|
||||
eoGenContinue < Indi > genContPara2 (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara2 (genContPara2);
|
||||
eoCheckPoint<Indi> checkpoint2(continuatorPara2);
|
||||
|
|
@ -113,10 +113,10 @@ int main (int __argc, char *__argv[])
|
|||
eoRankingSelect<Indi> selectionStrategy2;
|
||||
eoSelectNumber<Indi> select2(selectionStrategy2,POP_SIZE);
|
||||
eoSegmentCrossover<Indi> crossover2;
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
eoUniformMutation<Indi> mutation2(EPSILON);
|
||||
peoTransform<Indi> transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE);
|
||||
peoPop < Indi > pop2;
|
||||
pop2.append (POP_SIZE, random2);
|
||||
pop2.append (POP_SIZE, random2);
|
||||
eoPlusReplacement<Indi> replace2;
|
||||
eoRandomSelect<Indi> mig_select_one2;
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_select_one2,MIG_SIZE,pop2);
|
||||
|
|
|
|||
|
|
@ -50,24 +50,24 @@ double f (const Indi & _indi)
|
|||
int main (int __argc, char *__argv[])
|
||||
{
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 100;
|
||||
const unsigned int MAX_GEN = 100;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const unsigned int MIG_FREQ = 10;
|
||||
const double omega = 1;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
const double C2 = 2.;
|
||||
rng.reseed (time(0));
|
||||
|
||||
// Island model
|
||||
|
||||
RingTopology topologyMig;
|
||||
|
||||
|
||||
// First
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
|
|
@ -93,9 +93,9 @@ int main (int __argc, char *__argv[])
|
|||
eoPeriodicContinue< Indi > mig_cont( MIG_FREQ );
|
||||
peoPSOSelect<Indi> mig_selec(topology);
|
||||
peoWorstPositionReplacement<Indi> mig_replac;
|
||||
|
||||
// Specific implementation (peoData.h)
|
||||
|
||||
|
||||
// Specific implementation (peoData.h)
|
||||
|
||||
eoContinuator<Indi> cont(mig_cont, pop);
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace (mig_replac,pop);
|
||||
|
|
@ -121,7 +121,7 @@ int main (int __argc, char *__argv[])
|
|||
eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity2 (topology2,omega,C1,C2,bnds2);
|
||||
eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2);
|
||||
|
||||
|
||||
// Island model
|
||||
|
||||
eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ );
|
||||
|
|
@ -133,15 +133,15 @@ int main (int __argc, char *__argv[])
|
|||
eoContinuator<Indi> cont2(mig_cont2,pop2);
|
||||
eoSelector <Indi, peoPop<Indi> > mig_select2 (mig_selec2,1,pop2);
|
||||
eoReplace <Indi, peoPop<Indi> > mig_replace2 (mig_replac2,pop2);
|
||||
|
||||
|
||||
|
||||
// Island model
|
||||
|
||||
|
||||
peoAsyncIslandMig< Indi, peoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig, pop, pop);
|
||||
checkpoint.add( mig );
|
||||
peoAsyncIslandMig< Indi, peoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2);
|
||||
checkpoint2.add( mig2 );
|
||||
|
||||
|
||||
|
||||
// Parallel algorithm
|
||||
|
||||
|
|
@ -156,10 +156,10 @@ int main (int __argc, char *__argv[])
|
|||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
pop2.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||
}
|
||||
{
|
||||
pop.sort();
|
||||
pop2.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,13 +59,13 @@ int main (int __argc, char * * __argv)
|
|||
{
|
||||
|
||||
peo :: init (__argc, __argv);
|
||||
loadParameters (__argc, __argv);
|
||||
loadParameters (__argc, __argv);
|
||||
RouteInit route_init;
|
||||
RouteEval full_eval;
|
||||
OrderXover order_cross;
|
||||
OrderXover order_cross;
|
||||
PartialMappedXover pm_cross;
|
||||
EdgeXover edge_cross;
|
||||
CitySwap city_swap_mut;
|
||||
CitySwap city_swap_mut;
|
||||
|
||||
// Initialization of the local search
|
||||
TwoOptInit pmx_two_opt_init;
|
||||
|
|
@ -76,7 +76,7 @@ int main (int __argc, char * * __argv)
|
|||
|
||||
// EA
|
||||
eoPop <Route> pop (POP_SIZE, route_init);
|
||||
eoGenContinue <Route> cont (NUM_GEN);
|
||||
eoGenContinue <Route> cont (NUM_GEN);
|
||||
eoCheckPoint <Route> checkpoint (cont);
|
||||
eoEvalFuncCounter< Route > eval(full_eval);
|
||||
eoStochTournamentSelect <Route> select_one;
|
||||
|
|
@ -86,16 +86,16 @@ int main (int __argc, char * * __argv)
|
|||
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
peo :: run ();
|
||||
peo :: finalize ();
|
||||
peo :: finalize ();
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std :: cout << "\nResult before the local search\n";
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
}
|
||||
|
||||
{
|
||||
pop.sort();
|
||||
std :: cout << "\nResult before the local search\n";
|
||||
for (unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
}
|
||||
|
||||
// Local search
|
||||
peo :: init (__argc, __argv);
|
||||
peoMultiStart <Route> initParallelHC (hc);
|
||||
|
|
@ -105,10 +105,10 @@ int main (int __argc, char * * __argv)
|
|||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult after the local search\n";
|
||||
pop.sort();
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
}
|
||||
{
|
||||
std :: cout << "\nResult after the local search\n";
|
||||
pop.sort();
|
||||
for (unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,13 +58,13 @@ int main (int __argc, char * * __argv)
|
|||
{
|
||||
|
||||
peo :: init (__argc, __argv);
|
||||
loadParameters (__argc, __argv);
|
||||
loadParameters (__argc, __argv);
|
||||
RouteInit route_init;
|
||||
RouteEval full_eval;
|
||||
OrderXover order_cross;
|
||||
OrderXover order_cross;
|
||||
PartialMappedXover pm_cross;
|
||||
EdgeXover edge_cross;
|
||||
CitySwap city_swap_mut;
|
||||
CitySwap city_swap_mut;
|
||||
|
||||
// Local search
|
||||
TwoOptInit pmx_two_opt_init;
|
||||
|
|
@ -80,17 +80,17 @@ int main (int __argc, char * * __argv)
|
|||
peo :: finalize( );
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult before the EA\n";
|
||||
pop.sort();
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
std :: cout << "\n\n";
|
||||
}
|
||||
{
|
||||
std :: cout << "\nResult before the EA\n";
|
||||
pop.sort();
|
||||
for (unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
std :: cout << "\n\n";
|
||||
}
|
||||
|
||||
// EA
|
||||
peo :: init (__argc, __argv);
|
||||
eoGenContinue <Route> cont (NUM_GEN);
|
||||
eoGenContinue <Route> cont (NUM_GEN);
|
||||
eoCheckPoint <Route> checkpoint (cont);
|
||||
eoEvalFuncCounter< Route > eval(full_eval);
|
||||
eoStochTournamentSelect <Route> select_one;
|
||||
|
|
@ -100,14 +100,14 @@ int main (int __argc, char * * __argv)
|
|||
eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace );
|
||||
peoWrapper parallelEA( eaAlg, pop);
|
||||
peo :: run ();
|
||||
peo :: finalize ();
|
||||
peo :: finalize ();
|
||||
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
std :: cout << "\nResult after the EA\n";
|
||||
pop.sort();
|
||||
for(unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
std :: cout << "\n\n";
|
||||
}
|
||||
{
|
||||
std :: cout << "\nResult after the EA\n";
|
||||
pop.sort();
|
||||
for (unsigned i=0;i<pop.size();i++)
|
||||
std::cout<<"\n"<<pop[i].fitness();
|
||||
std :: cout << "\n\n";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,39 +50,40 @@ double f (const Indi & _indi)
|
|||
|
||||
template <class EOT>
|
||||
class eoResizerInit: public eoInit<EOT>
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename EOT::AtomType AtomType;
|
||||
|
||||
eoResizerInit(unsigned _size)
|
||||
: size(_size){}
|
||||
eoResizerInit(unsigned _size)
|
||||
: size(_size)
|
||||
{}
|
||||
|
||||
virtual void operator()(EOT& chrom)
|
||||
{
|
||||
chrom.resize(size);
|
||||
chrom.invalidate();
|
||||
}
|
||||
private :
|
||||
unsigned size;
|
||||
};
|
||||
virtual void operator()(EOT& chrom)
|
||||
{
|
||||
chrom.resize(size);
|
||||
chrom.invalidate();
|
||||
}
|
||||
private :
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
|
||||
int main( int __argc, char** __argv )
|
||||
{
|
||||
|
||||
|
||||
peo :: init( __argc, __argv );
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int VEC_SIZE = 2;
|
||||
const unsigned int POP_SIZE = 20;
|
||||
const unsigned int NEIGHBORHOOD_SIZE= 6;
|
||||
const unsigned int MAX_GEN = 300;
|
||||
const unsigned int MAX_GEN = 300;
|
||||
const double INIT_POSITION_MIN = -2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_POSITION_MAX = 2.0;
|
||||
const double INIT_VELOCITY_MIN = -1.;
|
||||
const double INIT_VELOCITY_MAX = 1.;
|
||||
const double omega = 1;
|
||||
const double omega = 1;
|
||||
const double C1 = 0.5;
|
||||
const double C2 = 2.;
|
||||
const double C2 = 2.;
|
||||
rng.reseed (time(0));
|
||||
eoGenContinue < Indi > genContPara (MAX_GEN);
|
||||
eoCombinedContinue <Indi> continuatorPara (genContPara);
|
||||
|
|
@ -96,7 +97,7 @@ int main( int __argc, char** __argv )
|
|||
eoLinearTopology<Indi> topology(NEIGHBORHOOD_SIZE);
|
||||
eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||
eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds);
|
||||
|
||||
|
||||
eoResizerInit<Indi> sizeInit(VEC_SIZE);
|
||||
// need at least a size initialization
|
||||
eoPop < Indi > pop(POP_SIZE,sizeInit);
|
||||
|
|
@ -105,7 +106,7 @@ int main( int __argc, char** __argv )
|
|||
peoWrapper random (initRandom,pop);
|
||||
initRandom.setOwner(random);
|
||||
peo :: run( );
|
||||
peo :: finalize( );
|
||||
peo :: finalize( );
|
||||
|
||||
// Parallel algorithm
|
||||
|
||||
|
|
@ -119,8 +120,8 @@ int main( int __argc, char** __argv )
|
|||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,24 +44,24 @@
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
peo :: init( argc,argv );
|
||||
eoParser parser(argc, argv);
|
||||
eoState state;
|
||||
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
|
||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||
moeoArchive<FlowShop> arch;
|
||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
||||
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||
peoWrapper parallelMOEO( algo, pop);
|
||||
eval.setOwner(parallelMOEO);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
peo :: init( argc,argv );
|
||||
eoParser parser(argc, argv);
|
||||
eoState state;
|
||||
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
|
||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||
moeoArchive<FlowShop> arch;
|
||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
||||
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||
peoWrapper parallelMOEO( algo, pop);
|
||||
eval.setOwner(parallelMOEO);
|
||||
peo :: run();
|
||||
peo :: finalize();
|
||||
if (getNodeRank()==1)
|
||||
{
|
||||
pop.sort();
|
||||
std::cout << "Final population :\n" << pop << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,13 +88,13 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
|
|||
}
|
||||
// maxEval
|
||||
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
|
||||
/* if (maxEvalParam.value())
|
||||
{
|
||||
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
||||
_state.storeFunctor(evalCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
||||
}*/
|
||||
/* if (maxEvalParam.value())
|
||||
{
|
||||
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
||||
_state.storeFunctor(evalCont);
|
||||
// and "add" to combined
|
||||
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
||||
}*/
|
||||
// maxTime
|
||||
eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
|
||||
if (maxTimeParam.value()) // positive: -> define and store
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ static int screen;
|
|||
/*
|
||||
gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ;
|
||||
|
||||
gdk_gc_set_foreground (gc, & color_green) ;
|
||||
gdk_gc_set_foreground (gc, & color_green) ;
|
||||
|
||||
for (int i = 0 ; i < (int) numNodes ; i ++) {
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ for (int i = 0 ; i < (int) numNodes ; i ++) {
|
|||
Y_new_coord [opt_route [i]],
|
||||
X_new_coord [opt_route [(i + 1) % numNodes]],
|
||||
Y_new_coord [opt_route [(i + 1) % numNodes]]);
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
void openMainWindow (const char * __filename)
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
||||
) : pop (__pop)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DisplayBestRoute :: operator () ()
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ PartRouteEval :: PartRouteEval (float __from,
|
|||
float __to
|
||||
) : from (__from),
|
||||
to (__to)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void PartRouteEval :: operator () (Route & __route)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue