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
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue