git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@810 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
f0b21ecfae
commit
7526792805
49 changed files with 449 additions and 420 deletions
|
|
@ -46,6 +46,7 @@ static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of regist
|
|||
|
||||
unsigned Communicable :: num_comm = 0;
|
||||
|
||||
|
||||
Communicable :: Communicable () {
|
||||
|
||||
comm_to_key [this] = key = ++ num_comm;
|
||||
|
|
@ -70,7 +71,7 @@ Communicable * getCommunicable (COMM_ID __key) {
|
|||
}
|
||||
|
||||
COMM_ID getKey (const Communicable * __comm) {
|
||||
|
||||
|
||||
return comm_to_key [__comm];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ class Communicable {
|
|||
public :
|
||||
|
||||
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 */
|
||||
|
|
@ -67,7 +67,7 @@ protected :
|
|||
COMM_ID key;
|
||||
|
||||
sem_t sem_lock;
|
||||
|
||||
|
||||
sem_t sem_stop;
|
||||
};
|
||||
|
||||
|
|
@ -75,6 +75,4 @@ extern void initCommunicableEnv ();
|
|||
|
||||
extern Communicable * getCommunicable (COMM_ID __key);
|
||||
|
||||
//extern COMM_ID getKey (const Communicable * __comm);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public :
|
|||
void setOwner (Runner & __runner);
|
||||
|
||||
virtual void pack () = 0;
|
||||
|
||||
|
||||
virtual void unpack () = 0;
|
||||
|
||||
void send (Cooperative * __coop);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,14 @@
|
|||
|
||||
template <class F, class T> void pack (const eoVector <F, T> & __v) {
|
||||
|
||||
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 ++)
|
||||
|
|
@ -53,9 +60,16 @@ template <class F, class T> void pack (const eoVector <F, T> & __v) {
|
|||
|
||||
template <class F, class T> void unpack (eoVector <F, T> & __v) {
|
||||
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
unsigned valid; unpack(valid);
|
||||
|
||||
if (! valid) {
|
||||
__v.invalidate();
|
||||
}
|
||||
else {
|
||||
F fit;
|
||||
unpack (fit);
|
||||
__v.fitness (fit);
|
||||
}
|
||||
|
||||
unsigned len;
|
||||
unpack (len);
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ extern void pack (const char * __str);
|
|||
|
||||
/* Pointer */
|
||||
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) {
|
||||
|
||||
|
||||
pack (__pair.first);
|
||||
pack (__pair.second);
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ extern void unpack (char * __str);
|
|||
|
||||
/* Pointer */
|
||||
template <class T> void unpack (T * & __ptr) {
|
||||
|
||||
|
||||
unsigned long p;
|
||||
unpack (p);
|
||||
__ptr = (T *) p;
|
||||
|
|
@ -124,10 +124,9 @@ template <class T> void unpack (T * & __ptr) {
|
|||
|
||||
/* Pair */
|
||||
template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
|
||||
|
||||
|
||||
unpack (__pair.first);
|
||||
unpack (__pair.second);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -50,12 +50,14 @@
|
|||
|
||||
#define DEBUG_PATH "./log/"
|
||||
|
||||
|
||||
static bool debug = true;
|
||||
|
||||
static char host [MAX_BUFF_SIZE];
|
||||
|
||||
std :: vector <FILE *> files;
|
||||
|
||||
|
||||
void setDebugMode (bool __dbg) {
|
||||
|
||||
debug = __dbg;
|
||||
|
|
@ -65,7 +67,7 @@ void setDebugMode (bool __dbg) {
|
|||
extern int getNodeRank ();
|
||||
|
||||
void initDebugging () {
|
||||
|
||||
|
||||
mkdir (DEBUG_PATH, S_IRWXU);
|
||||
// files.push_back (stdout);
|
||||
char buff [MAX_BUFF_SIZE];
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ void peo :: finalize () {
|
|||
printDebugMessage ("waiting for the termination of all threads");
|
||||
|
||||
joinRunners ();
|
||||
|
||||
finalizeRMC ();
|
||||
|
||||
printDebugMessage ("this is the end");
|
||||
|
|
|
|||
|
|
@ -38,11 +38,14 @@
|
|||
|
||||
#include "peo_init.h"
|
||||
#include "peo_param.h"
|
||||
|
||||
#include "peo_debug.h"
|
||||
#include "rmc.h"
|
||||
#include "runner.h"
|
||||
|
||||
|
||||
extern void initCommunicableEnv ();
|
||||
extern void initBuffers ();
|
||||
|
||||
extern void initThreadsEnv ();
|
||||
extern void initReactiveThreadsEnv ();
|
||||
|
|
@ -50,10 +53,14 @@ extern void initReactiveThreadsEnv ();
|
|||
extern void initRunnersEnv ();
|
||||
extern void initWorkersEnv ();
|
||||
|
||||
extern void initScheduler ();
|
||||
|
||||
|
||||
static void initExecutionEnv() {
|
||||
|
||||
initCommunicableEnv ();
|
||||
initBuffers ();
|
||||
initScheduler();
|
||||
|
||||
initThreadsEnv ();
|
||||
initReactiveThreadsEnv ();
|
||||
|
|
@ -62,27 +69,28 @@ static void initExecutionEnv() {
|
|||
initWorkersEnv ();
|
||||
}
|
||||
|
||||
|
||||
namespace peo {
|
||||
|
||||
int * argc;
|
||||
|
||||
|
||||
char * * * argv;
|
||||
|
||||
void init (int & __argc, char * * & __argv) {
|
||||
|
||||
argc = & __argc;
|
||||
|
||||
|
||||
argv = & __argv;
|
||||
|
||||
/* Initializing the execution environment */
|
||||
initExecutionEnv();
|
||||
|
||||
/* Initializing the the Resource Management and Communication */
|
||||
initRMC (__argc, __argv);
|
||||
|
||||
/* Loading the common parameters */
|
||||
loadParameters (__argc, __argv);
|
||||
|
||||
/* Initializing the the Resource Management and Communication */
|
||||
initRMC ( *peo::argc, *peo::argv);
|
||||
|
||||
/* */
|
||||
initDebugging ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@
|
|||
namespace peo {
|
||||
|
||||
extern int * argc;
|
||||
|
||||
|
||||
extern char * * * argv;
|
||||
|
||||
|
||||
extern void init (int & __argc, char * * & __argv);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
#include "peo_debug.h"
|
||||
|
||||
|
||||
|
||||
void peo :: loadParameters (int & __argc, char * * & __argv) {
|
||||
|
||||
eoParser parser (__argc, __argv);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#define __peo_param_h
|
||||
|
||||
namespace peo {
|
||||
|
||||
|
||||
extern void loadParameters (int & __argc, char * * & __argv);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,11 +34,11 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "peo_init.h"
|
||||
#include "peo_run.h"
|
||||
#include "rmc.h"
|
||||
#include "runner.h"
|
||||
|
||||
|
||||
void peo :: run () {
|
||||
|
||||
startRunners ();
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
#define __peo_run_h
|
||||
|
||||
namespace peo {
|
||||
|
||||
|
||||
extern void run ();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ static bool the_end = false;
|
|||
|
||||
static std :: vector <ReactiveThread *> reac_threads;
|
||||
|
||||
|
||||
ReactiveThread :: ReactiveThread () {
|
||||
|
||||
reac_threads.push_back (this);
|
||||
|
|
|
|||
|
|
@ -43,14 +43,14 @@
|
|||
|
||||
|
||||
class ReactiveThread : public Thread {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* Ctor */
|
||||
ReactiveThread ();
|
||||
|
||||
void sleep ();
|
||||
|
||||
|
||||
void wakeUp ();
|
||||
|
||||
private:
|
||||
|
|
@ -62,6 +62,4 @@ extern void initReactiveThreadsEnv ();
|
|||
|
||||
extern void stopReactiveThreads ();
|
||||
|
||||
extern bool theEnd ();
|
||||
|
||||
#endif /*REAC_THREAD_H_*/
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ void RingTopology :: setNeighbors (Cooperative * __mig,
|
|||
__to.clear () ;
|
||||
|
||||
int len = mig.size () ;
|
||||
|
||||
|
||||
for (int i = 0 ; i < len ; i ++)
|
||||
if (mig [i] == __mig) {
|
||||
__from.push_back (mig [(i - 1 + len) % len]) ;
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@
|
|||
#include "topology.h"
|
||||
|
||||
class RingTopology : public Topology {
|
||||
|
||||
|
||||
public :
|
||||
|
||||
|
||||
void setNeighbors (Cooperative * __mig,
|
||||
std :: vector <Cooperative *> & __from,
|
||||
std :: vector <Cooperative *> & __to);
|
||||
|
|
|
|||
|
|
@ -95,50 +95,19 @@ Runner * getRunner (RUNNER_ID __key) {
|
|||
return dynamic_cast <Runner *> (getCommunicable (__key));
|
||||
}
|
||||
|
||||
void packExecutionContext () {
|
||||
|
||||
num_local_exec_runners = 0;
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||
if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++;
|
||||
pack(num_local_exec_runners);
|
||||
}
|
||||
|
||||
void unpackExecutionContext () {
|
||||
|
||||
unsigned num_remote_runners;
|
||||
unpack(num_remote_runners);
|
||||
num_exec_runners += num_remote_runners;
|
||||
}
|
||||
|
||||
void initializeContext () {
|
||||
|
||||
initMessage ();
|
||||
packExecutionContext ();
|
||||
sendMessageToAll (EXECUTION_CONTEXT_TAG);
|
||||
num_local_exec_runners = 0;
|
||||
|
||||
int src, tag;
|
||||
for (unsigned i = 0; i < getNumberOfNodes(); i ++) {
|
||||
|
||||
cleanBuffers ();
|
||||
waitMessage ();
|
||||
|
||||
probeMessage ( src, tag );
|
||||
receiveMessage( src, tag );
|
||||
|
||||
initMessage ();
|
||||
unpackExecutionContext ();
|
||||
// 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 ++;
|
||||
}
|
||||
|
||||
cleanBuffers ();
|
||||
collectiveCountOfRunners( &num_local_exec_runners, &num_exec_runners );
|
||||
|
||||
// setting up the execution IDs
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||
the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] );
|
||||
|
||||
|
||||
// synchronizing - all the nodes have to finish initializing
|
||||
// the context before actually executing the runners
|
||||
synchronizeNodes ();
|
||||
// synchronizeNodes ();
|
||||
|
||||
for (unsigned i = 0; i < the_runners.size (); i ++)
|
||||
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
|
||||
|
|
@ -217,6 +186,7 @@ void unpackTerminationOfRunner () {
|
|||
|
||||
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
|
||||
stopReactiveThreads ();
|
||||
printDebugMessage ("Reactive threads stopped!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ void Service :: setOwner (Thread & __owner) {
|
|||
|
||||
owner = & __owner;
|
||||
}
|
||||
|
||||
|
||||
Thread * Service :: getOwner () {
|
||||
|
||||
return owner;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class Service : public Communicable {
|
|||
public :
|
||||
|
||||
void setOwner (Thread & __owner);
|
||||
|
||||
|
||||
Thread * getOwner ();
|
||||
|
||||
void requestResourceRequest (unsigned __how_many = 1);
|
||||
|
|
@ -58,7 +58,7 @@ public :
|
|||
virtual void unpackData ();
|
||||
|
||||
virtual void execute ();
|
||||
|
||||
|
||||
virtual void packResult ();
|
||||
virtual void unpackResult ();
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,9 @@ static std :: vector <Thread *> threads;
|
|||
|
||||
unsigned num_act = 0;
|
||||
|
||||
|
||||
Thread :: Thread () {
|
||||
|
||||
|
||||
threads.push_back (this);
|
||||
act = false;
|
||||
}
|
||||
|
|
@ -53,8 +54,6 @@ Thread :: ~ Thread () {
|
|||
/* Nothing ! */
|
||||
}
|
||||
|
||||
extern int getNodeRank ();
|
||||
|
||||
void Thread :: setActive () {
|
||||
|
||||
if (! act) {
|
||||
|
|
@ -70,7 +69,7 @@ void Thread :: setPassive () {
|
|||
|
||||
act = false;
|
||||
num_act --;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initThreadsEnv () {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@
|
|||
|
||||
/* A high-level thread */
|
||||
class Thread {
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/* Ctor */
|
||||
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
/* Dtor */
|
||||
virtual ~ Thread ();
|
||||
|
||||
|
||||
/* Go ! */
|
||||
virtual void start () = 0;
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ public:
|
|||
(but it may receive messages) */
|
||||
|
||||
private :
|
||||
|
||||
|
||||
bool act;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -37,12 +37,11 @@
|
|||
#include "topology.h"
|
||||
|
||||
Topology :: ~ Topology () {
|
||||
|
||||
|
||||
/* Nothing ! */
|
||||
}
|
||||
|
||||
void Topology :: add (Cooperative & __mig) {
|
||||
|
||||
mig.push_back (& __mig) ;
|
||||
}
|
||||
|
||||
mig.push_back (& __mig) ;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue