Style for PEO

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@906 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
canape 2008-01-25 16:14:06 +00:00
commit b74a446baa
82 changed files with 1946 additions and 1663 deletions

View file

@ -1,4 +1,4 @@
/*
/*
* <communicable.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -47,7 +47,8 @@ static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of regist
unsigned Communicable :: num_comm = 0;
Communicable :: Communicable () {
Communicable :: Communicable ()
{
comm_to_key [this] = key = ++ num_comm;
key_to_comm.push_back (this);
@ -55,46 +56,54 @@ Communicable :: Communicable () {
sem_init (& sem_stop, 0, 0);
}
Communicable :: ~ Communicable () {
Communicable :: ~ Communicable ()
{
}
COMM_ID Communicable :: getKey () {
COMM_ID Communicable :: getKey ()
{
return key;
}
Communicable * getCommunicable (COMM_ID __key) {
Communicable * getCommunicable (COMM_ID __key)
{
assert (__key < key_to_comm.size ());
return key_to_comm [__key];
return key_to_comm [__key];
}
COMM_ID getKey (const Communicable * __comm) {
COMM_ID getKey (const Communicable * __comm)
{
return comm_to_key [__comm];
}
void Communicable :: lock () {
void Communicable :: lock ()
{
sem_wait (& sem_lock);
}
sem_wait (& sem_lock);
}
void Communicable :: unlock () {
void Communicable :: unlock ()
{
sem_post (& sem_lock);
}
void Communicable :: stop () {
void Communicable :: stop ()
{
sem_wait (& sem_stop);
}
void Communicable :: resume () {
void Communicable :: resume ()
{
sem_post (& sem_stop);
}
void initCommunicableEnv () {
void initCommunicableEnv ()
{
key_to_comm.resize (1);
comm_to_key.clear ();

View file

@ -1,4 +1,4 @@
/*
/*
* <communicable.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -42,37 +42,38 @@
typedef unsigned COMM_ID;
class Communicable {
class Communicable
{
public :
public :
Communicable ();
Communicable ();
virtual ~ Communicable ();
virtual ~ Communicable ();
COMM_ID getKey ();
COMM_ID getKey ();
void lock (); /* It suspends the current process if the semaphore is locked */
void unlock (); /* It unlocks the shared semaphore */
void lock (); /* It suspends the current process if the semaphore is locked */
void unlock (); /* It unlocks the shared semaphore */
void stop (); /* It suspends the current process */
void resume (); /* It resumes ___________ */
void stop (); /* It suspends the current process */
void resume (); /* It resumes ___________ */
public :
public :
static unsigned num_comm;
static unsigned num_comm;
protected :
protected :
COMM_ID key;
COMM_ID key;
sem_t sem_lock;
sem_t sem_lock;
sem_t sem_stop;
};
sem_t sem_stop;
};
extern void initCommunicableEnv ();
extern Communicable * getCommunicable (COMM_ID __key);
extern Communicable * getCommunicable (COMM_ID __key);
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* <cooperative.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -43,38 +43,39 @@
typedef unsigned COOP_ID;
class Cooperative : public Communicable {
class Cooperative : public Communicable
{
public :
public :
Runner * getOwner ();
Runner * getOwner ();
void setOwner (Runner & __runner);
void setOwner (Runner & __runner);
virtual void pack () = 0;
virtual void pack () = 0;
virtual void unpack () = 0;
virtual void unpack () = 0;
virtual void packSynchronizeReq () = 0;
virtual void packSynchronizeReq () = 0;
void send (Cooperative * __coop);
void send (Cooperative * __coop);
void synchronizeCoopEx ();
void synchronizeCoopEx ();
virtual void notifySending ();
virtual void notifySending ();
virtual void notifyReceiving ();
virtual void notifyReceiving ();
virtual void notifySendingSyncReq ();
virtual void notifySendingSyncReq ();
virtual void notifySynchronized ();
virtual void notifySynchronized ();
private :
private :
Runner * owner;
Runner * owner;
};
};
extern Cooperative * getCooperative (COOP_ID __key);
extern Cooperative * getCooperative (COOP_ID __key);
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* <eoPop_comm.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -42,14 +42,16 @@
#include "messaging.h"
template <class EOT> void pack (const eoPop <EOT> & __pop) {
template <class EOT> void pack (const eoPop <EOT> & __pop)
{
pack ((unsigned) __pop.size ());
for (unsigned i = 0; i < __pop.size (); i ++)
pack (__pop [i]);
}
template <class EOT> void unpack (eoPop <EOT> & __pop) {
template <class EOT> void unpack (eoPop <EOT> & __pop)
{
unsigned n;

View file

@ -1,4 +1,4 @@
/*
/*
* <eoVector_comm.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -43,34 +43,41 @@
#include "messaging.h"
template <class F, class T> void pack (const eoVector <F, T> & __v) {
template <class F, class T> void pack (const eoVector <F, T> & __v)
{
if (__v.invalid()) {
pack((unsigned)0);
}
else {
pack((unsigned)1);
pack (__v.fitness ());
}
if (__v.invalid())
{
pack((unsigned)0);
}
else
{
pack((unsigned)1);
pack (__v.fitness ());
}
unsigned len = __v.size ();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (__v [i]);
pack (__v [i]);
}
template <class F, class T> void unpack (eoVector <F, T> & __v) {
template <class F, class T> void unpack (eoVector <F, T> & __v)
{
unsigned valid; unpack(valid);
unsigned valid;
unpack(valid);
if (! valid) {
__v.invalidate();
}
else {
F fit;
unpack (fit);
__v.fitness (fit);
}
if (! valid)
{
__v.invalidate();
}
else
{
F fit;
unpack (fit);
__v.fitness (fit);
}
unsigned len;
unpack (len);
@ -79,125 +86,132 @@ template <class F, class T> void unpack (eoVector <F, T> & __v) {
unpack (__v [i]);
}
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) {
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v)
{
if (__v.invalid()) {
pack((unsigned)0);
}
else {
pack((unsigned)1);
pack (__v.fitness ());
pack (__v.best());
}
if (__v.invalid())
{
pack((unsigned)0);
}
else
{
pack((unsigned)1);
pack (__v.fitness ());
pack (__v.best());
}
unsigned len = __v.size ();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (__v [i]);
pack (__v [i]);
for (unsigned i = 0 ; i < len; i ++)
pack (__v.bestPositions[i]);
pack (__v.bestPositions[i]);
for (unsigned i = 0 ; i < len; i ++)
pack (__v.velocities[i]);
pack (__v.velocities[i]);
}
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v) {
template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & __v)
{
unsigned valid; unpack(valid);
unsigned valid;
unpack(valid);
if (! valid) {
__v.invalidate();
}
else {
F fit;
unpack (fit);
__v.fitness (fit);
if (! valid)
{
__v.invalidate();
}
else
{
F fit;
unpack (fit);
__v.fitness (fit);
unpack(fit);
__v.best(fit);
}
__v.best(fit);
}
unsigned len;
unpack (len);
__v.resize (len);
for (unsigned i = 0 ; i < len; i ++)
unpack (__v [i]);
unpack (__v [i]);
for (unsigned i = 0 ; i < len; i ++)
unpack (__v.bestPositions[i]);
unpack (__v.bestPositions[i]);
for (unsigned i = 0 ; i < len; i ++)
unpack (__v.velocities[i]);
unpack (__v.velocities[i]);
}
template <class F, class T, class V, class W> void unpack (moeoVector <F,T,V,W> &_v)
template <class F, class T, class V, class W> void unpack (moeoVector <F,T,V,W> &_v)
{
unsigned valid;
unpack(valid);
if (! valid)
_v.invalidate();
else
unsigned valid;
unpack(valid);
if (! valid)
_v.invalidate();
else
{
T fit;
unpack (fit);
_v.fitness (fit);
}
unpack(valid);
if (! valid)
_v.invalidateDiversity();
else
{
V diver;
unpack(diver);
_v.diversity(diver);
T fit;
unpack (fit);
_v.fitness (fit);
}
unsigned len;
unpack (len);
_v.resize (len);
for (unsigned i = 0 ; i < len; i ++)
unpack (_v [i]);
unpack(valid);
if (! valid)
_v.invalidateObjectiveVector();
else
unpack(valid);
if (! valid)
_v.invalidateDiversity();
else
{
F object;
unpack (len);
object.resize(len);
for (unsigned i = 0 ; i < len; i ++)
unpack (object[i]);
_v.objectiveVector(object);
V diver;
unpack(diver);
_v.diversity(diver);
}
unsigned len;
unpack (len);
_v.resize (len);
for (unsigned i = 0 ; i < len; i ++)
unpack (_v [i]);
unpack(valid);
if (! valid)
_v.invalidateObjectiveVector();
else
{
F object;
unpack (len);
object.resize(len);
for (unsigned i = 0 ; i < len; i ++)
unpack (object[i]);
_v.objectiveVector(object);
}
}
template <class F, class T, class V, class W> void pack (moeoVector <F,T,V,W> &_v)
template <class F, class T, class V, class W> void pack (moeoVector <F,T,V,W> &_v)
{
if (_v.invalid())
pack((unsigned)0);
else
if (_v.invalid())
pack((unsigned)0);
else
{
pack((unsigned)1);
pack (_v.fitness ());
pack((unsigned)1);
pack (_v.fitness ());
}
if (_v.invalidDiversity())
pack((unsigned)0);
else
if (_v.invalidDiversity())
pack((unsigned)0);
else
{
pack((unsigned)1);
pack(_v.diversity());
pack((unsigned)1);
pack(_v.diversity());
}
unsigned len = _v.size ();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (_v[i]);
if (_v.invalidObjectiveVector())
pack((unsigned)0);
else
unsigned len = _v.size ();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (_v[i]);
if (_v.invalidObjectiveVector())
pack((unsigned)0);
else
{
pack((unsigned)1);
F object;
object=_v.objectiveVector();
len=object.nObjectives();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (object[i]);
pack((unsigned)1);
F object;
object=_v.objectiveVector();
len=object.nObjectives();
pack (len);
for (unsigned i = 0 ; i < len; i ++)
pack (object[i]);
}
}

View file

@ -1,4 +1,4 @@
/*
/*
* <messaging.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -47,41 +47,43 @@ extern void pack (const char & __c);
extern void pack (const bool & __b, int __nitem = 1);
/* Float */
extern void pack (const float & __f, int __nitem = 1);
extern void pack (const float & __f, int __nitem = 1);
/* Double */
extern void pack (const double & __d, int __nitem = 1);
extern void pack (const double & __d, int __nitem = 1);
/* Integer */
extern void pack (const int & __i, int __nitem = 1);
extern void pack (const int & __i, int __nitem = 1);
/* Unsigned int. */
extern void pack (const unsigned int & __ui, int __nitem = 1);
extern void pack (const unsigned int & __ui, int __nitem = 1);
/* Short int. */
extern void pack (const short & __sh, int __nitem = 1);
extern void pack (const short & __sh, int __nitem = 1);
/* Unsigned short */
extern void pack (const unsigned short & __ush, int __nitem = 1);
/* Long */
extern void pack (const long & __l, int __nitem = 1);
extern void pack (const long & __l, int __nitem = 1);
/* Unsigned long */
extern void pack (const unsigned long & __ul, int __nitem = 1);
extern void pack (const unsigned long & __ul, int __nitem = 1);
/* String */
extern void pack (const char * __str);
extern void pack (const std::string & __str);
/* Pointer */
template <class T> void pack (const T * __ptr) {
template <class T> void pack (const T * __ptr)
{
pack ((unsigned long) __ptr);
pack ((unsigned long) __ptr);
}
/* Pair */
template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
template <class U, class V> void pack (const std :: pair <U, V> & __pair)
{
pack (__pair.first);
pack (__pair.second);
@ -90,41 +92,42 @@ template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
/* Char */
extern void unpack (char & __c);
extern void unpack (char & __c);
/* Boolean */
extern void unpack (bool & __b, int __nitem = 1);
/* Float */
extern void unpack (float & __f, int __nitem = 1);
extern void unpack (float & __f, int __nitem = 1);
/* Double */
extern void unpack (double & __d, int __nitem = 1);
extern void unpack (double & __d, int __nitem = 1);
/* Integer */
extern void unpack (int & __i, int __nitem = 1);
extern void unpack (int & __i, int __nitem = 1);
/* Unsigned int. */
extern void unpack (unsigned int & __ui, int __nitem = 1);
extern void unpack (unsigned int & __ui, int __nitem = 1);
/* Short int. */
extern void unpack (short & __sh, int __nitem = 1);
extern void unpack (short & __sh, int __nitem = 1);
/* Unsigned short */
extern void unpack (unsigned short & __ush, int __nitem = 1);
/* Long */
extern void unpack (long & __l, int __nitem = 1);
extern void unpack (long & __l, int __nitem = 1);
/* Unsigned long */
extern void unpack (unsigned long & __ul, int __nitem = 1);
extern void unpack (unsigned long & __ul, int __nitem = 1);
/* String */
extern void unpack (char * __str);
extern void unpack (char * __str);
extern void unpack (std::string & __str);
/* Pointer */
template <class T> void unpack (T * & __ptr) {
template <class T> void unpack (T * & __ptr)
{
unsigned long p;
unpack (p);
@ -132,7 +135,8 @@ template <class T> void unpack (T * & __ptr) {
}
/* Pair */
template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
template <class U, class V> void unpack (std :: pair <U, V> & __pair)
{
unpack (__pair.first);
unpack (__pair.second);

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_debug.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -58,7 +58,8 @@ static char host [MAX_BUFF_SIZE];
std :: vector <FILE *> files;
void setDebugMode (bool __dbg) {
void setDebugMode (bool __dbg)
{
debug = __dbg;
gethostname (host, MAX_BUFF_SIZE);
@ -66,7 +67,8 @@ void setDebugMode (bool __dbg) {
extern int getNodeRank ();
void initDebugging () {
void initDebugging ()
{
mkdir (DEBUG_PATH, S_IRWXU);
// files.push_back (stdout);
@ -75,7 +77,8 @@ void initDebugging () {
files.push_back (fopen (buff, "w"));
}
void endDebugging () {
void endDebugging ()
{
for (unsigned i = 0; i < files.size (); i ++)
if (files [i] != stdout)
@ -83,29 +86,32 @@ void endDebugging () {
files.clear();
}
void printDebugMessage (const char * __mess) {
void printDebugMessage (const char * __mess)
{
if (debug) {
if (debug)
{
char buff [MAX_BUFF_SIZE];
char localTime [MAX_BUFF_SIZE];
time_t t = time (0);
char buff [MAX_BUFF_SIZE];
char localTime [MAX_BUFF_SIZE];
time_t t = time (0);
/* Date */
strcpy( localTime, ctime (& t) );
localTime[ strlen( localTime )-1 ] = ']';
sprintf (buff, "[%s][%s: ", host, localTime );
/* Date */
strcpy( localTime, ctime (& t) );
localTime[ strlen( localTime )-1 ] = ']';
sprintf (buff, "[%s][%s: ", host, localTime );
for (unsigned i = 0; i < files.size (); i ++)
fprintf (files [i], buff);
for (unsigned i = 0; i < files.size (); i ++)
fprintf (files [i], buff);
/* Message */
sprintf (buff, "%s", __mess);
/* Message */
sprintf (buff, "%s", __mess);
for (unsigned i = 0; i < files.size (); i ++) {
fputs (buff, files [i]);
fputs ("\n", files [i]);
fflush (files [i]);
for (unsigned i = 0; i < files.size (); i ++)
{
fputs (buff, files [i]);
fputs ("\n", files [i]);
fflush (files [i]);
}
}
}
}

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_debug.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_fin.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,7 +39,8 @@
#include "runner.h"
#include "rmc.h"
void peo :: finalize () {
void peo :: finalize ()
{
printDebugMessage ("waiting for the termination of all threads");

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_fin.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -37,7 +37,8 @@
#ifndef __peo_finalize_h
#define __peo_finalize_h
namespace peo {
namespace peo
{
extern void finalize ();
}

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_init.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -57,7 +57,8 @@ extern void initScheduler ();
extern void initSynchron ();
static void initExecutionEnv() {
static void initExecutionEnv()
{
initCommunicableEnv ();
initBuffers ();
@ -72,13 +73,15 @@ static void initExecutionEnv() {
}
namespace peo {
namespace peo
{
int * argc;
char * * * argv;
void init (int & __argc, char * * & __argv) {
void init (int & __argc, char * * & __argv)
{
argc = & __argc;
@ -87,7 +90,7 @@ namespace peo {
/* Initializing the execution environment */
initExecutionEnv();
/* Loading the common parameters */
/* Loading the common parameters */
loadParameters (__argc, __argv);
/* Initializing the the Resource Management and Communication */

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_init.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -37,7 +37,8 @@
#ifndef __peo_init_h
#define __peo_init_h
namespace peo {
namespace peo
{
extern int * argc;

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_param.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -40,7 +40,8 @@
#include "peo_debug.h"
void peo :: loadParameters (int & __argc, char * * & __argv) {
void peo :: loadParameters (int & __argc, char * * & __argv)
{
eoParser parser (__argc, __argv);

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_param.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -37,7 +37,8 @@
#ifndef __peo_param_h
#define __peo_param_h
namespace peo {
namespace peo
{
extern void loadParameters (int & __argc, char * * & __argv);
}

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_run.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,7 +39,8 @@
#include "runner.h"
void peo :: run () {
void peo :: run ()
{
startRunners ();

View file

@ -1,4 +1,4 @@
/*
/*
* <peo_run.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -37,7 +37,8 @@
#ifndef __peo_run_h
#define __peo_run_h
namespace peo {
namespace peo
{
extern void run ();
}

View file

@ -1,4 +1,4 @@
/*
/*
* <reac_thread.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -41,29 +41,34 @@ static bool the_end = false;
static std :: vector <ReactiveThread *> reac_threads;
ReactiveThread :: ReactiveThread () {
ReactiveThread :: ReactiveThread ()
{
reac_threads.push_back (this);
sem_init (& sem, 0, 0);
}
void ReactiveThread :: sleep () {
void ReactiveThread :: sleep ()
{
sem_wait (& sem);
sem_wait (& sem);
}
void ReactiveThread :: wakeUp () {
void ReactiveThread :: wakeUp ()
{
sem_post (& sem);
sem_post (& sem);
}
void initReactiveThreadsEnv () {
void initReactiveThreadsEnv ()
{
the_end = false;
reac_threads.clear ();
}
void stopReactiveThreads () {
void stopReactiveThreads ()
{
the_end = true;
for (unsigned i = 0; i < reac_threads.size (); i ++)
@ -71,4 +76,7 @@ void stopReactiveThreads () {
reac_threads.clear ();
}
bool theEnd () { return the_end; }
bool theEnd ()
{
return the_end;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <reac_thread.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -42,21 +42,22 @@
#include "thread.h"
class ReactiveThread : public Thread {
class ReactiveThread : public Thread
{
public:
public:
/* Ctor */
ReactiveThread ();
/* Ctor */
ReactiveThread ();
void sleep ();
void sleep ();
void wakeUp ();
void wakeUp ();
private:
private:
sem_t sem;
};
sem_t sem;
};
extern void initReactiveThreadsEnv ();

View file

@ -1,4 +1,4 @@
/*
/*
* <ring_topo.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -37,17 +37,19 @@
#include "ring_topo.h"
void RingTopology :: setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) {
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to)
{
__from.clear () ;
__to.clear () ;
int len = mig.size () ;
int len = mig.size () ;
for (int i = 0 ; i < len ; i ++)
if (mig [i] == __mig) {
__from.push_back (mig [(i - 1 + len) % len]) ;
__to.push_back (mig [(i + 1) % len]) ;
break;
for (int i = 0 ; i < len ; i ++)
if (mig [i] == __mig)
{
__from.push_back (mig [(i - 1 + len) % len]) ;
__to.push_back (mig [(i + 1) % len]) ;
break;
}
}

View file

@ -1,4 +1,4 @@
/*
/*
* <ring_topo.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,14 +39,15 @@
#include "topology.h"
class RingTopology : public Topology {
class RingTopology : public Topology
{
public :
public :
void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to);
};
void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to);
};
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* <rmc.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -39,7 +39,7 @@
extern void initRMC (int & __argc, char * * & __argv);
extern void runRMC (); /* Resource Management and Communication */
extern void runRMC (); /* Resource Management and Communication */
extern void finalizeRMC ();

View file

@ -1,4 +1,4 @@
/*
/*
* <runner.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -48,7 +48,7 @@
#include "../rmc/mpi/schema.h"
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
static std :: vector <pthread_t *> ll_threads; /* Low-level runner threads */
static std :: vector <Runner *> the_runners;
@ -66,7 +66,8 @@ extern int getNumberOfNodes ();
extern void wakeUpCommunicator ();
Runner :: Runner () {
Runner :: Runner ()
{
exec_id = 0;
def_id = ++ num_def_runners;
@ -77,35 +78,41 @@ Runner :: Runner () {
sem_init (& sem_cntxt, 0, 0);
}
RUNNER_ID Runner :: getDefinitionID () {
RUNNER_ID Runner :: getDefinitionID ()
{
return def_id;
}
RUNNER_ID Runner :: getExecutionID () {
RUNNER_ID Runner :: getExecutionID ()
{
return exec_id;
}
void Runner :: setExecutionID (const RUNNER_ID& execution_id) {
void Runner :: setExecutionID (const RUNNER_ID& execution_id)
{
exec_id = execution_id;
}
Runner * getRunner (RUNNER_ID __key) {
Runner * getRunner (RUNNER_ID __key)
{
return dynamic_cast <Runner *> (getCommunicable (__key));
}
void initializeContext () {
void initializeContext ()
{
num_local_exec_runners = 0;
// setting up the execution IDs & counting the number of local exec. runners
for (unsigned i = 0; i < the_runners.size (); i ++) {
the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] );
if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++;
}
for (unsigned i = 0; i < the_runners.size (); i ++)
{
the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] );
if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++;
}
collectiveCountOfRunners( &num_local_exec_runners, &num_exec_runners );
@ -115,17 +122,20 @@ void initializeContext () {
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
}
void Runner :: waitStarting () {
void Runner :: waitStarting ()
{
sem_wait (& sem_start);
}
void Runner :: waitContextInitialization () {
void Runner :: waitContextInitialization ()
{
sem_wait (& sem_cntxt);
}
void Runner :: start () {
void Runner :: start ()
{
setActive ();
@ -136,46 +146,54 @@ void Runner :: start () {
terminate ();
}
void startRunners () {
void startRunners ()
{
/* Runners */
for (unsigned i = 0; i < the_runners.size (); i ++)
if (the_runners [i] -> isAssignedLocally ()) {
addThread (the_runners [i], ll_threads);
the_runners [i] -> waitStarting ();
}
if (the_runners [i] -> isAssignedLocally ())
{
addThread (the_runners [i], ll_threads);
the_runners [i] -> waitStarting ();
}
printDebugMessage ("launched the parallel runners");
}
void joinRunners () {
void joinRunners ()
{
joinThreads (ll_threads);
the_runners.clear();
}
bool atLeastOneActiveRunner () {
bool atLeastOneActiveRunner ()
{
return num_exec_runners;
}
unsigned numberOfActiveRunners () {
unsigned numberOfActiveRunners ()
{
return num_exec_runners;
}
void Runner :: notifyContextInitialized () {
void Runner :: notifyContextInitialized ()
{
sem_post (& sem_cntxt);
}
void Runner :: notifySendingTermination () {
void Runner :: notifySendingTermination ()
{
printDebugMessage ("I am informed that everyone received my termination notification.");
setPassive ();
}
void unpackTerminationOfRunner () {
void unpackTerminationOfRunner ()
{
RUNNER_ID finished_id;
unpack (finished_id);
@ -184,17 +202,19 @@ void unpackTerminationOfRunner () {
printDebugMessage ("I'm noticed of the termination of a runner");
if (!num_exec_runners) {
if (!num_exec_runners)
{
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
stopReactiveThreads ();
printDebugMessage ("Reactive threads stopped!");
}
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
stopReactiveThreads ();
printDebugMessage ("Reactive threads stopped!");
}
wakeUpCommunicator ();
}
void initRunnersEnv () {
void initRunnersEnv ()
{
ll_threads.clear ();
the_runners.clear ();

View file

@ -1,4 +1,4 @@
/*
/*
* <runner.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -46,49 +46,50 @@
typedef unsigned RUNNER_ID;
class Runner : public Communicable, public Thread {
class Runner : public Communicable, public Thread
{
public :
public :
Runner ();
Runner ();
RUNNER_ID getDefinitionID ();
RUNNER_ID getDefinitionID ();
RUNNER_ID getExecutionID ();
RUNNER_ID getExecutionID ();
void setExecutionID (const RUNNER_ID& execution_id);
void setExecutionID (const RUNNER_ID& execution_id);
bool isAssignedLocally ();
bool isAssignedLocally ();
void waitStarting ();
void waitStarting ();
void waitContextInitialization ();
void waitContextInitialization ();
void start ();
void start ();
virtual void run () = 0;
virtual void run () = 0;
void terminate ();
void terminate ();
void notifyContextInitialized ();
void notifyContextInitialized ();
void notifySendingTermination ();
void notifySendingTermination ();
void packTermination ();
void packTermination ();
private :
private :
sem_t sem_start;
sem_t sem_cntxt;
sem_t sem_start;
sem_t sem_cntxt;
unsigned def_id;
unsigned exec_id;
};
unsigned def_id;
unsigned exec_id;
};
extern void initRunnersEnv ();
extern Runner * getRunner (RUNNER_ID __key);
extern Runner * getRunner (RUNNER_ID __key);
extern void initializeContext ();

View file

@ -1,4 +1,4 @@
/*
/*
* <service.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -36,38 +36,49 @@
#include "service.h"
void Service :: setOwner (Thread & __owner) {
void Service :: setOwner (Thread & __owner)
{
owner = & __owner;
}
Thread * Service :: getOwner () {
Thread * Service :: getOwner ()
{
return owner;
}
Service * getService (SERVICE_ID __key) {
Service * getService (SERVICE_ID __key)
{
return dynamic_cast <Service *> (getCommunicable (__key));
}
void Service :: notifySendingData () { }
void Service :: notifySendingData ()
{ }
void Service :: notifySendingResourceRequest () {
void Service :: notifySendingResourceRequest ()
{
num_sent_rr --;
if (! num_sent_rr)
notifySendingAllResourceRequests ();
}
void Service :: notifySendingAllResourceRequests () { }
void Service :: notifySendingAllResourceRequests ()
{ }
void Service :: packData () {}
void Service :: packData ()
{}
void Service :: unpackData () {}
void Service :: unpackData ()
{}
void Service :: execute () {}
void Service :: execute ()
{}
void Service :: packResult () {}
void Service :: packResult ()
{}
void Service :: unpackResult () {}
void Service :: unpackResult ()
{}

View file

@ -1,4 +1,4 @@
/*
/*
* <service.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -43,37 +43,38 @@
typedef unsigned SERVICE_ID;
class Service : public Communicable {
class Service : public Communicable
{
public :
public :
void setOwner (Thread & __owner);
void setOwner (Thread & __owner);
Thread * getOwner ();
Thread * getOwner ();
void requestResourceRequest (unsigned __how_many = 1);
void packResourceRequest ();
void requestResourceRequest (unsigned __how_many = 1);
void packResourceRequest ();
virtual void packData ();
virtual void unpackData ();
virtual void packData ();
virtual void unpackData ();
virtual void execute ();
virtual void execute ();
virtual void packResult ();
virtual void unpackResult ();
virtual void packResult ();
virtual void unpackResult ();
virtual void notifySendingData ();
virtual void notifySendingResourceRequest ();
virtual void notifySendingAllResourceRequests ();
virtual void notifySendingData ();
virtual void notifySendingResourceRequest ();
virtual void notifySendingAllResourceRequests ();
private :
private :
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
Thread * owner; /* Owner thread (i.e. 'uses' that service) */
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/
};
};
extern Service * getService (SERVICE_ID __key);
extern Service * getService (SERVICE_ID __key);
#endif

View file

@ -1,4 +1,4 @@
/*
/*
* <thread.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -43,66 +43,78 @@ static std :: vector <Thread *> threads;
unsigned num_act = 0;
Thread :: Thread () {
Thread :: Thread ()
{
threads.push_back (this);
act = false;
}
Thread :: ~ Thread () {
Thread :: ~ Thread ()
{
/* Nothing ! */
}
void Thread :: setActive () {
void Thread :: setActive ()
{
if (! act) {
if (! act)
{
act = true;
num_act ++;
}
act = true;
num_act ++;
}
}
void Thread :: setPassive () {
void Thread :: setPassive ()
{
if (act) {
if (act)
{
act = false;
num_act --;
}
act = false;
num_act --;
}
}
void initThreadsEnv () {
void initThreadsEnv ()
{
threads.clear ();
num_act = 0;
}
bool atLeastOneActiveThread () {
bool atLeastOneActiveThread ()
{
return num_act;
}
static void * launch (void * __arg) {
static void * launch (void * __arg)
{
Thread * thr = (Thread *) __arg;
Thread * thr = (Thread *) __arg;
thr -> start ();
return 0;
}
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads)
{
pthread_t * ll_thr = new pthread_t;
__ll_threads.push_back (ll_thr);
pthread_create (ll_thr, 0, launch, __hl_thread);
pthread_create (ll_thr, 0, launch, __hl_thread);
}
void joinThreads (std :: vector <pthread_t *> & __threads) {
void joinThreads (std :: vector <pthread_t *> & __threads)
{
for (unsigned i = 0; i < __threads.size (); i ++) {
pthread_join (* __threads [i], 0);
delete __threads [i];
}
for (unsigned i = 0; i < __threads.size (); i ++)
{
pthread_join (* __threads [i], 0);
delete __threads [i];
}
__threads.clear();
}

View file

@ -1,4 +1,4 @@
/*
/*
* <thread.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -41,27 +41,28 @@
/* A high-level thread */
class Thread {
class Thread
{
public:
public:
/* Ctor */
Thread ();
/* Ctor */
Thread ();
/* Dtor */
virtual ~ Thread ();
/* Dtor */
virtual ~ Thread ();
/* Go ! */
virtual void start () = 0;
/* Go ! */
virtual void start () = 0;
void setActive ();/* It means the current process is going to send messages soon */
void setPassive ();/* The current process is not going to perform send operations
(but it may receive messages) */
void setActive ();/* It means the current process is going to send messages soon */
void setPassive ();/* The current process is not going to perform send operations
(but it may receive messages) */
private :
private :
bool act;
};
bool act;
};
extern void initThreadsEnv ();

View file

@ -1,4 +1,4 @@
/*
/*
* <topology.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -36,17 +36,20 @@
#include "topology.h"
Topology :: ~ Topology () {
Topology :: ~ Topology ()
{
/* Nothing ! */
}
void Topology :: add (Cooperative & __mig) {
void Topology :: add (Cooperative & __mig)
{
mig.push_back (& __mig) ;
}
mig.push_back (& __mig) ;
}
Topology :: operator std :: vector <Cooperative *>& () {
Topology :: operator std :: vector <Cooperative *>& ()
{
return mig;
}

View file

@ -1,4 +1,4 @@
/*
/*
* <topology.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007
@ -41,23 +41,24 @@
#include "cooperative.h"
class Topology {
class Topology
{
public:
public:
virtual ~Topology ();
virtual ~Topology ();
void add (Cooperative & __mig);
void add (Cooperative & __mig);
virtual void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) = 0;
virtual void setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) = 0;
operator std :: vector <Cooperative *>& ();
operator std :: vector <Cooperative *>& ();
protected:
protected:
std :: vector <Cooperative *> mig;
};
std :: vector <Cooperative *> mig;
};
#endif