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

@ -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];
}
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);
}
}
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

@ -42,9 +42,10 @@
typedef unsigned COMM_ID;
class Communicable {
class Communicable
{
public :
public :
Communicable ();
@ -58,18 +59,18 @@ public :
void stop (); /* It suspends the current process */
void resume (); /* It resumes ___________ */
public :
public :
static unsigned num_comm;
protected :
protected :
COMM_ID key;
sem_t sem_lock;
sem_t sem_stop;
};
};
extern void initCommunicableEnv ();

View file

@ -43,9 +43,10 @@
typedef unsigned COOP_ID;
class Cooperative : public Communicable {
class Cooperative : public Communicable
{
public :
public :
Runner * getOwner ();
@ -69,11 +70,11 @@ public :
virtual void notifySynchronized ();
private :
private :
Runner * owner;
};
};
extern Cooperative * getCooperative (COOP_ID __key);

View file

@ -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

@ -43,12 +43,15 @@
#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);
}
else {
else
{
pack((unsigned)1);
pack (__v.fitness ());
}
@ -59,14 +62,18 @@ template <class F, class T> void pack (const eoVector <F, T> & __v) {
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();
}
else {
else
{
F fit;
unpack (fit);
__v.fitness (fit);
@ -79,12 +86,15 @@ 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()) {
if (__v.invalid())
{
pack((unsigned)0);
}
else {
else
{
pack((unsigned)1);
pack (__v.fitness ());
pack (__v.best());
@ -100,14 +110,18 @@ template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V>
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();
}
else {
else
{
F fit;
unpack (fit);
__v.fitness (fit);

View file

@ -75,13 +75,15 @@ 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);
}
/* 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);
@ -124,7 +126,8 @@ 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

@ -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,9 +86,11 @@ 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];
@ -102,7 +107,8 @@ void printDebugMessage (const char * __mess) {
/* Message */
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]);
fflush (files [i]);

View file

@ -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

@ -37,7 +37,8 @@
#ifndef __peo_finalize_h
#define __peo_finalize_h
namespace peo {
namespace peo
{
extern void finalize ();
}

View file

@ -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;

View file

@ -37,7 +37,8 @@
#ifndef __peo_init_h
#define __peo_init_h
namespace peo {
namespace peo
{
extern int * argc;

View file

@ -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

@ -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

@ -39,7 +39,8 @@
#include "runner.h"
void peo :: run () {
void peo :: run ()
{
startRunners ();

View file

@ -37,7 +37,8 @@
#ifndef __peo_run_h
#define __peo_run_h
namespace peo {
namespace peo
{
extern void run ();
}

View file

@ -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);
}
void ReactiveThread :: wakeUp () {
void ReactiveThread :: wakeUp ()
{
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

@ -42,9 +42,10 @@
#include "thread.h"
class ReactiveThread : public Thread {
class ReactiveThread : public Thread
{
public:
public:
/* Ctor */
ReactiveThread ();
@ -53,10 +54,10 @@ public:
void wakeUp ();
private:
private:
sem_t sem;
};
};
extern void initReactiveThreadsEnv ();

View file

@ -38,14 +38,16 @@
void RingTopology :: setNeighbors (Cooperative * __mig,
std :: vector <Cooperative *> & __from,
std :: vector <Cooperative *> & __to) {
std :: vector <Cooperative *> & __to)
{
__from.clear () ;
__to.clear () ;
int len = mig.size () ;
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]) ;
break;

View file

@ -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);
};
};
#endif

View file

@ -66,7 +66,8 @@ extern int getNumberOfNodes ();
extern void wakeUpCommunicator ();
Runner :: Runner () {
Runner :: Runner ()
{
exec_id = 0;
def_id = ++ num_def_runners;
@ -77,32 +78,38 @@ 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 ++) {
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 ++;
}
@ -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,11 +146,13 @@ void Runner :: start () {
terminate ();
}
void startRunners () {
void startRunners ()
{
/* Runners */
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 ();
}
@ -148,34 +160,40 @@ void startRunners () {
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,7 +202,8 @@ 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 ();
@ -194,7 +213,8 @@ void unpackTerminationOfRunner () {
wakeUpCommunicator ();
}
void initRunnersEnv () {
void initRunnersEnv ()
{
ll_threads.clear ();
the_runners.clear ();

View file

@ -46,9 +46,10 @@
typedef unsigned RUNNER_ID;
class Runner : public Communicable, public Thread {
class Runner : public Communicable, public Thread
{
public :
public :
Runner ();
@ -76,14 +77,14 @@ public :
void packTermination ();
private :
private :
sem_t sem_start;
sem_t sem_cntxt;
unsigned def_id;
unsigned exec_id;
};
};
extern void initRunnersEnv ();

View file

@ -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

@ -43,9 +43,10 @@
typedef unsigned SERVICE_ID;
class Service : public Communicable {
class Service : public Communicable
{
public :
public :
void setOwner (Thread & __owner);
@ -66,13 +67,13 @@ public :
virtual void notifySendingResourceRequest ();
virtual void notifySendingAllResourceRequests ();
private :
private :
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)*/
};
};
extern Service * getService (SERVICE_ID __key);

View file

@ -43,47 +43,56 @@ 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 ++;
}
}
void Thread :: setPassive () {
void Thread :: setPassive ()
{
if (act) {
if (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;
thr -> start ();
@ -91,16 +100,19 @@ static void * launch (void * __arg) {
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);
}
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];
}

View file

@ -41,9 +41,10 @@
/* A high-level thread */
class Thread {
class Thread
{
public:
public:
/* Ctor */
Thread ();
@ -58,10 +59,10 @@ public:
void setPassive ();/* The current process is not going to perform send operations
(but it may receive messages) */
private :
private :
bool act;
};
};
extern void initThreadsEnv ();

View file

@ -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) ;
}
}
Topology :: operator std :: vector <Cooperative *>& () {
Topology :: operator std :: vector <Cooperative *>& ()
{
return mig;
}

View file

@ -41,9 +41,10 @@
#include "cooperative.h"
class Topology {
class Topology
{
public:
public:
virtual ~Topology ();
@ -55,9 +56,9 @@ public:
operator std :: vector <Cooperative *>& ();
protected:
protected:
std :: vector <Cooperative *> mig;
};
};
#endif

View file

@ -234,8 +234,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack(
unlock();
}
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq() {
}
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq()
{}
template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrate()
{

View file

@ -44,21 +44,24 @@
/************************** DEFINE A DATA ******************************************/
/**************************************************************************************/
class peoData {
public:
class peoData
{
public:
virtual void pack () {}
virtual void unpack () {}
virtual void pack ()
{}
virtual void unpack ()
{}
};
};
// Specific implementation : migration of a population
template<class EOT>
class peoPop: public eoPop<EOT>, public peoData
{
public:
{
public:
virtual void pack ()
{
@ -76,7 +79,7 @@ public:
::unpack ((*this)[i]);
}
};
};
/**************************************************************************************/
@ -84,27 +87,30 @@ public:
/**************************************************************************************/
class continuator
{
public:
{
public:
virtual bool check()=0;
};
};
// Specific implementation : migration of a population
template < class EOT> class eoContinuator : public continuator{
public:
template < class EOT> class eoContinuator : public continuator
{
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);
}
protected:
protected:
eoContinue<EOT> & cont ;
const eoPop<EOT> & pop;
};
};
/**************************************************************************************/
@ -112,18 +118,20 @@ protected:
/**************************************************************************************/
template < class TYPE> class selector
{
public:
{
public:
virtual void operator()(TYPE &)=0;
};
};
// Specific implementation : migration of a population
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >{
public:
template < class EOT, class TYPE> class eoSelector : public selector< TYPE >
{
public:
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source){}
eoSelector(eoSelectOne<EOT> & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source)
{}
virtual void operator()(TYPE & _dest)
{
@ -133,11 +141,11 @@ public:
_dest[i] = selector(source);
}
protected:
protected:
eoSelectOne<EOT> & selector ;
unsigned nb_select;
const TYPE & source;
};
};
/**************************************************************************************/
@ -145,27 +153,29 @@ protected:
/**************************************************************************************/
template < class TYPE> class replacement
{
public:
{
public:
virtual void operator()(TYPE &)=0;
};
};
// Specific implementation : migration of a population
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >{
public:
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination){}
template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >
{
public:
eoReplace(eoReplacement<EOT> & _replace, TYPE & _destination): replace(_replace), destination(_destination)
{}
virtual void operator()(TYPE & _source)
{
replace(destination, _source);
}
protected:
protected:
eoReplacement<EOT> & replace;
TYPE & destination;
};
};
/**************************************************************************************/
@ -173,11 +183,12 @@ protected:
/**************************************************************************************/
class eoSyncContinue: public continuator
{
{
public:
public:
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) {}
eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter)
{}
virtual bool check()
{
@ -185,13 +196,13 @@ public:
}
private:
private:
unsigned period;
unsigned counter;
};
};
#endif

View file

@ -43,7 +43,7 @@ template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& >
template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& >
#endif
struct peoEvalFunc: public eoEvalFunc<EOT>
{
{
peoEvalFunc( FitT (* _eval)( FunctionArg ) )
: eoEvalFunc<EOT>(), evalFunc( _eval )
@ -56,7 +56,7 @@ struct peoEvalFunc: public eoEvalFunc<EOT>
private:
FitT (* evalFunc )( FunctionArg );
};
};
#endif

View file

@ -226,12 +226,12 @@ template< class EOT > void peoMoeoPopEval< EOT > :: unpackResult()
/* Unpacking the computed fitness */
// unpack( fit );
unsigned len;
std::vector < double > object;
unsigned len;
std::vector < double > object;
unpack(len);
object.resize(len);
for (unsigned i = 0 ; i < len; i ++)
unpack(len);
object.resize(len);
for (unsigned i = 0 ; i < len; i ++)
unpack (object[i]);
/* Unpacking the @ of the associated individual */
unpack( ad_sol );
@ -239,7 +239,7 @@ for (unsigned i = 0 ; i < len; i ++)
/* Associating the fitness the local solution */
// merge_eval( *ad_sol, object );
ad_sol->objectiveVector(object);
ad_sol->objectiveVector(object);
progression[ ad_sol ].second--;
/* Notifying the container of the termination of the evaluation */

View file

@ -43,7 +43,7 @@
template < typename EntityType > class peoMultiStart : public Service
{
{
public:
@ -261,7 +261,7 @@ template < typename EntityType > class peoMultiStart : public Service
unsigned num_term;
unsigned dataIndex;
unsigned functionIndex;
};
};
template < typename EntityType > void peoMultiStart< EntityType >::packData()

View file

