diff --git a/trunk/paradiseo-peo/src/core/communicable.cpp b/trunk/paradiseo-peo/src/core/communicable.cpp index b6beca2ad..3d43db117 100644 --- a/trunk/paradiseo-peo/src/core/communicable.cpp +++ b/trunk/paradiseo-peo/src/core/communicable.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,7 +47,8 @@ static std :: map comm_to_key; /* Map of regist unsigned Communicable :: num_comm = 0; -Communicable :: Communicable () { +Communicable :: Communicable () +{ comm_to_key [this] = key = ++ num_comm; key_to_comm.push_back (this); @@ -55,46 +56,54 @@ Communicable :: Communicable () { sem_init (& sem_stop, 0, 0); } -Communicable :: ~ Communicable () { - +Communicable :: ~ Communicable () +{ } -COMM_ID Communicable :: getKey () { +COMM_ID Communicable :: getKey () +{ return key; } -Communicable * getCommunicable (COMM_ID __key) { +Communicable * getCommunicable (COMM_ID __key) +{ assert (__key < key_to_comm.size ()); - return key_to_comm [__key]; + return key_to_comm [__key]; } -COMM_ID getKey (const Communicable * __comm) { +COMM_ID getKey (const Communicable * __comm) +{ return comm_to_key [__comm]; } -void Communicable :: lock () { +void Communicable :: lock () + { - sem_wait (& sem_lock); -} + sem_wait (& sem_lock); + } -void Communicable :: unlock () { +void Communicable :: unlock () +{ sem_post (& sem_lock); } -void Communicable :: stop () { +void Communicable :: stop () +{ sem_wait (& sem_stop); } -void Communicable :: resume () { +void Communicable :: resume () +{ sem_post (& sem_stop); } -void initCommunicableEnv () { +void initCommunicableEnv () +{ key_to_comm.resize (1); comm_to_key.clear (); diff --git a/trunk/paradiseo-peo/src/core/communicable.h b/trunk/paradiseo-peo/src/core/communicable.h index 4d0dae9f2..37215299e 100644 --- a/trunk/paradiseo-peo/src/core/communicable.h +++ b/trunk/paradiseo-peo/src/core/communicable.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -42,37 +42,38 @@ typedef unsigned COMM_ID; -class Communicable { +class Communicable + { -public : + public : - Communicable (); + Communicable (); - virtual ~ Communicable (); + virtual ~ Communicable (); - COMM_ID getKey (); + COMM_ID getKey (); - void lock (); /* It suspends the current process if the semaphore is locked */ - void unlock (); /* It unlocks the shared semaphore */ + void lock (); /* It suspends the current process if the semaphore is locked */ + void unlock (); /* It unlocks the shared semaphore */ - void stop (); /* It suspends the current process */ - void resume (); /* It resumes ___________ */ + void stop (); /* It suspends the current process */ + void resume (); /* It resumes ___________ */ -public : + public : - static unsigned num_comm; + static unsigned num_comm; -protected : + protected : - COMM_ID key; + COMM_ID key; - sem_t sem_lock; + sem_t sem_lock; - sem_t sem_stop; -}; + sem_t sem_stop; + }; extern void initCommunicableEnv (); -extern Communicable * getCommunicable (COMM_ID __key); +extern Communicable * getCommunicable (COMM_ID __key); #endif diff --git a/trunk/paradiseo-peo/src/core/cooperative.h b/trunk/paradiseo-peo/src/core/cooperative.h index 65862d4b4..098107e51 100644 --- a/trunk/paradiseo-peo/src/core/cooperative.h +++ b/trunk/paradiseo-peo/src/core/cooperative.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,38 +43,39 @@ typedef unsigned COOP_ID; -class Cooperative : public Communicable { +class Cooperative : public Communicable + { -public : + public : - Runner * getOwner (); + Runner * getOwner (); - void setOwner (Runner & __runner); + void setOwner (Runner & __runner); - virtual void pack () = 0; + virtual void pack () = 0; - virtual void unpack () = 0; + virtual void unpack () = 0; - virtual void packSynchronizeReq () = 0; + virtual void packSynchronizeReq () = 0; - void send (Cooperative * __coop); + void send (Cooperative * __coop); - void synchronizeCoopEx (); + void synchronizeCoopEx (); - virtual void notifySending (); + virtual void notifySending (); - virtual void notifyReceiving (); + virtual void notifyReceiving (); - virtual void notifySendingSyncReq (); + virtual void notifySendingSyncReq (); - virtual void notifySynchronized (); + virtual void notifySynchronized (); -private : + private : - Runner * owner; + Runner * owner; -}; + }; -extern Cooperative * getCooperative (COOP_ID __key); +extern Cooperative * getCooperative (COOP_ID __key); #endif diff --git a/trunk/paradiseo-peo/src/core/eoPop_mesg.h b/trunk/paradiseo-peo/src/core/eoPop_mesg.h index 948e17ae2..ac409ed56 100644 --- a/trunk/paradiseo-peo/src/core/eoPop_mesg.h +++ b/trunk/paradiseo-peo/src/core/eoPop_mesg.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -42,14 +42,16 @@ #include "messaging.h" -template void pack (const eoPop & __pop) { +template void pack (const eoPop & __pop) +{ pack ((unsigned) __pop.size ()); for (unsigned i = 0; i < __pop.size (); i ++) pack (__pop [i]); } -template void unpack (eoPop & __pop) { +template void unpack (eoPop & __pop) +{ unsigned n; diff --git a/trunk/paradiseo-peo/src/core/eoVector_mesg.h b/trunk/paradiseo-peo/src/core/eoVector_mesg.h index 7581444df..5fbc98775 100644 --- a/trunk/paradiseo-peo/src/core/eoVector_mesg.h +++ b/trunk/paradiseo-peo/src/core/eoVector_mesg.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,34 +43,41 @@ #include "messaging.h" -template void pack (const eoVector & __v) { +template void pack (const eoVector & __v) +{ - if (__v.invalid()) { - pack((unsigned)0); - } - else { - pack((unsigned)1); - pack (__v.fitness ()); - } + if (__v.invalid()) + { + pack((unsigned)0); + } + else + { + pack((unsigned)1); + pack (__v.fitness ()); + } unsigned len = __v.size (); pack (len); for (unsigned i = 0 ; i < len; i ++) - pack (__v [i]); + pack (__v [i]); } -template void unpack (eoVector & __v) { +template void unpack (eoVector & __v) +{ - unsigned valid; unpack(valid); + unsigned valid; + unpack(valid); - if (! valid) { - __v.invalidate(); - } - else { - F fit; - unpack (fit); - __v.fitness (fit); - } + if (! valid) + { + __v.invalidate(); + } + else + { + F fit; + unpack (fit); + __v.fitness (fit); + } unsigned len; unpack (len); @@ -79,125 +86,132 @@ template void unpack (eoVector & __v) { unpack (__v [i]); } -template void pack (const eoVectorParticle & __v) { +template void pack (const eoVectorParticle & __v) +{ - if (__v.invalid()) { - pack((unsigned)0); - } - else { - pack((unsigned)1); - pack (__v.fitness ()); - pack (__v.best()); - } + if (__v.invalid()) + { + pack((unsigned)0); + } + else + { + pack((unsigned)1); + pack (__v.fitness ()); + pack (__v.best()); + } unsigned len = __v.size (); pack (len); for (unsigned i = 0 ; i < len; i ++) - pack (__v [i]); + pack (__v [i]); for (unsigned i = 0 ; i < len; i ++) - pack (__v.bestPositions[i]); + pack (__v.bestPositions[i]); for (unsigned i = 0 ; i < len; i ++) - pack (__v.velocities[i]); + pack (__v.velocities[i]); } -template void unpack (eoVectorParticle & __v) { +template void unpack (eoVectorParticle & __v) +{ -unsigned valid; unpack(valid); + unsigned valid; + unpack(valid); - if (! valid) { - __v.invalidate(); - } - else { - F fit; - unpack (fit); - __v.fitness (fit); + if (! valid) + { + __v.invalidate(); + } + else + { + F fit; + unpack (fit); + __v.fitness (fit); unpack(fit); - __v.best(fit); - - } + __v.best(fit); + + } unsigned len; unpack (len); __v.resize (len); for (unsigned i = 0 ; i < len; i ++) - unpack (__v [i]); + unpack (__v [i]); for (unsigned i = 0 ; i < len; i ++) - unpack (__v.bestPositions[i]); + unpack (__v.bestPositions[i]); for (unsigned i = 0 ; i < len; i ++) - unpack (__v.velocities[i]); + unpack (__v.velocities[i]); } -template void unpack (moeoVector &_v) +template void unpack (moeoVector &_v) { - unsigned valid; - unpack(valid); - if (! valid) - _v.invalidate(); - else + unsigned valid; + unpack(valid); + if (! valid) + _v.invalidate(); + else { - T fit; - unpack (fit); - _v.fitness (fit); - } - unpack(valid); - if (! valid) - _v.invalidateDiversity(); - else - { - V diver; - unpack(diver); - _v.diversity(diver); + T fit; + unpack (fit); + _v.fitness (fit); } - unsigned len; - unpack (len); - _v.resize (len); - for (unsigned i = 0 ; i < len; i ++) - unpack (_v [i]); - unpack(valid); - if (! valid) - _v.invalidateObjectiveVector(); - else + unpack(valid); + if (! valid) + _v.invalidateDiversity(); + else { - F object; - unpack (len); - object.resize(len); - for (unsigned i = 0 ; i < len; i ++) - unpack (object[i]); - _v.objectiveVector(object); + V diver; + unpack(diver); + _v.diversity(diver); + } + unsigned len; + unpack (len); + _v.resize (len); + for (unsigned i = 0 ; i < len; i ++) + unpack (_v [i]); + unpack(valid); + if (! valid) + _v.invalidateObjectiveVector(); + else + { + F object; + unpack (len); + object.resize(len); + for (unsigned i = 0 ; i < len; i ++) + unpack (object[i]); + _v.objectiveVector(object); } } -template void pack (moeoVector &_v) +template void pack (moeoVector &_v) { - if (_v.invalid()) - pack((unsigned)0); - else + if (_v.invalid()) + pack((unsigned)0); + else { - pack((unsigned)1); - pack (_v.fitness ()); + pack((unsigned)1); + pack (_v.fitness ()); } - if (_v.invalidDiversity()) - pack((unsigned)0); - else + if (_v.invalidDiversity()) + pack((unsigned)0); + else { - pack((unsigned)1); - pack(_v.diversity()); + pack((unsigned)1); + pack(_v.diversity()); } - unsigned len = _v.size (); - pack (len); - for (unsigned i = 0 ; i < len; i ++) - pack (_v[i]); - if (_v.invalidObjectiveVector()) - pack((unsigned)0); - else + unsigned len = _v.size (); + pack (len); + for (unsigned i = 0 ; i < len; i ++) + pack (_v[i]); + if (_v.invalidObjectiveVector()) + pack((unsigned)0); + else { - pack((unsigned)1); - F object; - object=_v.objectiveVector(); - len=object.nObjectives(); - pack (len); - for (unsigned i = 0 ; i < len; i ++) - pack (object[i]); + pack((unsigned)1); + F object; + object=_v.objectiveVector(); + len=object.nObjectives(); + pack (len); + for (unsigned i = 0 ; i < len; i ++) + pack (object[i]); } } diff --git a/trunk/paradiseo-peo/src/core/messaging.h b/trunk/paradiseo-peo/src/core/messaging.h index 78aedd9ad..9a5a74d6f 100644 --- a/trunk/paradiseo-peo/src/core/messaging.h +++ b/trunk/paradiseo-peo/src/core/messaging.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -47,41 +47,43 @@ extern void pack (const char & __c); extern void pack (const bool & __b, int __nitem = 1); /* Float */ -extern void pack (const float & __f, int __nitem = 1); +extern void pack (const float & __f, int __nitem = 1); /* Double */ -extern void pack (const double & __d, int __nitem = 1); +extern void pack (const double & __d, int __nitem = 1); /* Integer */ -extern void pack (const int & __i, int __nitem = 1); +extern void pack (const int & __i, int __nitem = 1); /* Unsigned int. */ -extern void pack (const unsigned int & __ui, int __nitem = 1); +extern void pack (const unsigned int & __ui, int __nitem = 1); /* Short int. */ -extern void pack (const short & __sh, int __nitem = 1); +extern void pack (const short & __sh, int __nitem = 1); /* Unsigned short */ extern void pack (const unsigned short & __ush, int __nitem = 1); /* Long */ -extern void pack (const long & __l, int __nitem = 1); +extern void pack (const long & __l, int __nitem = 1); /* Unsigned long */ -extern void pack (const unsigned long & __ul, int __nitem = 1); +extern void pack (const unsigned long & __ul, int __nitem = 1); /* String */ extern void pack (const char * __str); extern void pack (const std::string & __str); /* Pointer */ -template void pack (const T * __ptr) { +template void pack (const T * __ptr) +{ - pack ((unsigned long) __ptr); + pack ((unsigned long) __ptr); } /* Pair */ -template void pack (const std :: pair & __pair) { +template void pack (const std :: pair & __pair) +{ pack (__pair.first); pack (__pair.second); @@ -90,41 +92,42 @@ template void pack (const std :: pair & __pair) { /* Char */ -extern void unpack (char & __c); +extern void unpack (char & __c); /* Boolean */ extern void unpack (bool & __b, int __nitem = 1); /* Float */ -extern void unpack (float & __f, int __nitem = 1); +extern void unpack (float & __f, int __nitem = 1); /* Double */ -extern void unpack (double & __d, int __nitem = 1); +extern void unpack (double & __d, int __nitem = 1); /* Integer */ -extern void unpack (int & __i, int __nitem = 1); +extern void unpack (int & __i, int __nitem = 1); /* Unsigned int. */ -extern void unpack (unsigned int & __ui, int __nitem = 1); +extern void unpack (unsigned int & __ui, int __nitem = 1); /* Short int. */ -extern void unpack (short & __sh, int __nitem = 1); +extern void unpack (short & __sh, int __nitem = 1); /* Unsigned short */ extern void unpack (unsigned short & __ush, int __nitem = 1); /* Long */ -extern void unpack (long & __l, int __nitem = 1); +extern void unpack (long & __l, int __nitem = 1); /* Unsigned long */ -extern void unpack (unsigned long & __ul, int __nitem = 1); +extern void unpack (unsigned long & __ul, int __nitem = 1); /* String */ -extern void unpack (char * __str); +extern void unpack (char * __str); extern void unpack (std::string & __str); /* Pointer */ -template void unpack (T * & __ptr) { +template void unpack (T * & __ptr) +{ unsigned long p; unpack (p); @@ -132,7 +135,8 @@ template void unpack (T * & __ptr) { } /* Pair */ -template void unpack (std :: pair & __pair) { +template void unpack (std :: pair & __pair) +{ unpack (__pair.first); unpack (__pair.second); diff --git a/trunk/paradiseo-peo/src/core/peo_debug.cpp b/trunk/paradiseo-peo/src/core/peo_debug.cpp index dc79f09fd..0228a8bb9 100644 --- a/trunk/paradiseo-peo/src/core/peo_debug.cpp +++ b/trunk/paradiseo-peo/src/core/peo_debug.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -58,7 +58,8 @@ static char host [MAX_BUFF_SIZE]; std :: vector files; -void setDebugMode (bool __dbg) { +void setDebugMode (bool __dbg) +{ debug = __dbg; gethostname (host, MAX_BUFF_SIZE); @@ -66,7 +67,8 @@ void setDebugMode (bool __dbg) { extern int getNodeRank (); -void initDebugging () { +void initDebugging () +{ mkdir (DEBUG_PATH, S_IRWXU); // files.push_back (stdout); @@ -75,7 +77,8 @@ void initDebugging () { files.push_back (fopen (buff, "w")); } -void endDebugging () { +void endDebugging () +{ for (unsigned i = 0; i < files.size (); i ++) if (files [i] != stdout) @@ -83,29 +86,32 @@ void endDebugging () { files.clear(); } -void printDebugMessage (const char * __mess) { +void printDebugMessage (const char * __mess) +{ - if (debug) { + if (debug) + { - char buff [MAX_BUFF_SIZE]; - char localTime [MAX_BUFF_SIZE]; - time_t t = time (0); + char buff [MAX_BUFF_SIZE]; + char localTime [MAX_BUFF_SIZE]; + time_t t = time (0); - /* Date */ - strcpy( localTime, ctime (& t) ); - localTime[ strlen( localTime )-1 ] = ']'; - sprintf (buff, "[%s][%s: ", host, localTime ); + /* Date */ + strcpy( localTime, ctime (& t) ); + localTime[ strlen( localTime )-1 ] = ']'; + sprintf (buff, "[%s][%s: ", host, localTime ); - for (unsigned i = 0; i < files.size (); i ++) - fprintf (files [i], buff); + for (unsigned i = 0; i < files.size (); i ++) + fprintf (files [i], buff); - /* Message */ - sprintf (buff, "%s", __mess); + /* Message */ + sprintf (buff, "%s", __mess); - for (unsigned i = 0; i < files.size (); i ++) { - fputs (buff, files [i]); - fputs ("\n", files [i]); - fflush (files [i]); + for (unsigned i = 0; i < files.size (); i ++) + { + fputs (buff, files [i]); + fputs ("\n", files [i]); + fflush (files [i]); + } } - } } diff --git a/trunk/paradiseo-peo/src/core/peo_debug.h b/trunk/paradiseo-peo/src/core/peo_debug.h index d00b5e9c7..8c72f860b 100644 --- a/trunk/paradiseo-peo/src/core/peo_debug.h +++ b/trunk/paradiseo-peo/src/core/peo_debug.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/core/peo_fin.cpp b/trunk/paradiseo-peo/src/core/peo_fin.cpp index 8c0bf3ff4..6d104a991 100644 --- a/trunk/paradiseo-peo/src/core/peo_fin.cpp +++ b/trunk/paradiseo-peo/src/core/peo_fin.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,7 +39,8 @@ #include "runner.h" #include "rmc.h" -void peo :: finalize () { +void peo :: finalize () +{ printDebugMessage ("waiting for the termination of all threads"); diff --git a/trunk/paradiseo-peo/src/core/peo_fin.h b/trunk/paradiseo-peo/src/core/peo_fin.h index cf23cbfdb..de34ee2dd 100644 --- a/trunk/paradiseo-peo/src/core/peo_fin.h +++ b/trunk/paradiseo-peo/src/core/peo_fin.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -37,7 +37,8 @@ #ifndef __peo_finalize_h #define __peo_finalize_h -namespace peo { +namespace peo + { extern void finalize (); } diff --git a/trunk/paradiseo-peo/src/core/peo_init.cpp b/trunk/paradiseo-peo/src/core/peo_init.cpp index 52c35bcf5..f984ca126 100644 --- a/trunk/paradiseo-peo/src/core/peo_init.cpp +++ b/trunk/paradiseo-peo/src/core/peo_init.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -57,7 +57,8 @@ extern void initScheduler (); extern void initSynchron (); -static void initExecutionEnv() { +static void initExecutionEnv() +{ initCommunicableEnv (); initBuffers (); @@ -72,13 +73,15 @@ static void initExecutionEnv() { } -namespace peo { +namespace peo + { int * argc; char * * * argv; - void init (int & __argc, char * * & __argv) { + void init (int & __argc, char * * & __argv) + { argc = & __argc; @@ -87,7 +90,7 @@ namespace peo { /* Initializing the execution environment */ initExecutionEnv(); - /* Loading the common parameters */ + /* Loading the common parameters */ loadParameters (__argc, __argv); /* Initializing the the Resource Management and Communication */ diff --git a/trunk/paradiseo-peo/src/core/peo_init.h b/trunk/paradiseo-peo/src/core/peo_init.h index 9b4a90362..0e39ad506 100644 --- a/trunk/paradiseo-peo/src/core/peo_init.h +++ b/trunk/paradiseo-peo/src/core/peo_init.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -37,7 +37,8 @@ #ifndef __peo_init_h #define __peo_init_h -namespace peo { +namespace peo + { extern int * argc; diff --git a/trunk/paradiseo-peo/src/core/peo_param.cpp b/trunk/paradiseo-peo/src/core/peo_param.cpp index 6e3f4b6e5..5eab0da7f 100644 --- a/trunk/paradiseo-peo/src/core/peo_param.cpp +++ b/trunk/paradiseo-peo/src/core/peo_param.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -40,7 +40,8 @@ #include "peo_debug.h" -void peo :: loadParameters (int & __argc, char * * & __argv) { +void peo :: loadParameters (int & __argc, char * * & __argv) +{ eoParser parser (__argc, __argv); diff --git a/trunk/paradiseo-peo/src/core/peo_param.h b/trunk/paradiseo-peo/src/core/peo_param.h index 4ec838e0b..1860dce90 100644 --- a/trunk/paradiseo-peo/src/core/peo_param.h +++ b/trunk/paradiseo-peo/src/core/peo_param.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -37,7 +37,8 @@ #ifndef __peo_param_h #define __peo_param_h -namespace peo { +namespace peo + { extern void loadParameters (int & __argc, char * * & __argv); } diff --git a/trunk/paradiseo-peo/src/core/peo_run.cpp b/trunk/paradiseo-peo/src/core/peo_run.cpp index 166a45a44..d0d972fa0 100644 --- a/trunk/paradiseo-peo/src/core/peo_run.cpp +++ b/trunk/paradiseo-peo/src/core/peo_run.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,7 +39,8 @@ #include "runner.h" -void peo :: run () { +void peo :: run () +{ startRunners (); diff --git a/trunk/paradiseo-peo/src/core/peo_run.h b/trunk/paradiseo-peo/src/core/peo_run.h index b5ca43365..5eaf5483a 100644 --- a/trunk/paradiseo-peo/src/core/peo_run.h +++ b/trunk/paradiseo-peo/src/core/peo_run.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -37,7 +37,8 @@ #ifndef __peo_run_h #define __peo_run_h -namespace peo { +namespace peo + { extern void run (); } diff --git a/trunk/paradiseo-peo/src/core/reac_thread.cpp b/trunk/paradiseo-peo/src/core/reac_thread.cpp index bd669948f..c22402990 100644 --- a/trunk/paradiseo-peo/src/core/reac_thread.cpp +++ b/trunk/paradiseo-peo/src/core/reac_thread.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,29 +41,34 @@ static bool the_end = false; static std :: vector reac_threads; -ReactiveThread :: ReactiveThread () { +ReactiveThread :: ReactiveThread () +{ reac_threads.push_back (this); sem_init (& sem, 0, 0); } -void ReactiveThread :: sleep () { +void ReactiveThread :: sleep () +{ - sem_wait (& sem); + sem_wait (& sem); } -void ReactiveThread :: wakeUp () { +void ReactiveThread :: wakeUp () +{ - sem_post (& sem); + sem_post (& sem); } -void initReactiveThreadsEnv () { +void initReactiveThreadsEnv () +{ the_end = false; reac_threads.clear (); } -void stopReactiveThreads () { +void stopReactiveThreads () +{ the_end = true; for (unsigned i = 0; i < reac_threads.size (); i ++) @@ -71,4 +76,7 @@ void stopReactiveThreads () { reac_threads.clear (); } -bool theEnd () { return the_end; } +bool theEnd () +{ + return the_end; +} diff --git a/trunk/paradiseo-peo/src/core/reac_thread.h b/trunk/paradiseo-peo/src/core/reac_thread.h index 79619090a..943b4ccb3 100644 --- a/trunk/paradiseo-peo/src/core/reac_thread.h +++ b/trunk/paradiseo-peo/src/core/reac_thread.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -42,21 +42,22 @@ #include "thread.h" -class ReactiveThread : public Thread { +class ReactiveThread : public Thread + { -public: + public: - /* Ctor */ - ReactiveThread (); + /* Ctor */ + ReactiveThread (); - void sleep (); + void sleep (); - void wakeUp (); + void wakeUp (); -private: + private: - sem_t sem; -}; + sem_t sem; + }; extern void initReactiveThreadsEnv (); diff --git a/trunk/paradiseo-peo/src/core/ring_topo.cpp b/trunk/paradiseo-peo/src/core/ring_topo.cpp index c52ebb454..dfdbf571c 100644 --- a/trunk/paradiseo-peo/src/core/ring_topo.cpp +++ b/trunk/paradiseo-peo/src/core/ring_topo.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -37,17 +37,19 @@ #include "ring_topo.h" void RingTopology :: setNeighbors (Cooperative * __mig, - std :: vector & __from, - std :: vector & __to) { + std :: vector & __from, + std :: vector & __to) +{ __from.clear () ; __to.clear () ; - int len = mig.size () ; + int len = mig.size () ; - for (int i = 0 ; i < len ; i ++) - if (mig [i] == __mig) { - __from.push_back (mig [(i - 1 + len) % len]) ; - __to.push_back (mig [(i + 1) % len]) ; - break; + for (int i = 0 ; i < len ; i ++) + if (mig [i] == __mig) + { + __from.push_back (mig [(i - 1 + len) % len]) ; + __to.push_back (mig [(i + 1) % len]) ; + break; } } diff --git a/trunk/paradiseo-peo/src/core/ring_topo.h b/trunk/paradiseo-peo/src/core/ring_topo.h index 363a69850..b1715a99b 100644 --- a/trunk/paradiseo-peo/src/core/ring_topo.h +++ b/trunk/paradiseo-peo/src/core/ring_topo.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,14 +39,15 @@ #include "topology.h" -class RingTopology : public Topology { +class RingTopology : public Topology + { -public : + public : - void setNeighbors (Cooperative * __mig, - std :: vector & __from, - std :: vector & __to); - -}; + void setNeighbors (Cooperative * __mig, + std :: vector & __from, + std :: vector & __to); + + }; #endif diff --git a/trunk/paradiseo-peo/src/core/rmc.h b/trunk/paradiseo-peo/src/core/rmc.h index 7efb1bac3..be2f18e2e 100644 --- a/trunk/paradiseo-peo/src/core/rmc.h +++ b/trunk/paradiseo-peo/src/core/rmc.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -39,7 +39,7 @@ extern void initRMC (int & __argc, char * * & __argv); -extern void runRMC (); /* Resource Management and Communication */ +extern void runRMC (); /* Resource Management and Communication */ extern void finalizeRMC (); diff --git a/trunk/paradiseo-peo/src/core/runner.cpp b/trunk/paradiseo-peo/src/core/runner.cpp index 4f421b32f..a9ad96ee4 100644 --- a/trunk/paradiseo-peo/src/core/runner.cpp +++ b/trunk/paradiseo-peo/src/core/runner.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,7 +48,7 @@ #include "../rmc/mpi/schema.h" -static std :: vector ll_threads; /* Low-level runner threads */ +static std :: vector ll_threads; /* Low-level runner threads */ static std :: vector the_runners; @@ -66,7 +66,8 @@ extern int getNumberOfNodes (); extern void wakeUpCommunicator (); -Runner :: Runner () { +Runner :: Runner () +{ exec_id = 0; def_id = ++ num_def_runners; @@ -77,35 +78,41 @@ Runner :: Runner () { sem_init (& sem_cntxt, 0, 0); } -RUNNER_ID Runner :: getDefinitionID () { +RUNNER_ID Runner :: getDefinitionID () +{ return def_id; } -RUNNER_ID Runner :: getExecutionID () { +RUNNER_ID Runner :: getExecutionID () +{ return exec_id; } -void Runner :: setExecutionID (const RUNNER_ID& execution_id) { +void Runner :: setExecutionID (const RUNNER_ID& execution_id) +{ exec_id = execution_id; } -Runner * getRunner (RUNNER_ID __key) { +Runner * getRunner (RUNNER_ID __key) +{ return dynamic_cast (getCommunicable (__key)); } -void initializeContext () { +void initializeContext () +{ num_local_exec_runners = 0; // setting up the execution IDs & counting the number of local exec. runners - for (unsigned i = 0; i < the_runners.size (); i ++) { - the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] ); - if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++; - } + for (unsigned i = 0; i < the_runners.size (); i ++) + { + the_runners [i] -> setExecutionID ( my_node -> execution_id_run[ i ] ); + if (the_runners [i] -> isAssignedLocally ()) num_local_exec_runners ++; + } collectiveCountOfRunners( &num_local_exec_runners, &num_exec_runners ); @@ -115,17 +122,20 @@ void initializeContext () { if (the_runners [i] -> isAssignedLocally ()) the_runners [i] -> notifyContextInitialized (); } -void Runner :: waitStarting () { +void Runner :: waitStarting () +{ sem_wait (& sem_start); } -void Runner :: waitContextInitialization () { +void Runner :: waitContextInitialization () +{ sem_wait (& sem_cntxt); } -void Runner :: start () { +void Runner :: start () +{ setActive (); @@ -136,46 +146,54 @@ void Runner :: start () { terminate (); } -void startRunners () { +void startRunners () +{ /* Runners */ for (unsigned i = 0; i < the_runners.size (); i ++) - if (the_runners [i] -> isAssignedLocally ()) { - addThread (the_runners [i], ll_threads); - the_runners [i] -> waitStarting (); - } + if (the_runners [i] -> isAssignedLocally ()) + { + addThread (the_runners [i], ll_threads); + the_runners [i] -> waitStarting (); + } printDebugMessage ("launched the parallel runners"); } -void joinRunners () { +void joinRunners () +{ joinThreads (ll_threads); the_runners.clear(); } -bool atLeastOneActiveRunner () { +bool atLeastOneActiveRunner () +{ return num_exec_runners; } -unsigned numberOfActiveRunners () { +unsigned numberOfActiveRunners () +{ return num_exec_runners; } -void Runner :: notifyContextInitialized () { +void Runner :: notifyContextInitialized () +{ sem_post (& sem_cntxt); } -void Runner :: notifySendingTermination () { +void Runner :: notifySendingTermination () +{ printDebugMessage ("I am informed that everyone received my termination notification."); setPassive (); } -void unpackTerminationOfRunner () { +void unpackTerminationOfRunner () +{ RUNNER_ID finished_id; unpack (finished_id); @@ -184,17 +202,19 @@ void unpackTerminationOfRunner () { printDebugMessage ("I'm noticed of the termination of a runner"); - if (!num_exec_runners) { + if (!num_exec_runners) + { - printDebugMessage ("All the runners have terminated - now stopping the reactive threads."); - stopReactiveThreads (); - printDebugMessage ("Reactive threads stopped!"); - } + printDebugMessage ("All the runners have terminated - now stopping the reactive threads."); + stopReactiveThreads (); + printDebugMessage ("Reactive threads stopped!"); + } wakeUpCommunicator (); } -void initRunnersEnv () { +void initRunnersEnv () +{ ll_threads.clear (); the_runners.clear (); diff --git a/trunk/paradiseo-peo/src/core/runner.h b/trunk/paradiseo-peo/src/core/runner.h index fd6bf294e..7d6f6b927 100644 --- a/trunk/paradiseo-peo/src/core/runner.h +++ b/trunk/paradiseo-peo/src/core/runner.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,49 +46,50 @@ typedef unsigned RUNNER_ID; -class Runner : public Communicable, public Thread { +class Runner : public Communicable, public Thread + { -public : + public : - Runner (); + Runner (); - RUNNER_ID getDefinitionID (); + RUNNER_ID getDefinitionID (); - RUNNER_ID getExecutionID (); + RUNNER_ID getExecutionID (); - void setExecutionID (const RUNNER_ID& execution_id); + void setExecutionID (const RUNNER_ID& execution_id); - bool isAssignedLocally (); + bool isAssignedLocally (); - void waitStarting (); + void waitStarting (); - void waitContextInitialization (); + void waitContextInitialization (); - void start (); + void start (); - virtual void run () = 0; + virtual void run () = 0; - void terminate (); + void terminate (); - void notifyContextInitialized (); + void notifyContextInitialized (); - void notifySendingTermination (); + void notifySendingTermination (); - void packTermination (); + void packTermination (); -private : + private : - sem_t sem_start; - sem_t sem_cntxt; + sem_t sem_start; + sem_t sem_cntxt; - unsigned def_id; - unsigned exec_id; -}; + unsigned def_id; + unsigned exec_id; + }; extern void initRunnersEnv (); -extern Runner * getRunner (RUNNER_ID __key); +extern Runner * getRunner (RUNNER_ID __key); extern void initializeContext (); diff --git a/trunk/paradiseo-peo/src/core/service.cpp b/trunk/paradiseo-peo/src/core/service.cpp index 322769fe5..fafc5dc11 100644 --- a/trunk/paradiseo-peo/src/core/service.cpp +++ b/trunk/paradiseo-peo/src/core/service.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -36,38 +36,49 @@ #include "service.h" -void Service :: setOwner (Thread & __owner) { +void Service :: setOwner (Thread & __owner) +{ owner = & __owner; } -Thread * Service :: getOwner () { +Thread * Service :: getOwner () +{ return owner; } -Service * getService (SERVICE_ID __key) { +Service * getService (SERVICE_ID __key) +{ return dynamic_cast (getCommunicable (__key)); } -void Service :: notifySendingData () { } +void Service :: notifySendingData () +{ } -void Service :: notifySendingResourceRequest () { +void Service :: notifySendingResourceRequest () +{ num_sent_rr --; if (! num_sent_rr) notifySendingAllResourceRequests (); } -void Service :: notifySendingAllResourceRequests () { } +void Service :: notifySendingAllResourceRequests () +{ } -void Service :: packData () {} +void Service :: packData () +{} -void Service :: unpackData () {} +void Service :: unpackData () +{} -void Service :: execute () {} +void Service :: execute () +{} -void Service :: packResult () {} +void Service :: packResult () +{} -void Service :: unpackResult () {} +void Service :: unpackResult () +{} diff --git a/trunk/paradiseo-peo/src/core/service.h b/trunk/paradiseo-peo/src/core/service.h index 3e48ebd80..2198cac06 100644 --- a/trunk/paradiseo-peo/src/core/service.h +++ b/trunk/paradiseo-peo/src/core/service.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,37 +43,38 @@ typedef unsigned SERVICE_ID; -class Service : public Communicable { +class Service : public Communicable + { -public : + public : - void setOwner (Thread & __owner); + void setOwner (Thread & __owner); - Thread * getOwner (); + Thread * getOwner (); - void requestResourceRequest (unsigned __how_many = 1); - void packResourceRequest (); + void requestResourceRequest (unsigned __how_many = 1); + void packResourceRequest (); - virtual void packData (); - virtual void unpackData (); + virtual void packData (); + virtual void unpackData (); - virtual void execute (); + virtual void execute (); - virtual void packResult (); - virtual void unpackResult (); + virtual void packResult (); + virtual void unpackResult (); - virtual void notifySendingData (); - virtual void notifySendingResourceRequest (); - virtual void notifySendingAllResourceRequests (); + virtual void notifySendingData (); + virtual void notifySendingResourceRequest (); + virtual void notifySendingAllResourceRequests (); -private : + private : - Thread * owner; /* Owner thread (i.e. 'uses' that service) */ + Thread * owner; /* Owner thread (i.e. 'uses' that service) */ - unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/ + unsigned num_sent_rr; /* Number of RR not really sent (i.e. still in the sending queue)*/ -}; + }; -extern Service * getService (SERVICE_ID __key); +extern Service * getService (SERVICE_ID __key); #endif diff --git a/trunk/paradiseo-peo/src/core/thread.cpp b/trunk/paradiseo-peo/src/core/thread.cpp index 0c7ba956b..b085ca1d2 100644 --- a/trunk/paradiseo-peo/src/core/thread.cpp +++ b/trunk/paradiseo-peo/src/core/thread.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,66 +43,78 @@ static std :: vector threads; unsigned num_act = 0; -Thread :: Thread () { +Thread :: Thread () +{ threads.push_back (this); act = false; } -Thread :: ~ Thread () { +Thread :: ~ Thread () +{ /* Nothing ! */ } -void Thread :: setActive () { +void Thread :: setActive () +{ - if (! act) { + if (! act) + { - act = true; - num_act ++; - } + act = true; + num_act ++; + } } -void Thread :: setPassive () { +void Thread :: setPassive () +{ - if (act) { + if (act) + { - act = false; - num_act --; - } + act = false; + num_act --; + } } -void initThreadsEnv () { +void initThreadsEnv () +{ threads.clear (); num_act = 0; } -bool atLeastOneActiveThread () { +bool atLeastOneActiveThread () +{ return num_act; } -static void * launch (void * __arg) { +static void * launch (void * __arg) +{ - Thread * thr = (Thread *) __arg; + Thread * thr = (Thread *) __arg; thr -> start (); return 0; } -void addThread (Thread * __hl_thread, std :: vector & __ll_threads) { +void addThread (Thread * __hl_thread, std :: vector & __ll_threads) +{ pthread_t * ll_thr = new pthread_t; __ll_threads.push_back (ll_thr); - pthread_create (ll_thr, 0, launch, __hl_thread); + pthread_create (ll_thr, 0, launch, __hl_thread); } -void joinThreads (std :: vector & __threads) { +void joinThreads (std :: vector & __threads) +{ - for (unsigned i = 0; i < __threads.size (); i ++) { - pthread_join (* __threads [i], 0); - delete __threads [i]; - } + for (unsigned i = 0; i < __threads.size (); i ++) + { + pthread_join (* __threads [i], 0); + delete __threads [i]; + } __threads.clear(); } diff --git a/trunk/paradiseo-peo/src/core/thread.h b/trunk/paradiseo-peo/src/core/thread.h index 42b1c0edb..b8d90977e 100644 --- a/trunk/paradiseo-peo/src/core/thread.h +++ b/trunk/paradiseo-peo/src/core/thread.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,27 +41,28 @@ /* A high-level thread */ -class Thread { +class Thread + { -public: + public: - /* Ctor */ - Thread (); + /* Ctor */ + Thread (); - /* Dtor */ - virtual ~ Thread (); + /* Dtor */ + virtual ~ Thread (); - /* Go ! */ - virtual void start () = 0; + /* Go ! */ + virtual void start () = 0; - void setActive ();/* It means the current process is going to send messages soon */ - void setPassive ();/* The current process is not going to perform send operations - (but it may receive messages) */ + void setActive ();/* It means the current process is going to send messages soon */ + void setPassive ();/* The current process is not going to perform send operations + (but it may receive messages) */ -private : + private : - bool act; -}; + bool act; + }; extern void initThreadsEnv (); diff --git a/trunk/paradiseo-peo/src/core/topology.cpp b/trunk/paradiseo-peo/src/core/topology.cpp index 465210b93..318658fce 100644 --- a/trunk/paradiseo-peo/src/core/topology.cpp +++ b/trunk/paradiseo-peo/src/core/topology.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -36,17 +36,20 @@ #include "topology.h" -Topology :: ~ Topology () { +Topology :: ~ Topology () +{ /* Nothing ! */ } -void Topology :: add (Cooperative & __mig) { +void Topology :: add (Cooperative & __mig) + { - mig.push_back (& __mig) ; -} + mig.push_back (& __mig) ; + } -Topology :: operator std :: vector & () { +Topology :: operator std :: vector & () +{ return mig; } diff --git a/trunk/paradiseo-peo/src/core/topology.h b/trunk/paradiseo-peo/src/core/topology.h index 8c818561f..62c339feb 100644 --- a/trunk/paradiseo-peo/src/core/topology.h +++ b/trunk/paradiseo-peo/src/core/topology.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,23 +41,24 @@ #include "cooperative.h" -class Topology { +class Topology + { -public: + public: - virtual ~Topology (); + virtual ~Topology (); - void add (Cooperative & __mig); + void add (Cooperative & __mig); - virtual void setNeighbors (Cooperative * __mig, - std :: vector & __from, - std :: vector & __to) = 0; + virtual void setNeighbors (Cooperative * __mig, + std :: vector & __from, + std :: vector & __to) = 0; - operator std :: vector & (); + operator std :: vector & (); -protected: + protected: - std :: vector mig; -}; + std :: vector mig; + }; #endif diff --git a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h index 5d5e2a983..4f765a803 100644 --- a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h +++ b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h @@ -162,7 +162,7 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, peoData & __source, peoData & __destination ); - + //! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected //! from the source population and sent to the next island (defined by the topology object) while the immigrant @@ -234,20 +234,20 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack( unlock(); } -template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq() { -} +template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: packSynchronizeReq() +{} template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrate() { std :: vector< Cooperative* >in, out; topology.setNeighbors( this, in, out ); - + for ( unsigned i = 0; i < out.size(); i++ ) { TYPE mig; select(mig); - em.push( mig ); + em.push( mig ); coop_em.push( out[i] ); send( out[i] ); printDebugMessage( "sending some emigrants." ); @@ -257,13 +257,13 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: emigrat template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigrate() { - + lock (); { while ( !imm.empty() ) { - replace(imm.front() ); + replace(imm.front() ); imm.pop(); printDebugMessage( "receiving some immigrants." ); } @@ -274,8 +274,8 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()() { - - if (cont.check()) + + if (cont.check()) { emigrate(); // sending emigrants diff --git a/trunk/paradiseo-peo/src/peoData.h b/trunk/paradiseo-peo/src/peoData.h index 4234268e2..98eb10b09 100644 --- a/trunk/paradiseo-peo/src/peoData.h +++ b/trunk/paradiseo-peo/src/peoData.h @@ -44,39 +44,42 @@ /************************** DEFINE A DATA ******************************************/ /**************************************************************************************/ -class peoData { -public: +class peoData + { + public: - virtual void pack () {} - virtual void unpack () {} - -}; + virtual void pack () + {} + virtual void unpack () + {} + + }; // Specific implementation : migration of a population template class peoPop: public eoPop, public peoData -{ -public: - - virtual void pack () { - ::pack ((unsigned) this->size ()); - for (unsigned i = 0; i < this->size (); i ++) - ::pack ((*this)[i]); - } + public: - virtual void unpack () - { - unsigned n; - ::unpack (n); - this->resize (n); - for (unsigned i = 0; i < n; i ++) - ::unpack ((*this)[i]); - } + virtual void pack () + { + ::pack ((unsigned) this->size ()); + for (unsigned i = 0; i < this->size (); i ++) + ::pack ((*this)[i]); + } -}; + virtual void unpack () + { + unsigned n; + ::unpack (n); + this->resize (n); + for (unsigned i = 0; i < n; i ++) + ::unpack ((*this)[i]); + } + + }; /**************************************************************************************/ @@ -84,27 +87,30 @@ public: /**************************************************************************************/ class continuator -{ -public: - virtual bool check()=0; -}; + { + public: + virtual bool check()=0; + }; // Specific implementation : migration of a population -template < class EOT> class eoContinuator : public continuator{ -public: - - eoContinuator(eoContinue & _cont, const eoPop & _pop): cont (_cont), pop(_pop){} - - virtual bool check(){ - return cont(pop); - } +template < class EOT> class eoContinuator : public continuator + { + public: -protected: - eoContinue & cont ; - const eoPop & pop; -}; + eoContinuator(eoContinue & _cont, const eoPop & _pop): cont (_cont), pop(_pop) + {} + + virtual bool check() + { + return cont(pop); + } + + protected: + eoContinue & cont ; + const eoPop & pop; + }; /**************************************************************************************/ @@ -112,32 +118,34 @@ protected: /**************************************************************************************/ template < class TYPE> class selector -{ -public: - virtual void operator()(TYPE &)=0; -}; + { + public: + virtual void operator()(TYPE &)=0; + }; // Specific implementation : migration of a population -template < class EOT, class TYPE> class eoSelector : public selector< TYPE >{ -public: - - eoSelector(eoSelectOne & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source){} - - virtual void operator()(TYPE & _dest) - { - size_t target = static_cast(nb_select); - _dest.resize(target); - for (size_t i = 0; i < _dest.size(); ++i) - _dest[i] = selector(source); - } +template < class EOT, class TYPE> class eoSelector : public selector< TYPE > + { + public: -protected: - eoSelectOne & selector ; - unsigned nb_select; - const TYPE & source; -}; + eoSelector(eoSelectOne & _select, unsigned _nb_select, const TYPE & _source): selector (_select), nb_select(_nb_select), source(_source) + {} + + virtual void operator()(TYPE & _dest) + { + size_t target = static_cast(nb_select); + _dest.resize(target); + for (size_t i = 0; i < _dest.size(); ++i) + _dest[i] = selector(source); + } + + protected: + eoSelectOne & selector ; + unsigned nb_select; + const TYPE & source; + }; /**************************************************************************************/ @@ -145,27 +153,29 @@ protected: /**************************************************************************************/ template < class TYPE> class replacement -{ -public: - virtual void operator()(TYPE &)=0; -}; + { + public: + virtual void operator()(TYPE &)=0; + }; // Specific implementation : migration of a population -template < class EOT, class TYPE> class eoReplace : public replacement< TYPE >{ -public: - eoReplace(eoReplacement & _replace, TYPE & _destination): replace(_replace), destination(_destination){} - - virtual void operator()(TYPE & _source) - { - replace(destination, _source); - } +template < class EOT, class TYPE> class eoReplace : public replacement< TYPE > + { + public: + eoReplace(eoReplacement & _replace, TYPE & _destination): replace(_replace), destination(_destination) + {} -protected: - eoReplacement & replace; - TYPE & destination; -}; + virtual void operator()(TYPE & _source) + { + replace(destination, _source); + } + + protected: + eoReplacement & replace; + TYPE & destination; + }; /**************************************************************************************/ @@ -173,25 +183,26 @@ protected: /**************************************************************************************/ class eoSyncContinue: public continuator -{ - -public: - - eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) {} - - virtual bool check() { - return ((++ counter) % period) != 0 ; - } - - -private: - unsigned period; - - unsigned counter; + public: -}; + eoSyncContinue (unsigned __period, unsigned __init_counter = 0): period (__period),counter (__init_counter) + {} + + virtual bool check() + { + return ((++ counter) % period) != 0 ; + } + + + private: + + unsigned period; + + unsigned counter; + + }; #endif diff --git a/trunk/paradiseo-peo/src/peoEvalFunc.h b/trunk/paradiseo-peo/src/peoEvalFunc.h index b19e27335..b6e8486f3 100644 --- a/trunk/paradiseo-peo/src/peoEvalFunc.h +++ b/trunk/paradiseo-peo/src/peoEvalFunc.h @@ -43,20 +43,20 @@ template< class EOT, class FitT = EOT::Fitness, class FunctionArg = const EOT& > template< class EOT, class FitT = typename EOT::Fitness, class FunctionArg = const EOT& > #endif struct peoEvalFunc: public eoEvalFunc -{ - - peoEvalFunc( FitT (* _eval)( FunctionArg ) ) - : eoEvalFunc(), evalFunc( _eval ) - {}; - - virtual void operator() ( EOT & _peo ) { - _peo.fitness((*evalFunc)( _peo )); - }; + + peoEvalFunc( FitT (* _eval)( FunctionArg ) ) + : eoEvalFunc(), evalFunc( _eval ) + {}; + + virtual void operator() ( EOT & _peo ) + { + _peo.fitness((*evalFunc)( _peo )); + }; private: - FitT (* evalFunc )( FunctionArg ); -}; + FitT (* evalFunc )( FunctionArg ); + }; #endif diff --git a/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h b/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h index 8416a2f4d..6e3374c9c 100644 --- a/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h +++ b/trunk/paradiseo-peo/src/peoGlobalBestVelocity.h @@ -54,7 +54,7 @@ class peoGlobalBestVelocity : public eoReplacement typedef typename POT::ParticleVelocityType VelocityType; peoGlobalBestVelocity( const double & _c3, - eoVelocity < POT > &_velocity): + eoVelocity < POT > &_velocity): c3 (_c3), velocity (_velocity) {} diff --git a/trunk/paradiseo-peo/src/peoMoeoPopEval.h b/trunk/paradiseo-peo/src/peoMoeoPopEval.h index 1beda1f54..a2a68001b 100644 --- a/trunk/paradiseo-peo/src/peoMoeoPopEval.h +++ b/trunk/paradiseo-peo/src/peoMoeoPopEval.h @@ -143,7 +143,7 @@ template< class EOT > peoMoeoPopEval< EOT > :: peoMoeoPopEval( template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop ) { - this->operator()(__pop); + this->operator()(__pop); } template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __pop ) @@ -166,7 +166,7 @@ template< class EOT > void peoMoeoPopEval< EOT >::operator()(eoPop< EOT >& __pop template< class EOT > void peoMoeoPopEval< EOT > :: packData() -{ +{ // printDebugMessage ("debut pakc data"); pack( progression[ tasks.front() ].first-- ); @@ -180,7 +180,7 @@ template< class EOT > void peoMoeoPopEval< EOT > :: packData() template< class EOT > void peoMoeoPopEval< EOT > :: unpackData() -{ +{ unpack( num_func ); /* Unpacking the solution */ unpack( sol ); @@ -191,28 +191,28 @@ template< class EOT > void peoMoeoPopEval< EOT > :: unpackData() template< class EOT > void peoMoeoPopEval< EOT > :: execute() { - + /* Computing the fitness of the solution */ funcs[ num_func ]->operator()( sol ); } template< class EOT > void peoMoeoPopEval< EOT > :: packResult() -{ +{ // std::cout<<"\nD"; /* Packing the fitness of the solution */ - /* typedef typename PO < F >::Fitness Fitness; - MOEOObjectiveVector ObjectiveVector;*/ + /* typedef typename PO < F >::Fitness Fitness; + MOEOObjectiveVector ObjectiveVector;*/ std::vector < double > object; unsigned len; object=sol.objectiveVector(); len=object.size(); pack (len); for (unsigned i = 0 ; i < len; i ++) - pack (object[i]); - - - + pack (object[i]); + + + // pack( sol.fitness() ); /* Packing the @ of the individual */ pack( ad_sol ); @@ -221,25 +221,25 @@ template< class EOT > void peoMoeoPopEval< EOT > :: packResult() template< class EOT > void peoMoeoPopEval< EOT > :: unpackResult() -{ +{ // typename EOT :: Fitness fit; /* Unpacking the computed fitness */ // unpack( fit ); -unsigned len; -std::vector < double > object; + unsigned len; + std::vector < double > object; -unpack(len); -object.resize(len); -for (unsigned i = 0 ; i < len; i ++) - unpack (object[i]); + unpack(len); + object.resize(len); + for (unsigned i = 0 ; i < len; i ++) + unpack (object[i]); /* Unpacking the @ of the associated individual */ unpack( ad_sol ); /* Associating the fitness the local solution */ // merge_eval( *ad_sol, object ); -ad_sol->objectiveVector(object); + ad_sol->objectiveVector(object); progression[ ad_sol ].second--; /* Notifying the container of the termination of the evaluation */ @@ -265,7 +265,7 @@ template< class EOT > void peoMoeoPopEval< EOT > :: notifySendingData() template< class EOT > void peoMoeoPopEval< EOT > :: notifySendingAllResourceRequests() -{ +{ getOwner()->setPassive(); } diff --git a/trunk/paradiseo-peo/src/peoMultiStart.h b/trunk/paradiseo-peo/src/peoMultiStart.h index 319c00ffd..52670d69b 100644 --- a/trunk/paradiseo-peo/src/peoMultiStart.h +++ b/trunk/paradiseo-peo/src/peoMultiStart.h @@ -43,227 +43,227 @@ template < typename EntityType > class peoMultiStart : public Service -{ - - public: - - template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm ) { - singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm ); - algorithms.push_back( singularAlgorithm ); + public: - aggregationFunction = new NoAggregationFunction(); - } + template < typename AlgorithmType > peoMultiStart( AlgorithmType& externalAlgorithm ) + { - template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) - { + singularAlgorithm = new Algorithm< AlgorithmType >( externalAlgorithm ); + algorithms.push_back( singularAlgorithm ); - singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm ); - algorithms.push_back( singularAlgorithm ); + aggregationFunction = new NoAggregationFunction(); + } - aggregationFunction = new NoAggregationFunction(); - } + template < typename AlgorithmReturnType, typename AlgorithmDataType > peoMultiStart( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) + { - template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) - { + singularAlgorithm = new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm ); + algorithms.push_back( singularAlgorithm ); - for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) + aggregationFunction = new NoAggregationFunction(); + } + + template < typename AlgorithmType, typename AggregationFunctionType > peoMultiStart( std::vector< AlgorithmType* >& externalAlgorithms, AggregationFunctionType& externalAggregationFunction ) + { + + for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) + { + + algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) ); + } + + aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); + } + + template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType > + peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, + AggregationFunctionType& externalAggregationFunction ) + { + + for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) + { + + algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) ); + } + + aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); + } + + ~peoMultiStart() + { + + for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ]; + for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ]; + + delete aggregationFunction; + } + + + template < typename Type > void operator()( Type& externalData ) + { + + for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ ) + { + + data.push_back( new DataType< EntityType >( *externalDataIterator ) ); + } + + functionIndex = dataIndex = idx = num_term = 0; + requestResourceRequest( data.size() * algorithms.size() ); + stop(); + } + + + template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd ) + { + + for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ ) + { + + data.push_back( new DataType< EntityType >( *externalDataIterator ) ); + } + + functionIndex = dataIndex = idx = num_term = 0; + requestResourceRequest( data.size() * algorithms.size() ); + stop(); + } + + + void packData(); + + void unpackData(); + + void execute(); + + void packResult(); + + void unpackResult(); + + void notifySendingData(); + + void notifySendingAllResourceRequests(); + + + private: + + template < typename Type > struct DataType; + + struct AbstractDataType { - algorithms.push_back( new Algorithm< AlgorithmType >( *externalAlgorithms[ index ] ) ); - } + virtual ~AbstractDataType() + { } - aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); - } + template < typename Type > operator Type& () + { - template < typename AlgorithmReturnType, typename AlgorithmDataType, typename AggregationFunctionType > - peoMultiStart( std::vector< AlgorithmReturnType (*)( AlgorithmDataType& ) >& externalAlgorithms, - AggregationFunctionType& externalAggregationFunction ) - { - - for ( unsigned int index = 0; index < externalAlgorithms.size(); index++ ) - { - - algorithms.push_back( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithms[ index ] ) ); - } - - aggregationFunction = new AggregationAlgorithm< AggregationFunctionType >( externalAggregationFunction ); - } - - ~peoMultiStart() - { - - for ( unsigned int index = 0; index < data.size(); index++ ) delete data[ index ]; - for ( unsigned int index = 0; index < algorithms.size(); index++ ) delete algorithms[ index ]; - - delete aggregationFunction; - } - - - template < typename Type > void operator()( Type& externalData ) - { - - for ( typename Type::iterator externalDataIterator = externalData.begin(); externalDataIterator != externalData.end(); externalDataIterator++ ) - { - - data.push_back( new DataType< EntityType >( *externalDataIterator ) ); - } - - functionIndex = dataIndex = idx = num_term = 0; - requestResourceRequest( data.size() * algorithms.size() ); - stop(); - } - - - template < typename Type > void operator()( const Type& externalDataBegin, const Type& externalDataEnd ) - { - - for ( Type externalDataIterator = externalDataBegin; externalDataIterator != externalDataEnd; externalDataIterator++ ) - { - - data.push_back( new DataType< EntityType >( *externalDataIterator ) ); - } - - functionIndex = dataIndex = idx = num_term = 0; - requestResourceRequest( data.size() * algorithms.size() ); - stop(); - } - - - void packData(); - - void unpackData(); - - void execute(); - - void packResult(); - - void unpackResult(); - - void notifySendingData(); - - void notifySendingAllResourceRequests(); - - - private: - - template < typename Type > struct DataType; - - struct AbstractDataType - { - - virtual ~AbstractDataType() - { } - - template < typename Type > operator Type& () - { - - return ( dynamic_cast< DataType< Type >& >( *this ) ).data; - } - }; + return ( dynamic_cast< DataType< Type >& >( *this ) ).data; + } + }; template < typename Type > struct DataType : public AbstractDataType - { + { - DataType( Type& externalData ) : data( externalData ) - { } + DataType( Type& externalData ) : data( externalData ) + { } - Type& data; - }; + Type& data; + }; - struct AbstractAlgorithm - { + struct AbstractAlgorithm + { - virtual ~AbstractAlgorithm() - { } + virtual ~AbstractAlgorithm() + { } - virtual void operator()( AbstractDataType& dataTypeInstance ) - {} - }; + virtual void operator()( AbstractDataType& dataTypeInstance ) + {} + }; template < typename AlgorithmType > struct Algorithm : public AbstractAlgorithm - { + { - Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) - { } + Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) + { } - void operator()( AbstractDataType& dataTypeInstance ) - { - algorithm( dataTypeInstance ); - } + void operator()( AbstractDataType& dataTypeInstance ) + { + algorithm( dataTypeInstance ); + } - AlgorithmType& algorithm; - }; + AlgorithmType& algorithm; + }; template < typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm - { + { - FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm ) - { } + FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ) ) : algorithm( externalAlgorithm ) + { } - void operator()( AbstractDataType& dataTypeInstance ) - { - algorithm( dataTypeInstance ); - } + void operator()( AbstractDataType& dataTypeInstance ) + { + algorithm( dataTypeInstance ); + } - AlgorithmReturnType (*algorithm)( AlgorithmDataType& ); - }; + AlgorithmReturnType (*algorithm)( AlgorithmDataType& ); + }; - struct AbstractAggregationAlgorithm - { + struct AbstractAggregationAlgorithm + { - virtual ~AbstractAggregationAlgorithm() - { } + virtual ~AbstractAggregationAlgorithm() + { } - virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) - {}; - }; + virtual void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) + {}; + }; template < typename AggregationAlgorithmType > struct AggregationAlgorithm : public AbstractAggregationAlgorithm - { + { - AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm ) - { } + AggregationAlgorithm( AggregationAlgorithmType& externalAggregationAlgorithm ) : aggregationAlgorithm( externalAggregationAlgorithm ) + { } - void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) - { + void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) + { - aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB ); - } + aggregationAlgorithm( dataTypeInstanceA, dataTypeInstanceB ); + } - AggregationAlgorithmType& aggregationAlgorithm; - }; + AggregationAlgorithmType& aggregationAlgorithm; + }; struct NoAggregationFunction : public AbstractAggregationAlgorithm - { + { - void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) - { + void operator()( AbstractDataType& dataTypeInstanceA, AbstractDataType& dataTypeInstanceB ) + { - static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB ); - } + static_cast< EntityType& >( dataTypeInstanceA ) = static_cast< EntityType& >( dataTypeInstanceB ); + } + }; + + + + AbstractAlgorithm* singularAlgorithm; + + std::vector< AbstractAlgorithm* > algorithms; + AbstractAggregationAlgorithm* aggregationFunction; + + + EntityType entityTypeInstance; + std::vector< AbstractDataType* > data; + + unsigned idx; + unsigned num_term; + unsigned dataIndex; + unsigned functionIndex; }; - - AbstractAlgorithm* singularAlgorithm; - - std::vector< AbstractAlgorithm* > algorithms; - AbstractAggregationAlgorithm* aggregationFunction; - - - EntityType entityTypeInstance; - std::vector< AbstractDataType* > data; - - unsigned idx; - unsigned num_term; - unsigned dataIndex; - unsigned functionIndex; -}; - - template < typename EntityType > void peoMultiStart< EntityType >::packData() { @@ -274,11 +274,11 @@ template < typename EntityType > void peoMultiStart< EntityType >::packData() // 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 ) if ( idx == data.size() ) - { + { - ++functionIndex; - idx = 0; - } + ++functionIndex; + idx = 0; + } } template < typename EntityType > void peoMultiStart< EntityType >::unpackData() @@ -322,11 +322,11 @@ template < typename EntityType > void peoMultiStart< EntityType >::unpackResult( num_term++; if ( num_term == data.size() * algorithms.size() ) - { + { - getOwner()->setActive(); - resume(); - } + getOwner()->setActive(); + resume(); + } } template < typename EntityType > void peoMultiStart< EntityType >::notifySendingData() diff --git a/trunk/paradiseo-peo/src/peoNoAggEvalFunc.h b/trunk/paradiseo-peo/src/peoNoAggEvalFunc.h index 3e169341e..d6fa02152 100644 --- a/trunk/paradiseo-peo/src/peoNoAggEvalFunc.h +++ b/trunk/paradiseo-peo/src/peoNoAggEvalFunc.h @@ -45,13 +45,13 @@ //! The class is provided as a mean of declaring that no aggregation is required for the evaluation function - the fitness //! value is explicitly specified. template< class EOT > class peoNoAggEvalFunc : public peoAggEvalFunc< EOT > -{ + { -public : + public : - //! Operator which sets as fitness the __fit value for the __sol individual - void operator()( EOT& __sol, const typename EOT :: Fitness& __fit ); -}; + //! Operator which sets as fitness the __fit value for the __sol individual + void operator()( EOT& __sol, const typename EOT :: Fitness& __fit ); + }; template< class EOT > void peoNoAggEvalFunc< EOT > :: operator()( EOT& __sol, const typename EOT :: Fitness& __fit ) diff --git a/trunk/paradiseo-peo/src/peoPopEval.h b/trunk/paradiseo-peo/src/peoPopEval.h index a2792c46d..bcd391b90 100644 --- a/trunk/paradiseo-peo/src/peoPopEval.h +++ b/trunk/paradiseo-peo/src/peoPopEval.h @@ -143,7 +143,7 @@ template< class EOT > peoPopEval< EOT > :: peoPopEval( template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __dummy, eoPop< EOT >& __pop ) { - this->operator()(__pop); + this->operator()(__pop); } template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop ) @@ -166,7 +166,7 @@ template< class EOT > void peoPopEval< EOT >::operator()(eoPop< EOT >& __pop ) template< class EOT > void peoPopEval< EOT > :: packData() -{ +{ // printDebugMessage ("debut pakc data"); pack( progression[ tasks.front() ].first-- ); @@ -180,7 +180,7 @@ template< class EOT > void peoPopEval< EOT > :: packData() template< class EOT > void peoPopEval< EOT > :: unpackData() -{ +{ unpack( num_func ); /* Unpacking the solution */ unpack( sol ); @@ -191,14 +191,14 @@ template< class EOT > void peoPopEval< EOT > :: unpackData() template< class EOT > void peoPopEval< EOT > :: execute() { - + /* Computing the fitness of the solution */ funcs[ num_func ]->operator()( sol ); } template< class EOT > void peoPopEval< EOT > :: packResult() -{ +{ /* Packing the fitness of the solution */ pack( sol.fitness() ); /* Packing the @ of the individual */ @@ -207,7 +207,7 @@ template< class EOT > void peoPopEval< EOT > :: packResult() template< class EOT > void peoPopEval< EOT > :: unpackResult() -{ +{ typename EOT :: Fitness fit; /* Unpacking the computed fitness */ @@ -244,7 +244,7 @@ template< class EOT > void peoPopEval< EOT > :: notifySendingData() template< class EOT > void peoPopEval< EOT > :: notifySendingAllResourceRequests() -{ +{ getOwner()->setPassive(); } diff --git a/trunk/paradiseo-peo/src/peoSyncIslandMig.h b/trunk/paradiseo-peo/src/peoSyncIslandMig.h index e65fcac32..0f51809ab 100644 --- a/trunk/paradiseo-peo/src/peoSyncIslandMig.h +++ b/trunk/paradiseo-peo/src/peoSyncIslandMig.h @@ -147,61 +147,61 @@ //! the associated distinctly parametrized migration objects. The interconnecting element is the underlying topology, defined at step 1 //! (the same C++ migTopology object has to be passed as parameter for all the migration objects, in order to interconnect them). template< class EOT, class TYPE > class peoSyncIslandMig : public Cooperative, public eoUpdater -{ + { -public: + public: - //! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined - //! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters. - //! - //! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically; - //! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population; - //! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population; - //! @param Topology& __topology - topological model to be followed when performing migrations; - //! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected; - //! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated. - peoSyncIslandMig( - unsigned __frequency, - selector & __select, - replacement & __replace, - Topology& __topology, - peoData & __source, - peoData & __destination - ); + //! Constructor for the peoSyncIslandMig class; the characteristics of the migration model are defined + //! through the specified parameters - out of the box objects provided in EO, etc., or custom, derived objects may be passed as parameters. + //! + //! @param unsigned __frequency - frequency of the migrations - the migrations occur periodically; + //! @param eoSelect< EOT >& __select - selection strategy to be applied for constructing a list of emigrant individuals out of the source population; + //! @param eoReplacement< EOT >& __replace - replacement strategy used for integrating the immigrant individuals in the destination population; + //! @param Topology& __topology - topological model to be followed when performing migrations; + //! @param eoPop< EOT >& __source - source population from which the emigrant individuals are selected; + //! @param eoPop< EOT >& __destination - destination population in which the immigrant population are integrated. + peoSyncIslandMig( + unsigned __frequency, + selector & __select, + replacement & __replace, + Topology& __topology, + peoData & __source, + peoData & __destination + ); - //! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected - //! from the source population and sent to the next island (defined by the topology object) while the immigrant - //! individuals are integrated in the destination population. There is no need to explicitly call the function - the - //! wrapper checkpoint object (please refer to the above example) will perform the call when required. - void operator()(); + //! Function operator to be called as checkpoint for performing the migration step. The emigrant individuals are selected + //! from the source population and sent to the next island (defined by the topology object) while the immigrant + //! individuals are integrated in the destination population. There is no need to explicitly call the function - the + //! wrapper checkpoint object (please refer to the above example) will perform the call when required. + void operator()(); - //! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function. - void pack(); - //! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function. - void unpack(); - //! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function. - void packSynchronizeReq(); + //! Auxiliary function dealing with sending the emigrant individuals. There is no need to explicitly call the function. + void pack(); + //! Auxiliary function dealing with receiving immigrant individuals. There is no need to explicitly call the function. + void unpack(); + //! Auxiliary function dealing with the packing of synchronization requests. There is no need to explicitly call the function. + void packSynchronizeReq(); - //! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function. - void notifySending(); + //! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function. + void notifySending(); - //! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function. - void notifyReceiving(); + //! Auxiliary function dealing with migration notifications. There is no need to explicitly call the function. + void notifyReceiving(); - //! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function. - void notifySendingSyncReq(); + //! Auxiliary function dealing with synchronizing runners for migrations. There is no need to explicitly call the function. + void notifySendingSyncReq(); - //! Auxiliary function for notifying the synchronization of the runners involved in migration. - void notifySynchronized(); + //! Auxiliary function for notifying the synchronization of the runners involved in migration. + void notifySynchronized(); -private: + private: - void emigrate(); - void immigrate(); + void emigrate(); + void immigrate(); -private: + private: eoSyncContinue cont; // continuator selector & select; // the selection strategy @@ -213,14 +213,14 @@ private: std :: queue< TYPE > em; std :: queue< Cooperative* > coop_em; - sem_t sync; + sem_t sync; - bool explicitPassive; - bool standbyMigration; + bool explicitPassive; + bool standbyMigration; - std :: vector< Cooperative* > in, out, all; - unsigned nbMigrations; -}; + std :: vector< Cooperative* > in, out, all; + unsigned nbMigrations; + }; template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandMig( @@ -243,7 +243,7 @@ template< class EOT, class TYPE > peoSyncIslandMig< EOT,TYPE > :: peoSyncIslandM template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: pack() { ::pack( coop_em.front()->getKey() ); - em.front().pack(); + em.front().pack(); coop_em.pop(); em.pop(); } @@ -256,7 +256,8 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: unpack() explicitPassive = true; } -template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq() { +template< class EOT, class TYPE > void peoSyncIslandMig< EOT,TYPE > :: packSynchronizeReq() +{ packSynchronRequest( all ); } @@ -265,25 +266,26 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: emigrat { for ( unsigned i = 0; i < out.size(); i ++ ) - { + { - TYPE mig; - select( mig ); - em.push( mig ); - coop_em.push( out[ i ] ); - send( out[ i ] ); - printDebugMessage( "peoSyncIslandMig: sending some emigrants." ); - } + TYPE mig; + select( mig ); + em.push( mig ); + coop_em.push( out[ i ] ); + send( out[ i ] ); + printDebugMessage( "peoSyncIslandMig: sending some emigrants." ); + } } template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: immigrate() { assert( imm.size() ); - while ( imm.size() ) { - replace( imm.front() ) ; - imm.pop(); - } + while ( imm.size() ) + { + replace( imm.front() ) ; + imm.pop(); + } printDebugMessage( "peoSyncIslandMig: receiving some immigrants." ); } @@ -292,19 +294,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: operato { if ( cont.check() ) - { - explicitPassive = standbyMigration = false; - topology.setNeighbors( this, in, out ); all = topology; - nbMigrations = 0; - synchronizeCoopEx(); stop(); - // sending emigrants - emigrate(); - // synchronizing - sem_wait( &sync ); - // receiving immigrants - immigrate(); - synchronizeCoopEx(); stop(); - } + { + explicitPassive = standbyMigration = false; + topology.setNeighbors( this, in, out ); + all = topology; + nbMigrations = 0; + synchronizeCoopEx(); + stop(); + // sending emigrants + emigrate(); + // synchronizing + sem_wait( &sync ); + // receiving immigrants + immigrate(); + synchronizeCoopEx(); + stop(); + } } template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifySending() @@ -316,19 +321,22 @@ template< class EOT, class TYPE > void peoSyncIslandMig< EOT , TYPE > :: notifyR { nbMigrations++; - if ( nbMigrations == in.size() ) { + if ( nbMigrations == in.size() ) + { - if ( standbyMigration ) getOwner()->setActive(); - sem_post( &sync ); - } + if ( standbyMigration ) getOwner()->setActive(); + sem_post( &sync ); + } } -template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq () { +template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySendingSyncReq () +{ getOwner()->setPassive(); } -template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized () { +template< class EOT, class TYPE > void peoSyncIslandMig< EOT, TYPE > :: notifySynchronized () +{ standbyMigration = true; getOwner()->setActive(); diff --git a/trunk/paradiseo-peo/src/peoTransform.h b/trunk/paradiseo-peo/src/peoTransform.h index b7f43b386..a1035a780 100644 --- a/trunk/paradiseo-peo/src/peoTransform.h +++ b/trunk/paradiseo-peo/src/peoTransform.h @@ -47,49 +47,49 @@ extern int getNodeRank(); template< class EOT > class peoTransform : public Service, public eoTransform< EOT > -{ + { -public: + public: - peoTransform( + peoTransform( - eoQuadOp< EOT >& __cross, - double __cross_rate, - eoMonOp< EOT >& __mut, - double __mut_rate - ); + eoQuadOp< EOT >& __cross, + double __cross_rate, + eoMonOp< EOT >& __mut, + double __mut_rate + ); - void operator()( eoPop< EOT >& __pop ); + void operator()( eoPop< EOT >& __pop ); - void packData(); + void packData(); - void unpackData(); + void unpackData(); - void execute(); + void execute(); - void packResult(); + void packResult(); - void unpackResult(); + void unpackResult(); - void notifySendingData(); - void notifySendingAllResourceRequests(); + void notifySendingData(); + void notifySendingAllResourceRequests(); -private: + private: - eoQuadOp< EOT >& cross; - double cross_rate; + eoQuadOp< EOT >& cross; + double cross_rate; - eoMonOp< EOT >& mut; - double mut_rate; + eoMonOp< EOT >& mut; + double mut_rate; - unsigned idx; + unsigned idx; - eoPop< EOT >* pop; + eoPop< EOT >* pop; - EOT father, mother; + EOT father, mother; - unsigned num_term; -}; + unsigned num_term; + }; template< class EOT > peoTransform< EOT > :: peoTransform( @@ -151,11 +151,11 @@ template< class EOT > void peoTransform< EOT > :: unpackResult() // Can be used with an odd size if ( num_term == 2*(pop->size()/2) ) - { + { - getOwner()->setActive(); - resume(); - } + getOwner()->setActive(); + resume(); + } } diff --git a/trunk/paradiseo-peo/src/peoWrapper.h b/trunk/paradiseo-peo/src/peoWrapper.h index 1e380d2c8..e1d210328 100644 --- a/trunk/paradiseo-peo/src/peoWrapper.h +++ b/trunk/paradiseo-peo/src/peoWrapper.h @@ -45,117 +45,117 @@ class peoWrapper : public Runner -{ + { - public: + public: - template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm ) - : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) + template< typename AlgorithmType > peoWrapper( AlgorithmType& externalAlgorithm ) + : algorithm( new Algorithm< AlgorithmType, void >( externalAlgorithm ) ) {} - template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) - : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) + template< typename AlgorithmType, typename AlgorithmDataType > peoWrapper( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) + : algorithm( new Algorithm< AlgorithmType, AlgorithmDataType >( externalAlgorithm, externalData ) ) {} - template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() ) - : algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) ) + template< typename AlgorithmReturnType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)() ) + : algorithm( new FunctionAlgorithm< AlgorithmReturnType, void >( externalAlgorithm ) ) {} - template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) - : algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) ) + template< typename AlgorithmReturnType, typename AlgorithmDataType > peoWrapper( AlgorithmReturnType& (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) + : algorithm( new FunctionAlgorithm< AlgorithmReturnType, AlgorithmDataType >( externalAlgorithm, externalData ) ) {} - ~peoWrapper() + ~peoWrapper() { delete algorithm; } - void run() - { - algorithm->operator()(); - } + void run() + { + algorithm->operator()(); + } - private: + private: - struct AbstractAlgorithm - { + struct AbstractAlgorithm + { - // virtual destructor as we will be using inheritance and polymorphism - virtual ~AbstractAlgorithm() - { } + // virtual destructor as we will be using inheritance and polymorphism + virtual ~AbstractAlgorithm() + { } - // operator to be called for executing the algorithm - virtual void operator()() - { } - }; + // operator to be called for executing the algorithm + virtual void operator()() + { } + }; template< typename AlgorithmType, typename AlgorithmDataType > struct Algorithm : public AbstractAlgorithm - { + { - Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) - : algorithm( externalAlgorithm ), algorithmData( externalData ) - {} + Algorithm( AlgorithmType& externalAlgorithm, AlgorithmDataType& externalData ) + : algorithm( externalAlgorithm ), algorithmData( externalData ) + {} - virtual void operator()() - { - algorithm( algorithmData ); - } + virtual void operator()() + { + algorithm( algorithmData ); + } - AlgorithmType& algorithm; - AlgorithmDataType& algorithmData; - }; + AlgorithmType& algorithm; + AlgorithmDataType& algorithmData; + }; template< typename AlgorithmType > struct Algorithm< AlgorithmType, void > : public AbstractAlgorithm - { + { - Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) - {} + Algorithm( AlgorithmType& externalAlgorithm ) : algorithm( externalAlgorithm ) + {} - virtual void operator()() - { - algorithm(); - } + virtual void operator()() + { + algorithm(); + } - AlgorithmType& algorithm; - }; + AlgorithmType& algorithm; + }; template< typename AlgorithmReturnType, typename AlgorithmDataType > struct FunctionAlgorithm : public AbstractAlgorithm - { + { - FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) - : algorithm( externalAlgorithm ), algorithmData( externalData ) - {} + FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)( AlgorithmDataType& ), AlgorithmDataType& externalData ) + : algorithm( externalAlgorithm ), algorithmData( externalData ) + {} - virtual void operator()() - { - algorithm( algorithmData ); - } + virtual void operator()() + { + algorithm( algorithmData ); + } - AlgorithmReturnType (*algorithm)( AlgorithmDataType& ); - AlgorithmDataType& algorithmData; - }; + AlgorithmReturnType (*algorithm)( AlgorithmDataType& ); + AlgorithmDataType& algorithmData; + }; template< typename AlgorithmReturnType > struct FunctionAlgorithm< AlgorithmReturnType, void > : public AbstractAlgorithm - { + { - FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() ) - : algorithm( externalAlgorithm ) - {} + FunctionAlgorithm( AlgorithmReturnType (*externalAlgorithm)() ) + : algorithm( externalAlgorithm ) + {} - virtual void operator()() - { - algorithm(); - } + virtual void operator()() + { + algorithm(); + } - AlgorithmReturnType (*algorithm)(); + AlgorithmReturnType (*algorithm)(); + }; + + private: + + AbstractAlgorithm* algorithm; }; - private: - - AbstractAlgorithm* algorithm; -}; - #endif diff --git a/trunk/paradiseo-peo/src/rmc/mpi/comm.cpp b/trunk/paradiseo-peo/src/rmc/mpi/comm.cpp index 7210f1202..0cac09fca 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/comm.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/comm.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -52,29 +52,32 @@ static sem_t sem_comm_init; static Communicator * the_thread; -Communicator :: Communicator (int * __argc, char * * * __argv) { +Communicator :: Communicator (int * __argc, char * * * __argv) +{ - the_thread = this; + the_thread = this; initNode (__argc, __argv); loadRMCParameters (* __argc, * __argv); sem_post (& sem_comm_init); } -void Communicator :: start () { +void Communicator :: start () +{ - while (true) { + while (true) + { - /* Zzz Zzz Zzz :-))) */ - sleep (); + /* Zzz Zzz Zzz :-))) */ + sleep (); - sendMessages (); + sendMessages (); - if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ()) - break; + if (! atLeastOneActiveRunner () && ! atLeastOneActiveThread() && allResourcesFree ()) + break; - receiveMessages (); - } + receiveMessages (); + } waitBuffers (); printDebugMessage ("finalizing"); @@ -82,24 +85,28 @@ void Communicator :: start () { //synchronizeNodes (); } -void initCommunication () { +void initCommunication () +{ static bool initializedSemaphore = false; - if (initializedSemaphore) { - sem_destroy(& sem_comm_init); - } + if (initializedSemaphore) + { + sem_destroy(& sem_comm_init); + } sem_init (& sem_comm_init, 0, 0); initializedSemaphore = true; } -void waitNodeInitialization () { +void waitNodeInitialization () +{ sem_wait (& sem_comm_init); } -void wakeUpCommunicator () { +void wakeUpCommunicator () +{ the_thread -> wakeUp (); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/comm.h b/trunk/paradiseo-peo/src/rmc/mpi/comm.h index 7a343a595..ef19fa9ac 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/comm.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/comm.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -40,15 +40,16 @@ #include "../../core/communicable.h" #include "../../core/reac_thread.h" -class Communicator : public ReactiveThread { +class Communicator : public ReactiveThread + { -public : + public : - /* Ctor */ - Communicator (int * __argc, char * * * __argv); + /* Ctor */ + Communicator (int * __argc, char * * * __argv); - void start (); -}; + void start (); + }; extern void initCommunication (); diff --git a/trunk/paradiseo-peo/src/rmc/mpi/cooperative.cpp b/trunk/paradiseo-peo/src/rmc/mpi/cooperative.cpp index 8d750f4aa..ab12e5510 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/cooperative.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/cooperative.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,42 +41,48 @@ #include "mess.h" #include "../../core/peo_debug.h" -Runner * Cooperative :: getOwner () { +Runner * Cooperative :: getOwner () +{ return owner; } -void Cooperative :: setOwner (Runner & __runner) { +void Cooperative :: setOwner (Runner & __runner) +{ owner = & __runner; } -void Cooperative :: send (Cooperative * __coop) { +void Cooperative :: send (Cooperative * __coop) +{ :: send (this, getRankOfRunner (__coop -> getOwner () -> getDefinitionID ()), COOP_TAG); // stop (); } -void Cooperative :: synchronizeCoopEx () { +void Cooperative :: synchronizeCoopEx () +{ :: send (this, my_node -> rk_sched, SYNCHRONIZE_REQ_TAG); } -Cooperative * getCooperative (COOP_ID __key) { +Cooperative * getCooperative (COOP_ID __key) +{ return dynamic_cast (getCommunicable (__key)); } -void Cooperative :: notifySending () { +void Cooperative :: notifySending () +{ //getOwner -> setPassive (); // resume (); } -void Cooperative :: notifyReceiving () { -} +void Cooperative :: notifyReceiving () +{} -void Cooperative :: notifySendingSyncReq () { -} +void Cooperative :: notifySendingSyncReq () +{} -void Cooperative :: notifySynchronized () { -} +void Cooperative :: notifySynchronized () +{} diff --git a/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp b/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp index 075780378..af93c5117 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -42,62 +42,69 @@ #include "node.h" #define MPI_BUF_SIZE 1024*64 - + static char mpi_buf [MPI_BUF_SIZE]; - + static int pos_buf; static std :: vector act_buf; /* Active buffers */ static std :: vector act_req; /* Active requests */ -void initBuffers () { +void initBuffers () +{ pos_buf = 0; act_buf.clear (); act_req.clear (); } -void cleanBuffers () { +void cleanBuffers () +{ - for (unsigned i = 0; i < act_req.size ();) { + for (unsigned i = 0; i < act_req.size ();) + { - MPI_Status stat ; - int flag ; + MPI_Status stat ; + int flag ; - MPI_Test (act_req [i], & flag, & stat) ; - if (flag) { + MPI_Test (act_req [i], & flag, & stat) ; + if (flag) + { - delete[] act_buf [i] ; - delete act_req [i] ; - - act_buf [i] = act_buf.back () ; - act_buf.pop_back () ; + delete[] act_buf [i] ; + delete act_req [i] ; - act_req [i] = act_req.back () ; - act_req.pop_back () ; + act_buf [i] = act_buf.back () ; + act_buf.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"); - 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; @@ -111,19 +118,22 @@ bool probeMessage (int & __src, int & __tag) { return flag; } -void waitMessage () { +void waitMessage () +{ - MPI_Status stat; + MPI_Status stat; MPI_Probe (MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, & stat); } -void initMessage () { +void initMessage () +{ pos_buf = 0; } -void sendMessage (int __to, int __tag) { +void sendMessage (int __to, int __tag) +{ cleanBuffers (); act_buf.push_back (new char [pos_buf]); @@ -132,13 +142,15 @@ void sendMessage (int __to, int __tag) { MPI_Isend (act_buf.back (), pos_buf, MPI_PACKED, __to, __tag, MPI_COMM_WORLD, act_req.back ()); } -void sendMessageToAll (int __tag) { +void sendMessageToAll (int __tag) +{ for (int i = 0; i < getNumberOfNodes (); i ++) sendMessage (i, __tag); } -void receiveMessage (int __from, int __tag) { +void receiveMessage (int __from, int __tag) +{ MPI_Status stat; MPI_Request req; @@ -147,80 +159,93 @@ void receiveMessage (int __from, int __tag) { MPI_Wait (& req, & stat); } -void synchronizeNodes () { +void synchronizeNodes () +{ MPI_Barrier ( MPI_COMM_WORLD ); } /* Char */ -void pack (const char & __c) { +void pack (const char & __c) +{ MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Boolean */ -void pack (const bool & __b, int __nitem){ +void pack (const bool & __b, int __nitem) +{ MPI_Pack ((void *) & __b, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Float */ -void pack (const float & __f, int __nitem) { +void pack (const float & __f, int __nitem) +{ MPI_Pack ((void *) & __f, __nitem, MPI_FLOAT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Double */ -void pack (const double & __d, int __nitem) { +void pack (const double & __d, int __nitem) +{ MPI_Pack ((void *) & __d, __nitem, MPI_DOUBLE, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Integer */ -void pack (const int & __i, int __nitem) { +void pack (const int & __i, int __nitem) +{ MPI_Pack ((void *) & __i, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Unsigned int. */ -void pack (const unsigned int & __ui, int __nitem) { +void pack (const unsigned int & __ui, int __nitem) +{ MPI_Pack ((void *) & __ui, __nitem, MPI_UNSIGNED, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Short int. */ -void pack (const short & __sh, int __nitem) { +void pack (const short & __sh, int __nitem) +{ MPI_Pack ((void *) & __sh, __nitem, MPI_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Unsigned short */ -void pack (const unsigned short & __ush, int __nitem) { +void pack (const unsigned short & __ush, int __nitem) +{ MPI_Pack ((void *) & __ush, __nitem, MPI_UNSIGNED_SHORT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Long */ -void pack (const long & __l, int __nitem) { +void pack (const long & __l, int __nitem) +{ MPI_Pack ((void *) & __l, __nitem, MPI_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* Unsigned long */ -void pack (const unsigned long & __ul, int __nitem) { +void pack (const unsigned long & __ul, int __nitem) +{ MPI_Pack ((void *) & __ul, __nitem, MPI_UNSIGNED_LONG, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } /* String */ -void pack (const char * __str) { +void pack (const char * __str) +{ int len = strlen (__str) + 1; MPI_Pack (& len, 1, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } -void pack (const std::string & __str) { +void pack (const std::string & __str) +{ size_t size = __str.size() + 1; char * buffer = new char[ size ]; @@ -230,79 +255,91 @@ void pack (const std::string & __str) { } /* Char */ -void unpack (char & __c) { +void unpack (char & __c) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD); } /* Boolean */ -extern void unpack (bool & __b, int __nitem ){ +extern void unpack (bool & __b, int __nitem ) + { - MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD); -} + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD); + } /* Float */ -void unpack (float & __f, int __nitem) { +void unpack (float & __f, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __f, __nitem, MPI_FLOAT, MPI_COMM_WORLD); } /* Double */ -void unpack (double & __d, int __nitem) { +void unpack (double & __d, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __d, __nitem, MPI_DOUBLE, MPI_COMM_WORLD); } /* Integer */ -void unpack (int & __i, int __nitem) { +void unpack (int & __i, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __i, __nitem, MPI_INT, MPI_COMM_WORLD); } /* Unsigned int. */ -void unpack (unsigned int & __ui, int __nitem) { +void unpack (unsigned int & __ui, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ui, __nitem, MPI_UNSIGNED, MPI_COMM_WORLD); } /* Short int. */ -void unpack (short & __sh, int __nitem) { +void unpack (short & __sh, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __sh, __nitem, MPI_SHORT, MPI_COMM_WORLD); } /* Unsigned short */ -void unpack (unsigned short & __ush, int __nitem) { +void unpack (unsigned short & __ush, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ush, __nitem, MPI_UNSIGNED_SHORT, MPI_COMM_WORLD); } /* Long */ -void unpack (long & __l, int __nitem) { +void unpack (long & __l, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __l, __nitem, MPI_LONG, MPI_COMM_WORLD); } /* Unsigned long */ -void unpack (unsigned long & __ul, int __nitem) { +void unpack (unsigned long & __ul, int __nitem) +{ MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __ul, __nitem, MPI_UNSIGNED_LONG, MPI_COMM_WORLD); } /* String */ -void unpack (char * __str) { +void unpack (char * __str) +{ int len; MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD); - MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD); + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD); } -void unpack (std::string & __str) { - +void unpack (std::string & __str) +{ + char * buffer; int len; 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, buffer, len, MPI_CHAR, MPI_COMM_WORLD); - __str.assign( buffer ); - + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, buffer, len, MPI_CHAR, MPI_COMM_WORLD); + __str.assign( buffer ); + } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/mess.h b/trunk/paradiseo-peo/src/rmc/mpi/mess.h index f7efecee7..ac57c5665 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/mess.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/mess.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/node.cpp b/trunk/paradiseo-peo/src/rmc/mpi/node.cpp index e1e3707ce..ca996fcd7 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/node.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/node.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,50 +43,57 @@ #include "mess.h" -class MPIThreadedEnv { +class MPIThreadedEnv + { -public: + public: - static void init ( int * __argc, char * * * __argv ) { + static void init ( int * __argc, char * * * __argv ) + { - static MPIThreadedEnv mpiThreadedEnv( __argc, __argv ); - } - - static void finalize () { - - static bool finalizedEnvironment = false; - - if (! finalizedEnvironment ) { - - MPI_Finalize (); - finalizedEnvironment = true; + static MPIThreadedEnv mpiThreadedEnv( __argc, __argv ); } - } -private: + static void finalize () + { - /* No instance of this class can be created outside its domain! */ - MPIThreadedEnv ( int * __argc, char * * * __argv ) { + static bool finalizedEnvironment = false; - static bool MPIThreadedEnvInitialized = false; - int provided = 1; + if (! finalizedEnvironment ) + { - if (! MPIThreadedEnvInitialized) { - - MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided); - - assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded. - Yet, only one thread performs the comm. - operations */ - MPIThreadedEnvInitialized = true; + MPI_Finalize (); + finalizedEnvironment = true; + } } - } - ~MPIThreadedEnv() { + private: - finalize (); - } -}; + /* No instance of this class can be created outside its domain! */ + MPIThreadedEnv ( int * __argc, char * * * __argv ) + { + + static bool MPIThreadedEnvInitialized = false; + int provided = 1; + + if (! MPIThreadedEnvInitialized) + { + + MPI_Init_thread (__argc, __argv, MPI_THREAD_FUNNELED, & provided); + + assert (provided == MPI_THREAD_FUNNELED); /* The MPI implementation must be multi-threaded. + Yet, only one thread performs the comm. + operations */ + MPIThreadedEnvInitialized = true; + } + } + + ~MPIThreadedEnv() + { + + finalize (); + } + }; static int rk, sz; /* Rank & size */ @@ -96,27 +103,32 @@ static std :: map name_to_rk; static std :: vector rk_to_name; -int getNodeRank () { +int getNodeRank () +{ return rk; } -int getNumberOfNodes () { +int getNumberOfNodes () +{ return sz; } -void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners ) { +void collectiveCountOfRunners ( unsigned int* num_local_exec_runners, unsigned int* num_exec_runners ) +{ MPI_Allreduce( num_local_exec_runners, num_exec_runners, 1, MPI_UNSIGNED, MPI_SUM, MPI_COMM_WORLD ); } -int getRankFromName (const std :: string & __name) { +int getRankFromName (const std :: string & __name) +{ - return atoi (__name.c_str ()); + return atoi (__name.c_str ()); } -void initNode (int * __argc, char * * * __argv) { +void initNode (int * __argc, char * * * __argv) +{ rk_to_name.clear (); name_to_rk.clear (); @@ -130,12 +142,13 @@ void initNode (int * __argc, char * * * __argv) { char names [sz] [MPI_MAX_PROCESSOR_NAME]; int len; - /* Processor names */ - MPI_Get_processor_name (names [0], & len); /* Me */ + /* Processor names */ + MPI_Get_processor_name (names [0], & len); /* Me */ MPI_Allgather (names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, names, MPI_MAX_PROCESSOR_NAME, MPI_CHAR, MPI_COMM_WORLD); /* Broadcast */ - for (int i = 0; i < sz; i ++) { - rk_to_name.push_back (names [i]); - name_to_rk [names [i]] = i; - } + for (int i = 0; i < sz; i ++) + { + rk_to_name.push_back (names [i]); + name_to_rk [names [i]] = i; + } } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/node.h b/trunk/paradiseo-peo/src/rmc/mpi/node.h index 92d289bc1..631ad873a 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/node.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/node.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,15 +44,16 @@ typedef int RANK_ID; -struct Node { +struct Node + { - RANK_ID rk; /* Rank */ - std :: string name; /* Host name */ - unsigned num_workers; /* Number of parallel workers */ - int rk_sched; /* rank of the scheduler */ - std :: vector id_run; /* List of runner def. IDs */ - std :: vector execution_id_run; /* List of runtime execution runner IDs */ -}; + RANK_ID rk; /* Rank */ + std :: string name; /* Host name */ + unsigned num_workers; /* Number of parallel workers */ + int rk_sched; /* rank of the scheduler */ + std :: vector id_run; /* List of runner def. IDs */ + std :: vector execution_id_run; /* List of runtime execution runner IDs */ + }; extern Node * my_node; diff --git a/trunk/paradiseo-peo/src/rmc/mpi/param.cpp b/trunk/paradiseo-peo/src/rmc/mpi/param.cpp index 821e58179..c0cb02d9e 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/param.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/param.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -38,7 +38,8 @@ #include "schema.h" -void loadRMCParameters (int & __argc, char * * & __argv) { +void loadRMCParameters (int & __argc, char * * & __argv) +{ eoParser parser (__argc, __argv); diff --git a/trunk/paradiseo-peo/src/rmc/mpi/param.h b/trunk/paradiseo-peo/src/rmc/mpi/param.h index b868a1db7..9d36e9241 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/param.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/param.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/recv.cpp b/trunk/paradiseo-peo/src/rmc/mpi/recv.cpp index 4562cd8dd..4966fb384 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/recv.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/recv.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -45,106 +45,112 @@ #include "../../core/cooperative.h" #include "../../core/peo_debug.h" -void receiveMessages () { +void receiveMessages () +{ cleanBuffers (); - do { + do + { - if (! atLeastOneActiveThread ()) { - - waitMessage (); - } - - int src, tag; - - while (probeMessage (src, tag)) { - - receiveMessage (src, tag); - initMessage (); - - switch (tag) { - - case RUNNER_STOP_TAG: - unpackTerminationOfRunner (); - break; - - case SYNCHRONIZE_REQ_TAG: - unpackSynchronRequest (); - break; - - case SYNCHRONIZED_TAG: + if (! atLeastOneActiveThread ()) { - RUNNER_ID runner_id; - unpack (runner_id); - COOP_ID coop_id; - unpack (coop_id); - - getCooperative (coop_id) -> notifySynchronized (); - break; + waitMessage (); } - case COOP_TAG: - COOP_ID coop_id; - unpack (coop_id); - getCooperative (coop_id) -> unpack (); - getCooperative (coop_id) -> notifyReceiving (); - break; + int src, tag; - case SCHED_REQUEST_TAG: - unpackResourceRequest (); - break; - - case SCHED_RESULT_TAG: + while (probeMessage (src, 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 ... */ + receiveMessage (src, tag); initMessage (); - pack (worker_id); - pack (serv_id); - serv -> packData (); - serv -> notifySendingData (); - sendMessage (dest, TASK_DATA_TAG); - break; + + switch (tag) + { + + case RUNNER_STOP_TAG: + unpackTerminationOfRunner (); + break; + + case SYNCHRONIZE_REQ_TAG: + unpackSynchronRequest (); + break; + + case SYNCHRONIZED_TAG: + { + RUNNER_ID runner_id; + unpack (runner_id); + + COOP_ID coop_id; + unpack (coop_id); + + getCooperative (coop_id) -> notifySynchronized (); + break; + } + + case COOP_TAG: + COOP_ID coop_id; + unpack (coop_id); + getCooperative (coop_id) -> unpack (); + getCooperative (coop_id) -> notifyReceiving (); + 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: + ; + }; } - 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 ()*/ ); + while ( ! atLeastOneActiveThread () && atLeastOneActiveRunner () /*&& ! allResourcesFree ()*/ ); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/recv.h b/trunk/paradiseo-peo/src/rmc/mpi/recv.h index ad6eec330..80ab6bc95 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/recv.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/recv.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/rmc.cpp b/trunk/paradiseo-peo/src/rmc/mpi/rmc.cpp index 34e30a94a..af57cdb78 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/rmc.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/rmc.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -46,18 +46,21 @@ static std :: vector worker_threads; /* Worker threads */ static Communicator* communicator_thread = NULL; /* Communicator thread */ -void runRMC () { +void runRMC () +{ /* Worker(s) ? */ - for (unsigned i = 0; i < my_node -> num_workers; i ++) { - worker_threads.push_back (new Worker); - addThread (worker_threads.back(), ll_threads); - } + for (unsigned i = 0; i < my_node -> num_workers; i ++) + { + worker_threads.push_back (new Worker); + addThread (worker_threads.back(), ll_threads); + } wakeUpCommunicator (); } -void initRMC (int & __argc, char * * & __argv) { +void initRMC (int & __argc, char * * & __argv) +{ /* Communication */ initCommunication (); @@ -71,14 +74,16 @@ void initRMC (int & __argc, char * * & __argv) { initScheduler (); } -void finalizeRMC () { +void finalizeRMC () +{ printDebugMessage ("before join threads RMC"); joinThreads (ll_threads); - for (unsigned i = 0; i < worker_threads.size(); i++ ) { - delete worker_threads [i]; - } + for (unsigned i = 0; i < worker_threads.size(); i++ ) + { + delete worker_threads [i]; + } worker_threads.clear (); delete communicator_thread; diff --git a/trunk/paradiseo-peo/src/rmc/mpi/runner.cpp b/trunk/paradiseo-peo/src/rmc/mpi/runner.cpp index 67fb3e9fe..34ba0b582 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/runner.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/runner.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -43,7 +43,8 @@ #include "schema.h" -bool Runner :: isAssignedLocally () { +bool Runner :: isAssignedLocally () +{ for (unsigned i = 0; i < my_node -> id_run.size (); i ++) if (my_node -> id_run [i] == def_id) @@ -51,12 +52,14 @@ bool Runner :: isAssignedLocally () { return false; } -void Runner :: terminate () { +void Runner :: terminate () +{ sendToAll (this, RUNNER_STOP_TAG); } -void Runner :: packTermination () { +void Runner :: packTermination () +{ pack (def_id); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/scheduler.cpp b/trunk/paradiseo-peo/src/rmc/mpi/scheduler.cpp index 617c81cf5..21f924786 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/scheduler.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/scheduler.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -49,52 +49,59 @@ static unsigned initNumberOfRes = 0; extern void wakeUpCommunicator(); -void initScheduler () { +void initScheduler () +{ resources = std :: queue (); requests = std :: queue (); initNumberOfRes = 0; - for (unsigned i = 0; i < the_schema.size (); i ++) { + for (unsigned i = 0; i < the_schema.size (); i ++) + { - const Node & node = the_schema [i]; + const Node & node = the_schema [i]; - if (node.rk_sched == my_node -> rk) - for (unsigned j = 0; j < node.num_workers; j ++) - resources.push (std :: pair (i, j + 1)); - } + if (node.rk_sched == my_node -> rk) + for (unsigned j = 0; j < node.num_workers; j ++) + resources.push (std :: pair (i, j + 1)); + } initNumberOfRes = resources.size (); } -bool allResourcesFree () { +bool allResourcesFree () +{ return resources.size () == initNumberOfRes; } -unsigned numResourcesFree () { +unsigned numResourcesFree () +{ return resources.size (); } -static void update () { +static void update () +{ unsigned num_alloc = std :: min (resources.size (), requests.size ()); - for (unsigned i = 0; i < num_alloc; i ++) { + for (unsigned i = 0; i < num_alloc; i ++) + { - SCHED_REQUEST req = requests.front (); - requests.pop (); + SCHED_REQUEST req = requests.front (); + requests.pop (); - SCHED_RESOURCE res = resources.front (); - resources.pop (); + SCHED_RESOURCE res = resources.front (); + resources.pop (); - printDebugMessage ("allocating a resource."); - initMessage (); - pack (req.second); - pack (res); - sendMessage (req.first, SCHED_RESULT_TAG); - } + 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."); SCHED_REQUEST req; @@ -103,7 +110,8 @@ void unpackResourceRequest () { update (); } -void unpackTaskDone () { +void unpackTaskDone () +{ printDebugMessage ("I'm notified a worker is now idle."); SCHED_RESOURCE res; diff --git a/trunk/paradiseo-peo/src/rmc/mpi/scheduler.h b/trunk/paradiseo-peo/src/rmc/mpi/scheduler.h index f5fc71a13..186b33c78 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/scheduler.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/scheduler.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -53,7 +53,7 @@ extern void initScheduler (); extern void unpackResourceRequest (); /* Being known a worker is now idle :-) */ -extern void unpackTaskDone (); +extern void unpackTaskDone (); extern bool allResourcesFree (); diff --git a/trunk/paradiseo-peo/src/rmc/mpi/schema.cpp b/trunk/paradiseo-peo/src/rmc/mpi/schema.cpp index b1185d365..5cd27a425 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/schema.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/schema.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -51,17 +51,19 @@ Node * my_node; static unsigned maxSpecifiedRunnerID = 0; -RANK_ID getRankOfRunner (RUNNER_ID __key) { +RANK_ID getRankOfRunner (RUNNER_ID __key) +{ for (unsigned i = 0; i < the_schema.size (); i ++) for (unsigned j = 0; j < the_schema [i].id_run.size (); j ++) if (the_schema [i].id_run [j] == __key) return the_schema [i].rk; assert (false); - return 0; + return 0; } -static void loadNode (int __rk_sched) { +static void loadNode (int __rk_sched) +{ Node node; @@ -72,55 +74,62 @@ static void loadNode (int __rk_sched) { /* ATT: num_workers */ node.num_workers = atoi (getAttributeValue ("num_workers").c_str ()); - while (true) { + while (true) + { - /* TAG: | */ - std :: string name = getNextNode (); - assert (name == "runner" || name == "node"); - if (name == "runner") { - /* TAG: */ - node.id_run.push_back (atoi (getNextNode ().c_str ())); - if ( node.id_run.back() > maxSpecifiedRunnerID ) - maxSpecifiedRunnerID = node.id_run.back(); - /* TAG: */ - assert (getNextNode () == "runner"); + /* TAG: | */ + std :: string name = getNextNode (); + assert (name == "runner" || name == "node"); + if (name == "runner") + { + /* TAG: */ + node.id_run.push_back (atoi (getNextNode ().c_str ())); + if ( node.id_run.back() > maxSpecifiedRunnerID ) + maxSpecifiedRunnerID = node.id_run.back(); + /* TAG: */ + assert (getNextNode () == "runner"); + } + else + { + /* TAG: */ + node.execution_id_run = node.id_run; + the_schema.push_back (node); + break; + } } - else { - /* TAG: */ - node.execution_id_run = node.id_run; - the_schema.push_back (node); - break; - } - } } -static void loadGroup () { +static void loadGroup () +{ std :: string name; /* ATT: scheduler*/ int rk_sched = getRankFromName (getAttributeValue ("scheduler")); - while (true) { + while (true) + { - /* TAG: | */ - name = getNextNode (); - assert (name == "node" || name == "group"); - if (name == "node") - /* TAG: */ - loadNode (rk_sched); - else - /* TAG: */ - break; - } + /* TAG: | */ + name = getNextNode (); + assert (name == "node" || name == "group"); + if (name == "node") + /* TAG: */ + loadNode (rk_sched); + else + /* TAG: */ + break; + } } -bool isScheduleNode () { +bool isScheduleNode () +{ return my_node -> rk == my_node -> rk_sched; } -void loadSchema (const char * __filename) { +void loadSchema (const char * __filename) +{ openXMLDocument (__filename); @@ -133,37 +142,43 @@ void loadSchema (const char * __filename) { the_schema.clear(); maxSpecifiedRunnerID = 0; - while (true) { + while (true) + { - /* TAG: | */ - name = getNextNode (); - assert (name == "group" || name == "schema"); - if (name == "group") - /* TAG: */ - loadGroup (); - else - /* TAG: */ - break; - } - - - std :: set 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(); + /* TAG: | */ + name = getNextNode (); + assert (name == "group" || name == "schema"); + if (name == "group") + /* TAG: */ + loadGroup (); + else + /* TAG: */ + break; + } + + + std :: set 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 */ - for (unsigned i = 0; i < the_schema.size (); i ++) { - if (the_schema [i].rk == getNodeRank ()) - my_node = & (the_schema [i]); - } + for (unsigned i = 0; i < the_schema.size (); i ++) + { + if (the_schema [i].rk == getNodeRank ()) + my_node = & (the_schema [i]); + } /* About me */ @@ -175,16 +190,18 @@ void loadSchema (const char * __filename) { 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); - } + for (unsigned i = 0; i < my_node -> id_run.size (); i ++) + { + sprintf (mess, "I manage the runner %d", my_node -> id_run [i]); + printDebugMessage (mess); + } - if (my_node -> num_workers) { + if (my_node -> num_workers) + { - sprintf (mess, "I manage %d worker(s)", my_node -> num_workers); - printDebugMessage (mess); - } + sprintf (mess, "I manage %d worker(s)", my_node -> num_workers); + printDebugMessage (mess); + } closeXMLDocument (); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/schema.h b/trunk/paradiseo-peo/src/rmc/mpi/schema.h index 30e061c2c..ef46f54ab 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/schema.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/schema.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/send.cpp b/trunk/paradiseo-peo/src/rmc/mpi/send.cpp index cf10b9b6e..e78cb6e12 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/send.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/send.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -50,13 +50,15 @@ #define TO_ALL -1 -typedef struct { +typedef struct + { - Communicable * comm; - int to; - int tag; + Communicable * comm; + int to; + int tag; -} SEND_REQUEST; + } +SEND_REQUEST; static std :: queue mess; @@ -66,15 +68,17 @@ static sem_t sem_send; static bool contextInitialized = false; -void initSending () { +void initSending () +{ static bool initializedSemaphore = false; mess = std :: queue (); - if (initializedSemaphore) { - sem_destroy(& sem_send); - } + if (initializedSemaphore) + { + sem_destroy(& sem_send); + } sem_init (& sem_send, 0, 1); initializedSemaphore = true; @@ -82,9 +86,10 @@ void initSending () { contextInitialized = false; } -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.to = __to; req.tag = __tag; @@ -95,74 +100,79 @@ void send (Communicable * __comm, int __to, int __tag) { wakeUpCommunicator (); } -void sendToAll (Communicable * __comm, int __tag) { +void sendToAll (Communicable * __comm, int __tag) +{ send (__comm, TO_ALL, __tag); } extern void initializeContext (); -void sendMessages () { +void sendMessages () +{ - if (! contextInitialized) { - contextInitialized = true; - initializeContext(); - } + if (! contextInitialized) + { + contextInitialized = true; + initializeContext(); + } sem_wait (& sem_send); - while (! mess.empty ()) { + while (! mess.empty ()) + { - SEND_REQUEST req = mess.front (); + SEND_REQUEST req = mess.front (); - Communicable * comm = req.comm; + Communicable * comm = req.comm; - initMessage (); + initMessage (); - switch (req.tag) { + switch (req.tag) + { - case RUNNER_STOP_TAG: - dynamic_cast (comm) -> packTermination (); - dynamic_cast (comm) -> notifySendingTermination (); - break; + case RUNNER_STOP_TAG: + dynamic_cast (comm) -> packTermination (); + dynamic_cast (comm) -> notifySendingTermination (); + break; - case COOP_TAG: - dynamic_cast (comm) -> pack (); - dynamic_cast (comm) -> notifySending (); - break; + case COOP_TAG: + dynamic_cast (comm) -> pack (); + dynamic_cast (comm) -> notifySending (); + break; - case SYNCHRONIZE_REQ_TAG: - dynamic_cast (comm) -> packSynchronizeReq (); - dynamic_cast (comm) -> notifySendingSyncReq (); - break; + case SYNCHRONIZE_REQ_TAG: + dynamic_cast (comm) -> packSynchronizeReq (); + dynamic_cast (comm) -> notifySendingSyncReq (); + break; - case SCHED_REQUEST_TAG: - dynamic_cast (comm) -> packResourceRequest (); - dynamic_cast (comm) -> notifySendingResourceRequest (); - break; + case SCHED_REQUEST_TAG: + dynamic_cast (comm) -> packResourceRequest (); + dynamic_cast (comm) -> notifySendingResourceRequest (); + break; - case TASK_RESULT_TAG: - dynamic_cast (comm) -> packResult (); - dynamic_cast (comm) -> notifySendingResult (); - break; + case TASK_RESULT_TAG: + dynamic_cast (comm) -> packResult (); + dynamic_cast (comm) -> notifySendingResult (); + break; - case TASK_DONE_TAG: - dynamic_cast (comm) -> packTaskDone (); - dynamic_cast (comm) -> notifySendingTaskDone (); - break; + case TASK_DONE_TAG: + dynamic_cast (comm) -> packTaskDone (); + dynamic_cast (comm) -> notifySendingTaskDone (); + break; - default : - break; + default : + break; - }; + }; - if (req.to == TO_ALL) - sendMessageToAll (req.tag); - else - sendMessage (req.to, req.tag); + if (req.to == TO_ALL) + sendMessageToAll (req.tag); + else + sendMessage (req.to, req.tag); - mess.pop (); - } + mess.pop (); + } sem_post (& sem_send); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/send.h b/trunk/paradiseo-peo/src/rmc/mpi/send.h index b1bdc2300..deccf1799 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/send.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/send.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/service.cpp b/trunk/paradiseo-peo/src/rmc/mpi/service.cpp index df2556426..41b989447 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/service.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/service.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -41,14 +41,16 @@ #include "send.h" #include "scheduler.h" -void Service :: requestResourceRequest (unsigned __how_many) { +void Service :: requestResourceRequest (unsigned __how_many) +{ num_sent_rr = __how_many; for (unsigned i = 0; i < __how_many; i ++) send (this, my_node -> rk_sched, SCHED_REQUEST_TAG); } -void Service :: packResourceRequest () { +void Service :: packResourceRequest () +{ SCHED_REQUEST req; req.first = getNodeRank (); diff --git a/trunk/paradiseo-peo/src/rmc/mpi/synchron.cpp b/trunk/paradiseo-peo/src/rmc/mpi/synchron.cpp index 12468c226..b0a69dfb1 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/synchron.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/synchron.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -50,26 +50,30 @@ extern void wakeUpCommunicator(); extern RANK_ID getRankOfRunner (RUNNER_ID __key); /* Initializing the list of runners to be synchronized */ -void initSynchron () { +void initSynchron () +{ syncRunners = SYNC(); } /* packing a synchronization request from a service */ -void packSynchronRequest ( const std :: vector & coops ) { +void packSynchronRequest ( const std :: vector & coops ) +{ /* Number of coops to synchronize */ pack( (unsigned)( coops.size() ) ); /* Coops to synchronize */ - for (unsigned i = 0; i < coops.size(); i ++) { - pack( coops[ i ]->getOwner()->getDefinitionID() ); - pack( coops[ i ]->getKey() ); - } + for (unsigned i = 0; i < coops.size(); i ++) + { + pack( coops[ i ]->getOwner()->getDefinitionID() ); + pack( coops[ i ]->getKey() ); + } } /* Processing a synchronization request from a service */ -void unpackSynchronRequest () { +void unpackSynchronRequest () +{ unsigned req_num_entries; unpack (req_num_entries); @@ -79,45 +83,50 @@ void unpackSynchronRequest () { /* Adding entries for each of the runners to be synchronized */ SyncEntry req_entry; - for (unsigned i = 0; i < req_num_entries; i ++) { + for (unsigned i = 0; i < req_num_entries; i ++) + { - unpack (req_entry.runner); - unpack (req_entry.coop); + unpack (req_entry.runner); + unpack (req_entry.coop); - req_sync.first.push_back (req_entry); - } + req_sync.first.push_back (req_entry); + } /* Looking for the sync vector */ SYNC::iterator sync_it = syncRunners.find (req_sync); /* The vector does not exist - insert a new sync */ - if (sync_it == syncRunners.end ()) { - req_sync.second = 1; - syncRunners.insert (req_sync); - } - else { - - /* The vector exists - updating the entry */ - std::pair< SYNC_RUNNERS, unsigned >& sync_req_entry = const_cast< std::pair< SYNC_RUNNERS, unsigned >& > (*sync_it); - sync_req_entry.second ++; - - /* All the runners to be synchronized sent the SYNC_REQUEST signal */ - if (sync_req_entry.second == sync_req_entry.first.size()) { - - /* Remove the entry */ - syncRunners.erase (sync_it); - - /* Send SYNCHRONIZED signals to all the coop objects */ - for (unsigned i = 0; i < req_sync.first.size(); i ++) { - - initMessage (); - - pack (req_sync.first [i].runner); - pack (req_sync.first [i].coop); - - RANK_ID dest_rank = getRankOfRunner (req_sync.first [i].runner); - sendMessage (dest_rank, SYNCHRONIZED_TAG); - } + if (sync_it == syncRunners.end ()) + { + req_sync.second = 1; + syncRunners.insert (req_sync); + } + else + { + + /* The vector exists - updating the entry */ + std::pair< SYNC_RUNNERS, unsigned >& sync_req_entry = const_cast< std::pair< SYNC_RUNNERS, unsigned >& > (*sync_it); + sync_req_entry.second ++; + + /* All the runners to be synchronized sent the SYNC_REQUEST signal */ + if (sync_req_entry.second == sync_req_entry.first.size()) + { + + /* Remove the entry */ + syncRunners.erase (sync_it); + + /* Send SYNCHRONIZED signals to all the coop objects */ + for (unsigned i = 0; i < req_sync.first.size(); i ++) + { + + initMessage (); + + pack (req_sync.first [i].runner); + pack (req_sync.first [i].coop); + + RANK_ID dest_rank = getRankOfRunner (req_sync.first [i].runner); + sendMessage (dest_rank, SYNCHRONIZED_TAG); + } + } } - } } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/synchron.h b/trunk/paradiseo-peo/src/rmc/mpi/synchron.h index b9ac7e6b7..6f2d831af 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/synchron.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/synchron.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -44,31 +44,39 @@ #include "../../core/runner.h" #include "../../core/cooperative.h" -struct SyncEntry { +struct SyncEntry + { - RUNNER_ID runner; - COOP_ID coop; -}; + RUNNER_ID runner; + COOP_ID coop; + }; -struct SyncCompare { +struct SyncCompare + { - bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B ) { + bool operator()( const std::pair< std::vector< SyncEntry >, unsigned >& A, const std::pair< std::vector< SyncEntry >, unsigned >& B ) + { - const std::vector< SyncEntry >& syncA = A.first; - const std::vector< SyncEntry >& syncB = B.first; + const std::vector< SyncEntry >& syncA = A.first; + const std::vector< SyncEntry >& syncB = B.first; - if ( syncA.size() == syncB.size() ) { - std::vector< SyncEntry >::const_iterator itA = syncA.begin(); - std::vector< SyncEntry >::const_iterator itB = syncB.begin(); + if ( syncA.size() == syncB.size() ) + { + std::vector< SyncEntry >::const_iterator itA = syncA.begin(); + std::vector< SyncEntry >::const_iterator itB = syncB.begin(); - while ( (*itA).runner < (*itB).runner && itA != syncA.end() ) { itA++; itB++; } + while ( (*itA).runner < (*itB).runner && itA != syncA.end() ) + { + itA++; + itB++; + } - return itA == syncA.end(); + return itA == syncA.end(); + } + + return syncA.size() < syncB.size(); } - - return syncA.size() < syncB.size(); - } -}; + }; typedef std::vector< SyncEntry > SYNC_RUNNERS; typedef std::set< std::pair< SYNC_RUNNERS, unsigned >, SyncCompare > SYNC; diff --git a/trunk/paradiseo-peo/src/rmc/mpi/tags.h b/trunk/paradiseo-peo/src/rmc/mpi/tags.h index 67a7a71be..167b9e529 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/tags.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/tags.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/src/rmc/mpi/worker.cpp b/trunk/paradiseo-peo/src/rmc/mpi/worker.cpp index ee88cfb19..1da1de3bf 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/worker.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/worker.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -48,12 +48,14 @@ static std :: vector key_to_worker (1); /* Vector of registered worke extern void wakeUpCommunicator (); -Worker * getWorker (WORKER_ID __key) { +Worker * getWorker (WORKER_ID __key) +{ return key_to_worker [__key]; } -Worker :: Worker () { +Worker :: Worker () +{ recvAndCompleted = false; taskAssigned = 0; @@ -63,69 +65,79 @@ Worker :: Worker () { sem_init( &sem_task_done, 0, 0 ); } -void Worker :: packResult () { +void Worker :: packResult () +{ pack (serv_id); serv -> packResult (); } -void Worker :: unpackData () { +void Worker :: unpackData () +{ taskAssigned ++; printDebugMessage ("unpacking the ID. of the service."); unpack (serv_id); - serv = getService (serv_id); + serv = getService (serv_id); printDebugMessage ("found the service."); - serv -> unpackData (); + serv -> unpackData (); printDebugMessage ("unpacking the data."); setActive (); } -void Worker :: packTaskDone () { +void Worker :: packTaskDone () +{ pack (getNodeRank ()); pack (id); } -void Worker :: notifySendingResult () { +void Worker :: notifySendingResult () +{ /* Notifying the scheduler of the termination */ recvAndCompleted = true; wakeUp (); } -void Worker :: notifySendingTaskDone () { +void Worker :: notifySendingTaskDone () +{ sem_post(&sem_task_done); setPassive (); } -void Worker :: setSource (int __rank) { +void Worker :: setSource (int __rank) +{ src = __rank; } -void Worker :: start () { +void Worker :: start () +{ - while (true) { + while (true) + { - sleep (); + sleep (); - if (! atLeastOneActiveRunner () && ! taskAssigned) - break; + if (! atLeastOneActiveRunner () && ! taskAssigned) + break; - if (recvAndCompleted) { - send (this, my_node -> rk_sched, TASK_DONE_TAG); - recvAndCompleted = false; - sem_wait(&sem_task_done); - taskAssigned --; + if (recvAndCompleted) + { + send (this, my_node -> rk_sched, TASK_DONE_TAG); + recvAndCompleted = false; + sem_wait(&sem_task_done); + taskAssigned --; + } + else + { + + serv -> execute (); + send (this, src, TASK_RESULT_TAG); + } } - else { - - serv -> execute (); - send (this, src, TASK_RESULT_TAG); - } - } printDebugMessage ("Worker finished execution."); setPassive (); @@ -133,7 +145,8 @@ void Worker :: start () { wakeUpCommunicator(); } -void initWorkersEnv () { +void initWorkersEnv () +{ key_to_worker.resize (1); } diff --git a/trunk/paradiseo-peo/src/rmc/mpi/worker.h b/trunk/paradiseo-peo/src/rmc/mpi/worker.h index 5576fa4f0..26500ec05 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/worker.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/worker.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -42,41 +42,42 @@ #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); + void setSource (int __rank); -private : + private : - WORKER_ID id; - SERVICE_ID serv_id; - Service * serv; - int src; + WORKER_ID id; + SERVICE_ID serv_id; + Service * serv; + int src; - bool recvAndCompleted; - unsigned taskAssigned; + bool recvAndCompleted; + unsigned taskAssigned; - sem_t sem_task_done; - sem_t sem_task_asgn; -}; + sem_t sem_task_done; + sem_t sem_task_asgn; + }; extern void initWorkersEnv (); diff --git a/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.cpp b/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.cpp index 052f4c1b3..b5feaaa5b 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.cpp @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 @@ -40,23 +40,27 @@ static xmlTextReaderPtr reader; -void openXMLDocument (const char * __filename) { +void openXMLDocument (const char * __filename) +{ reader = xmlNewTextReaderFilename (__filename); - if (! reader) { + if (! reader) + { - fprintf (stderr, "unable to open '%s'.\n", __filename); - exit (1); - } + fprintf (stderr, "unable to open '%s'.\n", __filename); + exit (1); + } } -void closeXMLDocument () { +void closeXMLDocument () +{ xmlFreeTextReader (reader); } -std :: string getAttributeValue (const std :: string & __attr) { +std :: string getAttributeValue (const std :: string & __attr) +{ xmlChar * value = xmlTextReaderGetAttribute (reader, (const xmlChar *) __attr.c_str ()); @@ -67,7 +71,8 @@ std :: string getAttributeValue (const std :: string & __attr) { return str; } -static bool isSep (const xmlChar * __text) { +static bool isSep (const xmlChar * __text) +{ for (unsigned i = 0; i < strlen ((char *) __text); i ++) if (__text [i] != ' ' && __text [i] != '\t' && __text [i] != '\n') @@ -75,15 +80,18 @@ static bool isSep (const xmlChar * __text) { return true; } -std :: string getNextNode () { +std :: string getNextNode () +{ xmlChar * name, * value; - do { - xmlTextReaderRead (reader); - name = xmlTextReaderName (reader); - value = xmlTextReaderValue (reader); - } while (! strcmp ((char *) name, "#text") && isSep (value)); + do + { + xmlTextReaderRead (reader); + name = xmlTextReaderName (reader); + value = xmlTextReaderValue (reader); + } + while (! strcmp ((char *) name, "#text") && isSep (value)); std :: string str; diff --git a/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.h b/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.h index b54fbeed9..89cc7b5be 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.h +++ b/trunk/paradiseo-peo/src/rmc/mpi/xml_parser.h @@ -1,4 +1,4 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * (C) OPAC Team, LIFL, 2002-2007 diff --git a/trunk/paradiseo-peo/test/t-peoInsularPSO.cpp b/trunk/paradiseo-peo/test/t-peoInsularPSO.cpp index 4aad5eec3..cb8c44396 100644 --- a/trunk/paradiseo-peo/test/t-peoInsularPSO.cpp +++ b/trunk/paradiseo-peo/test/t-peoInsularPSO.cpp @@ -71,48 +71,48 @@ template < class POT > class eoPrint : public eoContinue void peoPSOSeq () { -/* - const unsigned int VEC_SIZE = 4; - const unsigned int POP_SIZE = 10; - const unsigned int NEIGHBORHOOD_SIZE= 5; - const unsigned int MAX_GEN = 100; - const double INIT_POSITION_MIN = -50.0; - const double INIT_POSITION_MAX = 50.0; - const double INIT_VELOCITY_MIN = -1; - const double INIT_VELOCITY_MAX = 1; - const double omega = 1.0; - const double C1 = 0.5; - const double C2 = 2; - rng.reseed (44); - std::cout<<"\n\nWith one PSO\n\n"; - eoEvalFuncPtr plainEvalSeq(f); - eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq); - eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX); - eoInitFixedLength < Indi > random (VEC_SIZE, uGen); - eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX); - eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); - eoFirstIsBestInit < Indi > localInit; - eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX); - eoStandardFlight < Indi > flight(bndsFlight); - eoPop < Indi > popSeq; - popSeq.append (POP_SIZE, random); - apply(evalSeq, popSeq); - ; - apply < Indi > (veloRandom, popSeq); - apply < Indi > (localInit, popSeq); - eoLinearTopology topologySeq(NEIGHBORHOOD_SIZE); - topologySeq.setup(popSeq); - eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq); - eoGenContinue < Indi > genContSeq (MAX_GEN); - eoPrint printSeq; - eoCombinedContinue continuatorSeq(genContSeq); - continuatorSeq.add(printSeq); - eoCheckPoint checkpointSeq(continuatorSeq); - eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight); - psaSeq (popSeq); - popSeq.sort (); - */ + /* + const unsigned int VEC_SIZE = 4; + const unsigned int POP_SIZE = 10; + const unsigned int NEIGHBORHOOD_SIZE= 5; + const unsigned int MAX_GEN = 100; + const double INIT_POSITION_MIN = -50.0; + const double INIT_POSITION_MAX = 50.0; + const double INIT_VELOCITY_MIN = -1; + const double INIT_VELOCITY_MAX = 1; + const double omega = 1.0; + const double C1 = 0.5; + const double C2 = 2; + rng.reseed (44); + std::cout<<"\n\nWith one PSO\n\n"; + eoEvalFuncPtr plainEvalSeq(f); + eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq); + eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX); + eoInitFixedLength < Indi > random (VEC_SIZE, uGen); + eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX); + eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); + eoFirstIsBestInit < Indi > localInit; + eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX); + eoStandardFlight < Indi > flight(bndsFlight); + eoPop < Indi > popSeq; + popSeq.append (POP_SIZE, random); + apply(evalSeq, popSeq); + ; + apply < Indi > (veloRandom, popSeq); + apply < Indi > (localInit, popSeq); + eoLinearTopology topologySeq(NEIGHBORHOOD_SIZE); + topologySeq.setup(popSeq); + eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); + eoStandardVelocity < Indi > velocitySeq (topologySeq,omega,C1,C2,bndsSeq); + eoGenContinue < Indi > genContSeq (MAX_GEN); + eoPrint printSeq; + eoCombinedContinue continuatorSeq(genContSeq); + continuatorSeq.add(printSeq); + eoCheckPoint checkpointSeq(continuatorSeq); + eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight); + psaSeq (popSeq); + popSeq.sort (); + */ } void peoPSOPara() diff --git a/trunk/paradiseo-peo/test/t-peoPSO.cpp b/trunk/paradiseo-peo/test/t-peoPSO.cpp index 3d5a088c8..c2526d715 100644 --- a/trunk/paradiseo-peo/test/t-peoPSO.cpp +++ b/trunk/paradiseo-peo/test/t-peoPSO.cpp @@ -52,54 +52,54 @@ double f (const Indi & _indi) double peoPSOSeq () { - /* - clock_t beginSeq,endSeq; - double timeSeq; - const unsigned int VEC_SIZE = 2; - const unsigned int POP_SIZE = 10; - const unsigned int NEIGHBORHOOD_SIZE= 5; - const unsigned int MAX_GEN = 5000; - const double FIT_CONT = -1e-6; - const double INIT_POSITION_MIN = -5.0; - const double INIT_POSITION_MAX = 5.0; - const double INIT_VELOCITY_MIN = -1; - const double INIT_VELOCITY_MAX = 1; - const double C1 = 2; - const double C2 = 2; - rng.reseed (36); - beginSeq=clock(); - eoEvalFuncPtr plainEvalSeq(f); - eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq); - eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX); - eoInitFixedLength < Indi > random (VEC_SIZE, uGen); - eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX); - eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); - eoFirstIsBestInit < Indi > localInit; - eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX); - eoStandardFlight < Indi > flight(bndsFlight); - eoPop < Indi > popSeq; - popSeq.append (POP_SIZE, random); - apply(evalSeq, popSeq); - ; - apply < Indi > (veloRandom, popSeq); - apply < Indi > (localInit, popSeq); - eoLinearTopology topologySeq(NEIGHBORHOOD_SIZE); - topologySeq.setup(popSeq); - eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); - eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq); - eoGenContinue < Indi > genContSeq (MAX_GEN); - eoFitContinue < Indi > fitContSeq (FIT_CONT); - eoCombinedContinue continuatorSeq (genContSeq); - continuatorSeq.add(fitContSeq); - eoCheckPoint checkpointSeq(continuatorSeq); - eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight); -//Sequential - psaSeq (popSeq); - popSeq.sort (); - endSeq=clock(); - timeSeq = endSeq-beginSeq; - return timeSeq; - */ + /* + clock_t beginSeq,endSeq; + double timeSeq; + const unsigned int VEC_SIZE = 2; + const unsigned int POP_SIZE = 10; + const unsigned int NEIGHBORHOOD_SIZE= 5; + const unsigned int MAX_GEN = 5000; + const double FIT_CONT = -1e-6; + const double INIT_POSITION_MIN = -5.0; + const double INIT_POSITION_MAX = 5.0; + const double INIT_VELOCITY_MIN = -1; + const double INIT_VELOCITY_MAX = 1; + const double C1 = 2; + const double C2 = 2; + rng.reseed (36); + beginSeq=clock(); + eoEvalFuncPtr plainEvalSeq(f); + eoEvalFuncCounter < Indi > evalSeq (plainEvalSeq); + eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX); + eoInitFixedLength < Indi > random (VEC_SIZE, uGen); + eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX); + eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); + eoFirstIsBestInit < Indi > localInit; + eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX); + eoStandardFlight < Indi > flight(bndsFlight); + eoPop < Indi > popSeq; + popSeq.append (POP_SIZE, random); + apply(evalSeq, popSeq); + ; + apply < Indi > (veloRandom, popSeq); + apply < Indi > (localInit, popSeq); + eoLinearTopology topologySeq(NEIGHBORHOOD_SIZE); + topologySeq.setup(popSeq); + eoRealVectorBounds bndsSeq(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); + eoStandardVelocity < Indi > velocitySeq (topologySeq,C1,C2,bndsSeq); + eoGenContinue < Indi > genContSeq (MAX_GEN); + eoFitContinue < Indi > fitContSeq (FIT_CONT); + eoCombinedContinue continuatorSeq (genContSeq); + continuatorSeq.add(fitContSeq); + eoCheckPoint checkpointSeq(continuatorSeq); + eoSyncEasyPSO < Indi > psaSeq(checkpointSeq, evalSeq, velocitySeq, flight); + //Sequential + psaSeq (popSeq); + popSeq.sort (); + endSeq=clock(); + timeSeq = endSeq-beginSeq; + return timeSeq; + */ } void peoPSOPara(long int arg) diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/mainEA.cpp b/trunk/paradiseo-peo/tutorial/Lesson1/mainEA.cpp index 01e4a2b8d..a6d5bf74f 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson1/mainEA.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson1/mainEA.cpp @@ -78,7 +78,7 @@ int main (int __argc, char *__argv[]) eoCheckPoint checkpoint(continuatorPara); // For a parallel evaluation - + peoEvalFunc plainEval(f); peoPopEval eval(plainEval); @@ -95,26 +95,26 @@ int main (int __argc, char *__argv[]) eoSegmentCrossover crossover; // Crossover eoUniformMutation mutation(EPSILON); // Mutation eoSGATransform transform(crossover,CROSS_RATE,mutation,MUT_RATE); - + // Replacement eoPlusReplacement replace; // Creation of the population eoPop < Indi > pop; pop.append (POP_SIZE, random); - + // Algorithm eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace ); //Parallel algorithm peoWrapper parallelEA( eaAlg, pop); eval.setOwner(parallelEA); - + peo :: run(); peo :: finalize(); if (getNodeRank()==1) - { - pop.sort(); - std::cout << "Final population :\n" << pop << std::endl; - } + { + pop.sort(); + std::cout << "Final population :\n" << pop << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson1/mainPSO.cpp b/trunk/paradiseo-peo/tutorial/Lesson1/mainPSO.cpp index e4f7293dc..5b8c9771d 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson1/mainPSO.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson1/mainPSO.cpp @@ -71,11 +71,11 @@ int main (int __argc, char *__argv[]) const double INIT_POSITION_MIN = -2.0; // For initialize x const double INIT_POSITION_MAX = 2.0; // In the case of the Rosenbrock function : -2 < x[i] < 2 - const double INIT_VELOCITY_MIN = -1.; - const double INIT_VELOCITY_MAX = 1.; + const double INIT_VELOCITY_MIN = -1.; + const double INIT_VELOCITY_MAX = 1.; const double weight = 1; - const double C1 = 0.5; - const double C2 = 2.; + const double C1 = 0.5; + const double C2 = 2.; rng.reseed (time(0)); // Stopping @@ -92,14 +92,14 @@ int main (int __argc, char *__argv[]) eoUniformGenerator < double >uGen (INIT_POSITION_MIN, INIT_POSITION_MAX); eoInitFixedLength < Indi > random (VEC_SIZE, uGen); -// Velocity +// Velocity eoUniformGenerator < double >sGen (INIT_VELOCITY_MIN, INIT_VELOCITY_MAX); eoVelocityInitFixedLength < Indi > veloRandom (VEC_SIZE, sGen); -// Initializing the best +// Initializing the best eoFirstIsBestInit < Indi > localInit; -// Flight +// Flight eoRealVectorBounds bndsFlight(VEC_SIZE,INIT_POSITION_MIN,INIT_POSITION_MAX); eoStandardFlight < Indi > flight(bndsFlight); @@ -111,20 +111,20 @@ int main (int __argc, char *__argv[]) eoLinearTopology topology(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); eoStandardVelocity < Indi > velocity (topology,weight,C1,C2,bnds); - + // Initialization eoInitializer init(eval,veloRandom,localInit,topology,pop); - + //Parallel algorithm eoSyncEasyPSO psa(init,checkpoint,eval, velocity, flight); peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); - + peo :: run(); peo :: finalize(); if (getNodeRank()==1) - { - pop.sort(); - std::cout << "Final population :\n" << pop << std::endl; - } + { + pop.sort(); + std::cout << "Final population :\n" << pop << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson2/mainEA.cpp b/trunk/paradiseo-peo/tutorial/Lesson2/mainEA.cpp index 69d62b6af..4ff15a1e7 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson2/mainEA.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson2/mainEA.cpp @@ -52,14 +52,14 @@ int main (int __argc, char *__argv[]) { peo :: init( __argc, __argv ); - const unsigned int VEC_SIZE = 2; - const unsigned int POP_SIZE = 20; - const unsigned int MAX_GEN = 300; + const unsigned int VEC_SIZE = 2; + const unsigned int POP_SIZE = 20; + const unsigned int MAX_GEN = 300; const double INIT_POSITION_MIN = -2.0; - const double INIT_POSITION_MAX = 2.0; - const float CROSS_RATE = 0.8; - const double EPSILON = 0.01; - const float MUT_RATE = 0.3; + const double INIT_POSITION_MAX = 2.0; + const float CROSS_RATE = 0.8; + const double EPSILON = 0.01; + const float MUT_RATE = 0.3; rng.reseed (time(0)); eoGenContinue < Indi > genContPara (MAX_GEN); eoCombinedContinue continuatorPara (genContPara); @@ -70,9 +70,9 @@ int main (int __argc, char *__argv[]) eoInitFixedLength < Indi > random (VEC_SIZE, uGen); eoRankingSelect selectionStrategy; eoSelectNumber select(selectionStrategy,POP_SIZE); - eoSegmentCrossover crossover; + eoSegmentCrossover crossover; eoUniformMutation mutation(EPSILON); - + peoTransform transform(crossover,CROSS_RATE,mutation,MUT_RATE); eoPlusReplacement replace; @@ -81,14 +81,14 @@ int main (int __argc, char *__argv[]) eoEasyEA< Indi > eaAlg( checkpoint, eval, select, transform, replace ); peoWrapper parallelEA( eaAlg, pop); eval.setOwner(parallelEA); - + transform.setOwner (parallelEA); - + peo :: run(); peo :: finalize(); if (getNodeRank()==1) - { - pop.sort(); - std::cout << "Final population :\n" << pop << std::endl; - } + { + pop.sort(); + std::cout << "Final population :\n" << pop << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson3/mainEA.cpp b/trunk/paradiseo-peo/tutorial/Lesson3/mainEA.cpp index bfb411bfc..d05964201 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson3/mainEA.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson3/mainEA.cpp @@ -71,7 +71,7 @@ int main (int __argc, char *__argv[]) // First algorithm /*****************************************************************************************/ - + eoGenContinue < Indi > genContPara (MAX_GEN); eoCombinedContinue continuatorPara (genContPara); eoCheckPoint checkpoint(continuatorPara); @@ -82,10 +82,10 @@ int main (int __argc, char *__argv[]) eoRankingSelect selectionStrategy; eoSelectNumber select(selectionStrategy,POP_SIZE); eoSegmentCrossover crossover; - eoUniformMutation mutation(EPSILON); - peoTransform transform(crossover,CROSS_RATE,mutation,MUT_RATE); + eoUniformMutation mutation(EPSILON); + peoTransform transform(crossover,CROSS_RATE,mutation,MUT_RATE); peoPop < Indi > pop; - pop.append (POP_SIZE, random); + pop.append (POP_SIZE, random); eoPlusReplacement replace; eoRandomSelect mig_select_one; eoSelector > mig_select (mig_select_one,MIG_SIZE,pop); @@ -102,7 +102,7 @@ int main (int __argc, char *__argv[]) // Second algorithm (on the same model but with others names) /*****************************************************************************************/ - + eoGenContinue < Indi > genContPara2 (MAX_GEN); eoCombinedContinue continuatorPara2 (genContPara2); eoCheckPoint checkpoint2(continuatorPara2); @@ -113,10 +113,10 @@ int main (int __argc, char *__argv[]) eoRankingSelect selectionStrategy2; eoSelectNumber select2(selectionStrategy2,POP_SIZE); eoSegmentCrossover crossover2; - eoUniformMutation mutation2(EPSILON); - peoTransform transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE); + eoUniformMutation mutation2(EPSILON); + peoTransform transform2(crossover2,CROSS_RATE,mutation2,MUT_RATE); peoPop < Indi > pop2; - pop2.append (POP_SIZE, random2); + pop2.append (POP_SIZE, random2); eoPlusReplacement replace2; eoRandomSelect mig_select_one2; eoSelector > mig_select2 (mig_select_one2,MIG_SIZE,pop2); diff --git a/trunk/paradiseo-peo/tutorial/Lesson3/mainPSO.cpp b/trunk/paradiseo-peo/tutorial/Lesson3/mainPSO.cpp index 3a21ce086..2e7b3a386 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson3/mainPSO.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson3/mainPSO.cpp @@ -50,24 +50,24 @@ double f (const Indi & _indi) int main (int __argc, char *__argv[]) { peo :: init( __argc, __argv ); - const unsigned int VEC_SIZE = 2; - const unsigned int POP_SIZE = 20; + const unsigned int VEC_SIZE = 2; + const unsigned int POP_SIZE = 20; const unsigned int NEIGHBORHOOD_SIZE= 6; - const unsigned int MAX_GEN = 100; + const unsigned int MAX_GEN = 100; const double INIT_POSITION_MIN = -2.0; - const double INIT_POSITION_MAX = 2.0; + const double INIT_POSITION_MAX = 2.0; const double INIT_VELOCITY_MIN = -1.; const double INIT_VELOCITY_MAX = 1.; const unsigned int MIG_FREQ = 10; const double omega = 1; const double C1 = 0.5; - const double C2 = 2.; + const double C2 = 2.; rng.reseed (time(0)); // Island model RingTopology topologyMig; - + // First eoGenContinue < Indi > genContPara (MAX_GEN); eoCombinedContinue continuatorPara (genContPara); @@ -93,9 +93,9 @@ int main (int __argc, char *__argv[]) eoPeriodicContinue< Indi > mig_cont( MIG_FREQ ); peoPSOSelect mig_selec(topology); peoWorstPositionReplacement mig_replac; - - // Specific implementation (peoData.h) - + +// Specific implementation (peoData.h) + eoContinuator cont(mig_cont, pop); eoSelector > mig_select (mig_selec,1,pop); eoReplace > mig_replace (mig_replac,pop); @@ -121,7 +121,7 @@ int main (int __argc, char *__argv[]) eoRealVectorBounds bnds2(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); eoStandardVelocity < Indi > velocity2 (topology2,omega,C1,C2,bnds2); eoInitializer init2(eval2,veloRandom2,localInit2,topology2,pop2); - + // Island model eoPeriodicContinue< Indi > mig_cont2( MIG_FREQ ); @@ -133,15 +133,15 @@ int main (int __argc, char *__argv[]) eoContinuator cont2(mig_cont2,pop2); eoSelector > mig_select2 (mig_selec2,1,pop2); eoReplace > mig_replace2 (mig_replac2,pop2); - + // Island model - + peoAsyncIslandMig< Indi, peoPop > mig(cont,mig_select, mig_replace, topologyMig, pop, pop); checkpoint.add( mig ); peoAsyncIslandMig< Indi, peoPop > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2); checkpoint2.add( mig2 ); - + // Parallel algorithm @@ -156,10 +156,10 @@ int main (int __argc, char *__argv[]) peo :: run(); peo :: finalize(); if (getNodeRank()==1) - { - pop.sort(); - pop2.sort(); - std::cout << "Final population :\n" << pop << std::endl; - std::cout << "Final population :\n" << pop2 << std::endl; - } + { + pop.sort(); + pop2.sort(); + std::cout << "Final population :\n" << pop << std::endl; + std::cout << "Final population :\n" << pop2 << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson4/mainEALS.cpp b/trunk/paradiseo-peo/tutorial/Lesson4/mainEALS.cpp index 9831a3360..ed545e979 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson4/mainEALS.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson4/mainEALS.cpp @@ -59,13 +59,13 @@ int main (int __argc, char * * __argv) { peo :: init (__argc, __argv); - loadParameters (__argc, __argv); + loadParameters (__argc, __argv); RouteInit route_init; RouteEval full_eval; - OrderXover order_cross; + OrderXover order_cross; PartialMappedXover pm_cross; EdgeXover edge_cross; - CitySwap city_swap_mut; + CitySwap city_swap_mut; // Initialization of the local search TwoOptInit pmx_two_opt_init; @@ -76,7 +76,7 @@ int main (int __argc, char * * __argv) // EA eoPop pop (POP_SIZE, route_init); - eoGenContinue cont (NUM_GEN); + eoGenContinue cont (NUM_GEN); eoCheckPoint checkpoint (cont); eoEvalFuncCounter< Route > eval(full_eval); eoStochTournamentSelect select_one; @@ -86,16 +86,16 @@ int main (int __argc, char * * __argv) eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace ); peoWrapper parallelEA( eaAlg, pop); peo :: run (); - peo :: finalize (); + peo :: finalize (); if (getNodeRank()==1) - { - pop.sort(); - std :: cout << "\nResult before the local search\n"; - for(unsigned i=0;i initParallelHC (hc); @@ -105,10 +105,10 @@ int main (int __argc, char * * __argv) peo :: finalize( ); if (getNodeRank()==1) - { - std :: cout << "\nResult after the local search\n"; - pop.sort(); - for(unsigned i=0;i cont (NUM_GEN); + eoGenContinue cont (NUM_GEN); eoCheckPoint checkpoint (cont); eoEvalFuncCounter< Route > eval(full_eval); eoStochTournamentSelect select_one; @@ -100,14 +100,14 @@ int main (int __argc, char * * __argv) eoEasyEA< Route > eaAlg( checkpoint, eval, select, transform, replace ); peoWrapper parallelEA( eaAlg, pop); peo :: run (); - peo :: finalize (); + peo :: finalize (); if (getNodeRank()==1) - { - std :: cout << "\nResult after the EA\n"; - pop.sort(); - for(unsigned i=0;i class eoResizerInit: public eoInit -{ - public: + { + public: typedef typename EOT::AtomType AtomType; - eoResizerInit(unsigned _size) - : size(_size){} + eoResizerInit(unsigned _size) + : size(_size) + {} - virtual void operator()(EOT& chrom) - { - chrom.resize(size); - chrom.invalidate(); - } - private : - unsigned size; -}; + virtual void operator()(EOT& chrom) + { + chrom.resize(size); + chrom.invalidate(); + } + private : + unsigned size; + }; int main( int __argc, char** __argv ) { - + peo :: init( __argc, __argv ); - const unsigned int VEC_SIZE = 2; - const unsigned int POP_SIZE = 20; + const unsigned int VEC_SIZE = 2; + const unsigned int POP_SIZE = 20; const unsigned int NEIGHBORHOOD_SIZE= 6; - const unsigned int MAX_GEN = 300; + const unsigned int MAX_GEN = 300; const double INIT_POSITION_MIN = -2.0; - const double INIT_POSITION_MAX = 2.0; + const double INIT_POSITION_MAX = 2.0; const double INIT_VELOCITY_MIN = -1.; const double INIT_VELOCITY_MAX = 1.; - const double omega = 1; + const double omega = 1; const double C1 = 0.5; - const double C2 = 2.; + const double C2 = 2.; rng.reseed (time(0)); eoGenContinue < Indi > genContPara (MAX_GEN); eoCombinedContinue continuatorPara (genContPara); @@ -96,7 +97,7 @@ int main( int __argc, char** __argv ) eoLinearTopology topology(NEIGHBORHOOD_SIZE); eoRealVectorBounds bnds(VEC_SIZE,INIT_VELOCITY_MIN,INIT_VELOCITY_MAX); eoStandardVelocity < Indi > velocity (topology,omega,C1,C2,bnds); - + eoResizerInit sizeInit(VEC_SIZE); // need at least a size initialization eoPop < Indi > pop(POP_SIZE,sizeInit); @@ -105,7 +106,7 @@ int main( int __argc, char** __argv ) peoWrapper random (initRandom,pop); initRandom.setOwner(random); peo :: run( ); - peo :: finalize( ); + peo :: finalize( ); // Parallel algorithm @@ -119,8 +120,8 @@ int main( int __argc, char** __argv ) peo :: run(); peo :: finalize(); if (getNodeRank()==1) - { - pop.sort(); - std::cout << "Final population :\n" << pop << std::endl; - } + { + pop.sort(); + std::cout << "Final population :\n" << pop << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson6/main.cpp b/trunk/paradiseo-peo/tutorial/Lesson6/main.cpp index f01a252fc..82f4c73fb 100644 --- a/trunk/paradiseo-peo/tutorial/Lesson6/main.cpp +++ b/trunk/paradiseo-peo/tutorial/Lesson6/main.cpp @@ -44,24 +44,24 @@ int main(int argc, char* argv[]) { - peo :: init( argc,argv ); - eoParser parser(argc, argv); - eoState state; - peoMoeoPopEval& eval = do_make_para_eval(parser, state); - eoInit& init = do_make_genotype(parser, state); - eoGenOp& op = do_make_op(parser, state); - eoPop& pop = do_make_pop(parser, state, init); - moeoArchive arch; - eoContinue& term = do_make_continue_moeo(parser, state, eval); - eoCheckPoint& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch); - eoAlgo& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch); - peoWrapper parallelMOEO( algo, pop); - eval.setOwner(parallelMOEO); - peo :: run(); - peo :: finalize(); - if (getNodeRank()==1) - { - pop.sort(); - std::cout << "Final population :\n" << pop << std::endl; - } + peo :: init( argc,argv ); + eoParser parser(argc, argv); + eoState state; + peoMoeoPopEval& eval = do_make_para_eval(parser, state); + eoInit& init = do_make_genotype(parser, state); + eoGenOp& op = do_make_op(parser, state); + eoPop& pop = do_make_pop(parser, state, init); + moeoArchive arch; + eoContinue& term = do_make_continue_moeo(parser, state, eval); + eoCheckPoint& checkpoint = do_make_checkpoint_moeo(parser, state, eval, term, pop, arch); + eoAlgo& algo = do_make_ea_moeo(parser, state, eval, checkpoint, op, arch); + peoWrapper parallelMOEO( algo, pop); + eval.setOwner(parallelMOEO); + peo :: run(); + peo :: finalize(); + if (getNodeRank()==1) + { + pop.sort(); + std::cout << "Final population :\n" << pop << std::endl; + } } diff --git a/trunk/paradiseo-peo/tutorial/Lesson6/make/make_continue_moeo.h b/trunk/paradiseo-peo/tutorial/Lesson6/make/make_continue_moeo.h index 014c274db..00461e745 100755 --- a/trunk/paradiseo-peo/tutorial/Lesson6/make/make_continue_moeo.h +++ b/trunk/paradiseo-peo/tutorial/Lesson6/make/make_continue_moeo.h @@ -88,13 +88,13 @@ eoContinue & do_make_continue_moeo(eoParser& _parser, eoState& _state, eo } // maxEval eoValueParam& maxEvalParam = _parser.getORcreateParam((unsigned long)(0), "maxEval", "Maximum number of evaluations (0 = none)", 'E', "Stopping criterion"); - /* if (maxEvalParam.value()) - { - eoEvalContinue *evalCont = new eoEvalContinue(_eval, maxEvalParam.value()); - _state.storeFunctor(evalCont); - // and "add" to combined - continuator = make_combinedContinue(continuator, evalCont); - }*/ + /* if (maxEvalParam.value()) + { + eoEvalContinue *evalCont = new eoEvalContinue(_eval, maxEvalParam.value()); + _state.storeFunctor(evalCont); + // and "add" to combined + continuator = make_combinedContinue(continuator, evalCont); + }*/ // maxTime eoValueParam& maxTimeParam = _parser.getORcreateParam((unsigned long)(0), "maxTime", "Maximum running time in seconds (0 = none)", 'T', "Stopping criterion"); if (maxTimeParam.value()) // positive: -> define and store diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/display.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/display.cpp index 66757006c..905ccbbe0 100644 --- a/trunk/paradiseo-peo/tutorial/examples/tsp/display.cpp +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/display.cpp @@ -71,7 +71,7 @@ static int screen; /* gdk_gc_set_line_attributes (gc, 2, GDK_LINE_ON_OFF_DASH, GDK_CAP_NOT_LAST, GDK_JOIN_MITER) ; -gdk_gc_set_foreground (gc, & color_green) ; +gdk_gc_set_foreground (gc, & color_green) ; for (int i = 0 ; i < (int) numNodes ; i ++) { @@ -80,7 +80,7 @@ for (int i = 0 ; i < (int) numNodes ; i ++) { Y_new_coord [opt_route [i]], X_new_coord [opt_route [(i + 1) % numNodes]], Y_new_coord [opt_route [(i + 1) % numNodes]]); - + }*/ void openMainWindow (const char * __filename) diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/display_best_route.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/display_best_route.cpp index bd4257833..cb2f0afdb 100644 --- a/trunk/paradiseo-peo/tutorial/examples/tsp/display_best_route.cpp +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/display_best_route.cpp @@ -40,7 +40,6 @@ DisplayBestRoute :: DisplayBestRoute (eoPop & __pop ) : pop (__pop) { - } void DisplayBestRoute :: operator () () diff --git a/trunk/paradiseo-peo/tutorial/examples/tsp/part_route_eval.cpp b/trunk/paradiseo-peo/tutorial/examples/tsp/part_route_eval.cpp index eb04105f0..0134f6065 100644 --- a/trunk/paradiseo-peo/tutorial/examples/tsp/part_route_eval.cpp +++ b/trunk/paradiseo-peo/tutorial/examples/tsp/part_route_eval.cpp @@ -41,8 +41,7 @@ PartRouteEval :: PartRouteEval (float __from, float __to ) : from (__from), to (__to) -{ -} +{} void PartRouteEval :: operator () (Route & __route) {