git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@790 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
atantar 2007-11-18 17:00:47 +00:00
commit adb6419766
60 changed files with 1017 additions and 1095 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <eoVector_comm.h> * <eoVector_comm.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -34,43 +34,28 @@
* *
*/ */
#ifndef __eoVector_comm_h #ifndef __eoVector_mesg_h
#define __eoVector_comm_h #define __eoVector_mesg_h
#include <eoVector.h> #include <eoVector.h>
#include "messaging.h" #include "messaging.h"
template <class F, class T> void pack (const eoVector <F, T> & __v) template <class F, class T> void pack (const eoVector <F, T> & __v) {
{
pack (__v.fitness ()) ;
if ( !__v.invalid() )
{
pack( (unsigned int) 1 );
pack (__v.fitness ()) ;
}
else
pack( (unsigned int) 0 );
unsigned len = __v.size (); unsigned len = __v.size ();
pack (len); pack (len);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
pack (__v [i]); pack (__v [i]);
} }
template <class F, class T> void unpack (eoVector <F, T> & __v) template <class F, class T> void unpack (eoVector <F, T> & __v) {
{
F fit;
unpack (fit);
__v.fitness (fit);
F fit;
unsigned int vfit;
unpack( vfit );
if ( vfit )
{
unpack (fit);
__v.fitness (fit);
}
else
__v.invalidate();
unsigned len; unsigned len;
unpack (len); unpack (len);
__v.resize (len); __v.resize (len);
@ -78,23 +63,21 @@ template <class F, class T> void unpack (eoVector <F, T> & __v)
unpack (__v [i]); unpack (__v [i]);
} }
template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) template <class F, class T, class V> void pack (const eoVectorParticle <F, T, V> & __v) {
{
pack (__v.fitness ()) ; pack (__v.fitness ()) ;
pack (__v.best()); pack (__v.best());
unsigned len = __v.size (); unsigned len = __v.size ();
pack (len); pack (len);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
pack (__v [i]); pack (__v [i]);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
pack (__v.bestPositions[i]); pack (__v.bestPositions[i]);
for (unsigned i = 0 ; i < len; 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) {
{
F fit; F fit;
unpack(fit); unpack(fit);
@ -105,11 +88,11 @@ template <class F, class T, class V> void unpack (eoVectorParticle <F, T, V> & _
unpack (len); unpack (len);
__v.resize (len); __v.resize (len);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
unpack (__v [i]); unpack (__v [i]);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
unpack (__v.bestPositions[i]); unpack (__v.bestPositions[i]);
for (unsigned i = 0 ; i < len; i ++) for (unsigned i = 0 ; i < len; i ++)
unpack (__v.velocities[i]); unpack (__v.velocities[i]);
} }
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <messaging.h> * <messaging.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -40,46 +40,44 @@
#include <utility> #include <utility>
/* Char */ /* Char */
extern void pack (const char & __c); extern void pack (const char & __c);
/* Float */ /* Float */
extern void pack (const float & __f, int __nitem = 1); extern void pack (const float & __f, int __nitem = 1);
/* Double */ /* Double */
extern void pack (const double & __d, int __nitem = 1); extern void pack (const double & __d, int __nitem = 1);
/* Integer */ /* Integer */
extern void pack (const int & __i, int __nitem = 1); extern void pack (const int & __i, int __nitem = 1);
/* Unsigned int. */ /* Unsigned int. */
extern void pack (const unsigned int & __ui, int __nitem = 1); extern void pack (const unsigned int & __ui, int __nitem = 1);
/* Short int. */ /* Short int. */
extern void pack (const short & __sh, int __nitem = 1); extern void pack (const short & __sh, int __nitem = 1);
/* Unsigned short */ /* Unsigned short */
extern void pack (const unsigned short & __ush, int __nitem = 1); extern void pack (const unsigned short & __ush, int __nitem = 1);
/* Long */ /* Long */
extern void pack (const long & __l, int __nitem = 1); extern void pack (const long & __l, int __nitem = 1);
/* Unsigned long */ /* Unsigned long */
extern void pack (const unsigned long & __ul, int __nitem = 1); extern void pack (const unsigned long & __ul, int __nitem = 1);
/* String */ /* String */
extern void pack (const char * __str); extern void pack (const char * __str);
/* Pointer */ /* Pointer */
template <class T> void pack (const T * __ptr) template <class T> void pack (const T * __ptr) {
{
pack ((unsigned long) __ptr);
pack ((unsigned long) __ptr);
} }
/* Pair */ /* Pair */
template <class U, class V> void pack (const std :: pair <U, V> & __pair) template <class U, class V> void pack (const std :: pair <U, V> & __pair) {
{
pack (__pair.first); pack (__pair.first);
pack (__pair.second); pack (__pair.second);
} }
@ -88,48 +86,46 @@ template <class U, class V> void pack (const std :: pair <U, V> & __pair)
// //
/* Char */ /* Char */
extern void unpack (char & __c); extern void unpack (char & __c);
/* Float */ /* Float */
extern void unpack (float & __f, int __nitem = 1); extern void unpack (float & __f, int __nitem = 1);
/* Double */ /* Double */
extern void unpack (double & __d, int __nitem = 1); extern void unpack (double & __d, int __nitem = 1);
/* Integer */ /* Integer */
extern void unpack (int & __i, int __nitem = 1); extern void unpack (int & __i, int __nitem = 1);
/* Unsigned int. */ /* Unsigned int. */
extern void unpack (unsigned int & __ui, int __nitem = 1); extern void unpack (unsigned int & __ui, int __nitem = 1);
/* Short int. */ /* Short int. */
extern void unpack (short & __sh, int __nitem = 1); extern void unpack (short & __sh, int __nitem = 1);
/* Unsigned short */ /* Unsigned short */
extern void unpack (unsigned short & __ush, int __nitem = 1); extern void unpack (unsigned short & __ush, int __nitem = 1);
/* Long */ /* Long */
extern void unpack (long & __l, int __nitem = 1); extern void unpack (long & __l, int __nitem = 1);
/* Unsigned long */ /* Unsigned long */
extern void unpack (unsigned long & __ul, int __nitem = 1); extern void unpack (unsigned long & __ul, int __nitem = 1);
/* String */ /* String */
extern void unpack (char * __str); extern void unpack (char * __str);
/* Pointer */ /* Pointer */
template <class T> void unpack (T * & __ptr) template <class T> void unpack (T * & __ptr) {
{
unsigned long p; unsigned long p;
unpack (p); unpack (p);
__ptr = (T *) p; __ptr = (T *) p;
} }
/* Pair */ /* Pair */
template <class U, class V> void unpack (std :: pair <U, V> & __pair) template <class U, class V> void unpack (std :: pair <U, V> & __pair) {
{
unpack (__pair.first); unpack (__pair.first);
unpack (__pair.second); unpack (__pair.second);
} }

View file

@ -1,4 +1,4 @@
/* /*
* <peo_debug.cpp> * <peo_debug.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -56,8 +56,7 @@ static char host [MAX_BUFF_SIZE];
std :: vector <FILE *> files; std :: vector <FILE *> files;
void setDebugMode (bool __dbg) void setDebugMode (bool __dbg) {
{
debug = __dbg; debug = __dbg;
gethostname (host, MAX_BUFF_SIZE); gethostname (host, MAX_BUFF_SIZE);
@ -65,9 +64,8 @@ void setDebugMode (bool __dbg)
extern int getNodeRank (); extern int getNodeRank ();
void initDebugging () void initDebugging () {
{
mkdir (DEBUG_PATH, S_IRWXU); mkdir (DEBUG_PATH, S_IRWXU);
// files.push_back (stdout); // files.push_back (stdout);
char buff [MAX_BUFF_SIZE]; char buff [MAX_BUFF_SIZE];
@ -75,37 +73,33 @@ void initDebugging ()
files.push_back (fopen (buff, "w")); files.push_back (fopen (buff, "w"));
} }
void endDebugging () void endDebugging () {
{
for (unsigned i = 0; i < files.size (); i ++) for (unsigned i = 0; i < files.size (); i ++)
if (files [i] != stdout) if (files [i] != stdout)
fclose (files [i]); fclose (files [i]);
} }
void printDebugMessage (const char * __mess) void printDebugMessage (const char * __mess) {
{ return;
if (debug) {
if (debug) char buff [MAX_BUFF_SIZE];
{ time_t t = time (0);
char buff [MAX_BUFF_SIZE]; /* Date */
time_t t = time (0); sprintf (buff, "[%s][%s: ", host, ctime (& t));
* strchr (buff, '\n') = ']';
for (unsigned i = 0; i < files.size (); i ++)
fprintf (files [i], buff);
/* Date */ /* Message */
sprintf (buff, "[%s][%s: ", host, ctime (& t)); sprintf (buff, "%s", __mess);
* strchr (buff, '\n') = ']';
for (unsigned i = 0; i < files.size (); i ++) for (unsigned i = 0; i < files.size (); i ++) {
fprintf (files [i], buff); fputs (buff, files [i]);
fputs ("\n", files [i]);
/* Message */ fflush (files [i]);
sprintf (buff, "%s", __mess);
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> * <peo_debug.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <peo_init.cpp> * <peo_init.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,26 +41,24 @@
#include "peo_debug.h" #include "peo_debug.h"
#include "rmc.h" #include "rmc.h"
namespace peo namespace peo {
{
int * argc; int * argc;
char * * * argv; char * * * argv;
void init (int & __argc, char * * & __argv) void init (int & __argc, char * * & __argv) {
{
argc = & __argc; argc = & __argc;
argv = & __argv; argv = & __argv;
/* Initializing the the Resource Management and Communication */ /* Initializing the the Resource Management and Communication */
initRMC (__argc, __argv); initRMC (__argc, __argv);
/* Loading the common parameters */ /* Loading the common parameters */
loadParameters (__argc, __argv); loadParameters (__argc, __argv);
/* */ /* */
initDebugging (); initDebugging ();
} }

View file

@ -1,4 +1,4 @@
/* /*
* <peo_init.h> * <peo_init.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -37,13 +37,12 @@
#ifndef __peo_init_h #ifndef __peo_init_h
#define __peo_init_h #define __peo_init_h
namespace peo namespace peo {
{
extern int * argc; extern int * argc;
extern char * * * argv; extern char * * * argv;
extern void init (int & __argc, char * * & __argv); extern void init (int & __argc, char * * & __argv);
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <runner.cpp> * <runner.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,104 +41,163 @@
#include "peo_debug.h" #include "peo_debug.h"
#include "messaging.h" #include "messaging.h"
static unsigned num_act = 0; /* Number of active runners */ #include "../rmc/mpi/mess.h"
#include "../rmc/mpi/tags.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; static std :: vector <Runner *> the_runners;
static unsigned num_runners = 0; static unsigned num_def_runners = 0; /* Number of defined runners */
Runner :: Runner () static unsigned num_local_exec_runners = 0; /* Number of locally executing runners */
{
static unsigned num_exec_runners = 0; /* Number of globally executing runners */
id = ++ num_runners;
the_runners.push_back (this);
sem_init (& sem_start, 0, 0);
num_act ++;
}
extern int getNodeRank (); extern int getNodeRank ();
extern int getNumberOfNodes (); extern int getNumberOfNodes ();
void unpackTerminationOfRunner ()
{
RUNNER_ID id; Runner :: Runner () {
unpack (id);
num_act --; def_id = ++ num_def_runners;
printDebugMessage ("I'm noticed of the termination of a runner"); the_runners.push_back (this);
if (! num_act) sem_init (& sem_start, 0, 0);
{ sem_init (& sem_cntxt, 0, 0);
printDebugMessage ("all the runners have terminated. Now stopping the reactive threads.");
stopReactiveThreads ();
}
} }
bool atLeastOneActiveRunner () RUNNER_ID Runner :: getDefinitionID () {
{
return num_act; return def_id;
} }
RUNNER_ID Runner :: getID () RUNNER_ID Runner :: getExecutionID () {
{
return id; return def_id;
} }
void Runner :: start () Runner * getRunner (RUNNER_ID __key) {
{
setActive ();
sem_post (& sem_start);
run ();
terminate ();
}
void Runner :: notifySendingTermination ()
{
/*
char b [1000];
sprintf (b, "Il reste encore %d !!!!!!!!!!!!", n);
printDebugMessage (b);
*/
printDebugMessage ("je suis informe que tout le monde a recu ma terminaison");
setPassive ();
}
void Runner :: waitStarting ()
{
sem_wait (& sem_start);
}
Runner * getRunner (RUNNER_ID __key)
{
return dynamic_cast <Runner *> (getCommunicable (__key)); return dynamic_cast <Runner *> (getCommunicable (__key));
} }
void startRunners () 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);
int src, tag;
for (unsigned i = 0; i < getNumberOfNodes(); i ++) {
cleanBuffers ();
waitMessage ();
probeMessage ( src, tag );
receiveMessage( src, tag );
initMessage ();
unpackExecutionContext ();
}
cleanBuffers ();
synchronizeNodes ();
for (unsigned i = 0; i < the_runners.size (); i ++)
if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized ();
}
void Runner :: waitStarting () {
sem_wait (& sem_start);
}
void Runner :: waitContextInitialization () {
sem_wait (& sem_cntxt);
}
void Runner :: start () {
setActive ();
sem_post (& sem_start);
waitContextInitialization ();
run ();
terminate ();
}
void startRunners () {
/* Runners */ /* Runners */
for (unsigned i = 0; i < the_runners.size (); i ++) for (unsigned i = 0; i < the_runners.size (); i ++)
if (the_runners [i] -> isLocal ()) if (the_runners [i] -> isAssignedLocally ()) {
{ addThread (the_runners [i], ll_threads);
addThread (the_runners [i], ll_threads); the_runners [i] -> waitStarting ();
the_runners [i] -> waitStarting (); }
}
printDebugMessage ("launched the parallel runners"); printDebugMessage ("launched the parallel runners");
} }
void joinRunners () {
void joinRunners ()
{
joinThreads (ll_threads); joinThreads (ll_threads);
} }
bool atLeastOneActiveRunner () {
return num_exec_runners;
}
unsigned numberOfActiveRunners () {
return num_exec_runners;
}
void Runner :: notifyContextInitialized () {
sem_post (& sem_cntxt);
}
void Runner :: notifySendingTermination () {
printDebugMessage ("I am informed that everyone received my termination notification.");
setPassive ();
}
void unpackTerminationOfRunner () {
RUNNER_ID finished_id;
unpack (finished_id);
num_exec_runners --;
printDebugMessage ("I'm noticed of the termination of a runner");
if (!num_exec_runners) {
printDebugMessage ("All the runners have terminated - now stopping the reactive threads.");
stopReactiveThreads ();
}
}

View file

@ -1,4 +1,4 @@
/* /*
* <runner.h> * <runner.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -42,46 +42,60 @@
#include "communicable.h" #include "communicable.h"
#include "thread.h" #include "thread.h"
typedef unsigned RUNNER_ID; typedef unsigned RUNNER_ID;
class Runner : public Communicable, public Thread
{
public : class Runner : public Communicable, public Thread {
Runner (); public :
void start (); Runner ();
void waitStarting (); RUNNER_ID getDefinitionID ();
bool isLocal (); RUNNER_ID getExecutionID ();
void terminate (); bool isAssignedLocally ();
virtual void run () = 0; void waitStarting ();
RUNNER_ID getID (); void waitContextInitialization ();
void packTermination (); void start ();
void notifySendingTermination (); virtual void run () = 0;
private : void terminate ();
sem_t sem_start; void notifyContextInitialized ();
unsigned id; void notifySendingTermination ();
};
extern bool atLeastOneActiveRunner (); void packTermination ();
extern void unpackTerminationOfRunner (); private :
extern Runner * getRunner (RUNNER_ID __key); sem_t sem_start;
sem_t sem_cntxt;
unsigned def_id;
};
extern Runner * getRunner (RUNNER_ID __key);
extern void initializeContext ();
extern void startRunners (); extern void startRunners ();
extern void joinRunners (); extern void joinRunners ();
extern bool atLeastOneActiveRunner ();
extern unsigned numberOfActiveRunners ();
extern void unpackTerminationOfRunner ();
#endif #endif

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <thread.cpp> * <thread.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -42,79 +42,59 @@ static std :: vector <Thread *> threads;
unsigned num_act = 0; unsigned num_act = 0;
Thread :: Thread () Thread :: Thread () {
{
threads.push_back (this); threads.push_back (this);
act = false; act = false;
} }
Thread :: ~ Thread () Thread :: ~ Thread () {
{
/* Nothing ! */ /* Nothing ! */
} }
extern int getNodeRank (); extern int getNodeRank ();
void Thread :: setActive () void Thread :: setActive () {
{
if (! act ) if (! act) {
{
act = true; act = true;
num_act ++; num_act ++;
// if (getNodeRank () == 1) }
// printf ("On passe a %d\n", num_act);
}
} }
void Thread :: setPassive () void Thread :: setPassive () {
{
if (act) if (act) {
{
act = false; act = false;
num_act --; num_act --;
// if (getNodeRank () == 1) }
// printf ("On passe a %d\n", num_act);
}
} }
bool atLeastOneActiveThread () bool atLeastOneActiveThread () {
{
return num_act; return num_act;
} }
unsigned numberOfActiveThreads () static void * launch (void * __arg) {
{
return num_act; Thread * thr = (Thread *) __arg;
}
static void * launch (void * __arg)
{
Thread * thr = (Thread *) __arg;
thr -> start (); thr -> start ();
return 0; return 0;
} }
void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads) {
{
pthread_t * ll_thr = new pthread_t; pthread_t * ll_thr = new pthread_t;
__ll_threads.push_back (ll_thr); __ll_threads.push_back (ll_thr);
pthread_create (ll_thr, 0, launch, __hl_thread); pthread_create (ll_thr, 0, launch, __hl_thread);
} }
void joinThreads (std :: vector <pthread_t *> & __threads) void joinThreads (std :: vector <pthread_t *> & __threads) {
{
for (unsigned i = 0; i < __threads.size (); i ++) for (unsigned i = 0; i < __threads.size (); i ++)
pthread_join (* __threads [i], 0); pthread_join (* __threads [i], 0);
} }

View file

@ -1,4 +1,4 @@
/* /*
* <thread.h> * <thread.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,28 +41,27 @@
/* A high-level thread */ /* A high-level thread */
class Thread class Thread {
{
public:
public: /* Ctor */
Thread ();
/* Ctor */ /* Dtor */
Thread (); virtual ~ Thread ();
/* Go ! */
virtual void start () = 0;
/* Dtor */ void setActive ();/* It means the current process is going to send messages soon */
virtual ~ Thread (); void setPassive ();/* The current process is not going to perform send operations
(but it may receive messages) */
/* Go ! */ private :
virtual void start () = 0;
bool act;
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 :
bool act;
};
extern void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads); extern void addThread (Thread * __hl_thread, std :: vector <pthread_t *> & __ll_threads);
@ -71,7 +70,4 @@ extern void joinThreads (std :: vector <pthread_t *> & __ll_threads);
extern bool atLeastOneActiveThread (); /* It returns 'true' iff at least one process is going extern bool atLeastOneActiveThread (); /* It returns 'true' iff at least one process is going
to send messages */ to send messages */
extern unsigned numberOfActiveThreads ();
#endif /*THREAD_H_*/ #endif /*THREAD_H_*/

View file

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

View file

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

View file

@ -315,17 +315,19 @@
//! //!
//!ParadisEO WebSite : http://paradiseo.gforge.inria.fr //!ParadisEO WebSite : http://paradiseo.gforge.inria.fr
//!Contact: paradiseo-help@lists.gforge.inria.fr //!Contact: paradiseo-help@lists.gforge.inria.fr
//!
#include "core/peo_init.h" #include "core/peo_init.h"
#include "core/peo_run.h" #include "core/peo_run.h"
#include "core/peo_fin.h" #include "core/peo_fin.h"
#include "core/eoVector_comm.h" #include "core/messaging.h"
#include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h"
#include "peoEA.h" #include "peoEA.h"
#include "peoParallelAlgorithmWrapper.h"
/* Parallel steps of the E.A. */ /* <------- components for parallel algorithms -------> */
#include "peoSeqTransform.h" #include "peoSeqTransform.h"
#include "peoParaSGATransform.h" #include "peoParaSGATransform.h"
#include "peoSeqPopEval.h" #include "peoSeqPopEval.h"
@ -334,13 +336,13 @@
/* Cooperative island model */ /* Cooperative island model */
#include "core/ring_topo.h" #include "core/ring_topo.h"
#include "peoAsyncIslandMig.h"
#include "peoSyncIslandMig.h" #include "peoSyncIslandMig.h"
#include "peoAsyncIslandMig.h"
/* Synchronous multi-start model */ /* Synchronous multi-start model */
#include "peoSyncMultiStart.h" #include "peoSyncMultiStart.h"
#include "peoParallelAlgorithmWrapper.h"
#include "peoSynchronousMultiStart.h" #include "peoSynchronousMultiStart.h"
/* <------- components for parallel algorithms -------> */
/* Parallel PSO */ /* Parallel PSO */
#include "peoInitializer.h" #include "peoInitializer.h"

View file

@ -47,9 +47,13 @@
#include <eoReplacement.h> #include <eoReplacement.h>
#include <eoPop.h> #include <eoPop.h>
#include "core/messaging.h"
#include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h"
#include "core/topology.h" #include "core/topology.h"
#include "core/thread.h"
#include "core/cooperative.h" #include "core/cooperative.h"
#include "core/eoPop_comm.h"
#include "core/peo_debug.h" #include "core/peo_debug.h"
@ -217,13 +221,12 @@ template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
{ {
lock (); lock ();
{
:: pack( coop_em.front()->getKey() ); ::pack( coop_em.front()->getKey() );
:: pack( em.front() ); ::pack( em.front() );
coop_em.pop(); coop_em.pop();
em.pop(); em.pop();
}
unlock(); unlock();
} }
@ -232,12 +235,11 @@ template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
{ {
lock (); lock ();
{
eoPop< EOT > mig; eoPop< EOT > mig;
:: unpack( mig ); ::unpack( mig );
imm.push( mig ); imm.push( mig );
}
unlock(); unlock();
} }

View file

@ -111,8 +111,8 @@ template< class EOT > void peoParaSGATransform< EOT > :: packData()
{ {
pack( idx ); pack( idx );
:: pack( pop->operator[]( idx++ ) ); pack( pop->operator[]( idx++ ) );
:: pack( pop->operator[]( idx++ ) ); pack( pop->operator[]( idx++ ) );
} }
@ -120,8 +120,8 @@ template< class EOT > void peoParaSGATransform< EOT > :: unpackData()
{ {
unpack( idx ); unpack( idx );
:: unpack( father ); unpack( father );
:: unpack( mother ); unpack( mother );
} }
@ -139,8 +139,8 @@ template< class EOT > void peoParaSGATransform< EOT > :: packResult()
{ {
pack( idx ); pack( idx );
:: pack( father ); pack( father );
:: pack( mother ); pack( mother );
} }
@ -150,10 +150,11 @@ template< class EOT > void peoParaSGATransform< EOT > :: unpackResult()
unsigned sidx; unsigned sidx;
unpack( sidx ); unpack( sidx );
:: unpack( pop->operator[]( sidx++ ) ); unpack( pop->operator[]( sidx++ ) );
:: unpack( pop->operator[]( sidx ) ); unpack( pop->operator[]( sidx ) );
num_term += 2; num_term += 2;
// Can be used with a odd size
// Can be used with an odd size
if ( num_term == 2*(pop->size()/2) ) if ( num_term == 2*(pop->size()/2) )
{ {

View file

@ -50,9 +50,13 @@
#include <eoReplacement.h> #include <eoReplacement.h>
#include <eoPop.h> #include <eoPop.h>
#include "core/messaging.h"
#include "core/eoPop_mesg.h"
#include "core/eoVector_mesg.h"
#include "core/topology.h" #include "core/topology.h"
#include "core/thread.h" #include "core/thread.h"
#include "core/eoPop_comm.h" #include "core/cooperative.h"
#include "core/peo_debug.h" #include "core/peo_debug.h"
@ -225,13 +229,12 @@ template< class EOT > void peoSyncIslandMig< EOT > :: pack()
{ {
lock (); lock ();
{
:: pack( coop_em.front()->getKey() ); pack( coop_em.front()->getKey() );
:: pack( em.front() ); pack( em.front() );
coop_em.pop(); coop_em.pop();
em.pop(); em.pop();
}
unlock(); unlock();
} }
@ -240,12 +243,11 @@ template< class EOT > void peoSyncIslandMig< EOT > :: unpack()
{ {
lock (); lock ();
{
eoPop< EOT > mig; eoPop< EOT > mig;
:: unpack( mig ); unpack( mig );
imm.push( mig ); imm.push( mig );
}
unlock(); unlock();
sem_post( &sync ); sem_post( &sync );

View file

@ -147,7 +147,7 @@ template< class EOT > peoSyncMultiStart< EOT > :: peoSyncMultiStart(
template< class EOT > void peoSyncMultiStart< EOT > :: packData() template< class EOT > void peoSyncMultiStart< EOT > :: packData()
{ {
:: pack( sel[ idx++ ] ); pack( sel[ idx++ ] );
} }

View file

@ -232,9 +232,9 @@ template < typename EntityType > class peoSynchronousMultiStart : public Service
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData() template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packData()
{ {
::pack( functionIndex ); pack( functionIndex );
::pack( idx ); pack( idx );
::pack( ( EntityType& ) *data[ idx++ ] ); pack( ( EntityType& ) *data[ idx++ ] );
// done with functionIndex for the entire data set - moving to another // done with functionIndex for the entire data set - moving to another
// function/algorithm starting all over with the entire data set ( idx is set to 0 ) // function/algorithm starting all over with the entire data set ( idx is set to 0 )
@ -249,9 +249,9 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::pa
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData() template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackData()
{ {
::unpack( functionIndex ); unpack( functionIndex );
::unpack( dataIndex ); unpack( dataIndex );
::unpack( entityTypeInstance ); unpack( entityTypeInstance );
} }
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute() template < typename EntityType > void peoSynchronousMultiStart< EntityType >::execute()
@ -268,15 +268,15 @@ template < typename EntityType > void peoSynchronousMultiStart< EntityType >::ex
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult() template < typename EntityType > void peoSynchronousMultiStart< EntityType >::packResult()
{ {
::pack( dataIndex ); pack( dataIndex );
::pack( entityTypeInstance ); pack( entityTypeInstance );
} }
template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult() template < typename EntityType > void peoSynchronousMultiStart< EntityType >::unpackResult()
{ {
::unpack( dataIndex ); unpack( dataIndex );
::unpack( entityTypeInstance ); unpack( entityTypeInstance );
// wrapping the unpacked data - the definition of an abstract algorithm imposes // wrapping the unpacked data - the definition of an abstract algorithm imposes
// that its internal function operator acts only on abstract data types // that its internal function operator acts only on abstract data types

View file

@ -1,4 +1,4 @@
/* /*
* <comm.cpp> * <comm.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -51,48 +51,45 @@ static sem_t sem_comm_init;
static Communicator * the_thread; static Communicator * the_thread;
Communicator :: Communicator (int * __argc, char * * * __argv) Communicator :: Communicator (int * __argc, char * * * __argv) {
{
the_thread = this; the_thread = this;
initNode (__argc, __argv); initNode (__argc, __argv);
loadRMCParameters (* __argc, * __argv); loadRMCParameters (* __argc, * __argv);
sem_post (& sem_comm_init); sem_post (& sem_comm_init);
} }
void Communicator :: start () void Communicator :: start () {
{
while (true) while (true) {
{
/* Zzz Zzz Zzz :-))) */ /* Zzz Zzz Zzz :-))) */
sleep (); sleep ();
sendMessages ();
if (! atLeastOneActiveRunner ()) sendMessages ();
break;
receiveMessages (); if (! atLeastOneActiveRunner ())
} break;
waitBuffers ();
receiveMessages ();
}
waitBuffers ();
printDebugMessage ("finalizing"); printDebugMessage ("finalizing");
MPI_Finalize (); MPI_Finalize ();
} }
void initCommunication () void initCommunication () {
{
sem_init (& sem_comm_init, 0, 0); sem_init (& sem_comm_init, 0, 0);
} }
void waitNodeInitialization () void waitNodeInitialization () {
{
sem_wait (& sem_comm_init); sem_wait (& sem_comm_init);
} }
void wakeUpCommunicator () void wakeUpCommunicator () {
{
the_thread -> wakeUp (); the_thread -> wakeUp ();
} }

View file

@ -1,4 +1,4 @@
/* /*
* <comm.h> * <comm.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -40,16 +40,15 @@
#include "../../core/communicable.h" #include "../../core/communicable.h"
#include "../../core/reac_thread.h" #include "../../core/reac_thread.h"
class Communicator : public ReactiveThread class Communicator : public ReactiveThread {
{
public : public :
/* Ctor */
Communicator (int * __argc, char * * * __argv);
/* Ctor */ void start ();
Communicator (int * __argc, char * * * __argv); };
void start ();
};
extern void initCommunication (); extern void initCommunication ();

View file

@ -1,4 +1,4 @@
/* /*
* <coop.cpp> * <coop.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,35 +41,29 @@
#include "mess.h" #include "mess.h"
#include "../../core/peo_debug.h" #include "../../core/peo_debug.h"
Runner * Cooperative :: getOwner () Runner * Cooperative :: getOwner () {
{
return owner; return owner;
} }
void Cooperative :: setOwner (Runner & __runner) void Cooperative :: setOwner (Runner & __runner) {
{
owner = & __runner; owner = & __runner;
} }
void Cooperative :: send (Cooperative * __coop) void Cooperative :: send (Cooperative * __coop) {
{
:: send (this, getRankOfRunner (__coop -> getOwner () -> getID ()), COOP_TAG); :: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG);
// stop (); // stop ();
} }
Cooperative * getCooperative (COOP_ID __key) Cooperative * getCooperative (COOP_ID __key) {
{
return dynamic_cast <Cooperative *> (getCommunicable (__key)); return dynamic_cast <Cooperative *> (getCommunicable (__key));
} }
void Cooperative :: notifySending () void Cooperative :: notifySending () {
{
//getOwner -> setPassive (); //getOwner -> setPassive ();
// resume (); // resume ();
// printDebugMessage (b);
} }

View file

@ -1,4 +1,4 @@
/* /*
* <mess.cpp> * <mess.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -42,60 +42,54 @@
#include "node.h" #include "node.h"
#define MPI_BUF_SIZE 1024*64 #define MPI_BUF_SIZE 1024*64
static char mpi_buf [MPI_BUF_SIZE]; static char mpi_buf [MPI_BUF_SIZE];
static int pos_buf ; static int pos_buf ;
static std :: vector <char *> act_buf; /* Active buffers */ static std :: vector <char *> act_buf; /* Active buffers */
static std :: vector <MPI_Request *> act_req; /* Active requests */ static std :: vector <MPI_Request *> act_req; /* Active requests */
void cleanBuffers () void cleanBuffers () {
{
for (unsigned i = 0; i < act_req.size ();) for (unsigned i = 0; i < act_req.size ();) {
{
MPI_Status stat ;
MPI_Status stat ; int flag ;
int flag ; MPI_Test (act_req [i], & flag, & stat) ;
MPI_Test (act_req [i], & flag, & stat) ; if (flag) {
if (flag)
{ delete[] act_buf [i] ;
delete act_req [i] ;
delete act_buf [i] ;
delete act_req [i] ; act_buf [i] = act_buf.back () ;
act_buf.pop_back () ;
act_buf [i] = act_buf.back () ;
act_buf.pop_back () ; act_req [i] = act_req.back () ;
act_req.pop_back () ;
act_req [i] = act_req.back () ;
act_req.pop_back () ;
}
else
i ++;
} }
else
i ++;
}
} }
void waitBuffers () void waitBuffers () {
{
printDebugMessage ("waiting the termination of the asynchronous operations to complete"); printDebugMessage ("waiting the termination of the asynchronous operations to complete");
for (unsigned i = 0; i < act_req.size (); i ++) for (unsigned i = 0; i < act_req.size (); i ++) {
{
MPI_Status stat ;
MPI_Status stat ; MPI_Wait (act_req [i], & stat) ;
MPI_Wait (act_req [i], & stat) ; delete[] act_buf [i] ;
delete act_req [i] ;
delete act_buf [i] ; }
delete act_req [i] ;
}
} }
bool probeMessage (int & __src, int & __tag) bool probeMessage (int & __src, int & __tag) {
{
int flag; int flag;
@ -109,188 +103,168 @@ bool probeMessage (int & __src, int & __tag)
return flag; return flag;
} }
void waitMessage () void waitMessage () {
{
MPI_Status stat; MPI_Status stat;
MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat); MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat);
} }
void initMessage () void initMessage () {
{
pos_buf = 0; pos_buf = 0;
} }
void sendMessage (int __to, int __tag) void sendMessage (int __to, int __tag) {
{
cleanBuffers (); cleanBuffers ();
act_buf.push_back (new char [pos_buf]); act_buf.push_back (new char [pos_buf]);
act_req.push_back (new MPI_Request); act_req.push_back (new MPI_Request);
memcpy (act_buf.back (), mpi_buf, pos_buf); memcpy (act_buf.back (), mpi_buf, pos_buf);
MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ()); MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ());
} }
void sendMessageToAll (int __tag) void sendMessageToAll (int __tag) {
{
for (int i = 0; i < getNumberOfNodes (); i ++) for (int i = 0; i < getNumberOfNodes (); i ++)
sendMessage (i, __tag); sendMessage (i, __tag);
} }
void receiveMessage (int __from, int __tag) void receiveMessage (int __from, int __tag) {
{
MPI_Status stat;
MPI_Status stat;
MPI_Request req; MPI_Request req;
MPI_Irecv (mpi_buf, MPI_BUF_SIZE, MPI_PACKED, __from, __tag, MPI_COMM_WORLD, & req) ; MPI_Irecv (mpi_buf, MPI_BUF_SIZE, MPI_PACKED, __from, __tag, MPI_COMM_WORLD, & req);
MPI_Wait (& req, & stat) ; MPI_Wait (& req, & stat);
}
void synchronizeNodes () {
MPI_Barrier ( MPI_COMM_WORLD );
} }
/* Char */ /* Char */
void pack (const char & __c) void pack (const char & __c) {
{
MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Float */ /* Float */
void pack (const float & __f, int __nitem) void pack (const float & __f, int __nitem) {
{
MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Double */ /* Double */
void pack (const double & __d, int __nitem) void pack (const double & __d, int __nitem) {
{
MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Integer */ /* Integer */
void pack (const int & __i, int __nitem) void pack (const int & __i, int __nitem) {
{
MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Unsigned int. */ /* Unsigned int. */
void pack (const unsigned int & __ui, int __nitem) void pack (const unsigned int & __ui, int __nitem) {
{
MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Short int. */ /* Short int. */
void pack (const short & __sh, int __nitem) void pack (const short & __sh, int __nitem) {
{
MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Unsigned short */ /* Unsigned short */
void pack (const unsigned short & __ush, int __nitem) void pack (const unsigned short & __ush, int __nitem) {
{
MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Long */ /* Long */
void pack (const long & __l, int __nitem) void pack (const long & __l, int __nitem) {
{
MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Unsigned long */ /* Unsigned long */
void pack (const unsigned long & __ul, int __nitem) void pack (const unsigned long & __ul, int __nitem) {
{
MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* String */ /* String */
void pack (const char * __str) void pack (const char * __str) {
{
int len = strlen (__str) + 1; int len = strlen (__str) + 1;
MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD);
} }
/* Char */ /* Char */
void unpack (char & __c) void unpack (char & __c) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD);
} }
/* Float */ /* Float */
void unpack (float & __f, int __nitem) void unpack (float & __f, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD);
} }
/* Double */ /* Double */
void unpack (double & __d, int __nitem) void unpack (double & __d, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD);
} }
/* Integer */ /* Integer */
void unpack (int & __i, int __nitem) void unpack (int & __i, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD);
} }
/* Unsigned int. */ /* Unsigned int. */
void unpack (unsigned int & __ui, int __nitem) void unpack (unsigned int & __ui, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD);
} }
/* Short int. */ /* Short int. */
void unpack (short & __sh, int __nitem) void unpack (short & __sh, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD);
} }
/* Unsigned short */ /* Unsigned short */
void unpack (unsigned short & __ush, int __nitem) void unpack (unsigned short & __ush, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD);
} }
/* Long */ /* Long */
void unpack (long & __l, int __nitem) void unpack (long & __l, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD);
} }
/* Unsigned long */ /* Unsigned long */
void unpack (unsigned long & __ul, int __nitem) void unpack (unsigned long & __ul, int __nitem) {
{
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
} }
/* String */ /* String */
void unpack (char * __str) void unpack (char * __str) {
{
int len; int len;
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD);
MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD);
} }

View file

@ -1,4 +1,4 @@
/* /*
* <mess.h> * <mess.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -55,5 +55,7 @@ extern bool probeMessage (int & __src, int & __tag);
extern void waitMessage (); extern void waitMessage ();
extern void synchronizeNodes ();
#endif #endif

View file

@ -1,4 +1,4 @@
/* /*
* <node.cpp> * <node.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,46 +46,41 @@ static std :: map <std :: string, int> name_to_rk;
static std :: vector <std :: string> rk_to_name; static std :: vector <std :: string> rk_to_name;
int getNodeRank () int getNodeRank () {
{
return rk; return rk;
} }
int getNumberOfNodes () int getNumberOfNodes () {
{
return sz; return sz;
} }
int getRankFromName (const std :: string & __name) int getRankFromName (const std :: string & __name) {
{
return atoi (__name.c_str ());
return atoi (__name.c_str ());
} }
void initNode (int * __argc, char * * * __argv) void initNode (int * __argc, char * * * __argv) {
{
int provided; int provided;
MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided); MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided);
assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded. assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded.
Yet, only one thread performs the comm. Yet, only one thread performs the comm.
operations */ operations */
MPI_Comm_rank (MPI_COMM_WORLD, & rk); /* Who ? */ MPI_Comm_rank (MPI_COMM_WORLD, & rk); /* Who ? */
MPI_Comm_size (MPI_COMM_WORLD, & sz); /* How many ? */ MPI_Comm_size (MPI_COMM_WORLD, & sz); /* How many ? */
char names [sz] [MPI_MAX_PROCESSOR_NAME]; char names [sz] [MPI_MAX_PROCESSOR_NAME];
int len; int len;
/* Processor names */ /* Processor names */
MPI_Get_processor_name (names [0], & len); /* Me */ MPI_Get_processor_name (names [0], & len); /* Me */
MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */ MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */
for (int i = 0; i < sz; i ++) for (int i = 0; i < sz; i ++) {
{ rk_to_name.push_back (names [i]);
rk_to_name.push_back (names [i]); name_to_rk [names [i]] = i;
name_to_rk [names [i]] = i; }
}
} }

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <recv.cpp> * <recv.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -44,103 +44,93 @@
#include "../../core/cooperative.h" #include "../../core/cooperative.h"
#include "../../core/peo_debug.h" #include "../../core/peo_debug.h"
void receiveMessages ()
{ void receiveMessages () {
cleanBuffers (); cleanBuffers ();
do do {
{
if (! atLeastOneActiveThread ()) if (! atLeastOneActiveThread ()) {
{
// printDebugMessage ("debut wait");
waitMessage ();
//printDebugMessage ("fin wait");
}
int src, tag;
while (probeMessage (src, tag))
{
receiveMessage (src, tag);
initMessage ();
/*
char b [1000];
sprintf (b, "traitement recv %d\n", tag);
printDebugMessage (b);
*/
switch (tag)
{
case RUNNER_STOP_TAG:
unpackTerminationOfRunner ();
wakeUpCommunicator ();
break;
case COOP_TAG:
// printDebugMessage ("reception de message de cooperation");
COOP_ID coop_id;
unpack (coop_id);
getCooperative (coop_id) -> unpack ();
break;
case SCHED_REQUEST_TAG:
unpackResourceRequest ();
break;
case SCHED_RESULT_TAG:
{
/* Unpacking the resource */
SERVICE_ID serv_id;
unpack (serv_id);
Service * serv = getService (serv_id);
int dest;
unpack (dest);
WORKER_ID worker_id;
unpack (worker_id);
/* Going back ... */
initMessage ();
pack (worker_id);
pack (serv_id);
serv -> packData ();
serv -> notifySendingData ();
sendMessage (dest, TASK_DATA_TAG);
break;
}
case TASK_DATA_TAG:
{
WORKER_ID worker_id;
unpack (worker_id);
Worker * worker = getWorker (worker_id);
worker -> setSource (src);
worker -> unpackData ();
worker -> wakeUp ();
break;
}
case TASK_RESULT_TAG:
{
SERVICE_ID serv_id;
unpack (serv_id);
Service * serv = getService (serv_id);
serv -> unpackResult ();
break;
}
case TASK_DONE_TAG:
unpackTaskDone ();
break;
default:
;
};
}
waitMessage ();
} }
while (! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/);
int src, tag;
while (probeMessage (src, tag)) {
receiveMessage (src, tag);
initMessage ();
switch (tag) {
case RUNNER_STOP_TAG:
unpackTerminationOfRunner ();
wakeUpCommunicator ();
break;
case COOP_TAG:
COOP_ID coop_id;
unpack (coop_id);
getCooperative (coop_id) -> unpack ();
break;
case SCHED_REQUEST_TAG:
unpackResourceRequest ();
break;
case SCHED_RESULT_TAG:
{
/* Unpacking the resource */
SERVICE_ID serv_id;
unpack (serv_id);
Service * serv = getService (serv_id);
int dest;
unpack (dest);
WORKER_ID worker_id;
unpack (worker_id);
/* Going back ... */
initMessage ();
pack (worker_id);
pack (serv_id);
serv -> packData ();
serv -> notifySendingData ();
sendMessage (dest, TASK_DATA_TAG);
break;
}
case TASK_DATA_TAG:
{
WORKER_ID worker_id;
unpack (worker_id);
Worker * worker = getWorker (worker_id);
worker -> setSource (src);
worker -> unpackData ();
worker -> wakeUp ();
break;
}
case TASK_RESULT_TAG:
{
SERVICE_ID serv_id;
unpack (serv_id);
Service * serv = getService (serv_id);
serv -> unpackResult ();
break;
}
case TASK_DONE_TAG:
unpackTaskDone ();
break;
default:
;
};
}
} while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/);
cleanBuffers ();
} }

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <rmc.cpp> * <rmc.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -43,18 +43,16 @@
static std :: vector <pthread_t *> ll_threads; /* Low level threads */ static std :: vector <pthread_t *> ll_threads; /* Low level threads */
void runRMC () void runRMC () {
{
/* Worker(s) ? */ /* Worker(s) ? */
for (unsigned i = 0; i < my_node -> num_workers; i ++) for (unsigned i = 0; i < my_node -> num_workers; i ++)
addThread (new Worker, ll_threads); addThread (new Worker, ll_threads);
wakeUpCommunicator (); wakeUpCommunicator ();
} }
void initRMC (int & __argc, char * * & __argv) void initRMC (int & __argc, char * * & __argv) {
{
/* Communication */ /* Communication */
initCommunication (); initCommunication ();
@ -69,8 +67,7 @@ void initRMC (int & __argc, char * * & __argv)
/// ///
} }
void finalizeRMC () void finalizeRMC () {
{
printDebugMessage ("before join threads RMC"); printDebugMessage ("before join threads RMC");
joinThreads (ll_threads); joinThreads (ll_threads);

View file

@ -1,4 +1,4 @@
/* /*
* <runner.cpp> * <runner.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -37,28 +37,26 @@
#include "../../core/messaging.h" #include "../../core/messaging.h"
#include "../../core/runner.h" #include "../../core/runner.h"
#include "node.h" #include "node.h"
#include "mess.h"
#include "send.h" #include "send.h"
#include "tags.h" #include "tags.h"
#include "schema.h" #include "schema.h"
bool Runner :: isLocal ()
{ bool Runner :: isAssignedLocally () {
for (unsigned i = 0; i < my_node -> id_run.size (); i ++) for (unsigned i = 0; i < my_node -> id_run.size (); i ++)
if (my_node -> id_run [i] == id) if (my_node -> id_run [i] == def_id)
return true; return true;
return false; return false;
} }
void Runner :: packTermination () void Runner :: terminate () {
{
pack (id);
}
void Runner :: terminate ()
{
sendToAll (this, RUNNER_STOP_TAG); sendToAll (this, RUNNER_STOP_TAG);
} }
void Runner :: packTermination () {
pack (def_id);
}

View file

@ -1,4 +1,4 @@
/* /*
* <scheduler.cpp> * <scheduler.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -47,51 +47,45 @@ static std :: queue <SCHED_REQUEST> requests; /* Requests */
static unsigned initNumberOfRes = 0; static unsigned initNumberOfRes = 0;
void initScheduler () void initScheduler () {
{
for (unsigned i = 0; i < the_schema.size (); i ++) {
for (unsigned i = 0; i < the_schema.size (); i ++)
{ const Node & node = the_schema [i];
const Node & node = the_schema [i]; if (node.rk_sched == my_node -> rk)
for (unsigned j = 0; j < node.num_workers; j ++)
if (node.rk_sched == my_node -> rk) resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
for (unsigned j = 0; j < node.num_workers; j ++) }
resources.push (std :: pair <RANK_ID, WORKER_ID> (i, j + 1));
}
initNumberOfRes = resources.size (); initNumberOfRes = resources.size ();
} }
bool allResourcesFree () bool allResourcesFree () {
{
return resources.size () == initNumberOfRes; return resources.size () == initNumberOfRes;
} }
static void update () static void update () {
{
unsigned num_alloc = std :: min (resources.size (), requests.size ()); unsigned num_alloc = std :: min (resources.size (), requests.size ());
for (unsigned i = 0; i < num_alloc; i ++) {
SCHED_REQUEST req = requests.front ();
requests.pop ();
SCHED_RESOURCE res = resources.front ();
resources.pop ();
for (unsigned i = 0; i < num_alloc; i ++) printDebugMessage ("allocating a resource.");
{ initMessage ();
pack (req.second);
SCHED_REQUEST req = requests.front (); pack (res);
requests.pop (); sendMessage (req.first, SCHED_RESULT_TAG);
}
SCHED_RESOURCE res = resources.front ();
resources.pop ();
printDebugMessage ("allocating a resource.");
initMessage ();
pack (req.second);
pack (res);
sendMessage (req.first, SCHED_RESULT_TAG);
}
} }
void unpackResourceRequest () void unpackResourceRequest () {
{
printDebugMessage ("queuing a resource request."); printDebugMessage ("queuing a resource request.");
SCHED_REQUEST req; SCHED_REQUEST req;
@ -100,8 +94,7 @@ void unpackResourceRequest ()
update (); update ();
} }
void unpackTaskDone () void unpackTaskDone () {
{
printDebugMessage ("I'm notified a worker is now idle."); printDebugMessage ("I'm notified a worker is now idle.");
SCHED_RESOURCE res; SCHED_RESOURCE res;

View file

@ -1,4 +1,4 @@
/* /*
* <scheduler.h> * <scheduler.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -53,7 +53,7 @@ extern void initScheduler ();
extern void unpackResourceRequest (); extern void unpackResourceRequest ();
/* Being known a worker is now idle :-) */ /* Being known a worker is now idle :-) */
extern void unpackTaskDone (); extern void unpackTaskDone ();
extern bool allResourcesFree (); extern bool allResourcesFree ();

View file

@ -1,4 +1,4 @@
/* /*
* <schema.cpp> * <schema.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -35,6 +35,7 @@
*/ */
#include <iostream> #include <iostream>
#include <set>
#include <assert.h> #include <assert.h>
#include "schema.h" #include "schema.h"
@ -43,23 +44,25 @@
#include "node.h" #include "node.h"
#include "../../core/peo_debug.h" #include "../../core/peo_debug.h"
std :: vector <Node> the_schema; std :: vector <Node> the_schema;
Node * my_node; Node * my_node;
RANK_ID getRankOfRunner (RUNNER_ID __key) static unsigned maxSpecifiedRunnerID = 0;
{
RANK_ID getRankOfRunner (RUNNER_ID __key) {
for (unsigned i = 0; i < the_schema.size (); i ++) for (unsigned i = 0; i < the_schema.size (); i ++)
for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++) for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++)
if (the_schema [i].id_run [j] == __key) if (the_schema [i].id_run [j] == __key)
return the_schema [i].rk; return the_schema [i].rk;
assert (false); assert (false);
return 0; return 0;
} }
static void loadNode (int __rk_sched) static void loadNode (int __rk_sched) {
{
Node node; Node node;
@ -70,59 +73,55 @@ static void loadNode (int __rk_sched)
/* ATT: num_workers */ /* ATT: num_workers */
node.num_workers = atoi (getAttributeValue ("num_workers").c_str ()); node.num_workers = atoi (getAttributeValue ("num_workers").c_str ());
while (true) while (true) {
{
/* TAG: <runner> | </node> */ /* TAG: <runner> | </node> */
std :: string name = getNextNode (); std :: string name = getNextNode ();
assert (name == "runner" || name == "node"); assert (name == "runner" || name == "node");
if (name == "runner") if (name == "runner") {
{ /* TAG: </node> */
/* TAG: </node> */ node.id_run.push_back (atoi (getNextNode ().c_str ()));
node.id_run.push_back (atoi (getNextNode ().c_str ())); if ( node.id_run.back() > maxSpecifiedRunnerID )
/* TAG: </runner> */ maxSpecifiedRunnerID = node.id_run.back();
assert (getNextNode () == "runner"); /* TAG: </runner> */
} assert (getNextNode () == "runner");
else
{
/* TAG: </node> */
the_schema.push_back (node);
break;
}
} }
else {
/* TAG: </node> */
node.execution_id_run = node.id_run;
the_schema.push_back (node);
break;
}
}
} }
static void loadGroup () static void loadGroup () {
{
std :: string name; std :: string name;
/* ATT: scheduler*/ /* ATT: scheduler*/
int rk_sched = getRankFromName (getAttributeValue ("scheduler")); int rk_sched = getRankFromName (getAttributeValue ("scheduler"));
while (true) while (true) {
{
/* TAG: <node> | </group> */ /* TAG: <node> | </group> */
name = getNextNode (); name = getNextNode ();
assert (name == "node" || name == "group"); assert (name == "node" || name == "group");
if (name == "node") if (name == "node")
/* TAG: <node> */ /* TAG: <node> */
loadNode (rk_sched); loadNode (rk_sched);
else else
/* TAG: </group> */ /* TAG: </group> */
break; break;
} }
} }
bool isScheduleNode () bool isScheduleNode () {
{
return my_node -> rk == my_node -> rk_sched; return my_node -> rk == my_node -> rk_sched;
} }
void loadSchema (const char * __filename) void loadSchema (const char * __filename) {
{
openXMLDocument (__filename); openXMLDocument (__filename);
@ -132,44 +131,61 @@ void loadSchema (const char * __filename)
name = getNextNode (); name = getNextNode ();
assert (name == "schema"); assert (name == "schema");
while (true) maxSpecifiedRunnerID = 0;
{
/* TAG: <group> | </schema> */
name = getNextNode (); while (true) {
assert (name == "group" || name == "schema");
if (name == "group") /* TAG: <group> | </schema> */
/* TAG: <group> */ name = getNextNode ();
loadGroup (); assert (name == "group" || name == "schema");
else if (name == "group")
/* TAG: </schema> */ /* TAG: <group> */
break; loadGroup ();
else
/* TAG: </schema> */
break;
}
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 ) {
the_schema [i].execution_id_run[j] = ++maxSpecifiedRunnerID;
}
nbUniqueIDs = uniqueRunnerIDs.size();
} }
}
/* Looking for my node */ /* Looking for my node */
for (unsigned i = 0; i < the_schema.size (); i ++) for (unsigned i = 0; i < the_schema.size (); i ++) {
if (the_schema [i].rk == getNodeRank ()) if (the_schema [i].rk == getNodeRank ())
my_node = & (the_schema [i]); my_node = & (the_schema [i]);
}
/* About me */ /* About me */
char mess [1000]; char mess [1000];
sprintf (mess, "my rank is %d", my_node -> rk); sprintf (mess, "my rank is %d", my_node -> rk);
printDebugMessage (mess); printDebugMessage (mess);
if (isScheduleNode ())
printDebugMessage ("I'am a scheduler");
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)
{
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers); if (isScheduleNode ())
printDebugMessage (mess); printDebugMessage ("I'am a scheduler");
}
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) {
sprintf (mess, "I manage %d worker(s)", my_node -> num_workers);
printDebugMessage (mess);
}
closeXMLDocument (); closeXMLDocument ();
} }

View file

@ -1,4 +1,4 @@
/* /*
* <schema.h> * <schema.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -45,15 +45,15 @@
typedef int RANK_ID; typedef int RANK_ID;
struct Node struct Node {
{
RANK_ID rk; /* Rank */
RANK_ID rk; /* Rank */ std :: string name; /* Host name */
std :: string name; /* Host name */ unsigned num_workers; /* Number of parallel workers */
unsigned num_workers; /* Number of parallel workers */ int rk_sched; /* rank of the scheduler */
int rk_sched; /* rank of the scheduler */ std :: vector <RUNNER_ID> id_run; /* List of runner def. IDs */
std :: vector <RUNNER_ID> id_run; /* List of runners */ std :: vector <RUNNER_ID> execution_id_run; /* List of runtime execution runner IDs */
}; };
extern std :: vector <Node> the_schema; extern std :: vector <Node> the_schema;

View file

@ -1,4 +1,4 @@
/* /*
* <send.cpp> * <send.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -49,30 +49,26 @@
#define TO_ALL -1 #define TO_ALL -1
typedef struct typedef struct {
{
Communicable * comm; Communicable * comm;
int to; int to;
int tag; int tag;
}
SEND_REQUEST;
} SEND_REQUEST;
static std :: queue <SEND_REQUEST> mess; static std :: queue <SEND_REQUEST> mess;
static sem_t sem_send; static sem_t sem_send;
void initSending () void initSending () {
{
sem_init (& sem_send, 0, 1); sem_init (& sem_send, 0, 1);
} }
void send (Communicable * __comm, int __to, int __tag) void send (Communicable * __comm, int __to, int __tag) {
{
SEND_REQUEST req; SEND_REQUEST req;
req.comm = __comm; req.comm = __comm;
req.to = __to; req.to = __to;
req.tag = __tag; req.tag = __tag;
@ -83,70 +79,70 @@ void send (Communicable * __comm, int __to, int __tag)
wakeUpCommunicator (); wakeUpCommunicator ();
} }
void sendToAll (Communicable * __comm, int __tag) void sendToAll (Communicable * __comm, int __tag) {
{
send (__comm, TO_ALL, __tag); send (__comm, TO_ALL, __tag);
} }
void sendMessages () extern void initializeContext ();
{
void sendMessages () {
sem_wait (& sem_send); sem_wait (& sem_send);
while (! mess.empty ()) static bool contextInitialized = false;
{
SEND_REQUEST req = mess.front (); if (! contextInitialized) {
/* contextInitialized = true;
char b [1000]; initializeContext();
sprintf (b, "traitement send %d\n", req.tag); }
printDebugMessage (b);
*/
Communicable * comm = req.comm; while (! mess.empty ()) {
SEND_REQUEST req = mess.front ();
Communicable * comm = req.comm;
initMessage (); initMessage ();
switch (req.tag) switch (req.tag) {
{
case RUNNER_STOP_TAG: case RUNNER_STOP_TAG:
dynamic_cast <Runner *> (comm) -> packTermination (); dynamic_cast <Runner *> (comm) -> packTermination ();
dynamic_cast <Runner *> (comm) -> notifySendingTermination (); dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
break; break;
case COOP_TAG: case COOP_TAG:
dynamic_cast <Cooperative *> (comm) -> pack (); dynamic_cast <Cooperative *> (comm) -> pack ();
dynamic_cast <Cooperative *> (comm) -> notifySending (); dynamic_cast <Cooperative *> (comm) -> notifySending ();
break; break;
case SCHED_REQUEST_TAG: case SCHED_REQUEST_TAG:
dynamic_cast <Service *> (comm) -> packResourceRequest (); dynamic_cast <Service *> (comm) -> packResourceRequest ();
dynamic_cast <Service *> (comm) -> notifySendingResourceRequest (); dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
break; break;
case TASK_RESULT_TAG: case TASK_RESULT_TAG:
dynamic_cast <Worker *> (comm) -> packResult (); dynamic_cast <Worker *> (comm) -> packResult ();
dynamic_cast <Worker *> (comm) -> notifySendingResult (); dynamic_cast <Worker *> (comm) -> notifySendingResult ();
break; break;
case TASK_DONE_TAG: case TASK_DONE_TAG:
dynamic_cast <Worker *> (comm) -> packTaskDone (); dynamic_cast <Worker *> (comm) -> packTaskDone ();
dynamic_cast <Worker *> (comm) -> notifySendingTaskDone (); dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
break; break;
default :
break;
default : };
break;
if (req.to == TO_ALL)
sendMessageToAll (req.tag);
else
sendMessage (req.to, req.tag);
mess.pop ();
}
}; sem_post (& sem_send);
if (req.to == TO_ALL)
sendMessageToAll (req.tag);
else
sendMessage (req.to, req.tag);
mess.pop ();
}
sem_post (& sem_send);
} }

View file

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

View file

@ -1,4 +1,4 @@
/* /*
* <service.cpp> * <service.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,16 +41,14 @@
#include "send.h" #include "send.h"
#include "scheduler.h" #include "scheduler.h"
void Service :: requestResourceRequest (unsigned __how_many) void Service :: requestResourceRequest (unsigned __how_many) {
{
num_sent_rr = __how_many; num_sent_rr = __how_many;
for (unsigned i = 0; i < __how_many; i ++) for (unsigned i = 0; i < __how_many; i ++)
send (this, my_node -> rk_sched, SCHED_REQUEST_TAG); send (this, my_node -> rk_sched, SCHED_REQUEST_TAG);
} }
void Service :: packResourceRequest () void Service :: packResourceRequest () {
{
SCHED_REQUEST req; SCHED_REQUEST req;
req.first = getNodeRank (); req.first = getNodeRank ();

View file

@ -1,4 +1,4 @@
/* /*
* <tags.h> * <tags.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -37,6 +37,8 @@
#ifndef __tags_h #ifndef __tags_h
#define __tags_h #define __tags_h
#define EXECUTION_CONTEXT_TAG 1000
#define RUNNER_STOP_TAG 13 #define RUNNER_STOP_TAG 13
#define COOP_TAG 14 #define COOP_TAG 14

View file

@ -1,4 +1,4 @@
/* /*
* <worker.cpp> * <worker.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -46,88 +46,76 @@
static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */ static std :: vector <Worker *> key_to_worker (1); /* Vector of registered workers */
Worker * getWorker (WORKER_ID __key) Worker * getWorker (WORKER_ID __key) {
{
return key_to_worker [__key]; return key_to_worker [__key];
} }
Worker :: Worker () Worker :: Worker () {
{
toto = false; toto = false;
id = key_to_worker.size (); id = key_to_worker.size ();
key_to_worker.push_back (this); key_to_worker.push_back (this);
} }
void Worker :: packResult () void Worker :: packResult () {
{
pack (serv_id); pack (serv_id);
serv -> packResult (); serv -> packResult ();
} }
void Worker :: unpackData () void Worker :: unpackData () {
{
printDebugMessage ("unpacking the ID. of the service."); printDebugMessage ("unpacking the ID. of the service.");
unpack (serv_id); unpack (serv_id);
serv = getService (serv_id); serv = getService (serv_id);
printDebugMessage ("found the service."); printDebugMessage ("found the service.");
serv -> unpackData (); serv -> unpackData ();
printDebugMessage ("unpacking the data."); printDebugMessage ("unpacking the data.");
setActive (); setActive ();
} }
void Worker :: packTaskDone () void Worker :: packTaskDone () {
{
pack (getNodeRank ()); pack (getNodeRank ());
pack (id); pack (id);
} }
void Worker :: notifySendingResult () void Worker :: notifySendingResult () {
{
/* Notifying the scheduler of the termination */ /* Notifying the scheduler of the termination */
toto = true; toto = true;
wakeUp (); wakeUp ();
} }
void Worker :: notifySendingTaskDone () void Worker :: notifySendingTaskDone () {
{
setPassive (); setPassive ();
} }
void Worker :: setSource (int __rank) void Worker :: setSource (int __rank) {
{
src = __rank; src = __rank;
} }
void Worker :: start () void Worker :: start () {
{
while (true) while (true) {
{
sleep ();
sleep (); if (! atLeastOneActiveRunner ())
break;
if (! atLeastOneActiveRunner ())
break; if (toto) {
send (this, my_node -> rk_sched, TASK_DONE_TAG);
if (toto) toto = false;
{
send (this, my_node -> rk_sched, TASK_DONE_TAG);
toto = false;
}
else
{
printDebugMessage ("executing the task.");
serv -> execute ();
send (this, src, TASK_RESULT_TAG);
}
} }
else {
printDebugMessage ("executing the task.");
serv -> execute ();
send (this, src, TASK_RESULT_TAG);
}
}
} }

View file

@ -1,4 +1,4 @@
/* /*
* <worker.h> * <worker.h>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -41,38 +41,37 @@
#include "../../core/reac_thread.h" #include "../../core/reac_thread.h"
#include "../../core/service.h" #include "../../core/service.h"
typedef unsigned WORKER_ID; typedef unsigned WORKER_ID;
class Worker : public Communicable, public ReactiveThread class Worker : public Communicable, public ReactiveThread {
{
public : public :
Worker (); Worker ();
void start (); void start ();
void packResult (); void packResult ();
void unpackData (); void unpackData ();
void packTaskDone (); void packTaskDone ();
void notifySendingResult (); void notifySendingResult ();
void notifySendingTaskDone (); void notifySendingTaskDone ();
void setSource (int __rank);
private :
void setSource (int __rank); WORKER_ID id;
SERVICE_ID serv_id;
Service * serv;
int src;
private : bool toto;
};
WORKER_ID id;
SERVICE_ID serv_id;
Service * serv;
int src;
bool toto;
};
extern Worker * getWorker (WORKER_ID __key); extern Worker * getWorker (WORKER_ID __key);

View file

@ -1,4 +1,4 @@
/* /*
* <xml_parser.cpp> * <xml_parser.cpp>
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
@ -40,59 +40,51 @@
static xmlTextReaderPtr reader; static xmlTextReaderPtr reader;
void openXMLDocument (const char * __filename) void openXMLDocument (const char * __filename) {
{
reader = xmlNewTextReaderFilename (__filename); reader = xmlNewTextReaderFilename (__filename);
if (! reader) if (! reader) {
{
fprintf (stderr, "unable to open '%s'.\n", __filename);
fprintf (stderr, "unable to open '%s'.\n", __filename); exit (1);
exit (1); }
}
} }
void closeXMLDocument () void closeXMLDocument () {
{
xmlFreeTextReader (reader); xmlFreeTextReader (reader);
} }
std :: string getAttributeValue (const std :: string & __attr) std :: string getAttributeValue (const std :: string & __attr) {
{
xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ()); xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ());
std :: string str ((const char *) value); std :: string str ((const char *) value);
xmlFree (value); xmlFree (value);
return str; return str;
} }
static bool isSep (const xmlChar * __text) static bool isSep (const xmlChar * __text) {
{
for (unsigned i = 0; i < strlen ((char *) __text); i ++) for (unsigned i = 0; i < strlen ((char *) __text); i ++)
if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n') if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n')
return false; return false;
return true; return true;
} }
std :: string getNextNode () std :: string getNextNode () {
{
xmlChar * name, * value; xmlChar * name, * value;
do do {
{ xmlTextReaderRead (reader);
xmlTextReaderRead (reader); name = xmlTextReaderName (reader);
name = xmlTextReaderName (reader); value = xmlTextReaderValue (reader);
value = xmlTextReaderValue (reader); // printf ("value = %s\n", value);
// printf ("value = %s\n", value); } while (! strcmp ((char *) name, "#text") && isSep (value));
}
while (! strcmp ((char *) name, "#text") && isSep (value));
std :: string str; std :: string str;
@ -100,12 +92,12 @@ std :: string getNextNode ()
str.assign ((char *) name); str.assign ((char *) name);
else else
str.assign ((char *) value); str.assign ((char *) value);
if (name) if (name)
xmlFree (name); xmlFree (name);
if (value) if (value)
xmlFree (value); xmlFree (value);
return str; return str;
} }

View file

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