00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __peoAsyncIslandMig_h
00010 #define __peoAsyncIslandMig_h
00011
00012
00013 #include <queue>
00014
00015 #include <utils/eoUpdater.h>
00016
00017 #include <eoContinue.h>
00018 #include <eoSelect.h>
00019 #include <eoReplacement.h>
00020 #include <eoPop.h>
00021
00022 #include "core/topology.h"
00023 #include "core/cooperative.h"
00024 #include "core/eoPop_comm.h"
00025 #include "core/peo_debug.h"
00026
00027
00029
00112 template< class EOT > class peoAsyncIslandMig : public Cooperative, public eoUpdater {
00113
00114 public:
00115
00125 peoAsyncIslandMig(
00126 eoContinue< EOT >& __cont,
00127 eoSelect< EOT >& __select,
00128 eoReplacement< EOT >& __replace,
00129 Topology& __topology,
00130 eoPop< EOT >& __source,
00131 eoPop< EOT >& __destination
00132 );
00133
00138 void operator()();
00139
00141 void pack();
00143 void unpack();
00144
00145
00146 private:
00147
00148 void emigrate();
00149 void immigrate();
00150
00151
00152 private:
00153
00154 eoContinue< EOT >& cont;
00155 eoSelect< EOT >& select;
00156 eoReplacement< EOT >& replace;
00157 Topology& topology;
00158
00159
00160 eoPop< EOT >& source;
00161 eoPop< EOT >& destination;
00162
00163
00164 std :: queue< eoPop< EOT > > imm;
00165 std :: queue< eoPop< EOT > > em;
00166
00167 std :: queue< Cooperative* > coop_em;
00168 };
00169
00170
00171 template< class EOT > peoAsyncIslandMig< EOT > :: peoAsyncIslandMig(
00172
00173 eoContinue< EOT >& __cont,
00174 eoSelect< EOT >& __select,
00175 eoReplacement< EOT >& __replace,
00176 Topology& __topology,
00177 eoPop< EOT >& __source,
00178 eoPop< EOT >& __destination
00179
00180 ) : cont( __cont ), select( __select ), replace( __replace ), topology( __topology ), source( __source ), destination( __destination )
00181 {
00182
00183 __topology.add( *this );
00184 }
00185
00186
00187 template< class EOT > void peoAsyncIslandMig< EOT > :: pack()
00188 {
00189
00190 lock(); {
00191
00192 :: pack( coop_em.front()->getKey() );
00193 :: pack( em.front() );
00194 coop_em.pop();
00195 em.pop();
00196 }
00197 unlock();
00198 }
00199
00200
00201 template< class EOT > void peoAsyncIslandMig< EOT > :: unpack()
00202 {
00203
00204 lock(); {
00205
00206 eoPop< EOT > mig;
00207 :: unpack( mig );
00208 imm.push( mig );
00209 }
00210 unlock();
00211 }
00212
00213
00214 template< class EOT > void peoAsyncIslandMig< EOT > :: emigrate()
00215 {
00216
00217 std :: vector< Cooperative* >in, out;
00218 topology.setNeighbors( this, in, out );
00219
00220 for ( unsigned i = 0; i < out.size(); i++ ) {
00221
00222 eoPop< EOT > mig;
00223 select( source, mig );
00224 em.push( mig );
00225 coop_em.push( out[i] );
00226 send( out[i] );
00227 printDebugMessage( "sending some emigrants." );
00228 }
00229 }
00230
00231
00232 template< class EOT > void peoAsyncIslandMig< EOT > :: immigrate()
00233 {
00234
00235 lock(); {
00236
00237 while ( !imm.empty() ) {
00238
00239 replace( destination, imm.front() );
00240 imm.pop();
00241 printDebugMessage( "receiving some immigrants." );
00242 }
00243 }
00244 unlock();
00245 }
00246
00247
00248 template< class EOT > void peoAsyncIslandMig< EOT > :: operator()() {
00249
00250 if ( !cont( source ) ) {
00251
00252 emigrate();
00253 immigrate();
00254 }
00255 }
00256
00257
00258 #endif