@ -45,13 +45,13 @@
//! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness
//! value is explicitly specified.
template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT >
{
{
public :
public :
//! Operator which sets as fitness the <b>__fit</b> value for the <b>__sol</b> individual
void operator()( EOT& __sol, const typename EOT :: Fitness& __fit );
};
};
template< class EOT > void peoNoAggEvalFunc< EOT > :: operator()( EOT& __sol, const typename EOT :: Fitness& __fit )

View file

@ -147,9 +147,9 @@
//! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1
//! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them).
template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater
{
{
public:
public:
//! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined
//! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters.
@ -195,13 +195,13 @@ public:
void notifySynchronized();
private:
private:
void emigrate();
void immigrate();
private:
private:
eoSyncContinue cont; // continuator
selector <TYPE> & select; // the selection strategy
@ -220,7 +220,7 @@ private:
std :: vector< Cooperative* > in, out, all;
unsigned nbMigrations;
};
};
template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandMig(
@ -256,7 +256,8 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: unpack()
explicitPassive = true;
}
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq() {
template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq()
{
packSynchronRequest( all );
}
@ -280,7 +281,8 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: immigra
{
assert( imm.size() );
while ( imm.size() ) {
while ( imm.size() )
{
replace( imm.front() ) ;
imm.pop();
}
@ -294,16 +296,19 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: operato
if ( cont.check() )
{
explicitPassive = standbyMigration = false;
topology.setNeighbors( this, in, out ); all = topology;
topology.setNeighbors( this, in, out );
all = topology;
nbMigrations = 0;
synchronizeCoopEx(); stop();
synchronizeCoopEx();
stop();
// sending emigrants
emigrate();
// synchronizing
sem_wait( &sync );
// receiving immigrants
immigrate();
synchronizeCoopEx(); stop();
synchronizeCoopEx();
stop();
}
}
@ -316,19 +321,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifyR
{
nbMigrations++;
if ( nbMigrations == in.size() ) {
if ( nbMigrations == in.size() )
{
if ( standbyMigration ) getOwner()->setActive();
sem_post( &sync );
}
}
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq () {
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq ()
{
getOwner()->setPassive();
}
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized () {
template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized ()
{
standbyMigration = true;
getOwner()->setActive();

View file

@ -47,9 +47,9 @@ extern int getNodeRank();
template< class EOT > class peoTransform : public Service, public eoTransform< EOT >
{
{
public:
public:
peoTransform(
@ -74,7 +74,7 @@ public:
void notifySendingData();
void notifySendingAllResourceRequests();
private:
private:
eoQuadOp< EOT >& cross;
double cross_rate;
@ -89,7 +89,7 @@ private:
EOT father, mother;
unsigned num_term;
};
};
template< class EOT > peoTransform< EOT > :: peoTransform(

View file

@ -45,7 +45,7 @@
class peoWrapper : public Runner
{
{
public:
@ -155,7 +155,7 @@ class peoWrapper : public Runner
private:
AbstractAlgorithm* algorithm;
};
};
#endif

View file

@ -52,7 +52,8 @@ static sem_t sem_comm_init;
static Communicator * the_thread;
Communicator :: Communicator (int * __argc, char * * * __argv) {
Communicator :: Communicator (int * __argc, char * * * __argv)
{
the_thread = this;
initNode (__argc, __argv);
@ -61,9 +62,11 @@ Communicator :: Communicator (int * __argc, char * * * __argv) {
sem_post (& sem_comm_init);
}
void Communicator :: start () {
void Communicator :: start ()
{
while (true) {
while (true)
{
/* Zzz Zzz Zzz :-))) */
sleep ();
@ -82,11 +85,13 @@ void Communicator :: start () {
//synchronizeNodes ();
}
void initCommunication () {
void initCommunication ()
{
static bool initializedSemaphore = false;
if (initializedSemaphore) {
if (initializedSemaphore)
{
sem_destroy(& sem_comm_init);
}
@ -94,12 +99,14 @@ void initCommunication () {
initializedSemaphore = true;
}
void waitNodeInitialization () {
void waitNodeInitialization ()
{
sem_wait (& sem_comm_init);
}
void wakeUpCommunicator () {
void wakeUpCommunicator ()
{
the_thread -> wakeUp ();
}

View file

@ -40,15 +40,16 @@
#include "../../core/communicable.h"
#include "../../core/reac_thread.h"
class Communicator : public ReactiveThread {
class Communicator : public ReactiveThread
{
public :
public :
/* Ctor */
Communicator (int * __argc, char * * * __argv);
void start ();
};
};
extern void initCommunication ();

View file

@ -41,42 +41,48 @@
#include "mess.h"
#include "../../core/peo_debug.h"
Runner * Cooperative :: getOwner () {
Runner * Cooperative :: getOwner ()
{
return owner;
}
void Cooperative :: setOwner (Runner & __runner) {
void Cooperative :: setOwner (Runner & __runner)
{
owner = & __runner;
}
void Cooperative :: send (Cooperative * __coop) {
void Cooperative :: send (Cooperative * __coop)
{
:: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG);
// stop ();
}
void Cooperative :: synchronizeCoopEx () {
void Cooperative :: synchronizeCoopEx ()
{
:: send (this, my_node -> rk_sched, SYNCHRONIZE_REQ_TAG);
}
Cooperative * getCooperative (COOP_ID __key) {
Cooperative * getCooperative (COOP_ID __key)
{
return dynamic_cast <Cooperative *> (getCommunicable (__key));
}
void Cooperative :: notifySending () {
void Cooperative :: notifySending ()
{
//getOwner -> setPassive ();
// resume ();
}
void Cooperative :: notifyReceiving () {
}
void Cooperative :: notifyReceiving ()
{}
void Cooperative :: notifySendingSyncReq () {
}
void Cooperative :: notifySendingSyncReq ()
{}
void Cooperative :: notifySynchronized () {
}
void Cooperative :: notifySynchronized ()
{}

View file

@ -51,22 +51,26 @@ static std :: vector <char *> act_buf; /* Active buffers */
static std :: vector <MPI_Request *> act_req; /* Active requests */
void initBuffers () {
void initBuffers ()
{
pos_buf = 0;
act_buf.clear ();
act_req.clear ();
}
void cleanBuffers () {
void cleanBuffers ()
{
for (unsigned i = 0; i < act_req.size ();) {
for (unsigned i = 0; i < act_req.size ();)
{
MPI_Status stat ;
int flag ;
MPI_Test (act_req [i], & flag, & stat) ;
if (flag) {
if (flag)
{
delete[] act_buf [i] ;
delete act_req [i] ;
@ -82,11 +86,13 @@ void cleanBuffers () {
}
}
void waitBuffers () {
void waitBuffers ()
{
printDebugMessage ("waiting the termination of the asynchronous operations to complete");
for (unsigned i = 0; i < act_req.size (); i ++) {
for (unsigned i = 0; i < act_req.size (); i ++)
{
MPI_Status stat ;
@ -97,7 +103,8 @@ void waitBuffers () {
}
}
bool probeMessage (int & __src, int & __tag) {
bool probeMessage (int & __src, int & __tag)
{
int flag;
@ -111,19 +118,22 @@ bool probeMessage (int & __src, int & __tag) {
return flag;
}
void waitMessage () {
void waitMessage ()
{
MPI_Status stat;
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
}
void initMessage () {
void initMessage ()
{
pos_buf = 0;
}
void sendMessage (int __to, int __tag) {
void sendMessage (int __to, int __tag)
{
cleanBuffers ();
act_buf.push_back (new char [pos_buf]);
@ -132,13 +142,15 @@ void sendMessage (int __to, int __tag) {
MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ());
}
void sendMessageToAll (int __tag) {
void sendMessageToAll (int __tag)
{
for (int i = 0; i < getNumberOfNodes (); i ++)
sendMessage (i, __tag);
}
void receiveMessage (int __from, int __tag) {
void receiveMessage (int __from, int __tag)
{
MPI_Status stat;
MPI_Request req;
@ -147,80 +159,93 @@ void receiveMessage (int __from, int __tag) {
MPI_Wait (& req, & stat);
}
void synchronizeNodes () {
void synchronizeNodes ()
{
MPI_Barrier ( MPI_COMM_WORLD );
}
/* Char */
void pack (const char & __c) {
void pack (const char & __c)
{
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Boolean */
void pack (const bool & __b, int __nitem){
void pack (const bool & __b, int __nitem)
{
MPI_Pack ((void *) & __b, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Float */
void pack (const float & __f, int __nitem) {
void pack (const float & __f, int __nitem)
{
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Double */
void pack (const double & __d, int __nitem) {
void pack (const double & __d, int __nitem)
{
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Integer */
void pack (const int & __i, int __nitem) {
void pack (const int & __i, int __nitem)
{
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Unsigned int. */
void pack (const unsigned int & __ui, int __nitem) {
void pack (const unsigned int & __ui, int __nitem)
{
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Short int. */
void pack (const short & __sh, int __nitem) {
void pack (const short & __sh, int __nitem)
{
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Unsigned short */
void pack (const unsigned short & __ush, int __nitem) {
void pack (const unsigned short & __ush, int __nitem)
{
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Long */
void pack (const long & __l, int __nitem) {
void pack (const long & __l, int __nitem)
{
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* Unsigned long */
void pack (const unsigned long & __ul, int __nitem) {
void pack (const unsigned long & __ul, int __nitem)
{
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
/* String */
void pack (const char * __str) {
void pack (const char * __str)
{
int len = strlen (__str) + 1;
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
}
void pack (const std::string & __str) {
void pack (const std::string & __str)
{
size_t size = __str.size() + 1;
char * buffer = new char[ size ];
@ -230,73 +255,85 @@ void pack (const std::string & __str) {
}
/* Char */
void unpack (char & __c) {
void unpack (char & __c)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
}
/* Boolean */
extern void unpack (bool & __b, int __nitem ){
extern void unpack (bool & __b, int __nitem )
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD);
}
}
/* Float */
void unpack (float & __f, int __nitem) {
void unpack (float & __f, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
}
/* Double */
void unpack (double & __d, int __nitem) {
void unpack (double & __d, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
}
/* Integer */
void unpack (int & __i, int __nitem) {
void unpack (int & __i, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
}
/* Unsigned int. */
void unpack (unsigned int & __ui, int __nitem) {
void unpack (unsigned int & __ui, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
}
/* Short int. */
void unpack (short & __sh, int __nitem) {
void unpack (short & __sh, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
}
/* Unsigned short */
void unpack (unsigned short & __ush, int __nitem) {
void unpack (unsigned short & __ush, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
}
/* Long */
void unpack (long & __l, int __nitem) {
void unpack (long & __l, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
}
/* Unsigned long */
void unpack (unsigned long & __ul, int __nitem) {
void unpack (unsigned long & __ul, int __nitem)
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
}
/* String */
void unpack (char * __str) {
void unpack (char * __str)
{
int len;
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
}
void unpack (std::string & __str) {
void unpack (std::string & __str)
{
char * buffer;
int len;

View file

@ -43,35 +43,41 @@
#include "mess.h"
class MPIThreadedEnv {
class MPIThreadedEnv
{
public:
public:
static void init ( int * __argc, char * * * __argv ) {
static void init ( int * __argc, char * * * __argv )
{
static MPIThreadedEnv mpiThreadedEnv( __argc, __argv );
}
static void finalize () {
static void finalize ()
{
static bool finalizedEnvironment = false;
if (! finalizedEnvironment ) {
if (! finalizedEnvironment )
{
MPI_Finalize ();
finalizedEnvironment = true;
}
}
private:
private:
/* No instance of this class can be created outside its domain! */
MPIThreadedEnv ( int * __argc, char * * * __argv ) {
MPIThreadedEnv ( int * __argc, char * * * __argv )
{
static bool MPIThreadedEnvInitialized = false;
int provided = 1;
if (! MPIThreadedEnvInitialized) {
if (! MPIThreadedEnvInitialized)
{
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
@ -82,11 +88,12 @@ private:
}
}
~MPIThreadedEnv() {
~MPIThreadedEnv()
{
finalize ();
}
};
};
static int rk, sz; /* Rank & size */
@ -96,27 +103,32 @@ static std :: map <std :: string, int> name_to_rk;
static std :: vector <std :: string> rk_to_name;
int getNodeRank () {
int getNodeRank ()
{
return rk;
}
int getNumberOfNodes () {
int getNumberOfNodes ()
{
return sz;
}
void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners ) {
void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners )
{
MPI_Allreduce( num_local_exec_runners, num_exec_runners, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD );
}
int getRankFromName (const std :: string & __name) {
int getRankFromName (const std :: string & __name)
{
return atoi (__name.c_str ());
}
void initNode (int * __argc, char * * * __argv) {
void initNode (int * __argc, char * * * __argv)
{
rk_to_name.clear ();
name_to_rk.clear ();
@ -134,7 +146,8 @@ void initNode (int * __argc, char * * * __argv) {
MPI_Get_processor_name (names [0], & len); /* Me */
MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
for (int i = 0; i < sz; i ++) {
for (int i = 0; i < sz; i ++)
{
rk_to_name.push_back (names [i]);
name_to_rk [names [i]] = i;
}

View file

@ -44,7 +44,8 @@
typedef int RANK_ID;
struct Node {
struct Node
{
RANK_ID rk; /* Rank */
std :: string name; /* Host name */
@ -52,7 +53,7 @@ struct Node {
int rk_sched; /* rank of the scheduler */
std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
};
};
extern Node * my_node;

View file

@ -38,7 +38,8 @@
#include "schema.h"
void loadRMCParameters (int & __argc, char * * & __argv) {
void loadRMCParameters (int & __argc, char * * & __argv)
{
eoParser parser (__argc, __argv);

View file

@ -45,25 +45,30 @@
#include "../../core/cooperative.h"
#include "../../core/peo_debug.h"
void receiveMessages () {
void receiveMessages ()
{
cleanBuffers ();
do {
do
{
if (! atLeastOneActiveThread ()) {
if (! atLeastOneActiveThread ())
{
waitMessage ();
}
int src, tag;
while (probeMessage (src, tag)) {
while (probeMessage (src, tag))
{
receiveMessage (src, tag);
initMessage ();
switch (tag) {
switch (tag)
{
case RUNNER_STOP_TAG:
unpackTerminationOfRunner ();
@ -146,5 +151,6 @@ void receiveMessages () {
};
}
} while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/ );
}
while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/ );
}

View file

@ -46,10 +46,12 @@ static std :: vector <Worker *> worker_threads; /* Worker threads */
static Communicator* communicator_thread = NULL; /* Communicator thread */
void runRMC () {
void runRMC ()
{
/* Worker(s) ? */
for (unsigned i = 0; i < my_node -> num_workers; i ++) {
for (unsigned i = 0; i < my_node -> num_workers; i ++)
{
worker_threads.push_back (new Worker);
addThread (worker_threads.back(), ll_threads);
}
@ -57,7 +59,8 @@ void runRMC () {
wakeUpCommunicator ();
}
void initRMC (int & __argc, char * * & __argv) {
void initRMC (int & __argc, char * * & __argv)
{
/* Communication */
initCommunication ();
@ -71,12 +74,14 @@ void initRMC (int & __argc, char * * & __argv) {
initScheduler ();
}
void finalizeRMC () {
void finalizeRMC ()
{
printDebugMessage ("before join threads RMC");
joinThreads (ll_threads);
for (unsigned i = 0; i < worker_threads.size(); i++ ) {
for (unsigned i = 0; i < worker_threads.size(); i++ )
{
delete worker_threads [i];
}
worker_threads.clear ();

View file

@ -43,7 +43,8 @@
#include "schema.h"
bool Runner :: isAssignedLocally () {
bool Runner :: isAssignedLocally ()
{
for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
if (my_node -> id_run [i] == def_id)
@ -51,12 +52,14 @@ bool Runner :: isAssignedLocally () {
return false;
}
void Runner :: terminate () {
void Runner :: terminate ()
{
sendToAll (this, RUNNER_STOP_TAG);
}
void Runner :: packTermination () {
void Runner :: packTermination ()
{
pack (def_id);
}

View file

@ -49,13 +49,15 @@ static unsigned initNumberOfRes = 0;
extern void wakeUpCommunicator();
void initScheduler () {
void initScheduler ()
{
resources = std :: queue <SCHED_RESOURCE> ();
requests = std :: queue <SCHED_REQUEST> ();
initNumberOfRes = 0;
for (unsigned i = 0; i < the_schema.size (); i ++) {
for (unsigned i = 0; i < the_schema.size (); i ++)
{
const Node & node = the_schema [i];
@ -66,19 +68,23 @@ void initScheduler () {
initNumberOfRes = resources.size ();
}
bool allResourcesFree () {
bool allResourcesFree ()
{
return resources.size () == initNumberOfRes;
}
unsigned numResourcesFree () {
unsigned numResourcesFree ()
{
return resources.size ();
}
static void update () {
static void update ()
{
unsigned num_alloc = std :: min (resources.size (), requests.size ());
for (unsigned i = 0; i < num_alloc; i ++) {
for (unsigned i = 0; i < num_alloc; i ++)
{
SCHED_REQUEST req = requests.front ();
requests.pop ();
@ -94,7 +100,8 @@ static void update () {
}
}
void unpackResourceRequest () {
void unpackResourceRequest ()
{
printDebugMessage ("queuing a resource request.");
SCHED_REQUEST req;
@ -103,7 +110,8 @@ void unpackResourceRequest () {
update ();
}
void unpackTaskDone () {
void unpackTaskDone ()
{
printDebugMessage ("I'm notified a worker is now idle.");
SCHED_RESOURCE res;

View file

@ -51,7 +51,8 @@ Node * my_node;
static unsigned maxSpecifiedRunnerID = 0;
RANK_ID getRankOfRunner (RUNNER_ID __key) {
RANK_ID getRankOfRunner (RUNNER_ID __key)
{
for (unsigned i = 0; i < the_schema.size (); i ++)
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
@ -61,7 +62,8 @@ RANK_ID getRankOfRunner (RUNNER_ID __key) {
return 0;
}
static void loadNode (int __rk_sched) {
static void loadNode (int __rk_sched)
{
Node node;
@ -72,12 +74,14 @@ static void loadNode (int __rk_sched) {
/* ATT: num_workers */
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
while (true) {
while (true)
{
/* TAG: <runner> | </node> */
std :: string name = getNextNode ();
assert (name == "runner" || name == "node");
if (name == "runner") {
if (name == "runner")
{
/* TAG: </node> */
node.id_run.push_back (atoi (getNextNode ().c_str ()));
if ( node.id_run.back() > maxSpecifiedRunnerID )
@ -85,7 +89,8 @@ static void loadNode (int __rk_sched) {
/* TAG: </runner> */
assert (getNextNode () == "runner");
}
else {
else
{
/* TAG: </node> */
node.execution_id_run = node.id_run;
the_schema.push_back (node);
@ -94,14 +99,16 @@ static void loadNode (int __rk_sched) {
}
}
static void loadGroup () {
static void loadGroup ()
{
std :: string name;
/* ATT: scheduler*/
int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
while (true) {
while (true)
{
/* TAG: <node> | </group> */
name = getNextNode ();
@ -115,12 +122,14 @@ static void loadGroup () {
}
}
bool isScheduleNode () {
bool isScheduleNode ()
{
return my_node -> rk == my_node -> rk_sched;
}
void loadSchema (const char * __filename) {
void loadSchema (const char * __filename)
{
openXMLDocument (__filename);
@ -133,7 +142,8 @@ void loadSchema (const char * __filename) {
the_schema.clear();
maxSpecifiedRunnerID = 0;
while (true) {
while (true)
{
/* TAG: <group> | </schema> */
name = getNextNode ();
@ -147,12 +157,16 @@ void loadSchema (const char * __filename) {
}
std :: set<unsigned> uniqueRunnerIDs; unsigned nbUniqueIDs = 0;
for (unsigned i = 0; i < the_schema.size (); i ++) {
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++) {
std :: set<unsigned> uniqueRunnerIDs;
unsigned nbUniqueIDs = 0;
for (unsigned i = 0; i < the_schema.size (); i ++)
{
for (unsigned j = 0; j < the_schema [i].id_run.size(); j ++)
{
uniqueRunnerIDs.insert( the_schema [i].id_run[j] );
/* In case a duplicate ID has been found */
if ( uniqueRunnerIDs.size() == nbUniqueIDs ) {
if ( uniqueRunnerIDs.size() == nbUniqueIDs )
{
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
}
nbUniqueIDs = uniqueRunnerIDs.size();
@ -160,7 +174,8 @@ void loadSchema (const char * __filename) {
}
/* 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]);
}
@ -175,12 +190,14 @@ void loadSchema (const char * __filename) {
if (isScheduleNode ())
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);
}
if (my_node -> num_workers) {
if (my_node -> num_workers)
{
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
printDebugMessage (mess);

View file

@ -50,13 +50,15 @@
#define TO_ALL -1
typedef struct {
typedef struct
{
Communicable * comm;
int to;
int tag;
} SEND_REQUEST;
}
SEND_REQUEST;
static std :: queue <SEND_REQUEST> mess;
@ -66,13 +68,15 @@ static sem_t sem_send;
static bool contextInitialized = false;
void initSending () {
void initSending ()
{
static bool initializedSemaphore = false;
mess = std :: queue <SEND_REQUEST> ();
if (initializedSemaphore) {
if (initializedSemaphore)
{
sem_destroy(& sem_send);
}
@ -82,7 +86,8 @@ void initSending () {
contextInitialized = false;
}
void send (Communicable * __comm, int __to, int __tag) {
void send (Communicable * __comm, int __to, int __tag)
{
SEND_REQUEST req;
req.comm = __comm;
@ -95,23 +100,27 @@ void send (Communicable * __comm, int __to, int __tag) {
wakeUpCommunicator ();
}
void sendToAll (Communicable * __comm, int __tag) {
void sendToAll (Communicable * __comm, int __tag)
{
send (__comm, TO_ALL, __tag);
}
extern void initializeContext ();
void sendMessages () {
void sendMessages ()
{
if (! contextInitialized) {
if (! contextInitialized)
{
contextInitialized = true;
initializeContext();
}
sem_wait (& sem_send);
while (! mess.empty ()) {
while (! mess.empty ())
{
SEND_REQUEST req = mess.front ();
@ -119,7 +128,8 @@ void sendMessages () {
initMessage ();
switch (req.tag) {
switch (req.tag)
{
case RUNNER_STOP_TAG:
dynamic_cast <Runner *> (comm) -> packTermination ();

View file

@ -41,14 +41,16 @@
#include "send.h"
#include "scheduler.h"
void Service :: requestResourceRequest (unsigned __how_many) {
void Service :: requestResourceRequest (unsigned __how_many)
{
num_sent_rr = __how_many;
for (unsigned i = 0; i < __how_many; i ++)
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
}
void Service :: packResourceRequest () {
void Service :: packResourceRequest ()
{
SCHED_REQUEST req;
req.first = getNodeRank ();

View file

@ -50,26 +50,30 @@ extern void wakeUpCommunicator();
extern RANK_ID getRankOfRunner (RUNNER_ID __key);
/* Initializing the list of runners to be synchronized */
void initSynchron () {
void initSynchron ()
{
syncRunners = SYNC();
}
/* packing a synchronization request from a service */
void packSynchronRequest ( const std :: vector <Cooperative *>& coops ) {
void packSynchronRequest ( const std :: vector <Cooperative *>& coops )
{
/* Number of coops to synchronize */
pack( (unsigned)( coops.size() ) );
/* Coops to synchronize */
for (unsigned i = 0; i < coops.size(); i ++) {
for (unsigned i = 0; i < coops.size(); i ++)
{
pack( coops[ i ]->getOwner()->getDefinitionID() );
pack( coops[ i ]->getKey() );
}
}
/* Processing a synchronization request from a service */
void unpackSynchronRequest () {
void unpackSynchronRequest ()
{
unsigned req_num_entries;
unpack (req_num_entries);
@ -79,7 +83,8 @@ void unpackSynchronRequest () {
/* Adding entries for each of the runners to be synchronized */
SyncEntry req_entry;
for (unsigned i = 0; i < req_num_entries; i ++) {
for (unsigned i = 0; i < req_num_entries; i ++)
{
unpack (req_entry.runner);
unpack (req_entry.coop);
@ -91,24 +96,28 @@ void unpackSynchronRequest () {
SYNC::iterator sync_it = syncRunners.find (req_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);
}
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 ++;
/* All the runners to be synchronized sent the SYNC_REQUEST signal */
if (sync_req_entry.second == sync_req_entry.first.size()) {
if (sync_req_entry.second == sync_req_entry.first.size())
{
/* Remove the entry */
syncRunners.erase (sync_it);
/* Send SYNCHRONIZED signals to all the coop objects */
for (unsigned i = 0; i < req_sync.first.size(); i ++) {
for (unsigned i = 0; i < req_sync.first.size(); i ++)
{
initMessage ();

View file

@ -44,31 +44,39 @@
#include "../../core/runner.h"
#include "../../core/cooperative.h"
struct SyncEntry {
struct SyncEntry
{
RUNNER_ID runner;
COOP_ID coop;
};
};
struct SyncCompare {
struct SyncCompare
{
bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B ) {
bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B )
{
const std::vector< SyncEntry >& syncA = A.first;
const std::vector< SyncEntry >& syncB = B.first;
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();
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 syncA.size() < syncB.size();
}
};
};
typedef std::vector< SyncEntry > SYNC_RUNNERS;
typedef std::set< std::pair< SYNC_RUNNERS, unsigned >, SyncCompare > SYNC;

View file

@ -48,12 +48,14 @@ static std :: vector <Worker *> key_to_worker (1); /* Vector of registered worke
extern void wakeUpCommunicator ();
Worker * getWorker (WORKER_ID __key) {
Worker * getWorker (WORKER_ID __key)
{
return key_to_worker [__key];
}
Worker :: Worker () {
Worker :: Worker ()
{
recvAndCompleted = false;
taskAssigned = 0;
@ -63,13 +65,15 @@ Worker :: Worker () {
sem_init( &sem_task_done, 0, 0 );
}
void Worker :: packResult () {
void Worker :: packResult ()
{
pack (serv_id);
serv -> packResult ();
}
void Worker :: unpackData () {
void Worker :: unpackData ()
{
taskAssigned ++;
printDebugMessage ("unpacking the ID. of the service.");
@ -81,46 +85,54 @@ void Worker :: unpackData () {
setActive ();
}
void Worker :: packTaskDone () {
void Worker :: packTaskDone ()
{
pack (getNodeRank ());
pack (id);
}
void Worker :: notifySendingResult () {
void Worker :: notifySendingResult ()
{
/* Notifying the scheduler of the termination */
recvAndCompleted = true;
wakeUp ();
}
void Worker :: notifySendingTaskDone () {
void Worker :: notifySendingTaskDone ()
{
sem_post(&sem_task_done);
setPassive ();
}
void Worker :: setSource (int __rank) {
void Worker :: setSource (int __rank)
{
src = __rank;
}
void Worker :: start () {
void Worker :: start ()
{
while (true) {
while (true)
{
sleep ();
if (! atLeastOneActiveRunner () && ! taskAssigned)
break;
if (recvAndCompleted) {
if (recvAndCompleted)
{
send (this, my_node -> rk_sched, TASK_DONE_TAG);
recvAndCompleted = false;
sem_wait(&sem_task_done);
taskAssigned --;
}
else {
else
{
serv -> execute ();
send (this, src, TASK_RESULT_TAG);
@ -133,7 +145,8 @@ void Worker :: start () {
wakeUpCommunicator();
}
void initWorkersEnv () {
void initWorkersEnv ()
{
key_to_worker.resize (1);
}

View file

@ -44,9 +44,10 @@
typedef unsigned WORKER_ID;
class Worker : public Communicable, public ReactiveThread {
class Worker : public Communicable, public ReactiveThread
{
public :
public :
Worker ();
@ -64,7 +65,7 @@ public :
void setSource (int __rank);
private :
private :
WORKER_ID id;
SERVICE_ID serv_id;
@ -76,7 +77,7 @@ private :
sem_t sem_task_done;
sem_t sem_task_asgn;
};
};
extern void initWorkersEnv ();

View file

@ -40,23 +40,27 @@
static xmlTextReaderPtr reader;
void openXMLDocument (const char * __filename) {
void openXMLDocument (const char * __filename)
{
reader = xmlNewTextReaderFilename (__filename);
if (! reader) {
if (! reader)
{
fprintf (stderr, "unable to open '%s'.\n", __filename);
exit (1);
}
}
void closeXMLDocument () {
void closeXMLDocument ()
{
xmlFreeTextReader (reader);
}
std :: string getAttributeValue (const std :: string & __attr) {
std :: string getAttributeValue (const std :: string & __attr)
{
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
@ -67,7 +71,8 @@ std :: string getAttributeValue (const std :: string & __attr) {
return str;
}
static bool isSep (const xmlChar * __text) {
static bool isSep (const xmlChar * __text)
{
for (unsigned i = 0; i < strlen ((char *) __text); i ++)
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
@ -75,15 +80,18 @@ static bool isSep (const xmlChar * __text) {
return true;
}
std :: string getNextNode () {
std :: string getNextNode ()
{
xmlChar * name, * value;
do {
do
{
xmlTextReaderRead (reader);
name = xmlTextReaderName (reader);
value = xmlTextReaderValue (reader);
} while (! strcmp ((char *) name, "#text") && isSep (value));
}
while (! strcmp ((char *) name, "#text") && isSep (value));
std :: string str;

View file

@ -71,7 +71,7 @@ template < class POT > class eoPrint : public eoContinue <POT>
void peoPSOSeq ()
{
/*
/*
const unsigned int VEC_SIZE = 4;
const unsigned int POP_SIZE = 10;
const unsigned int NEIGHBORHOOD_SIZE= 5;

View file

@ -93,7 +93,7 @@ double peoPSOSeq ()
continuatorSeq.add(fitContSeq);
eoCheckPoint<Indi> checkpointSeq(continuatorSeq);
eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight);
//Sequential
//Sequential
psaSeq (popSeq);
popSeq.sort ();
endSeq=clock();

View file

@ -94,7 +94,7 @@ int main (int __argc, char *__argv[])
peoPSOSelect<Indi> mig_selec(topology);
peoWorstPositionReplacement<Indi> mig_replac;
// Specific implementation (peoData.h)
// Specific implementation (peoData.h)
eoContinuator<Indi> cont(mig_cont, pop);
eoSelector <Indi, peoPop<Indi> > mig_select (mig_selec,1,pop);

View file

@ -92,7 +92,7 @@ int main (int __argc, char * * __argv)
{
pop.sort();
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();
}
@ -108,7 +108,7 @@ int main (int __argc, char * * __argv)
{
std :: cout << "\nResult after the local search\n";
pop.sort();
for(unsigned i=0;i<pop.size();i++)
for (unsigned i=0;i<pop.size();i++)
std::cout<<"\n"<<pop[i].fitness();
}
}

View file

@ -83,7 +83,7 @@ int main (int __argc, char * * __argv)
{
std :: cout << "\nResult before the EA\n";
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\n";
}
@ -106,7 +106,7 @@ int main (int __argc, char * * __argv)
{
std :: cout << "\nResult after the EA\n";
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\n";
}

View file

@ -50,13 +50,14 @@ double f (const Indi & _indi)
template <class EOT>
class eoResizerInit: public eoInit<EOT>
{
{
public:
typedef typename EOT::AtomType AtomType;
eoResizerInit(unsigned _size)
: size(_size){}
: size(_size)
{}
virtual void operator()(EOT& chrom)
{
@ -65,7 +66,7 @@ class eoResizerInit: public eoInit<EOT>
}
private :
unsigned size;
};
};
int main( int __argc, char** __argv )

View file

@ -40,7 +40,6 @@
DisplayBestRoute :: DisplayBestRoute (eoPop <Route> & __pop
) : pop (__pop)
{
}
void DisplayBestRoute :: operator () ()

View file

@ -41,8 +41,7 @@ PartRouteEval :: PartRouteEval (float __from,
float __to
) : from (__from),
to (__to)
{
}
{}
void PartRouteEval :: operator () (Route & __route)
{