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
|
|
@ -47,7 +47,8 @@ static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of regist
|
||||||
unsigned Communicable :: num_comm = 0;
|
unsigned Communicable :: num_comm = 0;
|
||||||
|
|
||||||
|
|
||||||
Communicable :: Communicable () {
|
Communicable :: Communicable ()
|
||||||
|
{
|
||||||
|
|
||||||
comm_to_key [this] = key = ++ num_comm;
|
comm_to_key [this] = key = ++ num_comm;
|
||||||
key_to_comm.push_back (this);
|
key_to_comm.push_back (this);
|
||||||
|
|
@ -55,46 +56,54 @@ Communicable :: Communicable () {
|
||||||
sem_init (& sem_stop, 0, 0);
|
sem_init (& sem_stop, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Communicable :: ~ Communicable () {
|
Communicable :: ~ Communicable ()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
COMM_ID Communicable :: getKey () {
|
COMM_ID Communicable :: getKey ()
|
||||||
|
{
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
Communicable * getCommunicable (COMM_ID __key) {
|
Communicable * getCommunicable (COMM_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
assert (__key < key_to_comm.size ());
|
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];
|
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);
|
sem_post (& sem_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: stop () {
|
void Communicable :: stop ()
|
||||||
|
{
|
||||||
sem_wait (& sem_stop);
|
sem_wait (& sem_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicable :: resume () {
|
void Communicable :: resume ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post (& sem_stop);
|
sem_post (& sem_stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCommunicableEnv () {
|
void initCommunicableEnv ()
|
||||||
|
{
|
||||||
|
|
||||||
key_to_comm.resize (1);
|
key_to_comm.resize (1);
|
||||||
comm_to_key.clear ();
|
comm_to_key.clear ();
|
||||||
|
|
|
||||||
|
|
@ -42,34 +42,35 @@
|
||||||
|
|
||||||
typedef unsigned COMM_ID;
|
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 lock (); /* It suspends the current process if the semaphore is locked */
|
||||||
void unlock (); /* It unlocks the shared semaphore */
|
void unlock (); /* It unlocks the shared semaphore */
|
||||||
|
|
||||||
void stop (); /* It suspends the current process */
|
void stop (); /* It suspends the current process */
|
||||||
void resume (); /* It resumes ___________ */
|
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 void initCommunicableEnv ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,37 +43,38 @@
|
||||||
|
|
||||||
typedef unsigned COOP_ID;
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,16 @@
|
||||||
#include "messaging.h"
|
#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 ());
|
pack ((unsigned) __pop.size ());
|
||||||
for (unsigned i = 0; i < __pop.size (); i ++)
|
for (unsigned i = 0; i < __pop.size (); i ++)
|
||||||
pack (__pop [i]);
|
pack (__pop [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class EOT> void unpack (eoPop <EOT> & __pop) {
|
template <class EOT> void unpack (eoPop <EOT> & __pop)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,18 @@
|
||||||
#include "messaging.h"
|
#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()) {
|
if (__v.invalid())
|
||||||
pack((unsigned)0);
|
{
|
||||||
}
|
pack((unsigned)0);
|
||||||
else {
|
}
|
||||||
pack((unsigned)1);
|
else
|
||||||
pack (__v.fitness ());
|
{
|
||||||
}
|
pack((unsigned)1);
|
||||||
|
pack (__v.fitness ());
|
||||||
|
}
|
||||||
|
|
||||||
unsigned len = __v.size ();
|
unsigned len = __v.size ();
|
||||||
pack (len);
|
pack (len);
|
||||||
|
|
@ -59,18 +62,22 @@ template <class F, class T> void pack (const eoVector <F, T> & __v) {
|
||||||
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) {
|
if (! valid)
|
||||||
__v.invalidate();
|
{
|
||||||
}
|
__v.invalidate();
|
||||||
else {
|
}
|
||||||
F fit;
|
else
|
||||||
unpack (fit);
|
{
|
||||||
__v.fitness (fit);
|
F fit;
|
||||||
}
|
unpack (fit);
|
||||||
|
__v.fitness (fit);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned len;
|
unsigned len;
|
||||||
unpack (len);
|
unpack (len);
|
||||||
|
|
@ -79,16 +86,19 @@ template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
||||||
unpack (__v [i]);
|
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()) {
|
if (__v.invalid())
|
||||||
pack((unsigned)0);
|
{
|
||||||
}
|
pack((unsigned)0);
|
||||||
else {
|
}
|
||||||
pack((unsigned)1);
|
else
|
||||||
pack (__v.fitness ());
|
{
|
||||||
pack (__v.best());
|
pack((unsigned)1);
|
||||||
}
|
pack (__v.fitness ());
|
||||||
|
pack (__v.best());
|
||||||
|
}
|
||||||
|
|
||||||
unsigned len = __v.size ();
|
unsigned len = __v.size ();
|
||||||
pack (len);
|
pack (len);
|
||||||
|
|
@ -100,21 +110,25 @@ template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V>
|
||||||
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) {
|
if (! valid)
|
||||||
__v.invalidate();
|
{
|
||||||
}
|
__v.invalidate();
|
||||||
else {
|
}
|
||||||
F fit;
|
else
|
||||||
unpack (fit);
|
{
|
||||||
__v.fitness (fit);
|
F fit;
|
||||||
|
unpack (fit);
|
||||||
|
__v.fitness (fit);
|
||||||
unpack(fit);
|
unpack(fit);
|
||||||
__v.best(fit);
|
__v.best(fit);
|
||||||
|
|
||||||
}
|
}
|
||||||
unsigned len;
|
unsigned len;
|
||||||
unpack (len);
|
unpack (len);
|
||||||
__v.resize (len);
|
__v.resize (len);
|
||||||
|
|
@ -128,76 +142,76 @@ unsigned valid; unpack(valid);
|
||||||
|
|
||||||
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;
|
unsigned valid;
|
||||||
unpack(valid);
|
unpack(valid);
|
||||||
if (! valid)
|
if (! valid)
|
||||||
_v.invalidate();
|
_v.invalidate();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
T fit;
|
T fit;
|
||||||
unpack (fit);
|
unpack (fit);
|
||||||
_v.fitness (fit);
|
_v.fitness (fit);
|
||||||
}
|
|
||||||
unpack(valid);
|
|
||||||
if (! valid)
|
|
||||||
_v.invalidateDiversity();
|
|
||||||
else
|
|
||||||
{
|
|
||||||
V diver;
|
|
||||||
unpack(diver);
|
|
||||||
_v.diversity(diver);
|
|
||||||
}
|
}
|
||||||
unsigned len;
|
unpack(valid);
|
||||||
unpack (len);
|
if (! valid)
|
||||||
_v.resize (len);
|
_v.invalidateDiversity();
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
else
|
||||||
unpack (_v [i]);
|
|
||||||
unpack(valid);
|
|
||||||
if (! valid)
|
|
||||||
_v.invalidateObjectiveVector();
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
F object;
|
V diver;
|
||||||
unpack (len);
|
unpack(diver);
|
||||||
object.resize(len);
|
_v.diversity(diver);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
}
|
||||||
unpack (object[i]);
|
unsigned len;
|
||||||
_v.objectiveVector(object);
|
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())
|
if (_v.invalid())
|
||||||
pack((unsigned)0);
|
pack((unsigned)0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pack((unsigned)1);
|
pack((unsigned)1);
|
||||||
pack (_v.fitness ());
|
pack (_v.fitness ());
|
||||||
}
|
}
|
||||||
if (_v.invalidDiversity())
|
if (_v.invalidDiversity())
|
||||||
pack((unsigned)0);
|
pack((unsigned)0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pack((unsigned)1);
|
pack((unsigned)1);
|
||||||
pack(_v.diversity());
|
pack(_v.diversity());
|
||||||
}
|
}
|
||||||
unsigned len = _v.size ();
|
unsigned len = _v.size ();
|
||||||
pack (len);
|
pack (len);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
pack (_v[i]);
|
pack (_v[i]);
|
||||||
if (_v.invalidObjectiveVector())
|
if (_v.invalidObjectiveVector())
|
||||||
pack((unsigned)0);
|
pack((unsigned)0);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pack((unsigned)1);
|
pack((unsigned)1);
|
||||||
F object;
|
F object;
|
||||||
object=_v.objectiveVector();
|
object=_v.objectiveVector();
|
||||||
len=object.nObjectives();
|
len=object.nObjectives();
|
||||||
pack (len);
|
pack (len);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
pack (object[i]);
|
pack (object[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -75,13 +75,15 @@ extern void pack (const char * __str);
|
||||||
extern void pack (const std::string & __str);
|
extern void pack (const std::string & __str);
|
||||||
|
|
||||||
/* Pointer */
|
/* 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 */
|
/* 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.first);
|
||||||
pack (__pair.second);
|
pack (__pair.second);
|
||||||
|
|
@ -124,7 +126,8 @@ extern void unpack (char * __str);
|
||||||
extern void unpack (std::string & __str);
|
extern void unpack (std::string & __str);
|
||||||
|
|
||||||
/* Pointer */
|
/* Pointer */
|
||||||
template <class T> void unpack (T * & __ptr) {
|
template <class T> void unpack (T * & __ptr)
|
||||||
|
{
|
||||||
|
|
||||||
unsigned long p;
|
unsigned long p;
|
||||||
unpack (p);
|
unpack (p);
|
||||||
|
|
@ -132,7 +135,8 @@ template <class T> void unpack (T * & __ptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pair */
|
/* 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.first);
|
||||||
unpack (__pair.second);
|
unpack (__pair.second);
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ static char host [MAX_BUFF_SIZE];
|
||||||
std :: vector <FILE *> files;
|
std :: vector <FILE *> files;
|
||||||
|
|
||||||
|
|
||||||
void setDebugMode (bool __dbg) {
|
void setDebugMode (bool __dbg)
|
||||||
|
{
|
||||||
|
|
||||||
debug = __dbg;
|
debug = __dbg;
|
||||||
gethostname (host, MAX_BUFF_SIZE);
|
gethostname (host, MAX_BUFF_SIZE);
|
||||||
|
|
@ -66,7 +67,8 @@ void setDebugMode (bool __dbg) {
|
||||||
|
|
||||||
extern int getNodeRank ();
|
extern int getNodeRank ();
|
||||||
|
|
||||||
void initDebugging () {
|
void initDebugging ()
|
||||||
|
{
|
||||||
|
|
||||||
mkdir (DEBUG_PATH, S_IRWXU);
|
mkdir (DEBUG_PATH, S_IRWXU);
|
||||||
// files.push_back (stdout);
|
// files.push_back (stdout);
|
||||||
|
|
@ -75,7 +77,8 @@ void initDebugging () {
|
||||||
files.push_back (fopen (buff, "w"));
|
files.push_back (fopen (buff, "w"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void endDebugging () {
|
void endDebugging ()
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < files.size (); i ++)
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
if (files [i] != stdout)
|
if (files [i] != stdout)
|
||||||
|
|
@ -83,29 +86,32 @@ void endDebugging () {
|
||||||
files.clear();
|
files.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDebugMessage (const char * __mess) {
|
void printDebugMessage (const char * __mess)
|
||||||
|
{
|
||||||
|
|
||||||
if (debug) {
|
if (debug)
|
||||||
|
{
|
||||||
|
|
||||||
char buff [MAX_BUFF_SIZE];
|
char buff [MAX_BUFF_SIZE];
|
||||||
char localTime [MAX_BUFF_SIZE];
|
char localTime [MAX_BUFF_SIZE];
|
||||||
time_t t = time (0);
|
time_t t = time (0);
|
||||||
|
|
||||||
/* Date */
|
/* Date */
|
||||||
strcpy( localTime, ctime (& t) );
|
strcpy( localTime, ctime (& t) );
|
||||||
localTime[ strlen( localTime )-1 ] = ']';
|
localTime[ strlen( localTime )-1 ] = ']';
|
||||||
sprintf (buff, "[%s][%s: ", host, localTime );
|
sprintf (buff, "[%s][%s: ", host, localTime );
|
||||||
|
|
||||||
for (unsigned i = 0; i < files.size (); i ++)
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
fprintf (files [i], buff);
|
fprintf (files [i], buff);
|
||||||
|
|
||||||
/* Message */
|
/* Message */
|
||||||
sprintf (buff, "%s", __mess);
|
sprintf (buff, "%s", __mess);
|
||||||
|
|
||||||
for (unsigned i = 0; i < files.size (); i ++) {
|
for (unsigned i = 0; i < files.size (); i ++)
|
||||||
fputs (buff, files [i]);
|
{
|
||||||
fputs ("\n", files [i]);
|
fputs (buff, files [i]);
|
||||||
fflush (files [i]);
|
fputs ("\n", files [i]);
|
||||||
|
fflush (files [i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
#include "rmc.h"
|
#include "rmc.h"
|
||||||
|
|
||||||
void peo :: finalize () {
|
void peo :: finalize ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("waiting for the termination of all threads");
|
printDebugMessage ("waiting for the termination of all threads");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@
|
||||||
#ifndef __peo_finalize_h
|
#ifndef __peo_finalize_h
|
||||||
#define __peo_finalize_h
|
#define __peo_finalize_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void finalize ();
|
extern void finalize ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ extern void initScheduler ();
|
||||||
extern void initSynchron ();
|
extern void initSynchron ();
|
||||||
|
|
||||||
|
|
||||||
static void initExecutionEnv() {
|
static void initExecutionEnv()
|
||||||
|
{
|
||||||
|
|
||||||
initCommunicableEnv ();
|
initCommunicableEnv ();
|
||||||
initBuffers ();
|
initBuffers ();
|
||||||
|
|
@ -72,13 +73,15 @@ static void initExecutionEnv() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
int * argc;
|
int * argc;
|
||||||
|
|
||||||
char * * * argv;
|
char * * * argv;
|
||||||
|
|
||||||
void init (int & __argc, char * * & __argv) {
|
void init (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
argc = & __argc;
|
argc = & __argc;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@
|
||||||
#ifndef __peo_init_h
|
#ifndef __peo_init_h
|
||||||
#define __peo_init_h
|
#define __peo_init_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern int * argc;
|
extern int * argc;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,8 @@
|
||||||
#include "peo_debug.h"
|
#include "peo_debug.h"
|
||||||
|
|
||||||
|
|
||||||
void peo :: loadParameters (int & __argc, char * * & __argv) {
|
void peo :: loadParameters (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
eoParser parser (__argc, __argv);
|
eoParser parser (__argc, __argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@
|
||||||
#ifndef __peo_param_h
|
#ifndef __peo_param_h
|
||||||
#define __peo_param_h
|
#define __peo_param_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void loadParameters (int & __argc, char * * & __argv);
|
extern void loadParameters (int & __argc, char * * & __argv);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@
|
||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
||||||
|
|
||||||
void peo :: run () {
|
void peo :: run ()
|
||||||
|
{
|
||||||
|
|
||||||
startRunners ();
|
startRunners ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,8 @@
|
||||||
#ifndef __peo_run_h
|
#ifndef __peo_run_h
|
||||||
#define __peo_run_h
|
#define __peo_run_h
|
||||||
|
|
||||||
namespace peo {
|
namespace peo
|
||||||
|
{
|
||||||
|
|
||||||
extern void run ();
|
extern void run ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,29 +41,34 @@ static bool the_end = false;
|
||||||
static std :: vector <ReactiveThread *> reac_threads;
|
static std :: vector <ReactiveThread *> reac_threads;
|
||||||
|
|
||||||
|
|
||||||
ReactiveThread :: ReactiveThread () {
|
ReactiveThread :: ReactiveThread ()
|
||||||
|
{
|
||||||
|
|
||||||
reac_threads.push_back (this);
|
reac_threads.push_back (this);
|
||||||
sem_init (& sem, 0, 0);
|
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;
|
the_end = false;
|
||||||
reac_threads.clear ();
|
reac_threads.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopReactiveThreads () {
|
void stopReactiveThreads ()
|
||||||
|
{
|
||||||
|
|
||||||
the_end = true;
|
the_end = true;
|
||||||
for (unsigned i = 0; i < reac_threads.size (); i ++)
|
for (unsigned i = 0; i < reac_threads.size (); i ++)
|
||||||
|
|
@ -71,4 +76,7 @@ void stopReactiveThreads () {
|
||||||
reac_threads.clear ();
|
reac_threads.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool theEnd () { return the_end; }
|
bool theEnd ()
|
||||||
|
{
|
||||||
|
return the_end;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,21 +42,22 @@
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
|
|
||||||
class ReactiveThread : public Thread {
|
class ReactiveThread : public Thread
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Ctor */
|
/* Ctor */
|
||||||
ReactiveThread ();
|
ReactiveThread ();
|
||||||
|
|
||||||
void sleep ();
|
void sleep ();
|
||||||
|
|
||||||
void wakeUp ();
|
void wakeUp ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
sem_t sem;
|
sem_t sem;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void initReactiveThreadsEnv ();
|
extern void initReactiveThreadsEnv ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,17 +37,19 @@
|
||||||
#include "ring_topo.h"
|
#include "ring_topo.h"
|
||||||
|
|
||||||
void RingTopology :: setNeighbors (Cooperative * __mig,
|
void RingTopology :: setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __from,
|
std :: vector <Cooperative *> & __from,
|
||||||
std :: vector <Cooperative *> & __to) {
|
std :: vector <Cooperative *> & __to)
|
||||||
|
{
|
||||||
__from.clear () ;
|
__from.clear () ;
|
||||||
__to.clear () ;
|
__to.clear () ;
|
||||||
|
|
||||||
int len = mig.size () ;
|
int len = mig.size () ;
|
||||||
|
|
||||||
for (int i = 0 ; i < len ; i ++)
|
for (int i = 0 ; i < len ; i ++)
|
||||||
if (mig [i] == __mig) {
|
if (mig [i] == __mig)
|
||||||
__from.push_back (mig [(i - 1 + len) % len]) ;
|
{
|
||||||
__to.push_back (mig [(i + 1) % len]) ;
|
__from.push_back (mig [(i - 1 + len) % len]) ;
|
||||||
break;
|
__to.push_back (mig [(i + 1) % len]) ;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,14 +39,15 @@
|
||||||
|
|
||||||
#include "topology.h"
|
#include "topology.h"
|
||||||
|
|
||||||
class RingTopology : public Topology {
|
class RingTopology : public Topology
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
void setNeighbors (Cooperative * __mig,
|
void setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __from,
|
std :: vector <Cooperative *> & __from,
|
||||||
std :: vector <Cooperative *> & __to);
|
std :: vector <Cooperative *> & __to);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,8 @@ extern int getNumberOfNodes ();
|
||||||
extern void wakeUpCommunicator ();
|
extern void wakeUpCommunicator ();
|
||||||
|
|
||||||
|
|
||||||
Runner :: Runner () {
|
Runner :: Runner ()
|
||||||
|
{
|
||||||
|
|
||||||
exec_id = 0;
|
exec_id = 0;
|
||||||
def_id = ++ num_def_runners;
|
def_id = ++ num_def_runners;
|
||||||
|
|
@ -77,35 +78,41 @@ Runner :: Runner () {
|
||||||
sem_init (& sem_cntxt, 0, 0);
|
sem_init (& sem_cntxt, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
RUNNER_ID Runner :: getDefinitionID () {
|
RUNNER_ID Runner :: getDefinitionID ()
|
||||||
|
{
|
||||||
|
|
||||||
return def_id;
|
return def_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
RUNNER_ID Runner :: getExecutionID () {
|
RUNNER_ID Runner :: getExecutionID ()
|
||||||
|
{
|
||||||
|
|
||||||
return exec_id;
|
return exec_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: setExecutionID (const RUNNER_ID& execution_id) {
|
void Runner :: setExecutionID (const RUNNER_ID& execution_id)
|
||||||
|
{
|
||||||
|
|
||||||
exec_id = execution_id;
|
exec_id = execution_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
Runner * getRunner (RUNNER_ID __key) {
|
Runner * getRunner (RUNNER_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return dynamic_cast <Runner *> (getCommunicable (__key));
|
return dynamic_cast <Runner *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeContext () {
|
void initializeContext ()
|
||||||
|
{
|
||||||
|
|
||||||
num_local_exec_runners = 0;
|
num_local_exec_runners = 0;
|
||||||
|
|
||||||
// setting up the execution IDs & counting the number of local exec. runners
|
// setting up the execution IDs & counting the number of local exec. runners
|
||||||
for (unsigned i = 0; i < the_runners.size (); i ++) {
|
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 ++;
|
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 );
|
collectiveCountOfRunners( &num_local_exec_runners, &num_exec_runners );
|
||||||
|
|
||||||
|
|
@ -115,17 +122,20 @@ void initializeContext () {
|
||||||
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
|
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: waitStarting () {
|
void Runner :: waitStarting ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_start);
|
sem_wait (& sem_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: waitContextInitialization () {
|
void Runner :: waitContextInitialization ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_cntxt);
|
sem_wait (& sem_cntxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: start () {
|
void Runner :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
setActive ();
|
setActive ();
|
||||||
|
|
||||||
|
|
@ -136,46 +146,54 @@ void Runner :: start () {
|
||||||
terminate ();
|
terminate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startRunners () {
|
void startRunners ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Runners */
|
/* Runners */
|
||||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||||
if (the_runners [i] -> isAssignedLocally ()) {
|
if (the_runners [i] -> isAssignedLocally ())
|
||||||
addThread (the_runners [i], ll_threads);
|
{
|
||||||
the_runners [i] -> waitStarting ();
|
addThread (the_runners [i], ll_threads);
|
||||||
}
|
the_runners [i] -> waitStarting ();
|
||||||
|
}
|
||||||
|
|
||||||
printDebugMessage ("launched the parallel runners");
|
printDebugMessage ("launched the parallel runners");
|
||||||
}
|
}
|
||||||
|
|
||||||
void joinRunners () {
|
void joinRunners ()
|
||||||
|
{
|
||||||
|
|
||||||
joinThreads (ll_threads);
|
joinThreads (ll_threads);
|
||||||
the_runners.clear();
|
the_runners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool atLeastOneActiveRunner () {
|
bool atLeastOneActiveRunner ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_exec_runners;
|
return num_exec_runners;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned numberOfActiveRunners () {
|
unsigned numberOfActiveRunners ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_exec_runners;
|
return num_exec_runners;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: notifyContextInitialized () {
|
void Runner :: notifyContextInitialized ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post (& sem_cntxt);
|
sem_post (& sem_cntxt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: notifySendingTermination () {
|
void Runner :: notifySendingTermination ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("I am informed that everyone received my termination notification.");
|
printDebugMessage ("I am informed that everyone received my termination notification.");
|
||||||
setPassive ();
|
setPassive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpackTerminationOfRunner () {
|
void unpackTerminationOfRunner ()
|
||||||
|
{
|
||||||
|
|
||||||
RUNNER_ID finished_id;
|
RUNNER_ID finished_id;
|
||||||
unpack (finished_id);
|
unpack (finished_id);
|
||||||
|
|
@ -184,17 +202,19 @@ void unpackTerminationOfRunner () {
|
||||||
|
|
||||||
printDebugMessage ("I'm noticed of the termination of a runner");
|
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.");
|
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
|
||||||
stopReactiveThreads ();
|
stopReactiveThreads ();
|
||||||
printDebugMessage ("Reactive threads stopped!");
|
printDebugMessage ("Reactive threads stopped!");
|
||||||
}
|
}
|
||||||
|
|
||||||
wakeUpCommunicator ();
|
wakeUpCommunicator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRunnersEnv () {
|
void initRunnersEnv ()
|
||||||
|
{
|
||||||
|
|
||||||
ll_threads.clear ();
|
ll_threads.clear ();
|
||||||
the_runners.clear ();
|
the_runners.clear ();
|
||||||
|
|
|
||||||
|
|
@ -46,44 +46,45 @@
|
||||||
typedef unsigned RUNNER_ID;
|
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_start;
|
||||||
sem_t sem_cntxt;
|
sem_t sem_cntxt;
|
||||||
|
|
||||||
unsigned def_id;
|
unsigned def_id;
|
||||||
unsigned exec_id;
|
unsigned exec_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
extern void initRunnersEnv ();
|
extern void initRunnersEnv ();
|
||||||
|
|
|
||||||
|
|
@ -36,38 +36,49 @@
|
||||||
|
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
void Service :: setOwner (Thread & __owner) {
|
void Service :: setOwner (Thread & __owner)
|
||||||
|
{
|
||||||
|
|
||||||
owner = & __owner;
|
owner = & __owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread * Service :: getOwner () {
|
Thread * Service :: getOwner ()
|
||||||
|
{
|
||||||
|
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
Service * getService (SERVICE_ID __key) {
|
Service * getService (SERVICE_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return dynamic_cast <Service *> (getCommunicable (__key));
|
return dynamic_cast <Service *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: notifySendingData () { }
|
void Service :: notifySendingData ()
|
||||||
|
{ }
|
||||||
|
|
||||||
void Service :: notifySendingResourceRequest () {
|
void Service :: notifySendingResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
num_sent_rr --;
|
num_sent_rr --;
|
||||||
if (! num_sent_rr)
|
if (! num_sent_rr)
|
||||||
notifySendingAllResourceRequests ();
|
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 ()
|
||||||
|
{}
|
||||||
|
|
|
||||||
|
|
@ -43,36 +43,37 @@
|
||||||
|
|
||||||
typedef unsigned SERVICE_ID;
|
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 requestResourceRequest (unsigned __how_many = 1);
|
||||||
void packResourceRequest ();
|
void packResourceRequest ();
|
||||||
|
|
||||||
virtual void packData ();
|
virtual void packData ();
|
||||||
virtual void unpackData ();
|
virtual void unpackData ();
|
||||||
|
|
||||||
virtual void execute ();
|
virtual void execute ();
|
||||||
|
|
||||||
virtual void packResult ();
|
virtual void packResult ();
|
||||||
virtual void unpackResult ();
|
virtual void unpackResult ();
|
||||||
|
|
||||||
virtual void notifySendingData ();
|
virtual void notifySendingData ();
|
||||||
virtual void notifySendingResourceRequest ();
|
virtual void notifySendingResourceRequest ();
|
||||||
virtual void notifySendingAllResourceRequests ();
|
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,47 +43,56 @@ static std :: vector <Thread *> threads;
|
||||||
unsigned num_act = 0;
|
unsigned num_act = 0;
|
||||||
|
|
||||||
|
|
||||||
Thread :: Thread () {
|
Thread :: Thread ()
|
||||||
|
{
|
||||||
|
|
||||||
threads.push_back (this);
|
threads.push_back (this);
|
||||||
act = false;
|
act = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread :: ~ Thread () {
|
Thread :: ~ Thread ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Nothing ! */
|
/* Nothing ! */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread :: setActive () {
|
void Thread :: setActive ()
|
||||||
|
{
|
||||||
|
|
||||||
if (! act) {
|
if (! act)
|
||||||
|
{
|
||||||
|
|
||||||
act = true;
|
act = true;
|
||||||
num_act ++;
|
num_act ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread :: setPassive () {
|
void Thread :: setPassive ()
|
||||||
|
{
|
||||||
|
|
||||||
if (act) {
|
if (act)
|
||||||
|
{
|
||||||
|
|
||||||
act = false;
|
act = false;
|
||||||
num_act --;
|
num_act --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initThreadsEnv () {
|
void initThreadsEnv ()
|
||||||
|
{
|
||||||
|
|
||||||
threads.clear ();
|
threads.clear ();
|
||||||
num_act = 0;
|
num_act = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool atLeastOneActiveThread () {
|
bool atLeastOneActiveThread ()
|
||||||
|
{
|
||||||
|
|
||||||
return num_act;
|
return num_act;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * launch (void * __arg) {
|
static void * launch (void * __arg)
|
||||||
|
{
|
||||||
|
|
||||||
Thread * thr = (Thread *) __arg;
|
Thread * thr = (Thread *) __arg;
|
||||||
thr -> start ();
|
thr -> start ();
|
||||||
|
|
@ -91,18 +100,21 @@ static void * launch (void * __arg) {
|
||||||
return 0;
|
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;
|
pthread_t * ll_thr = new pthread_t;
|
||||||
__ll_threads.push_back (ll_thr);
|
__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 ++) {
|
for (unsigned i = 0; i < __threads.size (); i ++)
|
||||||
pthread_join (* __threads [i], 0);
|
{
|
||||||
delete __threads [i];
|
pthread_join (* __threads [i], 0);
|
||||||
}
|
delete __threads [i];
|
||||||
|
}
|
||||||
__threads.clear();
|
__threads.clear();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,27 +41,28 @@
|
||||||
|
|
||||||
|
|
||||||
/* A high-level thread */
|
/* A high-level thread */
|
||||||
class Thread {
|
class Thread
|
||||||
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Ctor */
|
/* Ctor */
|
||||||
Thread ();
|
Thread ();
|
||||||
|
|
||||||
/* Dtor */
|
/* Dtor */
|
||||||
virtual ~ Thread ();
|
virtual ~ Thread ();
|
||||||
|
|
||||||
/* Go ! */
|
/* Go ! */
|
||||||
virtual void start () = 0;
|
virtual void start () = 0;
|
||||||
|
|
||||||
void setActive ();/* It means the current process is going to send messages soon */
|
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
|
void setPassive ();/* The current process is not going to perform send operations
|
||||||
(but it may receive messages) */
|
(but it may receive messages) */
|
||||||
|
|
||||||
private :
|
private :
|
||||||
|
|
||||||
bool act;
|
bool act;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void initThreadsEnv ();
|
extern void initThreadsEnv ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,17 +36,20 @@
|
||||||
|
|
||||||
#include "topology.h"
|
#include "topology.h"
|
||||||
|
|
||||||
Topology :: ~ Topology () {
|
Topology :: ~ Topology ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Nothing ! */
|
/* 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;
|
return mig;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,23 +41,24 @@
|
||||||
|
|
||||||
#include "cooperative.h"
|
#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,
|
virtual void setNeighbors (Cooperative * __mig,
|
||||||
std :: vector <Cooperative *> & __from,
|
std :: vector <Cooperative *> & __from,
|
||||||
std :: vector <Cooperative *> & __to) = 0;
|
std :: vector <Cooperative *> & __to) = 0;
|
||||||
|
|
||||||
operator std :: vector <Cooperative *>& ();
|
operator std :: vector <Cooperative *>& ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std :: vector <Cooperative *> mig;
|
std :: vector <Cooperative *> mig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack(
|
||||||
unlock();
|
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()
|
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrate()
|
||||||
{
|
{
|
||||||
|
|
@ -247,7 +247,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrat
|
||||||
|
|
||||||
TYPE mig;
|
TYPE mig;
|
||||||
select(mig);
|
select(mig);
|
||||||
em.push( mig );
|
em.push( mig );
|
||||||
coop_em.push( out[i] );
|
coop_em.push( out[i] );
|
||||||
send( out[i] );
|
send( out[i] );
|
||||||
printDebugMessage( "sending some emigrants." );
|
printDebugMessage( "sending some emigrants." );
|
||||||
|
|
@ -263,7 +263,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
|
||||||
|
|
||||||
while ( !imm.empty() )
|
while ( !imm.empty() )
|
||||||
{
|
{
|
||||||
replace(imm.front() );
|
replace(imm.front() );
|
||||||
imm.pop();
|
imm.pop();
|
||||||
printDebugMessage( "receiving some immigrants." );
|
printDebugMessage( "receiving some immigrants." );
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +275,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra
|
||||||
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
|
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (cont.check())
|
if (cont.check())
|
||||||
{
|
{
|
||||||
|
|
||||||
emigrate(); // sending emigrants
|
emigrate(); // sending emigrants
|
||||||
|
|
|
||||||
|
|
@ -44,39 +44,42 @@
|
||||||
/************************** DEFINE A DATA ******************************************/
|
/************************** DEFINE A DATA ******************************************/
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
||||||
class peoData {
|
class peoData
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
virtual void pack () {}
|
virtual void pack ()
|
||||||
virtual void unpack () {}
|
{}
|
||||||
|
virtual void unpack ()
|
||||||
|
{}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Specific implementation : migration of a population
|
// Specific implementation : migration of a population
|
||||||
|
|
||||||
template<class EOT>
|
template<class EOT>
|
||||||
class peoPop: public eoPop<EOT>, public peoData
|
class peoPop: public eoPop<EOT>, public peoData
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
virtual void pack ()
|
|
||||||
{
|
{
|
||||||
::pack ((unsigned) this->size ());
|
public:
|
||||||
for (unsigned i = 0; i < this->size (); i ++)
|
|
||||||
::pack ((*this)[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void unpack ()
|
virtual void pack ()
|
||||||
{
|
{
|
||||||
unsigned n;
|
::pack ((unsigned) this->size ());
|
||||||
::unpack (n);
|
for (unsigned i = 0; i < this->size (); i ++)
|
||||||
this->resize (n);
|
::pack ((*this)[i]);
|
||||||
for (unsigned i = 0; i < n; i ++)
|
}
|
||||||
::unpack ((*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
|
class continuator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool check()=0;
|
virtual bool check()=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Specific implementation : migration of a population
|
// Specific implementation : migration of a population
|
||||||
|
|
||||||
template < class EOT> class eoContinuator : public continuator{
|
template < class EOT> class eoContinuator : public continuator
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop){}
|
eoContinuator(eoContinue<EOT> & _cont, const eoPop<EOT> & _pop): cont (_cont), pop(_pop)
|
||||||
|
{}
|
||||||
|
|
||||||
virtual bool check(){
|
virtual bool check()
|
||||||
return cont(pop);
|
{
|
||||||
}
|
return cont(pop);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoContinue<EOT> & cont ;
|
eoContinue<EOT> & cont ;
|
||||||
const eoPop<EOT> & pop;
|
const eoPop<EOT> & pop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
@ -112,32 +118,34 @@ protected:
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
||||||
template < class TYPE> class selector
|
template < class TYPE> class selector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void operator()(TYPE &)=0;
|
virtual void operator()(TYPE &)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Specific implementation : migration of a population
|
// Specific implementation : migration of a population
|
||||||
|
|
||||||
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >{
|
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source){}
|
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source)
|
||||||
|
{}
|
||||||
|
|
||||||
virtual void operator()(TYPE & _dest)
|
virtual void operator()(TYPE & _dest)
|
||||||
{
|
{
|
||||||
size_t target = static_cast<size_t>(nb_select);
|
size_t target = static_cast<size_t>(nb_select);
|
||||||
_dest.resize(target);
|
_dest.resize(target);
|
||||||
for (size_t i = 0; i < _dest.size(); ++i)
|
for (size_t i = 0; i < _dest.size(); ++i)
|
||||||
_dest[i] = selector(source);
|
_dest[i] = selector(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoSelectOne<EOT> & selector ;
|
eoSelectOne<EOT> & selector ;
|
||||||
unsigned nb_select;
|
unsigned nb_select;
|
||||||
const TYPE & source;
|
const TYPE & source;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
@ -145,27 +153,29 @@ protected:
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
||||||
template < class TYPE> class replacement
|
template < class TYPE> class replacement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void operator()(TYPE &)=0;
|
virtual void operator()(TYPE &)=0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Specific implementation : migration of a population
|
// Specific implementation : migration of a population
|
||||||
|
|
||||||
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >{
|
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
|
||||||
public:
|
{
|
||||||
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination){}
|
public:
|
||||||
|
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination)
|
||||||
|
{}
|
||||||
|
|
||||||
virtual void operator()(TYPE & _source)
|
virtual void operator()(TYPE & _source)
|
||||||
{
|
{
|
||||||
replace(destination, _source);
|
replace(destination, _source);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoReplacement<EOT> & replace;
|
eoReplacement<EOT> & replace;
|
||||||
TYPE & destination;
|
TYPE & destination;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
@ -173,25 +183,26 @@ protected:
|
||||||
/**************************************************************************************/
|
/**************************************************************************************/
|
||||||
|
|
||||||
class eoSyncContinue: public continuator
|
class eoSyncContinue: public continuator
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) {}
|
|
||||||
|
|
||||||
virtual bool check()
|
|
||||||
{
|
{
|
||||||
return ((++ counter) % period) != 0 ;
|
|
||||||
}
|
public:
|
||||||
|
|
||||||
|
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter)
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual bool check()
|
||||||
|
{
|
||||||
|
return ((++ counter) % period) != 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
unsigned period;
|
unsigned period;
|
||||||
|
|
||||||
unsigned counter;
|
unsigned counter;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#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& >
|
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
|
||||||
#endif
|
#endif
|
||||||
struct peoEvalFunc: public eoEvalFunc<EOT>
|
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:
|
private:
|
||||||
FitT (* evalFunc )( FunctionArg );
|
FitT (* evalFunc )( FunctionArg );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ class peoGlobalBestVelocity : public eoReplacement<POT>
|
||||||
typedef typename POT::ParticleVelocityType VelocityType;
|
typedef typename POT::ParticleVelocityType VelocityType;
|
||||||
|
|
||||||
peoGlobalBestVelocity( const double & _c3,
|
peoGlobalBestVelocity( const double & _c3,
|
||||||
eoVelocity < POT > &_velocity):
|
eoVelocity < POT > &_velocity):
|
||||||
c3 (_c3),
|
c3 (_c3),
|
||||||
velocity (_velocity)
|
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 )
|
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 )
|
template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
||||||
|
|
@ -201,15 +201,15 @@ template< class EOT > void peoMoeoPopEval< EOT > :: packResult()
|
||||||
{
|
{
|
||||||
// std::cout<<"\nD";
|
// std::cout<<"\nD";
|
||||||
/* Packing the fitness of the solution */
|
/* Packing the fitness of the solution */
|
||||||
/* typedef typename PO < F >::Fitness Fitness;
|
/* typedef typename PO < F >::Fitness Fitness;
|
||||||
MOEOObjectiveVector ObjectiveVector;*/
|
MOEOObjectiveVector ObjectiveVector;*/
|
||||||
std::vector < double > object;
|
std::vector < double > object;
|
||||||
unsigned len;
|
unsigned len;
|
||||||
object=sol.objectiveVector();
|
object=sol.objectiveVector();
|
||||||
len=object.size();
|
len=object.size();
|
||||||
pack (len);
|
pack (len);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
pack (object[i]);
|
pack (object[i]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -226,20 +226,20 @@ template< class EOT > void peoMoeoPopEval< EOT > :: unpackResult()
|
||||||
|
|
||||||
/* Unpacking the computed fitness */
|
/* Unpacking the computed fitness */
|
||||||
// unpack( fit );
|
// unpack( fit );
|
||||||
unsigned len;
|
unsigned len;
|
||||||
std::vector < double > object;
|
std::vector < double > object;
|
||||||
|
|
||||||
unpack(len);
|
unpack(len);
|
||||||
object.resize(len);
|
object.resize(len);
|
||||||
for (unsigned i = 0 ; i < len; i ++)
|
for (unsigned i = 0 ; i < len; i ++)
|
||||||
unpack (object[i]);
|
unpack (object[i]);
|
||||||
/* Unpacking the @ of the associated individual */
|
/* Unpacking the @ of the associated individual */
|
||||||
unpack( ad_sol );
|
unpack( ad_sol );
|
||||||
|
|
||||||
|
|
||||||
/* Associating the fitness the local solution */
|
/* Associating the fitness the local solution */
|
||||||
// merge_eval( *ad_sol, object );
|
// merge_eval( *ad_sol, object );
|
||||||
ad_sol->objectiveVector(object);
|
ad_sol->objectiveVector(object);
|
||||||
progression[ ad_sol ].second--;
|
progression[ ad_sol ].second--;
|
||||||
|
|
||||||
/* Notifying the container of the termination of the evaluation */
|
/* Notifying the container of the termination of the evaluation */
|
||||||
|
|
|
||||||
|
|
@ -43,227 +43,227 @@
|
||||||
|
|
||||||
|
|
||||||
template < typename EntityType > class peoMultiStart : public Service
|
template < typename EntityType > class peoMultiStart : public Service
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm );
|
public:
|
||||||
algorithms.push_back( singularAlgorithm );
|
|
||||||
|
|
||||||
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 );
|
aggregationFunction = new NoAggregationFunction();
|
||||||
algorithms.push_back( singularAlgorithm );
|
}
|
||||||
|
|
||||||
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();
|
||||||
{
|
}
|
||||||
|
|
||||||
algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) );
|
template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction )
|
||||||
}
|
{
|
||||||
|
|
||||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
||||||
}
|
{
|
||||||
|
|
||||||
template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType >
|
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,
|
peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms,
|
||||||
AggregationFunctionType& externalAggregationFunction )
|
AggregationFunctionType& externalAggregationFunction )
|
||||||
{
|
{
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ )
|
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 FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) );
|
virtual ~AbstractDataType()
|
||||||
}
|
{ }
|
||||||
|
|
||||||
aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction );
|
template < typename Type > operator Type& ()
|
||||||
}
|
{
|
||||||
|
|
||||||
~peoMultiStart()
|
return ( dynamic_cast< DataType< Type >& >( *this ) ).data;
|
||||||
{
|
}
|
||||||
|
};
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename Type > struct DataType : public AbstractDataType
|
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
|
template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void operator()( AbstractDataType& dataTypeInstance )
|
void operator()( AbstractDataType& dataTypeInstance )
|
||||||
{
|
{
|
||||||
algorithm( dataTypeInstance );
|
algorithm( dataTypeInstance );
|
||||||
}
|
}
|
||||||
|
|
||||||
AlgorithmType& algorithm;
|
AlgorithmType& algorithm;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
|
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 )
|
void operator()( AbstractDataType& dataTypeInstance )
|
||||||
{
|
{
|
||||||
algorithm( 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
|
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
|
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()
|
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
|
// 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 )
|
// function/algorithm starting all over with the entire data set ( idx is set to 0 )
|
||||||
if ( idx == data.size() )
|
if ( idx == data.size() )
|
||||||
{
|
{
|
||||||
|
|
||||||
++functionIndex;
|
++functionIndex;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoMultiStart< EntityType >::unpackData()
|
template < typename EntityType > void peoMultiStart< EntityType >::unpackData()
|
||||||
|
|
@ -322,11 +322,11 @@ template < typename EntityType > void peoMultiStart< EntityType >::unpackResult(
|
||||||
num_term++;
|
num_term++;
|
||||||
|
|
||||||
if ( num_term == data.size() * algorithms.size() )
|
if ( num_term == data.size() * algorithms.size() )
|
||||||
{
|
{
|
||||||
|
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename EntityType > void peoMultiStart< EntityType >::notifySendingData()
|
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
|
//! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness
|
||||||
//! value is explicitly specified.
|
//! value is explicitly specified.
|
||||||
template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT >
|
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
|
//! 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 );
|
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > void peoNoAggEvalFunc< EOT > :: 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 )
|
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 )
|
template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop )
|
||||||
|
|
|
||||||
|
|
@ -147,61 +147,61 @@
|
||||||
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
|
//! 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).
|
//! (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
|
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
|
//! 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.
|
//! 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 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 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 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 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 >& __source - source population from which the emigrant individuals are selected;
|
||||||
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
//! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated.
|
||||||
peoSyncIslandMig(
|
peoSyncIslandMig(
|
||||||
unsigned __frequency,
|
unsigned __frequency,
|
||||||
selector <TYPE> & __select,
|
selector <TYPE> & __select,
|
||||||
replacement <TYPE> & __replace,
|
replacement <TYPE> & __replace,
|
||||||
Topology& __topology,
|
Topology& __topology,
|
||||||
peoData & __source,
|
peoData & __source,
|
||||||
peoData & __destination
|
peoData & __destination
|
||||||
);
|
);
|
||||||
|
|
||||||
//! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected
|
//! 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
|
//! 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
|
//! 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.
|
//! wrapper checkpoint object (please refer to the above example) will perform the call when required.
|
||||||
void operator()();
|
void operator()();
|
||||||
|
|
||||||
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function.
|
||||||
void pack();
|
void pack();
|
||||||
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function.
|
||||||
void unpack();
|
void unpack();
|
||||||
//! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function.
|
||||||
void packSynchronizeReq();
|
void packSynchronizeReq();
|
||||||
|
|
||||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||||
void notifySending();
|
void notifySending();
|
||||||
|
|
||||||
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function.
|
||||||
void notifyReceiving();
|
void notifyReceiving();
|
||||||
|
|
||||||
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
|
//! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function.
|
||||||
void notifySendingSyncReq();
|
void notifySendingSyncReq();
|
||||||
|
|
||||||
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
|
//! Auxiliary function for notifying the synchronization of the runners involved in migration.
|
||||||
void notifySynchronized();
|
void notifySynchronized();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void emigrate();
|
void emigrate();
|
||||||
void immigrate();
|
void immigrate();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoSyncContinue cont; // continuator
|
eoSyncContinue cont; // continuator
|
||||||
selector <TYPE> & select; // the selection strategy
|
selector <TYPE> & select; // the selection strategy
|
||||||
|
|
@ -213,14 +213,14 @@ private:
|
||||||
std :: queue< TYPE > em;
|
std :: queue< TYPE > em;
|
||||||
std :: queue< Cooperative* > coop_em;
|
std :: queue< Cooperative* > coop_em;
|
||||||
|
|
||||||
sem_t sync;
|
sem_t sync;
|
||||||
|
|
||||||
bool explicitPassive;
|
bool explicitPassive;
|
||||||
bool standbyMigration;
|
bool standbyMigration;
|
||||||
|
|
||||||
std :: vector< Cooperative* > in, out, all;
|
std :: vector< Cooperative* > in, out, all;
|
||||||
unsigned nbMigrations;
|
unsigned nbMigrations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandMig(
|
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()
|
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: pack()
|
||||||
{
|
{
|
||||||
::pack( coop_em.front()->getKey() );
|
::pack( coop_em.front()->getKey() );
|
||||||
em.front().pack();
|
em.front().pack();
|
||||||
coop_em.pop();
|
coop_em.pop();
|
||||||
em.pop();
|
em.pop();
|
||||||
}
|
}
|
||||||
|
|
@ -256,7 +256,8 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: unpack()
|
||||||
explicitPassive = true;
|
explicitPassive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq() {
|
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq()
|
||||||
|
{
|
||||||
|
|
||||||
packSynchronRequest( all );
|
packSynchronRequest( all );
|
||||||
}
|
}
|
||||||
|
|
@ -265,25 +266,26 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: emigrat
|
||||||
{
|
{
|
||||||
|
|
||||||
for ( unsigned i = 0; i < out.size(); i ++ )
|
for ( unsigned i = 0; i < out.size(); i ++ )
|
||||||
{
|
{
|
||||||
|
|
||||||
TYPE mig;
|
TYPE mig;
|
||||||
select( mig );
|
select( mig );
|
||||||
em.push( mig );
|
em.push( mig );
|
||||||
coop_em.push( out[ i ] );
|
coop_em.push( out[ i ] );
|
||||||
send( out[ i ] );
|
send( out[ i ] );
|
||||||
printDebugMessage( "peoSyncIslandMig: sending some emigrants." );
|
printDebugMessage( "peoSyncIslandMig: sending some emigrants." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: immigrate()
|
template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: immigrate()
|
||||||
{
|
{
|
||||||
assert( imm.size() );
|
assert( imm.size() );
|
||||||
|
|
||||||
while ( imm.size() ) {
|
while ( imm.size() )
|
||||||
replace( imm.front() ) ;
|
{
|
||||||
imm.pop();
|
replace( imm.front() ) ;
|
||||||
}
|
imm.pop();
|
||||||
|
}
|
||||||
|
|
||||||
printDebugMessage( "peoSyncIslandMig: receiving some immigrants." );
|
printDebugMessage( "peoSyncIslandMig: receiving some immigrants." );
|
||||||
}
|
}
|
||||||
|
|
@ -292,19 +294,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: operato
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( cont.check() )
|
if ( cont.check() )
|
||||||
{
|
{
|
||||||
explicitPassive = standbyMigration = false;
|
explicitPassive = standbyMigration = false;
|
||||||
topology.setNeighbors( this, in, out ); all = topology;
|
topology.setNeighbors( this, in, out );
|
||||||
nbMigrations = 0;
|
all = topology;
|
||||||
synchronizeCoopEx(); stop();
|
nbMigrations = 0;
|
||||||
// sending emigrants
|
synchronizeCoopEx();
|
||||||
emigrate();
|
stop();
|
||||||
// synchronizing
|
// sending emigrants
|
||||||
sem_wait( &sync );
|
emigrate();
|
||||||
// receiving immigrants
|
// synchronizing
|
||||||
immigrate();
|
sem_wait( &sync );
|
||||||
synchronizeCoopEx(); stop();
|
// receiving immigrants
|
||||||
}
|
immigrate();
|
||||||
|
synchronizeCoopEx();
|
||||||
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifySending()
|
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++;
|
nbMigrations++;
|
||||||
|
|
||||||
if ( nbMigrations == in.size() ) {
|
if ( nbMigrations == in.size() )
|
||||||
|
{
|
||||||
|
|
||||||
if ( standbyMigration ) getOwner()->setActive();
|
if ( standbyMigration ) getOwner()->setActive();
|
||||||
sem_post( &sync );
|
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();
|
getOwner()->setPassive();
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized () {
|
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized ()
|
||||||
|
{
|
||||||
|
|
||||||
standbyMigration = true;
|
standbyMigration = true;
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
|
|
|
||||||
|
|
@ -47,49 +47,49 @@ extern int getNodeRank();
|
||||||
|
|
||||||
|
|
||||||
template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
|
template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
peoTransform(
|
peoTransform(
|
||||||
|
|
||||||
eoQuadOp< EOT >& __cross,
|
eoQuadOp< EOT >& __cross,
|
||||||
double __cross_rate,
|
double __cross_rate,
|
||||||
eoMonOp< EOT >& __mut,
|
eoMonOp< EOT >& __mut,
|
||||||
double __mut_rate
|
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 notifySendingData();
|
||||||
void notifySendingAllResourceRequests();
|
void notifySendingAllResourceRequests();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
eoQuadOp< EOT >& cross;
|
eoQuadOp< EOT >& cross;
|
||||||
double cross_rate;
|
double cross_rate;
|
||||||
|
|
||||||
eoMonOp< EOT >& mut;
|
eoMonOp< EOT >& mut;
|
||||||
double mut_rate;
|
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(
|
template< class EOT > peoTransform< EOT > :: peoTransform(
|
||||||
|
|
||||||
|
|
@ -151,11 +151,11 @@ template< class EOT > void peoTransform< EOT > :: unpackResult()
|
||||||
|
|
||||||
// Can be used with an odd size
|
// Can be used with an odd size
|
||||||
if ( num_term == 2*(pop->size()/2) )
|
if ( num_term == 2*(pop->size()/2) )
|
||||||
{
|
{
|
||||||
|
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,117 +45,117 @@
|
||||||
|
|
||||||
|
|
||||||
class peoWrapper : public Runner
|
class peoWrapper : public Runner
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
|
template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm )
|
||||||
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
|
: algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||||
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
: algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
|
template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() )
|
||||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
|
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||||
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
: algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~peoWrapper()
|
~peoWrapper()
|
||||||
{
|
{
|
||||||
|
|
||||||
delete algorithm;
|
delete algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
algorithm->operator()();
|
algorithm->operator()();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct AbstractAlgorithm
|
struct AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
// virtual destructor as we will be using inheritance and polymorphism
|
// virtual destructor as we will be using inheritance and polymorphism
|
||||||
virtual ~AbstractAlgorithm()
|
virtual ~AbstractAlgorithm()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// operator to be called for executing the algorithm
|
// operator to be called for executing the algorithm
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm
|
template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData )
|
||||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
algorithm( algorithmData );
|
algorithm( algorithmData );
|
||||||
}
|
}
|
||||||
|
|
||||||
AlgorithmType& algorithm;
|
AlgorithmType& algorithm;
|
||||||
AlgorithmDataType& algorithmData;
|
AlgorithmDataType& algorithmData;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm
|
template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
algorithm();
|
algorithm();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlgorithmType& algorithm;
|
AlgorithmType& algorithm;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
|
template< typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData )
|
||||||
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
: algorithm( externalAlgorithm ), algorithmData( externalData )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
algorithm( algorithmData );
|
algorithm( algorithmData );
|
||||||
}
|
}
|
||||||
|
|
||||||
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
AlgorithmReturnType (*algorithm)( AlgorithmDataType& );
|
||||||
AlgorithmDataType& algorithmData;
|
AlgorithmDataType& algorithmData;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename AlgorithmReturnType > struct FunctionAlgorithm< AlgorithmReturnType, void > : public AbstractAlgorithm
|
template< typename AlgorithmReturnType > struct FunctionAlgorithm< AlgorithmReturnType, void > : public AbstractAlgorithm
|
||||||
{
|
{
|
||||||
|
|
||||||
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() )
|
FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() )
|
||||||
: algorithm( externalAlgorithm )
|
: algorithm( externalAlgorithm )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual void operator()()
|
virtual void operator()()
|
||||||
{
|
{
|
||||||
algorithm();
|
algorithm();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlgorithmReturnType (*algorithm)();
|
AlgorithmReturnType (*algorithm)();
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
AbstractAlgorithm* algorithm;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
AbstractAlgorithm* algorithm;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,8 @@ static sem_t sem_comm_init;
|
||||||
static Communicator * the_thread;
|
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);
|
initNode (__argc, __argv);
|
||||||
|
|
@ -61,20 +62,22 @@ Communicator :: Communicator (int * __argc, char * * * __argv) {
|
||||||
sem_post (& sem_comm_init);
|
sem_post (& sem_comm_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Communicator :: start () {
|
void Communicator :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
/* Zzz Zzz Zzz :-))) */
|
/* Zzz Zzz Zzz :-))) */
|
||||||
sleep ();
|
sleep ();
|
||||||
|
|
||||||
sendMessages ();
|
sendMessages ();
|
||||||
|
|
||||||
if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ())
|
if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
receiveMessages ();
|
receiveMessages ();
|
||||||
}
|
}
|
||||||
|
|
||||||
waitBuffers ();
|
waitBuffers ();
|
||||||
printDebugMessage ("finalizing");
|
printDebugMessage ("finalizing");
|
||||||
|
|
@ -82,24 +85,28 @@ void Communicator :: start () {
|
||||||
//synchronizeNodes ();
|
//synchronizeNodes ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCommunication () {
|
void initCommunication ()
|
||||||
|
{
|
||||||
|
|
||||||
static bool initializedSemaphore = false;
|
static bool initializedSemaphore = false;
|
||||||
|
|
||||||
if (initializedSemaphore) {
|
if (initializedSemaphore)
|
||||||
sem_destroy(& sem_comm_init);
|
{
|
||||||
}
|
sem_destroy(& sem_comm_init);
|
||||||
|
}
|
||||||
|
|
||||||
sem_init (& sem_comm_init, 0, 0);
|
sem_init (& sem_comm_init, 0, 0);
|
||||||
initializedSemaphore = true;
|
initializedSemaphore = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitNodeInitialization () {
|
void waitNodeInitialization ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_wait (& sem_comm_init);
|
sem_wait (& sem_comm_init);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wakeUpCommunicator () {
|
void wakeUpCommunicator ()
|
||||||
|
{
|
||||||
|
|
||||||
the_thread -> wakeUp ();
|
the_thread -> wakeUp ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,15 +40,16 @@
|
||||||
#include "../../core/communicable.h"
|
#include "../../core/communicable.h"
|
||||||
#include "../../core/reac_thread.h"
|
#include "../../core/reac_thread.h"
|
||||||
|
|
||||||
class Communicator : public ReactiveThread {
|
class Communicator : public ReactiveThread
|
||||||
|
{
|
||||||
|
|
||||||
public :
|
public :
|
||||||
|
|
||||||
/* Ctor */
|
/* Ctor */
|
||||||
Communicator (int * __argc, char * * * __argv);
|
Communicator (int * __argc, char * * * __argv);
|
||||||
|
|
||||||
void start ();
|
void start ();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void initCommunication ();
|
extern void initCommunication ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,42 +41,48 @@
|
||||||
#include "mess.h"
|
#include "mess.h"
|
||||||
#include "../../core/peo_debug.h"
|
#include "../../core/peo_debug.h"
|
||||||
|
|
||||||
Runner * Cooperative :: getOwner () {
|
Runner * Cooperative :: getOwner ()
|
||||||
|
{
|
||||||
|
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: setOwner (Runner & __runner) {
|
void Cooperative :: setOwner (Runner & __runner)
|
||||||
|
{
|
||||||
|
|
||||||
owner = & __runner;
|
owner = & __runner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: send (Cooperative * __coop) {
|
void Cooperative :: send (Cooperative * __coop)
|
||||||
|
{
|
||||||
|
|
||||||
:: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG);
|
:: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG);
|
||||||
// stop ();
|
// stop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: synchronizeCoopEx () {
|
void Cooperative :: synchronizeCoopEx ()
|
||||||
|
{
|
||||||
:: send (this, my_node -> rk_sched, SYNCHRONIZE_REQ_TAG);
|
:: 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));
|
return dynamic_cast <Cooperative *> (getCommunicable (__key));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: notifySending () {
|
void Cooperative :: notifySending ()
|
||||||
|
{
|
||||||
|
|
||||||
//getOwner -> setPassive ();
|
//getOwner -> setPassive ();
|
||||||
// resume ();
|
// resume ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cooperative :: notifyReceiving () {
|
void Cooperative :: notifyReceiving ()
|
||||||
}
|
{}
|
||||||
|
|
||||||
void Cooperative :: notifySendingSyncReq () {
|
void Cooperative :: notifySendingSyncReq ()
|
||||||
}
|
{}
|
||||||
|
|
||||||
void Cooperative :: notifySynchronized () {
|
void Cooperative :: notifySynchronized ()
|
||||||
}
|
{}
|
||||||
|
|
|
||||||
|
|
@ -51,53 +51,60 @@ static std :: vector <char *> act_buf; /* Active buffers */
|
||||||
|
|
||||||
static std :: vector <MPI_Request *> act_req; /* Active requests */
|
static std :: vector <MPI_Request *> act_req; /* Active requests */
|
||||||
|
|
||||||
void initBuffers () {
|
void initBuffers ()
|
||||||
|
{
|
||||||
|
|
||||||
pos_buf = 0;
|
pos_buf = 0;
|
||||||
act_buf.clear ();
|
act_buf.clear ();
|
||||||
act_req.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 ;
|
MPI_Status stat ;
|
||||||
int flag ;
|
int flag ;
|
||||||
|
|
||||||
MPI_Test (act_req [i], & flag, & stat) ;
|
MPI_Test (act_req [i], & flag, & stat) ;
|
||||||
if (flag) {
|
if (flag)
|
||||||
|
{
|
||||||
|
|
||||||
delete[] act_buf [i] ;
|
delete[] act_buf [i] ;
|
||||||
delete act_req [i] ;
|
delete act_req [i] ;
|
||||||
|
|
||||||
act_buf [i] = act_buf.back () ;
|
act_buf [i] = act_buf.back () ;
|
||||||
act_buf.pop_back () ;
|
act_buf.pop_back () ;
|
||||||
|
|
||||||
act_req [i] = act_req.back () ;
|
act_req [i] = act_req.back () ;
|
||||||
act_req.pop_back () ;
|
act_req.pop_back () ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
i ++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
i ++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitBuffers () {
|
void waitBuffers ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("waiting the termination of the asynchronous operations to complete");
|
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_buf [i] ;
|
||||||
delete act_req [i] ;
|
delete act_req [i] ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool probeMessage (int & __src, int & __tag) {
|
bool probeMessage (int & __src, int & __tag)
|
||||||
|
{
|
||||||
|
|
||||||
int flag;
|
int flag;
|
||||||
|
|
||||||
|
|
@ -111,19 +118,22 @@ bool probeMessage (int & __src, int & __tag) {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitMessage () {
|
void waitMessage ()
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Status stat;
|
MPI_Status stat;
|
||||||
|
|
||||||
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
|
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void initMessage () {
|
void initMessage ()
|
||||||
|
{
|
||||||
|
|
||||||
pos_buf = 0;
|
pos_buf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessage (int __to, int __tag) {
|
void sendMessage (int __to, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
cleanBuffers ();
|
cleanBuffers ();
|
||||||
act_buf.push_back (new char [pos_buf]);
|
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 ());
|
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 ++)
|
for (int i = 0; i < getNumberOfNodes (); i ++)
|
||||||
sendMessage (i, __tag);
|
sendMessage (i, __tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receiveMessage (int __from, int __tag) {
|
void receiveMessage (int __from, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Status stat;
|
MPI_Status stat;
|
||||||
MPI_Request req;
|
MPI_Request req;
|
||||||
|
|
@ -147,80 +159,93 @@ void receiveMessage (int __from, int __tag) {
|
||||||
MPI_Wait (& req, & stat);
|
MPI_Wait (& req, & stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void synchronizeNodes () {
|
void synchronizeNodes ()
|
||||||
|
{
|
||||||
|
|
||||||
MPI_Barrier ( MPI_COMM_WORLD );
|
MPI_Barrier ( MPI_COMM_WORLD );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Char */
|
/* 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);
|
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Boolean */
|
/* 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);
|
MPI_Pack ((void *) & __b, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Float */
|
/* 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);
|
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Double */
|
/* 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);
|
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Integer */
|
/* 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);
|
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* 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);
|
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short int. */
|
/* 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);
|
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned short */
|
/* 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);
|
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Long */
|
/* 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);
|
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned long */
|
/* 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);
|
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
void pack (const char * __str) {
|
void pack (const char * __str)
|
||||||
|
{
|
||||||
|
|
||||||
int len = strlen (__str) + 1;
|
int len = strlen (__str) + 1;
|
||||||
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
|
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);
|
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;
|
size_t size = __str.size() + 1;
|
||||||
char * buffer = new char[ size ];
|
char * buffer = new char[ size ];
|
||||||
|
|
@ -230,73 +255,85 @@ void pack (const std::string & __str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Char */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Boolean */
|
/* 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 */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Double */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Integer */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned int. */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Short int. */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned short */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Long */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unsigned long */
|
/* 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);
|
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* String */
|
/* String */
|
||||||
void unpack (char * __str) {
|
void unpack (char * __str)
|
||||||
|
{
|
||||||
|
|
||||||
int len;
|
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, & 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;
|
char * buffer;
|
||||||
int len;
|
int len;
|
||||||
|
|
|
||||||
|
|
@ -43,50 +43,57 @@
|
||||||
#include "mess.h"
|
#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 MPIThreadedEnv mpiThreadedEnv( __argc, __argv );
|
||||||
}
|
|
||||||
|
|
||||||
static void finalize () {
|
|
||||||
|
|
||||||
static bool finalizedEnvironment = false;
|
|
||||||
|
|
||||||
if (! finalizedEnvironment ) {
|
|
||||||
|
|
||||||
MPI_Finalize ();
|
|
||||||
finalizedEnvironment = true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
static void finalize ()
|
||||||
|
{
|
||||||
|
|
||||||
/* No instance of this class can be created outside its domain! */
|
static bool finalizedEnvironment = false;
|
||||||
MPIThreadedEnv ( int * __argc, char * * * __argv ) {
|
|
||||||
|
|
||||||
static bool MPIThreadedEnvInitialized = false;
|
if (! finalizedEnvironment )
|
||||||
int provided = 1;
|
{
|
||||||
|
|
||||||
if (! MPIThreadedEnvInitialized) {
|
MPI_Finalize ();
|
||||||
|
finalizedEnvironment = true;
|
||||||
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() {
|
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 */
|
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;
|
static std :: vector <std :: string> rk_to_name;
|
||||||
|
|
||||||
|
|
||||||
int getNodeRank () {
|
int getNodeRank ()
|
||||||
|
{
|
||||||
|
|
||||||
return rk;
|
return rk;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumberOfNodes () {
|
int getNumberOfNodes ()
|
||||||
|
{
|
||||||
|
|
||||||
return sz;
|
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 );
|
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 ();
|
rk_to_name.clear ();
|
||||||
name_to_rk.clear ();
|
name_to_rk.clear ();
|
||||||
|
|
@ -134,8 +146,9 @@ void initNode (int * __argc, char * * * __argv) {
|
||||||
MPI_Get_processor_name (names [0], & len); /* Me */
|
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 */
|
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 ++) {
|
for (int i = 0; i < sz; i ++)
|
||||||
rk_to_name.push_back (names [i]);
|
{
|
||||||
name_to_rk [names [i]] = i;
|
rk_to_name.push_back (names [i]);
|
||||||
}
|
name_to_rk [names [i]] = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,15 +44,16 @@
|
||||||
|
|
||||||
typedef int RANK_ID;
|
typedef int RANK_ID;
|
||||||
|
|
||||||
struct Node {
|
struct Node
|
||||||
|
{
|
||||||
|
|
||||||
RANK_ID rk; /* Rank */
|
RANK_ID rk; /* Rank */
|
||||||
std :: string name; /* Host name */
|
std :: string name; /* Host name */
|
||||||
unsigned num_workers; /* Number of parallel workers */
|
unsigned num_workers; /* Number of parallel workers */
|
||||||
int rk_sched; /* rank of the scheduler */
|
int rk_sched; /* rank of the scheduler */
|
||||||
std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
|
std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
|
||||||
std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
|
std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Node * my_node;
|
extern Node * my_node;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,8 @@
|
||||||
|
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
|
||||||
void loadRMCParameters (int & __argc, char * * & __argv) {
|
void loadRMCParameters (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
eoParser parser (__argc, __argv);
|
eoParser parser (__argc, __argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,106 +45,112 @@
|
||||||
#include "../../core/cooperative.h"
|
#include "../../core/cooperative.h"
|
||||||
#include "../../core/peo_debug.h"
|
#include "../../core/peo_debug.h"
|
||||||
|
|
||||||
void receiveMessages () {
|
void receiveMessages ()
|
||||||
|
{
|
||||||
|
|
||||||
cleanBuffers ();
|
cleanBuffers ();
|
||||||
|
|
||||||
do {
|
do
|
||||||
|
{
|
||||||
|
|
||||||
if (! atLeastOneActiveThread ()) {
|
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:
|
|
||||||
{
|
{
|
||||||
RUNNER_ID runner_id;
|
|
||||||
unpack (runner_id);
|
|
||||||
|
|
||||||
COOP_ID coop_id;
|
waitMessage ();
|
||||||
unpack (coop_id);
|
|
||||||
|
|
||||||
getCooperative (coop_id) -> notifySynchronized ();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case COOP_TAG:
|
int src, tag;
|
||||||
COOP_ID coop_id;
|
|
||||||
unpack (coop_id);
|
|
||||||
getCooperative (coop_id) -> unpack ();
|
|
||||||
getCooperative (coop_id) -> notifyReceiving ();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SCHED_REQUEST_TAG:
|
while (probeMessage (src, 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 ... */
|
receiveMessage (src, tag);
|
||||||
initMessage ();
|
initMessage ();
|
||||||
pack (worker_id);
|
|
||||||
pack (serv_id);
|
switch (tag)
|
||||||
serv -> packData ();
|
{
|
||||||
serv -> notifySendingData ();
|
|
||||||
sendMessage (dest, TASK_DATA_TAG);
|
case RUNNER_STOP_TAG:
|
||||||
break;
|
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 ()*/ );
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,21 @@ static std :: vector <Worker *> worker_threads; /* Worker threads */
|
||||||
static Communicator* communicator_thread = NULL; /* Communicator thread */
|
static Communicator* communicator_thread = NULL; /* Communicator thread */
|
||||||
|
|
||||||
|
|
||||||
void runRMC () {
|
void runRMC ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Worker(s) ? */
|
/* Worker(s) ? */
|
||||||
for (unsigned i = 0; i < my_node -> num_workers; i ++) {
|
for (unsigned i = 0; i < my_node -> num_workers; i ++)
|
||||||
worker_threads.push_back (new Worker);
|
{
|
||||||
addThread (worker_threads.back(), ll_threads);
|
worker_threads.push_back (new Worker);
|
||||||
}
|
addThread (worker_threads.back(), ll_threads);
|
||||||
|
}
|
||||||
|
|
||||||
wakeUpCommunicator ();
|
wakeUpCommunicator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRMC (int & __argc, char * * & __argv) {
|
void initRMC (int & __argc, char * * & __argv)
|
||||||
|
{
|
||||||
|
|
||||||
/* Communication */
|
/* Communication */
|
||||||
initCommunication ();
|
initCommunication ();
|
||||||
|
|
@ -71,14 +74,16 @@ void initRMC (int & __argc, char * * & __argv) {
|
||||||
initScheduler ();
|
initScheduler ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void finalizeRMC () {
|
void finalizeRMC ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("before join threads RMC");
|
printDebugMessage ("before join threads RMC");
|
||||||
|
|
||||||
joinThreads (ll_threads);
|
joinThreads (ll_threads);
|
||||||
for (unsigned i = 0; i < worker_threads.size(); i++ ) {
|
for (unsigned i = 0; i < worker_threads.size(); i++ )
|
||||||
delete worker_threads [i];
|
{
|
||||||
}
|
delete worker_threads [i];
|
||||||
|
}
|
||||||
worker_threads.clear ();
|
worker_threads.clear ();
|
||||||
delete communicator_thread;
|
delete communicator_thread;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@
|
||||||
#include "schema.h"
|
#include "schema.h"
|
||||||
|
|
||||||
|
|
||||||
bool Runner :: isAssignedLocally () {
|
bool Runner :: isAssignedLocally ()
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
|
||||||
if (my_node -> id_run [i] == def_id)
|
if (my_node -> id_run [i] == def_id)
|
||||||
|
|
@ -51,12 +52,14 @@ bool Runner :: isAssignedLocally () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: terminate () {
|
void Runner :: terminate ()
|
||||||
|
{
|
||||||
|
|
||||||
sendToAll (this, RUNNER_STOP_TAG);
|
sendToAll (this, RUNNER_STOP_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Runner :: packTermination () {
|
void Runner :: packTermination ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (def_id);
|
pack (def_id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,52 +49,59 @@ static unsigned initNumberOfRes = 0;
|
||||||
|
|
||||||
extern void wakeUpCommunicator();
|
extern void wakeUpCommunicator();
|
||||||
|
|
||||||
void initScheduler () {
|
void initScheduler ()
|
||||||
|
{
|
||||||
|
|
||||||
resources = std :: queue <SCHED_RESOURCE> ();
|
resources = std :: queue <SCHED_RESOURCE> ();
|
||||||
requests = std :: queue <SCHED_REQUEST> ();
|
requests = std :: queue <SCHED_REQUEST> ();
|
||||||
initNumberOfRes = 0;
|
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)
|
if (node.rk_sched == my_node -> rk)
|
||||||
for (unsigned j = 0; j < node.num_workers; j ++)
|
for (unsigned j = 0; j < node.num_workers; j ++)
|
||||||
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
|
||||||
}
|
}
|
||||||
initNumberOfRes = resources.size ();
|
initNumberOfRes = resources.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool allResourcesFree () {
|
bool allResourcesFree ()
|
||||||
|
{
|
||||||
return resources.size () == initNumberOfRes;
|
return resources.size () == initNumberOfRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned numResourcesFree () {
|
unsigned numResourcesFree ()
|
||||||
|
{
|
||||||
return resources.size ();
|
return resources.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update () {
|
static void update ()
|
||||||
|
{
|
||||||
|
|
||||||
unsigned num_alloc = std :: min (resources.size (), requests.size ());
|
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 ();
|
SCHED_REQUEST req = requests.front ();
|
||||||
requests.pop ();
|
requests.pop ();
|
||||||
|
|
||||||
SCHED_RESOURCE res = resources.front ();
|
SCHED_RESOURCE res = resources.front ();
|
||||||
resources.pop ();
|
resources.pop ();
|
||||||
|
|
||||||
printDebugMessage ("allocating a resource.");
|
printDebugMessage ("allocating a resource.");
|
||||||
initMessage ();
|
initMessage ();
|
||||||
pack (req.second);
|
pack (req.second);
|
||||||
pack (res);
|
pack (res);
|
||||||
sendMessage (req.first, SCHED_RESULT_TAG);
|
sendMessage (req.first, SCHED_RESULT_TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpackResourceRequest () {
|
void unpackResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("queuing a resource request.");
|
printDebugMessage ("queuing a resource request.");
|
||||||
SCHED_REQUEST req;
|
SCHED_REQUEST req;
|
||||||
|
|
@ -103,7 +110,8 @@ void unpackResourceRequest () {
|
||||||
update ();
|
update ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpackTaskDone () {
|
void unpackTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage ("I'm notified a worker is now idle.");
|
printDebugMessage ("I'm notified a worker is now idle.");
|
||||||
SCHED_RESOURCE res;
|
SCHED_RESOURCE res;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ Node * my_node;
|
||||||
static unsigned maxSpecifiedRunnerID = 0;
|
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 i = 0; i < the_schema.size (); i ++)
|
||||||
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
|
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
|
||||||
|
|
@ -61,7 +62,8 @@ RANK_ID getRankOfRunner (RUNNER_ID __key) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadNode (int __rk_sched) {
|
static void loadNode (int __rk_sched)
|
||||||
|
{
|
||||||
|
|
||||||
Node node;
|
Node node;
|
||||||
|
|
||||||
|
|
@ -72,55 +74,62 @@ static void loadNode (int __rk_sched) {
|
||||||
/* ATT: num_workers */
|
/* ATT: num_workers */
|
||||||
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
|
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
/* TAG: <runner> | </node> */
|
/* TAG: <runner> | </node> */
|
||||||
std :: string name = getNextNode ();
|
std :: string name = getNextNode ();
|
||||||
assert (name == "runner" || name == "node");
|
assert (name == "runner" || name == "node");
|
||||||
if (name == "runner") {
|
if (name == "runner")
|
||||||
/* TAG: </node> */
|
{
|
||||||
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
/* TAG: </node> */
|
||||||
if ( node.id_run.back() > maxSpecifiedRunnerID )
|
node.id_run.push_back (atoi (getNextNode ().c_str ()));
|
||||||
maxSpecifiedRunnerID = node.id_run.back();
|
if ( node.id_run.back() > maxSpecifiedRunnerID )
|
||||||
/* TAG: </runner> */
|
maxSpecifiedRunnerID = node.id_run.back();
|
||||||
assert (getNextNode () == "runner");
|
/* 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;
|
std :: string name;
|
||||||
|
|
||||||
/* ATT: scheduler*/
|
/* ATT: scheduler*/
|
||||||
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
|
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
/* TAG: <node> | </group> */
|
/* TAG: <node> | </group> */
|
||||||
name = getNextNode ();
|
name = getNextNode ();
|
||||||
assert (name == "node" || name == "group");
|
assert (name == "node" || name == "group");
|
||||||
if (name == "node")
|
if (name == "node")
|
||||||
/* TAG: <node> */
|
/* TAG: <node> */
|
||||||
loadNode (rk_sched);
|
loadNode (rk_sched);
|
||||||
else
|
else
|
||||||
/* TAG: </group> */
|
/* TAG: </group> */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isScheduleNode () {
|
bool isScheduleNode ()
|
||||||
|
{
|
||||||
|
|
||||||
return my_node -> rk == my_node -> rk_sched;
|
return my_node -> rk == my_node -> rk_sched;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadSchema (const char * __filename) {
|
void loadSchema (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
openXMLDocument (__filename);
|
openXMLDocument (__filename);
|
||||||
|
|
||||||
|
|
@ -133,37 +142,43 @@ void loadSchema (const char * __filename) {
|
||||||
the_schema.clear();
|
the_schema.clear();
|
||||||
maxSpecifiedRunnerID = 0;
|
maxSpecifiedRunnerID = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
/* TAG: <group> | </schema> */
|
/* TAG: <group> | </schema> */
|
||||||
name = getNextNode ();
|
name = getNextNode ();
|
||||||
assert (name == "group" || name == "schema");
|
assert (name == "group" || name == "schema");
|
||||||
if (name == "group")
|
if (name == "group")
|
||||||
/* TAG: <group> */
|
/* TAG: <group> */
|
||||||
loadGroup ();
|
loadGroup ();
|
||||||
else
|
else
|
||||||
/* TAG: </schema> */
|
/* TAG: </schema> */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std :: set<unsigned> uniqueRunnerIDs; unsigned nbUniqueIDs = 0;
|
std :: set<unsigned> uniqueRunnerIDs;
|
||||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
unsigned nbUniqueIDs = 0;
|
||||||
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++) {
|
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||||
uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
|
{
|
||||||
/* In case a duplicate ID has been found */
|
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++)
|
||||||
if ( uniqueRunnerIDs.size() == nbUniqueIDs ) {
|
{
|
||||||
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
|
uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
|
||||||
}
|
/* In case a duplicate ID has been found */
|
||||||
nbUniqueIDs = uniqueRunnerIDs.size();
|
if ( uniqueRunnerIDs.size() == nbUniqueIDs )
|
||||||
|
{
|
||||||
|
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
|
||||||
|
}
|
||||||
|
nbUniqueIDs = uniqueRunnerIDs.size();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Looking for my node */
|
/* Looking for my node */
|
||||||
for (unsigned i = 0; i < the_schema.size (); i ++) {
|
for (unsigned i = 0; i < the_schema.size (); i ++)
|
||||||
if (the_schema [i].rk == getNodeRank ())
|
{
|
||||||
my_node = & (the_schema [i]);
|
if (the_schema [i].rk == getNodeRank ())
|
||||||
}
|
my_node = & (the_schema [i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* About me */
|
/* About me */
|
||||||
|
|
@ -175,16 +190,18 @@ void loadSchema (const char * __filename) {
|
||||||
if (isScheduleNode ())
|
if (isScheduleNode ())
|
||||||
printDebugMessage ("I'am a scheduler");
|
printDebugMessage ("I'am a scheduler");
|
||||||
|
|
||||||
for (unsigned i = 0; i < my_node -> id_run.size (); i ++) {
|
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);
|
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);
|
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
|
||||||
printDebugMessage (mess);
|
printDebugMessage (mess);
|
||||||
}
|
}
|
||||||
|
|
||||||
closeXMLDocument ();
|
closeXMLDocument ();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,13 +50,15 @@
|
||||||
#define TO_ALL -1
|
#define TO_ALL -1
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
|
|
||||||
Communicable * comm;
|
Communicable * comm;
|
||||||
int to;
|
int to;
|
||||||
int tag;
|
int tag;
|
||||||
|
|
||||||
} SEND_REQUEST;
|
}
|
||||||
|
SEND_REQUEST;
|
||||||
|
|
||||||
|
|
||||||
static std :: queue <SEND_REQUEST> mess;
|
static std :: queue <SEND_REQUEST> mess;
|
||||||
|
|
@ -66,15 +68,17 @@ static sem_t sem_send;
|
||||||
static bool contextInitialized = false;
|
static bool contextInitialized = false;
|
||||||
|
|
||||||
|
|
||||||
void initSending () {
|
void initSending ()
|
||||||
|
{
|
||||||
|
|
||||||
static bool initializedSemaphore = false;
|
static bool initializedSemaphore = false;
|
||||||
|
|
||||||
mess = std :: queue <SEND_REQUEST> ();
|
mess = std :: queue <SEND_REQUEST> ();
|
||||||
|
|
||||||
if (initializedSemaphore) {
|
if (initializedSemaphore)
|
||||||
sem_destroy(& sem_send);
|
{
|
||||||
}
|
sem_destroy(& sem_send);
|
||||||
|
}
|
||||||
|
|
||||||
sem_init (& sem_send, 0, 1);
|
sem_init (& sem_send, 0, 1);
|
||||||
initializedSemaphore = true;
|
initializedSemaphore = true;
|
||||||
|
|
@ -82,7 +86,8 @@ void initSending () {
|
||||||
contextInitialized = false;
|
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.comm = __comm;
|
||||||
|
|
@ -95,74 +100,79 @@ void send (Communicable * __comm, int __to, int __tag) {
|
||||||
wakeUpCommunicator ();
|
wakeUpCommunicator ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendToAll (Communicable * __comm, int __tag) {
|
void sendToAll (Communicable * __comm, int __tag)
|
||||||
|
{
|
||||||
|
|
||||||
send (__comm, TO_ALL, __tag);
|
send (__comm, TO_ALL, __tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void initializeContext ();
|
extern void initializeContext ();
|
||||||
|
|
||||||
void sendMessages () {
|
void sendMessages ()
|
||||||
|
{
|
||||||
|
|
||||||
if (! contextInitialized) {
|
if (! contextInitialized)
|
||||||
contextInitialized = true;
|
{
|
||||||
initializeContext();
|
contextInitialized = true;
|
||||||
}
|
initializeContext();
|
||||||
|
}
|
||||||
|
|
||||||
sem_wait (& sem_send);
|
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:
|
case RUNNER_STOP_TAG:
|
||||||
dynamic_cast <Runner *> (comm) -> packTermination ();
|
dynamic_cast <Runner *> (comm) -> packTermination ();
|
||||||
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COOP_TAG:
|
case COOP_TAG:
|
||||||
dynamic_cast <Cooperative *> (comm) -> pack ();
|
dynamic_cast <Cooperative *> (comm) -> pack ();
|
||||||
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
dynamic_cast <Cooperative *> (comm) -> notifySending ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SYNCHRONIZE_REQ_TAG:
|
case SYNCHRONIZE_REQ_TAG:
|
||||||
dynamic_cast <Cooperative *> (comm) -> packSynchronizeReq ();
|
dynamic_cast <Cooperative *> (comm) -> packSynchronizeReq ();
|
||||||
dynamic_cast <Cooperative *> (comm) -> notifySendingSyncReq ();
|
dynamic_cast <Cooperative *> (comm) -> notifySendingSyncReq ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCHED_REQUEST_TAG:
|
case SCHED_REQUEST_TAG:
|
||||||
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
dynamic_cast <Service *> (comm) -> packResourceRequest ();
|
||||||
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TASK_RESULT_TAG:
|
case TASK_RESULT_TAG:
|
||||||
dynamic_cast <Worker *> (comm) -> packResult ();
|
dynamic_cast <Worker *> (comm) -> packResult ();
|
||||||
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
dynamic_cast <Worker *> (comm) -> notifySendingResult ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TASK_DONE_TAG:
|
case TASK_DONE_TAG:
|
||||||
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
dynamic_cast <Worker *> (comm) -> packTaskDone ();
|
||||||
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.to == TO_ALL)
|
if (req.to == TO_ALL)
|
||||||
sendMessageToAll (req.tag);
|
sendMessageToAll (req.tag);
|
||||||
else
|
else
|
||||||
sendMessage (req.to, req.tag);
|
sendMessage (req.to, req.tag);
|
||||||
|
|
||||||
mess.pop ();
|
mess.pop ();
|
||||||
}
|
}
|
||||||
|
|
||||||
sem_post (& sem_send);
|
sem_post (& sem_send);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,14 +41,16 @@
|
||||||
#include "send.h"
|
#include "send.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
|
||||||
void Service :: requestResourceRequest (unsigned __how_many) {
|
void Service :: requestResourceRequest (unsigned __how_many)
|
||||||
|
{
|
||||||
|
|
||||||
num_sent_rr = __how_many;
|
num_sent_rr = __how_many;
|
||||||
for (unsigned i = 0; i < __how_many; i ++)
|
for (unsigned i = 0; i < __how_many; i ++)
|
||||||
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
|
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service :: packResourceRequest () {
|
void Service :: packResourceRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
SCHED_REQUEST req;
|
SCHED_REQUEST req;
|
||||||
req.first = getNodeRank ();
|
req.first = getNodeRank ();
|
||||||
|
|
|
||||||
|
|
@ -50,26 +50,30 @@ extern void wakeUpCommunicator();
|
||||||
extern RANK_ID getRankOfRunner (RUNNER_ID __key);
|
extern RANK_ID getRankOfRunner (RUNNER_ID __key);
|
||||||
|
|
||||||
/* Initializing the list of runners to be synchronized */
|
/* Initializing the list of runners to be synchronized */
|
||||||
void initSynchron () {
|
void initSynchron ()
|
||||||
|
{
|
||||||
|
|
||||||
syncRunners = SYNC();
|
syncRunners = SYNC();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* packing a synchronization request from a service */
|
/* 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 */
|
/* Number of coops to synchronize */
|
||||||
pack( (unsigned)( coops.size() ) );
|
pack( (unsigned)( coops.size() ) );
|
||||||
|
|
||||||
/* Coops to synchronize */
|
/* Coops to synchronize */
|
||||||
for (unsigned i = 0; i < coops.size(); i ++) {
|
for (unsigned i = 0; i < coops.size(); i ++)
|
||||||
pack( coops[ i ]->getOwner()->getDefinitionID() );
|
{
|
||||||
pack( coops[ i ]->getKey() );
|
pack( coops[ i ]->getOwner()->getDefinitionID() );
|
||||||
}
|
pack( coops[ i ]->getKey() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Processing a synchronization request from a service */
|
/* Processing a synchronization request from a service */
|
||||||
void unpackSynchronRequest () {
|
void unpackSynchronRequest ()
|
||||||
|
{
|
||||||
|
|
||||||
unsigned req_num_entries;
|
unsigned req_num_entries;
|
||||||
unpack (req_num_entries);
|
unpack (req_num_entries);
|
||||||
|
|
@ -79,45 +83,50 @@ void unpackSynchronRequest () {
|
||||||
|
|
||||||
/* Adding entries for each of the runners to be synchronized */
|
/* Adding entries for each of the runners to be synchronized */
|
||||||
SyncEntry req_entry;
|
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.runner);
|
||||||
unpack (req_entry.coop);
|
unpack (req_entry.coop);
|
||||||
|
|
||||||
req_sync.first.push_back (req_entry);
|
req_sync.first.push_back (req_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Looking for the sync vector */
|
/* Looking for the sync vector */
|
||||||
SYNC::iterator sync_it = syncRunners.find (req_sync);
|
SYNC::iterator sync_it = syncRunners.find (req_sync);
|
||||||
|
|
||||||
/* The vector does not exist - insert a new sync */
|
/* The vector does not exist - insert a new sync */
|
||||||
if (sync_it == syncRunners.end ()) {
|
if (sync_it == syncRunners.end ())
|
||||||
req_sync.second = 1;
|
{
|
||||||
syncRunners.insert (req_sync);
|
req_sync.second = 1;
|
||||||
}
|
syncRunners.insert (req_sync);
|
||||||
else {
|
}
|
||||||
|
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 ++;
|
/* The vector exists - updating the entry */
|
||||||
|
std::pair< SYNC_RUNNERS, unsigned >& sync_req_entry = const_cast< std::pair< SYNC_RUNNERS, unsigned >& > (*sync_it);
|
||||||
/* All the runners to be synchronized sent the SYNC_REQUEST signal */
|
sync_req_entry.second ++;
|
||||||
if (sync_req_entry.second == sync_req_entry.first.size()) {
|
|
||||||
|
/* All the runners to be synchronized sent the SYNC_REQUEST signal */
|
||||||
/* Remove the entry */
|
if (sync_req_entry.second == sync_req_entry.first.size())
|
||||||
syncRunners.erase (sync_it);
|
{
|
||||||
|
|
||||||
/* Send SYNCHRONIZED signals to all the coop objects */
|
/* Remove the entry */
|
||||||
for (unsigned i = 0; i < req_sync.first.size(); i ++) {
|
syncRunners.erase (sync_it);
|
||||||
|
|
||||||
initMessage ();
|
/* Send SYNCHRONIZED signals to all the coop objects */
|
||||||
|
for (unsigned i = 0; i < req_sync.first.size(); i ++)
|
||||||
pack (req_sync.first [i].runner);
|
{
|
||||||
pack (req_sync.first [i].coop);
|
|
||||||
|
initMessage ();
|
||||||
RANK_ID dest_rank = getRankOfRunner (req_sync.first [i].runner);
|
|
||||||
sendMessage (dest_rank, SYNCHRONIZED_TAG);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,31 +44,39 @@
|
||||||
#include "../../core/runner.h"
|
#include "../../core/runner.h"
|
||||||
#include "../../core/cooperative.h"
|
#include "../../core/cooperative.h"
|
||||||
|
|
||||||
struct SyncEntry {
|
struct SyncEntry
|
||||||
|
{
|
||||||
|
|
||||||
RUNNER_ID runner;
|
RUNNER_ID runner;
|
||||||
COOP_ID coop;
|
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 >& syncA = A.first;
|
||||||
const std::vector< SyncEntry >& syncB = B.first;
|
const std::vector< SyncEntry >& syncB = B.first;
|
||||||
|
|
||||||
if ( syncA.size() == syncB.size() ) {
|
if ( syncA.size() == syncB.size() )
|
||||||
std::vector< SyncEntry >::const_iterator itA = syncA.begin();
|
{
|
||||||
std::vector< SyncEntry >::const_iterator itB = syncB.begin();
|
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::vector< SyncEntry > SYNC_RUNNERS;
|
||||||
typedef std::set< std::pair< SYNC_RUNNERS, unsigned >, SyncCompare > SYNC;
|
typedef std::set< std::pair< SYNC_RUNNERS, unsigned >, SyncCompare > SYNC;
|
||||||
|
|
|
||||||
|
|
@ -48,12 +48,14 @@ static std :: vector <Worker *> key_to_worker (1); /* Vector of registered worke
|
||||||
|
|
||||||
extern void wakeUpCommunicator ();
|
extern void wakeUpCommunicator ();
|
||||||
|
|
||||||
Worker * getWorker (WORKER_ID __key) {
|
Worker * getWorker (WORKER_ID __key)
|
||||||
|
{
|
||||||
|
|
||||||
return key_to_worker [__key];
|
return key_to_worker [__key];
|
||||||
}
|
}
|
||||||
|
|
||||||
Worker :: Worker () {
|
Worker :: Worker ()
|
||||||
|
{
|
||||||
|
|
||||||
recvAndCompleted = false;
|
recvAndCompleted = false;
|
||||||
taskAssigned = 0;
|
taskAssigned = 0;
|
||||||
|
|
@ -63,13 +65,15 @@ Worker :: Worker () {
|
||||||
sem_init( &sem_task_done, 0, 0 );
|
sem_init( &sem_task_done, 0, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: packResult () {
|
void Worker :: packResult ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (serv_id);
|
pack (serv_id);
|
||||||
serv -> packResult ();
|
serv -> packResult ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: unpackData () {
|
void Worker :: unpackData ()
|
||||||
|
{
|
||||||
|
|
||||||
taskAssigned ++;
|
taskAssigned ++;
|
||||||
printDebugMessage ("unpacking the ID. of the service.");
|
printDebugMessage ("unpacking the ID. of the service.");
|
||||||
|
|
@ -81,51 +85,59 @@ void Worker :: unpackData () {
|
||||||
setActive ();
|
setActive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: packTaskDone () {
|
void Worker :: packTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
pack (getNodeRank ());
|
pack (getNodeRank ());
|
||||||
pack (id);
|
pack (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: notifySendingResult () {
|
void Worker :: notifySendingResult ()
|
||||||
|
{
|
||||||
|
|
||||||
/* Notifying the scheduler of the termination */
|
/* Notifying the scheduler of the termination */
|
||||||
recvAndCompleted = true;
|
recvAndCompleted = true;
|
||||||
wakeUp ();
|
wakeUp ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: notifySendingTaskDone () {
|
void Worker :: notifySendingTaskDone ()
|
||||||
|
{
|
||||||
|
|
||||||
sem_post(&sem_task_done);
|
sem_post(&sem_task_done);
|
||||||
setPassive ();
|
setPassive ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: setSource (int __rank) {
|
void Worker :: setSource (int __rank)
|
||||||
|
{
|
||||||
|
|
||||||
src = __rank;
|
src = __rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Worker :: start () {
|
void Worker :: start ()
|
||||||
|
{
|
||||||
|
|
||||||
while (true) {
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
sleep ();
|
sleep ();
|
||||||
|
|
||||||
if (! atLeastOneActiveRunner () && ! taskAssigned)
|
if (! atLeastOneActiveRunner () && ! taskAssigned)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (recvAndCompleted) {
|
if (recvAndCompleted)
|
||||||
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
{
|
||||||
recvAndCompleted = false;
|
send (this, my_node -> rk_sched, TASK_DONE_TAG);
|
||||||
sem_wait(&sem_task_done);
|
recvAndCompleted = false;
|
||||||
taskAssigned --;
|
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.");
|
printDebugMessage ("Worker finished execution.");
|
||||||
setPassive ();
|
setPassive ();
|
||||||
|
|
@ -133,7 +145,8 @@ void Worker :: start () {
|
||||||
wakeUpCommunicator();
|
wakeUpCommunicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void initWorkersEnv () {
|
void initWorkersEnv ()
|
||||||
|
{
|
||||||
|
|
||||||
key_to_worker.resize (1);
|
key_to_worker.resize (1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,39 +44,40 @@
|
||||||
|
|
||||||
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;
|
WORKER_ID id;
|
||||||
SERVICE_ID serv_id;
|
SERVICE_ID serv_id;
|
||||||
Service * serv;
|
Service * serv;
|
||||||
int src;
|
int src;
|
||||||
|
|
||||||
bool recvAndCompleted;
|
bool recvAndCompleted;
|
||||||
unsigned taskAssigned;
|
unsigned taskAssigned;
|
||||||
|
|
||||||
sem_t sem_task_done;
|
sem_t sem_task_done;
|
||||||
sem_t sem_task_asgn;
|
sem_t sem_task_asgn;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void initWorkersEnv ();
|
extern void initWorkersEnv ();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,23 +40,27 @@
|
||||||
|
|
||||||
static xmlTextReaderPtr reader;
|
static xmlTextReaderPtr reader;
|
||||||
|
|
||||||
void openXMLDocument (const char * __filename) {
|
void openXMLDocument (const char * __filename)
|
||||||
|
{
|
||||||
|
|
||||||
reader = xmlNewTextReaderFilename (__filename);
|
reader = xmlNewTextReaderFilename (__filename);
|
||||||
|
|
||||||
if (! reader) {
|
if (! reader)
|
||||||
|
{
|
||||||
|
|
||||||
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
fprintf (stderr, "unable to open '%s'.\n", __filename);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void closeXMLDocument () {
|
void closeXMLDocument ()
|
||||||
|
{
|
||||||
|
|
||||||
xmlFreeTextReader (reader);
|
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 ());
|
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
|
||||||
|
|
||||||
|
|
@ -67,7 +71,8 @@ std :: string getAttributeValue (const std :: string & __attr) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isSep (const xmlChar * __text) {
|
static bool isSep (const xmlChar * __text)
|
||||||
|
{
|
||||||
|
|
||||||
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
|
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
|
||||||
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
|
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
|
||||||
|
|
@ -75,15 +80,18 @@ static bool isSep (const xmlChar * __text) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std :: string getNextNode () {
|
std :: string getNextNode ()
|
||||||
|
{
|
||||||
|
|
||||||
xmlChar * name, * value;
|
xmlChar * name, * value;
|
||||||
|
|
||||||
do {
|
do
|
||||||
xmlTextReaderRead (reader);
|
{
|
||||||
name = xmlTextReaderName (reader);
|
xmlTextReaderRead (reader);
|
||||||
value = xmlTextReaderValue (reader);
|
name = xmlTextReaderName (reader);
|
||||||
} while (! strcmp ((char *) name, "#text") && isSep (value));
|
value = xmlTextReaderValue (reader);
|
||||||
|
}
|
||||||
|
while (! strcmp ((char *) name, "#text") && isSep (value));
|
||||||
|
|
||||||
std :: string str;
|
std :: string str;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,48 +71,48 @@ template < class POT > class eoPrint : public eoContinue <POT>
|
||||||
|
|
||||||
void peoPSOSeq ()
|
void peoPSOSeq ()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
const unsigned int VEC_SIZE = 4;
|
const unsigned int VEC_SIZE = 4;
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
const unsigned int MAX_GEN = 100;
|
const unsigned int MAX_GEN = 100;
|
||||||
const double INIT_POSITION_MIN = -50.0;
|
const double INIT_POSITION_MIN = -50.0;
|
||||||
const double INIT_POSITION_MAX = 50.0;
|
const double INIT_POSITION_MAX = 50.0;
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
const double omega = 1.0;
|
const double omega = 1.0;
|
||||||
const double C1 = 0.5;
|
const double C1 = 0.5;
|
||||||
const double C2 = 2;
|
const double C2 = 2;
|
||||||
rng.reseed (44);
|
rng.reseed (44);
|
||||||
std::cout<<"\n\nWith one PSO\n\n";
|
std::cout<<"\n\nWith one PSO\n\n";
|
||||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > popSeq;
|
eoPop < Indi > popSeq;
|
||||||
popSeq.append (POP_SIZE, random);
|
popSeq.append (POP_SIZE, random);
|
||||||
apply(evalSeq, popSeq);
|
apply(evalSeq, popSeq);
|
||||||
;
|
;
|
||||||
apply < Indi > (veloRandom, popSeq);
|
apply < Indi > (veloRandom, popSeq);
|
||||||
apply < Indi > (localInit, popSeq);
|
apply < Indi > (localInit, popSeq);
|
||||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||||
topologySeq.setup(popSeq);
|
topologySeq.setup(popSeq);
|
||||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq);
|
eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq);
|
||||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||||
eoPrint <Indi> printSeq;
|
eoPrint <Indi> printSeq;
|
||||||
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
eoCombinedContinue <Indi> continuatorSeq(genContSeq);
|
||||||
continuatorSeq.add(printSeq);
|
continuatorSeq.add(printSeq);
|
||||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||||
psaSeq (popSeq);
|
psaSeq (popSeq);
|
||||||
popSeq.sort ();
|
popSeq.sort ();
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoPSOPara()
|
void peoPSOPara()
|
||||||
|
|
|
||||||
|
|
@ -52,54 +52,54 @@ double f (const Indi & _indi)
|
||||||
|
|
||||||
double peoPSOSeq ()
|
double peoPSOSeq ()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
clock_t beginSeq,endSeq;
|
clock_t beginSeq,endSeq;
|
||||||
double timeSeq;
|
double timeSeq;
|
||||||
const unsigned int VEC_SIZE = 2;
|
const unsigned int VEC_SIZE = 2;
|
||||||
const unsigned int POP_SIZE = 10;
|
const unsigned int POP_SIZE = 10;
|
||||||
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
const unsigned int NEIGHBORHOOD_SIZE= 5;
|
||||||
const unsigned int MAX_GEN = 5000;
|
const unsigned int MAX_GEN = 5000;
|
||||||
const double FIT_CONT = -1e-6;
|
const double FIT_CONT = -1e-6;
|
||||||
const double INIT_POSITION_MIN = -5.0;
|
const double INIT_POSITION_MIN = -5.0;
|
||||||
const double INIT_POSITION_MAX = 5.0;
|
const double INIT_POSITION_MAX = 5.0;
|
||||||
const double INIT_VELOCITY_MIN = -1;
|
const double INIT_VELOCITY_MIN = -1;
|
||||||
const double INIT_VELOCITY_MAX = 1;
|
const double INIT_VELOCITY_MAX = 1;
|
||||||
const double C1 = 2;
|
const double C1 = 2;
|
||||||
const double C2 = 2;
|
const double C2 = 2;
|
||||||
rng.reseed (36);
|
rng.reseed (36);
|
||||||
beginSeq=clock();
|
beginSeq=clock();
|
||||||
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
eoEvalFuncPtr<Indi, double, const Indi& > plainEvalSeq(f);
|
||||||
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq);
|
||||||
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX);
|
||||||
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
eoInitFixedLength < Indi > random (VEC_SIZE, uGen);
|
||||||
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX);
|
||||||
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen);
|
||||||
eoFirstIsBestInit < Indi > localInit;
|
eoFirstIsBestInit < Indi > localInit;
|
||||||
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX);
|
||||||
eoStandardFlight < Indi > flight(bndsFlight);
|
eoStandardFlight < Indi > flight(bndsFlight);
|
||||||
eoPop < Indi > popSeq;
|
eoPop < Indi > popSeq;
|
||||||
popSeq.append (POP_SIZE, random);
|
popSeq.append (POP_SIZE, random);
|
||||||
apply(evalSeq, popSeq);
|
apply(evalSeq, popSeq);
|
||||||
;
|
;
|
||||||
apply < Indi > (veloRandom, popSeq);
|
apply < Indi > (veloRandom, popSeq);
|
||||||
apply < Indi > (localInit, popSeq);
|
apply < Indi > (localInit, popSeq);
|
||||||
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
eoLinearTopology<Indi> topologySeq(NEIGHBORHOOD_SIZE);
|
||||||
topologySeq.setup(popSeq);
|
topologySeq.setup(popSeq);
|
||||||
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX);
|
||||||
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq);
|
||||||
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
eoGenContinue < Indi > genContSeq (MAX_GEN);
|
||||||
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
eoFitContinue < Indi > fitContSeq (FIT_CONT);
|
||||||
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
eoCombinedContinue <Indi> continuatorSeq (genContSeq);
|
||||||
continuatorSeq.add(fitContSeq);
|
continuatorSeq.add(fitContSeq);
|
||||||
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
|
||||||
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
|
||||||
//Sequential
|
//Sequential
|
||||||
psaSeq (popSeq);
|
psaSeq (popSeq);
|
||||||
popSeq.sort ();
|
popSeq.sort ();
|
||||||
endSeq=clock();
|
endSeq=clock();
|
||||||
timeSeq = endSeq-beginSeq;
|
timeSeq = endSeq-beginSeq;
|
||||||
return timeSeq;
|
return timeSeq;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoPSOPara(long int arg)
|
void peoPSOPara(long int arg)
|
||||||
|
|
|
||||||
|
|
@ -113,8 +113,8 @@ int main (int __argc, char *__argv[])
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,8 +123,8 @@ int main (int __argc, char *__argv[])
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ int main (int __argc, char *__argv[])
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ int main (int __argc, char *__argv[])
|
||||||
peoPSOSelect<Indi> mig_selec(topology);
|
peoPSOSelect<Indi> mig_selec(topology);
|
||||||
peoWorstPositionReplacement<Indi> mig_replac;
|
peoWorstPositionReplacement<Indi> mig_replac;
|
||||||
|
|
||||||
// Specific implementation (peoData.h)
|
// Specific implementation (peoData.h)
|
||||||
|
|
||||||
eoContinuator<Indi> cont(mig_cont, pop);
|
eoContinuator<Indi> cont(mig_cont, pop);
|
||||||
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
|
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);
|
||||||
|
|
@ -156,10 +156,10 @@ int main (int __argc, char *__argv[])
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
pop2.sort();
|
pop2.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
std::cout << "Final population :\n" << pop2 << std::endl;
|
std::cout << "Final population :\n" << pop2 << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,12 +89,12 @@ int main (int __argc, char * * __argv)
|
||||||
peo :: finalize ();
|
peo :: finalize ();
|
||||||
|
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std :: cout << "\nResult before the local search\n";
|
std :: cout << "\nResult before the local search\n";
|
||||||
for(unsigned i=0;i<pop.size();i++)
|
for (unsigned i=0;i<pop.size();i++)
|
||||||
std::cout<<"\n"<<pop[i].fitness();
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local search
|
// Local search
|
||||||
peo :: init (__argc, __argv);
|
peo :: init (__argc, __argv);
|
||||||
|
|
@ -105,10 +105,10 @@ int main (int __argc, char * * __argv)
|
||||||
peo :: finalize( );
|
peo :: finalize( );
|
||||||
|
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std :: cout << "\nResult after the local search\n";
|
std :: cout << "\nResult after the local search\n";
|
||||||
pop.sort();
|
pop.sort();
|
||||||
for(unsigned i=0;i<pop.size();i++)
|
for (unsigned i=0;i<pop.size();i++)
|
||||||
std::cout<<"\n"<<pop[i].fitness();
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,13 @@ int main (int __argc, char * * __argv)
|
||||||
peo :: finalize( );
|
peo :: finalize( );
|
||||||
|
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std :: cout << "\nResult before the EA\n";
|
std :: cout << "\nResult before the EA\n";
|
||||||
pop.sort();
|
pop.sort();
|
||||||
for(unsigned i=0;i<pop.size();i++)
|
for (unsigned i=0;i<pop.size();i++)
|
||||||
std::cout<<"\n"<<pop[i].fitness();
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
std :: cout << "\n\n";
|
std :: cout << "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// EA
|
// EA
|
||||||
peo :: init (__argc, __argv);
|
peo :: init (__argc, __argv);
|
||||||
|
|
@ -103,11 +103,11 @@ int main (int __argc, char * * __argv)
|
||||||
peo :: finalize ();
|
peo :: finalize ();
|
||||||
|
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
std :: cout << "\nResult after the EA\n";
|
std :: cout << "\nResult after the EA\n";
|
||||||
pop.sort();
|
pop.sort();
|
||||||
for(unsigned i=0;i<pop.size();i++)
|
for (unsigned i=0;i<pop.size();i++)
|
||||||
std::cout<<"\n"<<pop[i].fitness();
|
std::cout<<"\n"<<pop[i].fitness();
|
||||||
std :: cout << "\n\n";
|
std :: cout << "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,22 +50,23 @@ double f (const Indi & _indi)
|
||||||
|
|
||||||
template <class EOT>
|
template <class EOT>
|
||||||
class eoResizerInit: public eoInit<EOT>
|
class eoResizerInit: public eoInit<EOT>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef typename EOT::AtomType AtomType;
|
typedef typename EOT::AtomType AtomType;
|
||||||
|
|
||||||
eoResizerInit(unsigned _size)
|
eoResizerInit(unsigned _size)
|
||||||
: size(_size){}
|
: size(_size)
|
||||||
|
{}
|
||||||
|
|
||||||
virtual void operator()(EOT& chrom)
|
virtual void operator()(EOT& chrom)
|
||||||
{
|
{
|
||||||
chrom.resize(size);
|
chrom.resize(size);
|
||||||
chrom.invalidate();
|
chrom.invalidate();
|
||||||
}
|
}
|
||||||
private :
|
private :
|
||||||
unsigned size;
|
unsigned size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main( int __argc, char** __argv )
|
int main( int __argc, char** __argv )
|
||||||
|
|
@ -119,8 +120,8 @@ int main( int __argc, char** __argv )
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,24 +44,24 @@
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
peo :: init( argc,argv );
|
peo :: init( argc,argv );
|
||||||
eoParser parser(argc, argv);
|
eoParser parser(argc, argv);
|
||||||
eoState state;
|
eoState state;
|
||||||
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
|
peoMoeoPopEval<FlowShop>& eval = do_make_para_eval(parser, state);
|
||||||
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
eoInit<FlowShop>& init = do_make_genotype(parser, state);
|
||||||
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
eoGenOp<FlowShop>& op = do_make_op(parser, state);
|
||||||
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
eoPop<FlowShop>& pop = do_make_pop(parser, state, init);
|
||||||
moeoArchive<FlowShop> arch;
|
moeoArchive<FlowShop> arch;
|
||||||
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
eoContinue<FlowShop>& term = do_make_continue_moeo(parser, state, eval);
|
||||||
eoCheckPoint<FlowShop>& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch);
|
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);
|
eoAlgo<FlowShop>& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch);
|
||||||
peoWrapper parallelMOEO( algo, pop);
|
peoWrapper parallelMOEO( algo, pop);
|
||||||
eval.setOwner(parallelMOEO);
|
eval.setOwner(parallelMOEO);
|
||||||
peo :: run();
|
peo :: run();
|
||||||
peo :: finalize();
|
peo :: finalize();
|
||||||
if (getNodeRank()==1)
|
if (getNodeRank()==1)
|
||||||
{
|
{
|
||||||
pop.sort();
|
pop.sort();
|
||||||
std::cout << "Final population :\n" << pop << std::endl;
|
std::cout << "Final population :\n" << pop << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,13 +88,13 @@ eoContinue<MOEOT> & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo
|
||||||
}
|
}
|
||||||
// maxEval
|
// maxEval
|
||||||
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
|
eoValueParam<unsigned long>& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion");
|
||||||
/* if (maxEvalParam.value())
|
/* if (maxEvalParam.value())
|
||||||
{
|
{
|
||||||
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
eoEvalContinue<MOEOT> *evalCont = new eoEvalContinue<MOEOT>(_eval, maxEvalParam.value());
|
||||||
_state.storeFunctor(evalCont);
|
_state.storeFunctor(evalCont);
|
||||||
// and "add" to combined
|
// and "add" to combined
|
||||||
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
continuator = make_combinedContinue<MOEOT>(continuator, evalCont);
|
||||||
}*/
|
}*/
|
||||||
// maxTime
|
// maxTime
|
||||||
eoValueParam<unsigned long>& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion");
|
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
|
if (maxTimeParam.value()) // positive: -> define and store
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@
|
||||||
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
|
||||||
) : pop (__pop)
|
) : pop (__pop)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayBestRoute :: operator () ()
|
void DisplayBestRoute :: operator () ()
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,7 @@ PartRouteEval :: PartRouteEval (float __from,
|
||||||
float __to
|
float __to
|
||||||
) : from (__from),
|
) : from (__from),
|
||||||
to (__to)
|
to (__to)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void PartRouteEval :: operator () (Route & __route)
|
void PartRouteEval :: operator () (Route & __route)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue