From f7dc43d35bd7c427cd948828babb345c7f6222a3 Mon Sep 17 00:00:00 2001 From: legrand Date: Thu, 17 Jan 2008 13:11:41 +0000 Subject: [PATCH] generic island model OK ! git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@892 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/src/peoAsyncIslandMig.h | 50 +++++++++++-------- trunk/paradiseo-peo/src/peoPop.h | 45 ++++------------- .../paradiseo-peo/tutorial/Wrapper/main4.cpp | 9 ++-- 3 files changed, 44 insertions(+), 60 deletions(-) diff --git a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h index cef9c7c2a..22ea427c0 100644 --- a/trunk/paradiseo-peo/src/peoAsyncIslandMig.h +++ b/trunk/paradiseo-peo/src/peoAsyncIslandMig.h @@ -24,7 +24,7 @@ * professionals having in-depth computer knowledge. Users are therefore * encouraged to load and test the software's suitability as regards their * requirements in conditions enabling the security of their systems and/or -* data to be ensured and, more generally, to use and operate it in the +* peoData to be ensured and, more generally, to use and operate it in the * same conditions as regards security. * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. @@ -41,19 +41,18 @@ #include #include - #include #include #include #include -#include +#include #include + #include "core/messaging.h" #include "core/eoPop_mesg.h" #include "core/eoVector_mesg.h" - #include "core/topology.h" #include "core/thread.h" #include "core/cooperative.h" @@ -159,13 +158,14 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, //! @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. peoAsyncIslandMig( - //continuator< EOT, data < EOT >,bool > & __cont, + continuator & __cont, eoSelect< EOT >& __select, eoReplacement< EOT >& __replace, Topology& __topology, - data & __source, - data & __destination + 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 @@ -189,18 +189,19 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, private: - //continuator< EOT, data < EOT >,bool> & cont; // continuator + continuator & cont; // continuator + eoSelect< EOT >& select; // the selection strategy eoReplacement< EOT >& replace; // the replacement strategy Topology& topology; // the neighboring topology // source and destination populations - data & source; - data & destination; + peoData & source; + peoData & destination; // immigrants & emigrants in the queue - std :: queue< data* > imm; - std :: queue< data* > em; + std :: queue< peoData* > imm; + std :: queue< peoData* > em; std :: vector< TYPE > vect; @@ -210,14 +211,14 @@ template< class EOT, class TYPE > class peoAsyncIslandMig : public Cooperative, template< class EOT , class TYPE> peoAsyncIslandMig< EOT, TYPE > :: peoAsyncIslandMig( - // continuator< EOT, data < EOT >,bool> & __cont, + continuator & __cont, eoSelect< EOT >& __select, eoReplacement< EOT >& __replace, Topology& __topology, - data & __source, - data & __destination + peoData & __source, + peoData & __destination -) : select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination ) +) : select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination ), cont(__cont) { __topology.add( *this ); @@ -250,7 +251,7 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: unpack( lock (); - data mig; + peoData mig; //::unpack( mig ); mig.unpack(); imm.push( &mig ); @@ -305,14 +306,21 @@ template< class EOT , class TYPE> void peoAsyncIslandMig< EOT , TYPE> :: immigra template< class EOT , class TYPE> void peoAsyncIslandMig< EOT, TYPE > :: operator()() { - - // if ( !cont( source ) ) - // { + /* + if ( !cont( source ) && ! eocont(source) ) + { emigrate(); // sending emigrants immigrate(); // receiving immigrants - // } + } + */ + if (cont.check()) + { + + emigrate(); // sending emigrants + immigrate(); // receiving immigrants + } } diff --git a/trunk/paradiseo-peo/src/peoPop.h b/trunk/paradiseo-peo/src/peoPop.h index 9dee25cc9..f12ee1246 100644 --- a/trunk/paradiseo-peo/src/peoPop.h +++ b/trunk/paradiseo-peo/src/peoPop.h @@ -25,6 +25,7 @@ #ifndef _peoPop_H #define _peoPop_H +#include #include #include #include // needed for GCC 3.2 @@ -36,60 +37,32 @@ #include #include // for shuffle method -#include - -//#include "core/eoPop_mesg.h" - #include "core/eoVector_mesg.h" #include "core/messaging.h" template -class peoPop: public data, public eoPop +class peoPop: public eoPop, public peoData { public: virtual void pack () { - std::cout << "[peoPop][pack]" << std::endl; - - //::pack((*this)); ::pack ((unsigned) this->size ()); - for (unsigned i = 0; i < this->size (); i ++) - ::pack ((*this)[i]); + for (unsigned i = 0; i < this->size (); i ++) + ::pack ((*this)[i]); } virtual void unpack () { - // ::unpack((*this)); - - unsigned n; - - ::unpack (n); - this->resize (n); - for (unsigned i = 0; i < n; i ++) - ::unpack ((*this)[i]); + unsigned n; + ::unpack (n); + this->resize (n); + for (unsigned i = 0; i < n; i ++) + ::unpack ((*this)[i]); } }; -/* -template void pack (const peoPop & __pop) { - - pack ((unsigned) __pop.size ()); - for (unsigned i = 0; i < __pop.size (); i ++) - pack (__pop [i]); -} - -template void unpack (peoPop & __pop) { - - unsigned n; - - unpack (n); - __pop.resize (n); - for (unsigned i = 0; i < n; i ++) - unpack (__pop [i]); -} -*/ #endif diff --git a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp index f5f335334..8f03a2135 100644 --- a/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp +++ b/trunk/paradiseo-peo/tutorial/Wrapper/main4.cpp @@ -3,6 +3,8 @@ #include +#include + typedef eoRealParticle < double >Indi; double f (const Indi & _indi) @@ -96,11 +98,12 @@ int main( int __argc, char** __argv ) // Island model - peoAsyncIslandMig< Indi, peoPop > mig(mig_select, mig_replace, topologyMig, pop, pop); + eoContinuator cont(mig_cont, pop); + peoAsyncIslandMig< Indi, peoPop > mig(cont,mig_select, mig_replace, topologyMig, pop, pop); checkpoint.add( mig ); - - peoAsyncIslandMig< Indi, peoPop > mig2(mig_select2, mig_replace2, topologyMig, pop2, pop2); + eoContinuator cont2(mig_cont2,pop2); + peoAsyncIslandMig< Indi, peoPop > mig2(cont2,mig_select2, mig_replace2, topologyMig, pop2, pop2); checkpoint2.add( mig2 );