peoAsyncIslandMig.h

00001 /*
00002 * <peoAsyncIslandMig.h>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2008
00004 * (C) OPAC Team, LIFL, 2002-2008
00005 *
00006 * Sebastien Cahon, Alexandru-Adrian Tantar, Clive Canape
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * peoData to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 
00037 #ifndef __peoAsyncIslandMig_h
00038 #define __peoAsyncIslandMig_h
00039 
00040 
00041 #include <queue>
00042 
00043 #include <utils/eoUpdater.h>
00044 #include <eoContinue.h>
00045 #include <eoSelect.h>
00046 #include <eoReplacement.h>
00047 #include <eoPop.h>
00048 
00049 
00050 #include "core/messaging.h"
00051 #include "core/eoPop_mesg.h"
00052 #include "core/eoVector_mesg.h"
00053 #include "core/topology.h"
00054 #include "core/thread.h"
00055 #include "core/cooperative.h"
00056 #include "core/peo_debug.h"
00057 
00058 
00064 template< class TYPESELECT, class TYPEREPLACE > class peoAsyncIslandMig : public Cooperative, public eoUpdater
00065   {
00066 
00067   public:
00068 
00074     peoAsyncIslandMig(
00075       continuator & __cont,
00076       selector <TYPESELECT> & __select,
00077       replacement <TYPEREPLACE> & __replace,
00078       Topology& __topology
00079     );
00080 
00082     void operator()();
00084     void pack();
00086     void unpack();
00088     void packSynchronizeReq();
00089 
00090   private:
00092     void emigrate();
00094     void immigrate();
00095 
00096   private:
00104     continuator & cont;
00105     selector <TYPESELECT> & select;
00106     replacement <TYPEREPLACE> & replace;
00107     Topology& topology;
00108     std :: queue< TYPEREPLACE > imm;
00109     std :: queue< TYPESELECT > em;
00110     std :: queue< Cooperative* > coop_em;
00111   };
00112 
00113 
00114 template< class TYPESELECT , class TYPEREPLACE> peoAsyncIslandMig< TYPESELECT, TYPEREPLACE > :: peoAsyncIslandMig(
00115 
00116   continuator & __cont,
00117   selector <TYPESELECT> & __select,
00118   replacement <TYPEREPLACE> & __replace,
00119   Topology& __topology
00120 
00121 ) : select( __select ), replace( __replace ), topology( __topology ), cont(__cont)
00122 {
00123 
00124   __topology.add( *this );
00125 }
00126 
00127 
00128 template< class TYPESELECT , class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT, TYPEREPLACE > :: pack()
00129 {
00130   lock ();
00131   ::pack( coop_em.front()->getKey() );
00132   ::pack(em.front());
00133   coop_em.pop();
00134   em.pop();
00135   unlock();
00136 }
00137 
00138 
00139 template< class  TYPESELECT, class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT , TYPEREPLACE> :: unpack()
00140 {
00141   lock ();
00142   TYPEREPLACE mig;
00143   ::unpack(mig);
00144   imm.push( mig );
00145   unlock();
00146 }
00147 
00148 template< class TYPESELECT , class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT, TYPEREPLACE > :: packSynchronizeReq()
00149 {}
00150 
00151 template< class TYPESELECT , class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT , TYPEREPLACE> :: emigrate()
00152 {
00153   std :: vector< Cooperative* >in, out;
00154   topology.setNeighbors( this, in, out );
00155 
00156   for ( unsigned i = 0; i < out.size(); i++ )
00157     {
00158 
00159       TYPESELECT mig;
00160       select(mig);
00161       em.push( mig );
00162       coop_em.push( out[i] );
00163       send( out[i] );
00164       printDebugMessage( "sending some emigrants." );
00165     }
00166 }
00167 
00168 
00169 template< class  TYPESELECT, class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT , TYPEREPLACE> :: immigrate()
00170 {
00171 
00172   lock ();
00173   {
00174 
00175     while ( !imm.empty() )
00176       {
00177         replace(imm.front() );
00178         imm.pop();
00179         printDebugMessage( "receiving some immigrants." );
00180       }
00181   }
00182   unlock();
00183 }
00184 
00185 
00186 template< class TYPESELECT , class TYPEREPLACE> void peoAsyncIslandMig< TYPESELECT , TYPEREPLACE > :: operator()()
00187 {
00188 
00189   if (! cont.check())
00190     {
00191 
00192       emigrate();
00193       immigrate();
00194     }
00195 }
00196 
00197 
00198 #endif

Generated on Thu Mar 13 15:55:03 2008 for ParadisEO-PEO-ParallelanddistributedEvolvingObjects by  doxygen 1.4.7