peo style
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1120 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
32c90fd740
commit
ceeaa4b533
5 changed files with 677 additions and 575 deletions
|
|
@ -10,201 +10,243 @@
|
||||||
|
|
||||||
template < typename Type > struct Entity;
|
template < typename Type > struct Entity;
|
||||||
|
|
||||||
struct AbstractEntity {
|
struct AbstractEntity
|
||||||
|
{
|
||||||
virtual ~AbstractEntity() {}
|
|
||||||
|
|
||||||
template < typename EntityType > operator EntityType& () {
|
|
||||||
|
|
||||||
return ( dynamic_cast< Entity< EntityType >& >( *this ) ).entity;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AbstractFunctor : virtual public AbstractEntity {
|
virtual ~AbstractEntity() {}
|
||||||
|
|
||||||
virtual ~AbstractFunctor() {}
|
template < typename EntityType > operator EntityType& ()
|
||||||
|
{
|
||||||
virtual void operator()() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AbstractUnaryFunctor : virtual public AbstractEntity {
|
return ( dynamic_cast< Entity< EntityType >& >( *this ) ).entity;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
virtual ~AbstractUnaryFunctor() {}
|
struct AbstractFunctor : virtual public AbstractEntity
|
||||||
|
{
|
||||||
virtual void operator()( AbstractEntity& dataEntity ) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AbstractBinaryFunctor : virtual public AbstractEntity {
|
virtual ~AbstractFunctor() {}
|
||||||
|
|
||||||
virtual ~AbstractBinaryFunctor() {}
|
virtual void operator()() {}
|
||||||
|
};
|
||||||
|
|
||||||
virtual void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {};
|
struct AbstractUnaryFunctor : virtual public AbstractEntity
|
||||||
};
|
{
|
||||||
|
|
||||||
|
virtual ~AbstractUnaryFunctor() {}
|
||||||
|
|
||||||
|
virtual void operator()( AbstractEntity& dataEntity ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AbstractBinaryFunctor : virtual public AbstractEntity
|
||||||
|
{
|
||||||
|
|
||||||
|
virtual ~AbstractBinaryFunctor() {}
|
||||||
|
|
||||||
|
virtual void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template < typename EntityType > struct Entity : virtual public AbstractEntity {
|
template < typename EntityType > struct Entity : virtual public AbstractEntity
|
||||||
|
{
|
||||||
Entity( EntityType& externalEntityRef ) : entity( externalEntityRef ) {}
|
|
||||||
|
|
||||||
EntityType& entity;
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename FunctorType, typename DataType > struct FunctorEx : public Entity< DataType >, public AbstractFunctor {
|
Entity( EntityType& externalEntityRef ) : entity( externalEntityRef ) {}
|
||||||
|
|
||||||
FunctorEx( FunctorType& externalFunctorRef, DataType& externalDataRef )
|
|
||||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
|
||||||
|
|
||||||
void operator()() {
|
|
||||||
|
|
||||||
externalFunctor( Entity< DataType > :: entity );
|
|
||||||
}
|
|
||||||
|
|
||||||
FunctorType& externalFunctor;
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename FunctorType > struct FunctorEx< FunctorType, void > : public Entity< AbstractEntity >, public AbstractFunctor {
|
EntityType& entity;
|
||||||
|
};
|
||||||
FunctorEx( FunctorType& externalFunctorRef )
|
|
||||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
|
||||||
|
|
||||||
void operator()() {
|
|
||||||
|
|
||||||
externalFunctor();
|
|
||||||
}
|
|
||||||
|
|
||||||
FunctorType& externalFunctor;
|
template < typename FunctorType, typename DataType > struct FunctorEx : public Entity< DataType >, public AbstractFunctor
|
||||||
};
|
{
|
||||||
|
|
||||||
template < typename ReturnType, typename DataType > struct FnFunctorEx
|
FunctorEx( FunctorType& externalFunctorRef, DataType& externalDataRef )
|
||||||
: public Entity< DataType >, public AbstractFunctor {
|
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||||
|
|
||||||
FnFunctorEx( ReturnType (*externalFunctorRef)( DataType& ), DataType& externalDataRef )
|
void operator()()
|
||||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
{
|
||||||
|
|
||||||
void operator()() {
|
externalFunctor( Entity< DataType > :: entity );
|
||||||
|
}
|
||||||
externalFunctor( Entity< DataType > :: entity );
|
|
||||||
}
|
FunctorType& externalFunctor;
|
||||||
|
};
|
||||||
ReturnType (*externalFunctor)( DataType& );
|
|
||||||
};
|
template < typename FunctorType > struct FunctorEx< FunctorType, void > : public Entity< AbstractEntity >, public AbstractFunctor
|
||||||
|
{
|
||||||
|
|
||||||
|
FunctorEx( FunctorType& externalFunctorRef )
|
||||||
|
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||||
|
|
||||||
|
void operator()()
|
||||||
|
{
|
||||||
|
|
||||||
|
externalFunctor();
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctorType& externalFunctor;
|
||||||
|
};
|
||||||
|
|
||||||
|
template < typename ReturnType, typename DataType > struct FnFunctorEx
|
||||||
|
: public Entity< DataType >, public AbstractFunctor
|
||||||
|
{
|
||||||
|
|
||||||
|
FnFunctorEx( ReturnType (*externalFunctorRef)( DataType& ), DataType& externalDataRef )
|
||||||
|
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||||
|
|
||||||
|
void operator()()
|
||||||
|
{
|
||||||
|
|
||||||
|
externalFunctor( Entity< DataType > :: entity );
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnType (*externalFunctor)( DataType& );
|
||||||
|
};
|
||||||
|
|
||||||
template < typename ReturnType > struct FnFunctorEx< ReturnType, void >
|
template < typename ReturnType > struct FnFunctorEx< ReturnType, void >
|
||||||
: public Entity< AbstractEntity >, public AbstractFunctor {
|
: public Entity< AbstractEntity >, public AbstractFunctor
|
||||||
|
{
|
||||||
|
|
||||||
FnFunctorEx( ReturnType (*externalFunctorRef)() )
|
FnFunctorEx( ReturnType (*externalFunctorRef)() )
|
||||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||||
|
|
||||||
void operator()() {
|
void operator()()
|
||||||
|
{
|
||||||
externalFunctor();
|
|
||||||
}
|
externalFunctor();
|
||||||
|
}
|
||||||
ReturnType (*externalFunctor)();
|
|
||||||
};
|
ReturnType (*externalFunctor)();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template < typename FunctorType > struct UnaryFunctor : public Entity< FunctorType >, public AbstractUnaryFunctor {
|
template < typename FunctorType > struct UnaryFunctor : public Entity< FunctorType >, public AbstractUnaryFunctor
|
||||||
|
{
|
||||||
UnaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
|
||||||
|
|
||||||
void operator()( AbstractEntity& dataEntity ) {
|
|
||||||
|
|
||||||
Entity< FunctorType > :: entity( dataEntity );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename ReturnType, typename DataType > struct UnaryFnFunctor
|
UnaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||||
: public Entity< AbstractEntity >, public AbstractUnaryFunctor {
|
|
||||||
|
|
||||||
UnaryFnFunctor( ReturnType (*externalFnRef)( DataType& ) ) : Entity< AbstractEntity >( *this ), externalFn( externalFnRef ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()( AbstractEntity& dataEntity ) {
|
|
||||||
|
|
||||||
externalFn( dataEntity );
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnType (*externalFn)( DataType& );
|
void operator()( AbstractEntity& dataEntity )
|
||||||
};
|
{
|
||||||
|
|
||||||
template < typename FunctorType > struct BinaryFunctor : public Entity< FunctorType >, public AbstractBinaryFunctor {
|
Entity< FunctorType > :: entity( dataEntity );
|
||||||
|
}
|
||||||
BinaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
};
|
||||||
|
|
||||||
void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {
|
|
||||||
|
|
||||||
Entity< FunctorType > :: entity( dataEntityA, dataEntityB );
|
template < typename ReturnType, typename DataType > struct UnaryFnFunctor
|
||||||
}
|
: public Entity< AbstractEntity >, public AbstractUnaryFunctor
|
||||||
};
|
{
|
||||||
|
|
||||||
struct AbstractMsgTransferQueue : virtual public AbstractEntity {
|
UnaryFnFunctor( ReturnType (*externalFnRef)( DataType& ) ) : Entity< AbstractEntity >( *this ), externalFn( externalFnRef )
|
||||||
|
{
|
||||||
virtual ~AbstractMsgTransferQueue() {}
|
}
|
||||||
|
|
||||||
virtual void pushMessage() {}
|
|
||||||
virtual void popMessage() {}
|
|
||||||
|
|
||||||
virtual bool empty() { return true; }
|
|
||||||
|
|
||||||
virtual void packMessage() {}
|
|
||||||
virtual void unpackMessage() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template < typename EntityType > struct MsgTransferQueue : public Entity< EntityType >, public AbstractMsgTransferQueue {
|
void operator()( AbstractEntity& dataEntity )
|
||||||
|
{
|
||||||
MsgTransferQueue( EntityType& externalDataRef )
|
|
||||||
: Entity< EntityType >( externalDataRef ) {
|
externalFn( dataEntity );
|
||||||
|
}
|
||||||
aggregationFunctor = new BinaryFunctor< AssignmentFunctor >( assignmentFunctor );
|
|
||||||
}
|
ReturnType (*externalFn)( DataType& );
|
||||||
|
};
|
||||||
template < typename FunctorType >
|
|
||||||
MsgTransferQueue( EntityType& externalDataRef, FunctorType& externalFunctorRef )
|
template < typename FunctorType > struct BinaryFunctor : public Entity< FunctorType >, public AbstractBinaryFunctor
|
||||||
: Entity< EntityType >( externalDataRef ) {
|
{
|
||||||
|
|
||||||
aggregationFunctor = new BinaryFunctor< FunctorType >( externalFunctorRef );
|
BinaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||||
}
|
|
||||||
|
void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB )
|
||||||
~MsgTransferQueue() { delete aggregationFunctor; }
|
{
|
||||||
|
|
||||||
void pushMessage() {
|
Entity< FunctorType > :: entity( dataEntityA, dataEntityB );
|
||||||
|
}
|
||||||
transferQueue.push( Entity< EntityType > :: entity );
|
};
|
||||||
}
|
|
||||||
|
struct AbstractMsgTransferQueue : virtual public AbstractEntity
|
||||||
void popMessage() {
|
{
|
||||||
|
|
||||||
Entity< EntityType > message( transferQueue.front() );
|
virtual ~AbstractMsgTransferQueue() {}
|
||||||
aggregationFunctor->operator()( *this, message );
|
|
||||||
|
virtual void pushMessage() {}
|
||||||
transferQueue.pop();
|
virtual void popMessage() {}
|
||||||
}
|
|
||||||
|
virtual bool empty()
|
||||||
bool empty() { return transferQueue.empty(); }
|
{
|
||||||
|
return true;
|
||||||
void packMessage() {
|
}
|
||||||
|
|
||||||
pack( transferQueue.front() );
|
virtual void packMessage() {}
|
||||||
transferQueue.pop();
|
virtual void unpackMessage() {}
|
||||||
}
|
};
|
||||||
|
|
||||||
void unpackMessage() {
|
template < typename EntityType > struct MsgTransferQueue : public Entity< EntityType >, public AbstractMsgTransferQueue
|
||||||
|
{
|
||||||
EntityType transferredData;
|
|
||||||
unpack( transferredData );
|
MsgTransferQueue( EntityType& externalDataRef )
|
||||||
transferQueue.push( transferredData );
|
: Entity< EntityType >( externalDataRef )
|
||||||
}
|
{
|
||||||
|
|
||||||
struct AssignmentFunctor {
|
aggregationFunctor = new BinaryFunctor< AssignmentFunctor >( assignmentFunctor );
|
||||||
void operator()( EntityType& A, EntityType& B ) { A = B; }
|
}
|
||||||
} assignmentFunctor;
|
|
||||||
|
template < typename FunctorType >
|
||||||
std::queue< EntityType > transferQueue;
|
MsgTransferQueue( EntityType& externalDataRef, FunctorType& externalFunctorRef )
|
||||||
AbstractBinaryFunctor* aggregationFunctor;
|
: Entity< EntityType >( externalDataRef )
|
||||||
};
|
{
|
||||||
|
|
||||||
|
aggregationFunctor = new BinaryFunctor< FunctorType >( externalFunctorRef );
|
||||||
|
}
|
||||||
|
|
||||||
|
~MsgTransferQueue()
|
||||||
|
{
|
||||||
|
delete aggregationFunctor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pushMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
transferQueue.push( Entity< EntityType > :: entity );
|
||||||
|
}
|
||||||
|
|
||||||
|
void popMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
Entity< EntityType > message( transferQueue.front() );
|
||||||
|
aggregationFunctor->operator()( *this, message );
|
||||||
|
|
||||||
|
transferQueue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty()
|
||||||
|
{
|
||||||
|
return transferQueue.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void packMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
pack( transferQueue.front() );
|
||||||
|
transferQueue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void unpackMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
EntityType transferredData;
|
||||||
|
unpack( transferredData );
|
||||||
|
transferQueue.push( transferredData );
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AssignmentFunctor
|
||||||
|
{
|
||||||
|
void operator()( EntityType& A, EntityType& B )
|
||||||
|
{
|
||||||
|
A = B;
|
||||||
|
}
|
||||||
|
} assignmentFunctor;
|
||||||
|
|
||||||
|
std::queue< EntityType > transferQueue;
|
||||||
|
AbstractBinaryFunctor* aggregationFunctor;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,157 +16,167 @@
|
||||||
#include "core/peo_debug.h"
|
#include "core/peo_debug.h"
|
||||||
|
|
||||||
|
|
||||||
class peoAsyncDataTransfer : public Cooperative, public eoUpdater {
|
class peoAsyncDataTransfer : public Cooperative, public eoUpdater
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
template< typename EndPointType >
|
|
||||||
peoAsyncDataTransfer(
|
|
||||||
|
|
||||||
EndPointType& __endPoint,
|
|
||||||
Topology& __topology
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
{
|
||||||
|
|
||||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
|
||||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
|
||||||
__topology.add( *this );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename EndPointType, typename FunctorType >
|
public:
|
||||||
|
|
||||||
|
template< typename EndPointType >
|
||||||
peoAsyncDataTransfer(
|
peoAsyncDataTransfer(
|
||||||
|
|
||||||
EndPointType& __endPoint,
|
EndPointType& __endPoint,
|
||||||
Topology& __topology,
|
Topology& __topology
|
||||||
FunctorType& externalFunctorRef
|
|
||||||
|
) : topology( __topology )
|
||||||
) : topology( __topology )
|
{
|
||||||
{
|
|
||||||
|
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||||
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||||
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
__topology.add( *this );
|
||||||
__topology.add( *this );
|
}
|
||||||
}
|
|
||||||
|
template< typename EndPointType, typename FunctorType >
|
||||||
template< typename SourceEndPointType, typename DestinationEndPointType >
|
|
||||||
peoAsyncDataTransfer(
|
peoAsyncDataTransfer(
|
||||||
|
|
||||||
SourceEndPointType& __source,
|
|
||||||
DestinationEndPointType& __destination,
|
|
||||||
Topology& __topology
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
|
||||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
|
||||||
__topology.add( *this );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
EndPointType& __endPoint,
|
||||||
|
Topology& __topology,
|
||||||
|
FunctorType& externalFunctorRef
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||||
|
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||||
|
__topology.add( *this );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename SourceEndPointType, typename DestinationEndPointType >
|
||||||
peoAsyncDataTransfer(
|
peoAsyncDataTransfer(
|
||||||
|
|
||||||
SourceEndPointType& __source,
|
|
||||||
DestinationEndPointType& __destination,
|
|
||||||
Topology& __topology,
|
|
||||||
FunctorType& externalFunctorRef
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
|
||||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
|
||||||
__topology.add( *this );
|
|
||||||
}
|
|
||||||
|
|
||||||
~peoAsyncDataTransfer() {
|
|
||||||
delete source;
|
|
||||||
delete destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SourceEndPointType& __source,
|
||||||
void operator()();
|
DestinationEndPointType& __destination,
|
||||||
|
Topology& __topology
|
||||||
void pack();
|
|
||||||
void unpack();
|
|
||||||
|
|
||||||
void packSynchronizeReq();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void sendData();
|
|
||||||
void receiveData();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// the neighboring topology
|
) : topology( __topology )
|
||||||
Topology& topology;
|
{
|
||||||
|
|
||||||
// source and destination end-points
|
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
||||||
AbstractMsgTransferQueue* source;
|
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
||||||
AbstractMsgTransferQueue* destination;
|
__topology.add( *this );
|
||||||
|
}
|
||||||
std :: queue< Cooperative* > coop_em;
|
|
||||||
};
|
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
||||||
|
peoAsyncDataTransfer(
|
||||||
|
|
||||||
|
SourceEndPointType& __source,
|
||||||
|
DestinationEndPointType& __destination,
|
||||||
|
Topology& __topology,
|
||||||
|
FunctorType& externalFunctorRef
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
||||||
|
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
||||||
|
__topology.add( *this );
|
||||||
|
}
|
||||||
|
|
||||||
|
~peoAsyncDataTransfer()
|
||||||
|
{
|
||||||
|
delete source;
|
||||||
|
delete destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: pack() {
|
void operator()();
|
||||||
|
|
||||||
|
void pack();
|
||||||
|
void unpack();
|
||||||
|
|
||||||
|
void packSynchronizeReq();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void sendData();
|
||||||
|
void receiveData();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// the neighboring topology
|
||||||
|
Topology& topology;
|
||||||
|
|
||||||
|
// source and destination end-points
|
||||||
|
AbstractMsgTransferQueue* source;
|
||||||
|
AbstractMsgTransferQueue* destination;
|
||||||
|
|
||||||
|
std :: queue< Cooperative* > coop_em;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void peoAsyncDataTransfer :: pack()
|
||||||
|
{
|
||||||
|
|
||||||
lock ();
|
lock ();
|
||||||
|
|
||||||
::pack( coop_em.front()->getKey() );
|
::pack( coop_em.front()->getKey() );
|
||||||
source->packMessage();
|
source->packMessage();
|
||||||
coop_em.pop();
|
coop_em.pop();
|
||||||
|
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: unpack() {
|
void peoAsyncDataTransfer :: unpack()
|
||||||
|
{
|
||||||
|
|
||||||
lock ();
|
lock ();
|
||||||
destination->unpackMessage();
|
destination->unpackMessage();
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: packSynchronizeReq() {
|
void peoAsyncDataTransfer :: packSynchronizeReq()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: sendData() {
|
void peoAsyncDataTransfer :: sendData()
|
||||||
|
{
|
||||||
|
|
||||||
std :: vector< Cooperative* > in, out;
|
std :: vector< Cooperative* > in, out;
|
||||||
topology.setNeighbors( this, in, out );
|
topology.setNeighbors( this, in, out );
|
||||||
|
|
||||||
for ( unsigned i = 0; i < out.size(); i++ ) {
|
for ( unsigned i = 0; i < out.size(); i++ )
|
||||||
|
{
|
||||||
source->pushMessage();
|
|
||||||
|
source->pushMessage();
|
||||||
coop_em.push( out[i] );
|
|
||||||
send( out[i] );
|
coop_em.push( out[i] );
|
||||||
|
send( out[i] );
|
||||||
printDebugMessage( "peoAsyncDataTransfer: sending data." );
|
|
||||||
}
|
printDebugMessage( "peoAsyncDataTransfer: sending data." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: receiveData() {
|
void peoAsyncDataTransfer :: receiveData()
|
||||||
|
{
|
||||||
|
|
||||||
lock ();
|
lock ();
|
||||||
{
|
{
|
||||||
|
|
||||||
while ( !( destination->empty() ) ) {
|
while ( !( destination->empty() ) )
|
||||||
|
{
|
||||||
printDebugMessage( "peoAsyncDataTransfer: received data." );
|
|
||||||
destination->popMessage();
|
printDebugMessage( "peoAsyncDataTransfer: received data." );
|
||||||
printDebugMessage( "peoAsyncDataTransfer: done reading data." );
|
destination->popMessage();
|
||||||
}
|
printDebugMessage( "peoAsyncDataTransfer: done reading data." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoAsyncDataTransfer :: operator()() {
|
void peoAsyncDataTransfer :: operator()()
|
||||||
|
{
|
||||||
|
|
||||||
sendData(); // sending data
|
sendData(); // sending data
|
||||||
receiveData(); // receiving data
|
receiveData(); // receiving data
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,131 +22,134 @@
|
||||||
|
|
||||||
|
|
||||||
class peoSyncDataTransfer : public Cooperative, public eoUpdater
|
class peoSyncDataTransfer : public Cooperative, public eoUpdater
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
template< typename EndPointType >
|
||||||
|
peoSyncDataTransfer(
|
||||||
|
|
||||||
|
EndPointType& __endPoint,
|
||||||
|
Topology& __topology
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||||
|
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||||
|
__topology.add( *this );
|
||||||
|
|
||||||
|
sem_init( &sync, 0, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename EndPointType, typename FunctorType >
|
||||||
|
peoSyncDataTransfer(
|
||||||
|
|
||||||
|
EndPointType& __endPoint,
|
||||||
|
Topology& __topology,
|
||||||
|
FunctorType& externalFunctorRef
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||||
|
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
||||||
|
__topology.add( *this );
|
||||||
|
|
||||||
|
sem_init( &sync, 0, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename SourceEndPointType, typename DestinationEndPointType >
|
||||||
|
peoSyncDataTransfer(
|
||||||
|
|
||||||
|
SourceEndPointType& __source,
|
||||||
|
DestinationEndPointType& __destination,
|
||||||
|
Topology& __topology
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
||||||
|
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
||||||
|
__topology.add( *this );
|
||||||
|
|
||||||
|
sem_init( &sync, 0, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
||||||
|
peoSyncDataTransfer(
|
||||||
|
|
||||||
|
SourceEndPointType& __source,
|
||||||
|
DestinationEndPointType& __destination,
|
||||||
|
Topology& __topology,
|
||||||
|
FunctorType& externalFunctorRef
|
||||||
|
|
||||||
|
) : topology( __topology )
|
||||||
|
{
|
||||||
|
|
||||||
|
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
||||||
|
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
||||||
|
__topology.add( *this );
|
||||||
|
|
||||||
|
sem_init( &sync, 0, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void operator()();
|
||||||
|
|
||||||
|
void pack();
|
||||||
|
|
||||||
|
void unpack();
|
||||||
|
|
||||||
|
void packSynchronizeReq();
|
||||||
|
|
||||||
|
void notifySending();
|
||||||
|
|
||||||
|
void notifyReceiving();
|
||||||
|
|
||||||
|
void notifySendingSyncReq();
|
||||||
|
|
||||||
|
void notifySynchronized();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void sendData();
|
||||||
|
void receiveData();
|
||||||
|
|
||||||
|
Topology& topology; // neighboring topology
|
||||||
|
|
||||||
|
// source and destination end-points
|
||||||
|
AbstractMsgTransferQueue* source;
|
||||||
|
AbstractMsgTransferQueue* destination;
|
||||||
|
|
||||||
|
std :: queue< Cooperative* > coop_em;
|
||||||
|
|
||||||
|
sem_t sync;
|
||||||
|
|
||||||
|
bool standbyTransfer;
|
||||||
|
|
||||||
|
std :: vector< Cooperative* > in, out, all;
|
||||||
|
unsigned nbTransfersIn, nbTransfersOut;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void peoSyncDataTransfer :: pack()
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
template< typename EndPointType >
|
|
||||||
peoSyncDataTransfer(
|
|
||||||
|
|
||||||
EndPointType& __endPoint,
|
|
||||||
Topology& __topology
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
|
||||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
|
||||||
__topology.add( *this );
|
|
||||||
|
|
||||||
sem_init( &sync, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename EndPointType, typename FunctorType >
|
|
||||||
peoSyncDataTransfer(
|
|
||||||
|
|
||||||
EndPointType& __endPoint,
|
|
||||||
Topology& __topology,
|
|
||||||
FunctorType& externalFunctorRef
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
|
||||||
destination = new MsgTransferQueue< EndPointType >( __endPoint, externalFunctorRef );
|
|
||||||
__topology.add( *this );
|
|
||||||
|
|
||||||
sem_init( &sync, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename SourceEndPointType, typename DestinationEndPointType >
|
|
||||||
peoSyncDataTransfer(
|
|
||||||
|
|
||||||
SourceEndPointType& __source,
|
|
||||||
DestinationEndPointType& __destination,
|
|
||||||
Topology& __topology
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
|
||||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
|
||||||
__topology.add( *this );
|
|
||||||
|
|
||||||
sem_init( &sync, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename SourceEndPointType, typename DestinationEndPointType, typename FunctorType >
|
|
||||||
peoSyncDataTransfer(
|
|
||||||
|
|
||||||
SourceEndPointType& __source,
|
|
||||||
DestinationEndPointType& __destination,
|
|
||||||
Topology& __topology,
|
|
||||||
FunctorType& externalFunctorRef
|
|
||||||
|
|
||||||
) : topology( __topology )
|
|
||||||
{
|
|
||||||
|
|
||||||
source = new MsgTransferQueue< SourceEndPointType >( __source, externalFunctorRef );
|
|
||||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination, externalFunctorRef );
|
|
||||||
__topology.add( *this );
|
|
||||||
|
|
||||||
sem_init( &sync, 0, 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void operator()();
|
|
||||||
|
|
||||||
void pack();
|
|
||||||
|
|
||||||
void unpack();
|
|
||||||
|
|
||||||
void packSynchronizeReq();
|
|
||||||
|
|
||||||
void notifySending();
|
|
||||||
|
|
||||||
void notifyReceiving();
|
|
||||||
|
|
||||||
void notifySendingSyncReq();
|
|
||||||
|
|
||||||
void notifySynchronized();
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void sendData();
|
|
||||||
void receiveData();
|
|
||||||
|
|
||||||
Topology& topology; // neighboring topology
|
|
||||||
|
|
||||||
// source and destination end-points
|
|
||||||
AbstractMsgTransferQueue* source;
|
|
||||||
AbstractMsgTransferQueue* destination;
|
|
||||||
|
|
||||||
std :: queue< Cooperative* > coop_em;
|
|
||||||
|
|
||||||
sem_t sync;
|
|
||||||
|
|
||||||
bool standbyTransfer;
|
|
||||||
|
|
||||||
std :: vector< Cooperative* > in, out, all;
|
|
||||||
unsigned nbTransfersIn, nbTransfersOut;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void peoSyncDataTransfer :: pack() {
|
|
||||||
|
|
||||||
::pack( coop_em.front()->getKey() );
|
::pack( coop_em.front()->getKey() );
|
||||||
source->packMessage();
|
source->packMessage();
|
||||||
coop_em.pop();
|
coop_em.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: unpack() {
|
void peoSyncDataTransfer :: unpack()
|
||||||
|
{
|
||||||
|
|
||||||
destination->unpackMessage();
|
destination->unpackMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: packSynchronizeReq() {
|
void peoSyncDataTransfer :: packSynchronizeReq()
|
||||||
|
{
|
||||||
|
|
||||||
packSynchronRequest( all );
|
packSynchronRequest( all );
|
||||||
}
|
}
|
||||||
|
|
@ -154,92 +157,107 @@ void peoSyncDataTransfer :: packSynchronizeReq() {
|
||||||
extern void wakeUpCommunicator();
|
extern void wakeUpCommunicator();
|
||||||
extern int getNodeRank();
|
extern int getNodeRank();
|
||||||
|
|
||||||
void peoSyncDataTransfer :: sendData() {
|
void peoSyncDataTransfer :: sendData()
|
||||||
|
{
|
||||||
|
|
||||||
for ( unsigned i = 0; i < out.size(); i ++ ) {
|
for ( unsigned i = 0; i < out.size(); i ++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
source->pushMessage();
|
||||||
|
|
||||||
|
coop_em.push( out[ i ] );
|
||||||
|
send( out[ i ]);
|
||||||
|
|
||||||
|
printDebugMessage( "peoSyncDataTransfer: sending data." );
|
||||||
|
}
|
||||||
|
|
||||||
source->pushMessage();
|
|
||||||
|
|
||||||
coop_em.push( out[ i ] );
|
|
||||||
send( out[ i ]);
|
|
||||||
|
|
||||||
printDebugMessage( "peoSyncDataTransfer: sending data." );
|
|
||||||
}
|
|
||||||
|
|
||||||
wakeUpCommunicator();
|
wakeUpCommunicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: receiveData() {
|
void peoSyncDataTransfer :: receiveData()
|
||||||
|
{
|
||||||
|
|
||||||
assert( !( destination->empty() ) );
|
assert( !( destination->empty() ) );
|
||||||
|
|
||||||
while ( !( destination->empty() ) ) {
|
while ( !( destination->empty() ) )
|
||||||
|
{
|
||||||
printDebugMessage( "peoSyncDataTransfer: received data." );
|
|
||||||
destination->popMessage();
|
printDebugMessage( "peoSyncDataTransfer: received data." );
|
||||||
printDebugMessage( "peoSyncDataTransfer: done extracting received data." );
|
destination->popMessage();
|
||||||
}
|
printDebugMessage( "peoSyncDataTransfer: done extracting received data." );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: operator()() {
|
void peoSyncDataTransfer :: operator()()
|
||||||
|
{
|
||||||
|
|
||||||
standbyTransfer = false;
|
standbyTransfer = false;
|
||||||
nbTransfersIn = nbTransfersOut = 0;
|
nbTransfersIn = nbTransfersOut = 0;
|
||||||
|
|
||||||
topology.setNeighbors( this, in, out ); all = topology;
|
topology.setNeighbors( this, in, out );
|
||||||
|
all = topology;
|
||||||
synchronizeCoopEx(); stop();
|
|
||||||
|
synchronizeCoopEx();
|
||||||
|
stop();
|
||||||
|
|
||||||
// sending data out
|
// sending data out
|
||||||
sendData();
|
sendData();
|
||||||
// synchronizing
|
// synchronizing
|
||||||
sem_wait( &sync );
|
sem_wait( &sync );
|
||||||
// receiving data in
|
// receiving data in
|
||||||
receiveData();
|
receiveData();
|
||||||
|
|
||||||
synchronizeCoopEx(); stop();
|
synchronizeCoopEx();
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: notifySending() {
|
void peoSyncDataTransfer :: notifySending()
|
||||||
|
{
|
||||||
|
|
||||||
nbTransfersOut++;
|
nbTransfersOut++;
|
||||||
|
|
||||||
printDebugMessage( "peoSyncDataTransfer: notified of the completion of a transfer round." );
|
printDebugMessage( "peoSyncDataTransfer: notified of the completion of a transfer round." );
|
||||||
|
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() ) {
|
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||||
getOwner()->setPassive();
|
{
|
||||||
}
|
getOwner()->setPassive();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: notifyReceiving() {
|
void peoSyncDataTransfer :: notifyReceiving()
|
||||||
|
{
|
||||||
|
|
||||||
nbTransfersIn++;
|
nbTransfersIn++;
|
||||||
printDebugMessage( "peoSyncIslandMig: notified of incoming data." );
|
printDebugMessage( "peoSyncIslandMig: notified of incoming data." );
|
||||||
|
|
||||||
if ( standbyTransfer ) {
|
if ( standbyTransfer )
|
||||||
getOwner()->setActive();
|
{
|
||||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
getOwner()->setActive();
|
||||||
getOwner()->setPassive();
|
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||||
}
|
getOwner()->setPassive();
|
||||||
|
}
|
||||||
if ( nbTransfersIn == in.size() ) {
|
|
||||||
|
if ( nbTransfersIn == in.size() )
|
||||||
printDebugMessage( "peoSyncIslandMig: finished collecting incoming data." );
|
{
|
||||||
sem_post( &sync );
|
|
||||||
}
|
printDebugMessage( "peoSyncIslandMig: finished collecting incoming data." );
|
||||||
|
sem_post( &sync );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: notifySendingSyncReq () {
|
void peoSyncDataTransfer :: notifySendingSyncReq ()
|
||||||
|
{
|
||||||
|
|
||||||
getOwner()->setPassive();
|
getOwner()->setPassive();
|
||||||
printDebugMessage( "peoSyncIslandMig: synchronization request sent." );
|
printDebugMessage( "peoSyncIslandMig: synchronization request sent." );
|
||||||
}
|
}
|
||||||
|
|
||||||
void peoSyncDataTransfer :: notifySynchronized () {
|
void peoSyncDataTransfer :: notifySynchronized ()
|
||||||
|
{
|
||||||
|
|
||||||
printDebugMessage( "peoSyncIslandMig: cooperators synchronized." );
|
printDebugMessage( "peoSyncIslandMig: cooperators synchronized." );
|
||||||
|
|
||||||
standbyTransfer = true;
|
standbyTransfer = true;
|
||||||
getOwner()->setActive();
|
getOwner()->setActive();
|
||||||
resume();
|
resume();
|
||||||
|
|
|
||||||
|
|
@ -11,118 +11,143 @@
|
||||||
#define MIGRATIONS_AT_N_GENERATIONS 5
|
#define MIGRATIONS_AT_N_GENERATIONS 5
|
||||||
#define NUMBER_OF_MIGRANTS 10
|
#define NUMBER_OF_MIGRANTS 10
|
||||||
|
|
||||||
struct Representation : public eoVector< eoMinimizingFitness, double > {
|
struct Representation : public eoVector< eoMinimizingFitness, double >
|
||||||
|
{
|
||||||
|
|
||||||
Representation() { resize( SIZE ); }
|
Representation()
|
||||||
};
|
{
|
||||||
|
resize( SIZE );
|
||||||
struct Init : public eoInit< Representation > {
|
|
||||||
|
|
||||||
void operator()( Representation& rep ) {
|
|
||||||
|
|
||||||
for ( int i = 0; i < SIZE; i++ ) {
|
|
||||||
rep[ i ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
struct Eval : public eoEvalFunc< Representation > {
|
struct Init : public eoInit< Representation >
|
||||||
|
{
|
||||||
|
|
||||||
void operator()( Representation& rep ) {
|
void operator()( Representation& rep )
|
||||||
|
{
|
||||||
|
|
||||||
double fitnessValue = 0.0;
|
for ( int i = 0; i < SIZE; i++ )
|
||||||
for ( int i = 0; i < SIZE; i++ ) {
|
{
|
||||||
|
rep[ i ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||||
fitnessValue += pow( rep[ i ], 2.0 );
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
rep.fitness( fitnessValue );
|
struct Eval : public eoEvalFunc< Representation >
|
||||||
}
|
{
|
||||||
};
|
|
||||||
|
|
||||||
struct MutationOp : public eoMonOp< Representation > {
|
void operator()( Representation& rep )
|
||||||
|
{
|
||||||
|
|
||||||
bool operator()( Representation& rep ) {
|
double fitnessValue = 0.0;
|
||||||
|
for ( int i = 0; i < SIZE; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
unsigned int pos = (unsigned int)( rng.uniform() * SIZE );
|
fitnessValue += pow( rep[ i ], 2.0 );
|
||||||
rep[ pos ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
}
|
||||||
|
|
||||||
rep.invalidate();
|
rep.fitness( fitnessValue );
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct XoverOp : public eoQuadOp< Representation > {
|
|
||||||
|
|
||||||
bool operator()( Representation& repA, Representation& repB ) {
|
|
||||||
|
|
||||||
static Representation offA, offB;
|
|
||||||
double lambda = rng.uniform();
|
|
||||||
|
|
||||||
for ( int i = 0; i < SIZE; i++ ) {
|
|
||||||
|
|
||||||
offA[ i ] = lambda * repA[ i ] + ( 1.0 - lambda ) * repB[ i ];
|
|
||||||
offB[ i ] = lambda * repB[ i ] + ( 1.0 - lambda ) * repA[ i ];
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
repA = offA; repB = offB;
|
|
||||||
|
|
||||||
repA.invalidate();
|
struct MutationOp : public eoMonOp< Representation >
|
||||||
repB.invalidate();
|
{
|
||||||
|
|
||||||
return true;
|
bool operator()( Representation& rep )
|
||||||
}
|
{
|
||||||
};
|
|
||||||
|
unsigned int pos = (unsigned int)( rng.uniform() * SIZE );
|
||||||
|
rep[ pos ] = (rng.uniform() - 0.5) * DEF_DOMAIN;
|
||||||
|
|
||||||
|
rep.invalidate();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct XoverOp : public eoQuadOp< Representation >
|
||||||
|
{
|
||||||
|
|
||||||
|
bool operator()( Representation& repA, Representation& repB )
|
||||||
|
{
|
||||||
|
|
||||||
|
static Representation offA, offB;
|
||||||
|
double lambda = rng.uniform();
|
||||||
|
|
||||||
|
for ( int i = 0; i < SIZE; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
offA[ i ] = lambda * repA[ i ] + ( 1.0 - lambda ) * repB[ i ];
|
||||||
|
offB[ i ] = lambda * repB[ i ] + ( 1.0 - lambda ) * repA[ i ];
|
||||||
|
}
|
||||||
|
|
||||||
|
repA = offA;
|
||||||
|
repB = offB;
|
||||||
|
|
||||||
|
repA.invalidate();
|
||||||
|
repB.invalidate();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void pack( const Representation& rep ) {
|
void pack( const Representation& rep )
|
||||||
|
{
|
||||||
|
|
||||||
if ( rep.invalid() ) ::pack( (unsigned int)0 );
|
if ( rep.invalid() ) ::pack( (unsigned int)0 );
|
||||||
else {
|
else
|
||||||
::pack( (unsigned int)1 );
|
{
|
||||||
::pack( (double)(rep.fitness()) );
|
::pack( (unsigned int)1 );
|
||||||
}
|
::pack( (double)(rep.fitness()) );
|
||||||
|
}
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < SIZE; index++ ) {
|
for ( unsigned int index = 0; index < SIZE; index++ )
|
||||||
::pack( (double)rep[ index ] );
|
{
|
||||||
}
|
::pack( (double)rep[ index ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpack( Representation& rep ) {
|
void unpack( Representation& rep )
|
||||||
|
{
|
||||||
|
|
||||||
eoScalarFitness<double, std::greater<double> > fitness;
|
eoScalarFitness<double, std::greater<double> > fitness;
|
||||||
unsigned int validFitness;
|
unsigned int validFitness;
|
||||||
|
|
||||||
unpack( validFitness );
|
unpack( validFitness );
|
||||||
if ( validFitness ) {
|
if ( validFitness )
|
||||||
|
{
|
||||||
|
|
||||||
double fitnessValue; ::unpack( fitnessValue );
|
double fitnessValue;
|
||||||
rep.fitness( fitnessValue );
|
::unpack( fitnessValue );
|
||||||
}
|
rep.fitness( fitnessValue );
|
||||||
else {
|
}
|
||||||
rep.invalidate();
|
else
|
||||||
}
|
{
|
||||||
|
rep.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
double value;
|
double value;
|
||||||
for ( unsigned int index = 0; index < SIZE; index++ ) {
|
for ( unsigned int index = 0; index < SIZE; index++ )
|
||||||
::unpack( value );
|
{
|
||||||
rep[ index ] = value;
|
::unpack( value );
|
||||||
}
|
rep[ index ] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int __argc, char** __argv ) {
|
int main( int __argc, char** __argv )
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
rng.reseed( time( NULL ) );
|
rng.reseed( time( NULL ) );
|
||||||
srand( time( NULL ) );
|
srand( time( NULL ) );
|
||||||
|
|
||||||
peo::init( __argc, __argv );
|
peo::init( __argc, __argv );
|
||||||
|
|
||||||
|
|
||||||
eoParser parser ( __argc, __argv );
|
eoParser parser ( __argc, __argv );
|
||||||
|
|
||||||
eoValueParam < unsigned int > nbGenerations( NB_GEN, "maxGen");
|
eoValueParam < unsigned int > nbGenerations( NB_GEN, "maxGen");
|
||||||
parser.processParam ( nbGenerations );
|
parser.processParam ( nbGenerations );
|
||||||
|
|
||||||
|
|
@ -131,7 +156,7 @@ int main( int __argc, char** __argv ) {
|
||||||
|
|
||||||
|
|
||||||
RingTopology ring,topo;
|
RingTopology ring,topo;
|
||||||
unsigned int dataA, dataB, dataC;
|
unsigned int dataA, dataB, dataC;
|
||||||
|
|
||||||
dataA = 1;
|
dataA = 1;
|
||||||
dataB = 5;
|
dataB = 5;
|
||||||
|
|
@ -156,12 +181,12 @@ int main( int __argc, char** __argv ) {
|
||||||
eoCheckPoint< Representation > checkpoint( cont );
|
eoCheckPoint< Representation > checkpoint( cont );
|
||||||
eoEasyEA< Representation > algo( checkpoint, eval, selectN, transform, elitReplace );
|
eoEasyEA< Representation > algo( checkpoint, eval, selectN, transform, elitReplace );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
// MIGRATION CONTEXT DEFINITION
|
// MIGRATION CONTEXT DEFINITION
|
||||||
|
|
||||||
eoPeriodicContinue< Representation > mig_conti( MIGRATIONS_AT_N_GENERATIONS );
|
eoPeriodicContinue< Representation > mig_conti( MIGRATIONS_AT_N_GENERATIONS );
|
||||||
eoContinuator<Representation> mig_cont(mig_conti,pop);
|
eoContinuator<Representation> mig_cont(mig_conti,pop);
|
||||||
eoRandomSelect<Representation> mig_select_one;
|
eoRandomSelect<Representation> mig_select_one;
|
||||||
eoSelector <Representation, eoPop<Representation> > mig_select (mig_select_one,NUMBER_OF_MIGRANTS,pop);
|
eoSelector <Representation, eoPop<Representation> > mig_select (mig_select_one,NUMBER_OF_MIGRANTS,pop);
|
||||||
|
|
@ -185,7 +210,7 @@ int main( int __argc, char** __argv ) {
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
// MIGRATION CONTEXT DEFINITION
|
// MIGRATION CONTEXT DEFINITION
|
||||||
|
|
||||||
eoPeriodicContinue< Representation > mig_conti2( MIGRATIONS_AT_N_GENERATIONS );
|
eoPeriodicContinue< Representation > mig_conti2( MIGRATIONS_AT_N_GENERATIONS );
|
||||||
eoContinuator<Representation> mig_cont2(mig_conti2,pop2);
|
eoContinuator<Representation> mig_cont2(mig_conti2,pop2);
|
||||||
eoRandomSelect<Representation> mig_select_one2;
|
eoRandomSelect<Representation> mig_select_one2;
|
||||||
eoSelector <Representation, eoPop<Representation> > mig_select2 (mig_select_one2,NUMBER_OF_MIGRANTS,pop2);
|
eoSelector <Representation, eoPop<Representation> > mig_select2 (mig_select_one2,NUMBER_OF_MIGRANTS,pop2);
|
||||||
|
|
@ -208,7 +233,7 @@ int main( int __argc, char** __argv ) {
|
||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
// MIGRATION CONTEXT DEFINITION
|
// MIGRATION CONTEXT DEFINITION
|
||||||
|
|
||||||
eoPeriodicContinue< Representation > mig_conti3( MIGRATIONS_AT_N_GENERATIONS );
|
eoPeriodicContinue< Representation > mig_conti3( MIGRATIONS_AT_N_GENERATIONS );
|
||||||
eoContinuator<Representation> mig_cont3(mig_conti3,pop3);
|
eoContinuator<Representation> mig_cont3(mig_conti3,pop3);
|
||||||
eoRandomSelect<Representation> mig_select_one3;
|
eoRandomSelect<Representation> mig_select_one3;
|
||||||
|
|
@ -217,7 +242,7 @@ int main( int __argc, char** __argv ) {
|
||||||
eoReplace <Representation, eoPop<Representation> > mig_replace3 (replace_one3,pop3);
|
eoReplace <Representation, eoPop<Representation> > mig_replace3 (replace_one3,pop3);
|
||||||
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(MIGRATIONS_AT_N_GENERATIONS,mig_select3,mig_replace3,topo);
|
// peoSyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(MIGRATIONS_AT_N_GENERATIONS,mig_select3,mig_replace3,topo);
|
||||||
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(mig_cont3,mig_select3,mig_replace3,topo);
|
peoAsyncIslandMig< eoPop< Representation >, eoPop< Representation > > mig3(mig_cont3,mig_select3,mig_replace3,topo);
|
||||||
|
|
||||||
checkpoint3.add( mig3 );
|
checkpoint3.add( mig3 );
|
||||||
//-------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -237,11 +262,11 @@ int main( int __argc, char** __argv ) {
|
||||||
mig3.setOwner( algoPar3 );
|
mig3.setOwner( algoPar3 );
|
||||||
checkpoint3.add( dataTransferc );
|
checkpoint3.add( dataTransferc );
|
||||||
dataTransferc.setOwner( algoPar3 );
|
dataTransferc.setOwner( algoPar3 );
|
||||||
|
|
||||||
peo::run();
|
peo::run();
|
||||||
peo::finalize();
|
peo::finalize();
|
||||||
|
|
||||||
if ( getNodeRank() == 1 )
|
if ( getNodeRank() == 1 )
|
||||||
std::cout << "A: " << dataA << std::endl;
|
std::cout << "A: " << dataA << std::endl;
|
||||||
if ( getNodeRank() == 2 )
|
if ( getNodeRank() == 2 )
|
||||||
std::cout << "B: " << dataB << std::endl;
|
std::cout << "B: " << dataB << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -18,82 +18,89 @@
|
||||||
#define MUT_RATE 0.01
|
#define MUT_RATE 0.01
|
||||||
|
|
||||||
|
|
||||||
struct CoSearch
|
struct CoSearch
|
||||||
|
{
|
||||||
|
|
||||||
|
CoSearch(
|
||||||
|
eoPop< Route >& A, eoPop< Route >& B,
|
||||||
|
peoAsyncDataTransfer& asyncTransferA, peoAsyncDataTransfer& asyncTransferB
|
||||||
|
)
|
||||||
|
: transferA( A ), transferB( B ),
|
||||||
|
asyncDataTransferA( asyncTransferA ), asyncDataTransferB( asyncTransferB )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator()()
|
||||||
|
{
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < 100; index++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
asyncDataTransferA();
|
||||||
|
asyncDataTransferB();
|
||||||
|
|
||||||
|
eoPop< Route > intermed;
|
||||||
|
intermed = transferA;
|
||||||
|
transferA = transferB;
|
||||||
|
transferB = intermed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eoPop< Route >& transferA;
|
||||||
|
eoPop< Route >& transferB;
|
||||||
|
|
||||||
|
peoAsyncDataTransfer& asyncDataTransferA;
|
||||||
|
peoAsyncDataTransfer& asyncDataTransferB;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct PushBackAggregation
|
||||||
|
{
|
||||||
|
|
||||||
|
void operator()( eoPop< Route >& A, eoPop< Route >& B )
|
||||||
|
{
|
||||||
|
|
||||||
|
for ( unsigned int index = 0; index < B.size(); index++ )
|
||||||
|
{
|
||||||
|
|
||||||
|
A.push_back( B[ index ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main( int __argc, char** __argv )
|
||||||
{
|
{
|
||||||
|
|
||||||
CoSearch(
|
|
||||||
eoPop< Route >& A, eoPop< Route >& B,
|
|
||||||
peoAsyncDataTransfer& asyncTransferA, peoAsyncDataTransfer& asyncTransferB
|
|
||||||
)
|
|
||||||
: transferA( A ), transferB( B ),
|
|
||||||
asyncDataTransferA( asyncTransferA ), asyncDataTransferB( asyncTransferB ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void operator()() {
|
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < 100; index++ ) {
|
|
||||||
|
|
||||||
asyncDataTransferA();
|
|
||||||
asyncDataTransferB();
|
|
||||||
|
|
||||||
eoPop< Route > intermed;
|
|
||||||
intermed = transferA;
|
|
||||||
transferA = transferB;
|
|
||||||
transferB = intermed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eoPop< Route >& transferA;
|
|
||||||
eoPop< Route >& transferB;
|
|
||||||
|
|
||||||
peoAsyncDataTransfer& asyncDataTransferA;
|
|
||||||
peoAsyncDataTransfer& asyncDataTransferB;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct PushBackAggregation {
|
|
||||||
|
|
||||||
void operator()( eoPop< Route >& A, eoPop< Route >& B ) {
|
|
||||||
|
|
||||||
for ( unsigned int index = 0; index < B.size(); index++ ) {
|
|
||||||
|
|
||||||
A.push_back( B[ index ] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main( int __argc, char** __argv ) {
|
|
||||||
|
|
||||||
peo :: init( __argc, __argv );
|
peo :: init( __argc, __argv );
|
||||||
|
|
||||||
loadParameters( __argc, __argv );
|
loadParameters( __argc, __argv );
|
||||||
|
|
||||||
RouteInit route_init;
|
RouteInit route_init;
|
||||||
RouteEval full_eval;
|
RouteEval full_eval;
|
||||||
OrderXover crossover;
|
OrderXover crossover;
|
||||||
CitySwap mutation;
|
CitySwap mutation;
|
||||||
eoPop< Route > population( POP_SIZE, route_init );
|
eoPop< Route > population( POP_SIZE, route_init );
|
||||||
eoGenContinue< Route > eaCont( NUM_GEN );
|
eoGenContinue< Route > eaCont( NUM_GEN );
|
||||||
eoCheckPoint< Route > eaCheckpointContinue( eaCont );
|
eoCheckPoint< Route > eaCheckpointContinue( eaCont );
|
||||||
eoRankingSelect< Route > selectionStrategy;
|
eoRankingSelect< Route > selectionStrategy;
|
||||||
eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE );
|
eoSelectNumber< Route > eaSelect( selectionStrategy, POP_SIZE );
|
||||||
eoSGATransform< Route > transformA( crossover, CROSS_RATE, mutation, MUT_RATE );
|
eoSGATransform< Route > transformA( crossover, CROSS_RATE, mutation, MUT_RATE );
|
||||||
eoPlusReplacement< Route > eaReplace;
|
eoPlusReplacement< Route > eaReplace;
|
||||||
RingTopology ring;
|
RingTopology ring;
|
||||||
eoPlusReplacement< Route > transferReplace;
|
eoPlusReplacement< Route > transferReplace;
|
||||||
peoAsyncDataTransfer asyncEAEndPoint( population, population, ring, transferReplace );
|
peoAsyncDataTransfer asyncEAEndPoint( population, population, ring, transferReplace );
|
||||||
eaCheckpointContinue.add( asyncEAEndPoint );
|
eaCheckpointContinue.add( asyncEAEndPoint );
|
||||||
eoEasyEA< Route > eaAlg( eaCheckpointContinue, full_eval, eaSelect, transformA, eaReplace );
|
eoEasyEA< Route > eaAlg( eaCheckpointContinue, full_eval, eaSelect, transformA, eaReplace );
|
||||||
peoWrapper paraEAAlg( eaAlg, population );
|
peoWrapper paraEAAlg( eaAlg, population );
|
||||||
asyncEAEndPoint.setOwner( paraEAAlg );
|
asyncEAEndPoint.setOwner( paraEAAlg );
|
||||||
|
|
||||||
eoPop< Route > populationB( POP_SIZE, route_init );
|
eoPop< Route > populationB( POP_SIZE, route_init );
|
||||||
eoGenContinue< Route > eaContB( NUM_GEN );
|
eoGenContinue< Route > eaContB( NUM_GEN );
|
||||||
eoCheckPoint< Route > eaCheckpointContinueB( eaContB );
|
eoCheckPoint< Route > eaCheckpointContinueB( eaContB );
|
||||||
eoRankingSelect< Route > selectionStrategyB;
|
eoRankingSelect< Route > selectionStrategyB;
|
||||||
eoSelectNumber< Route > eaSelectB( selectionStrategyB, POP_SIZE );
|
eoSelectNumber< Route > eaSelectB( selectionStrategyB, POP_SIZE );
|
||||||
RingTopology ringB;
|
RingTopology ringB;
|
||||||
eoPlusReplacement< Route > transferReplaceB;
|
eoPlusReplacement< Route > transferReplaceB;
|
||||||
peoAsyncDataTransfer asyncEAEndPointB( populationB, populationB, ringB, transferReplaceB );
|
peoAsyncDataTransfer asyncEAEndPointB( populationB, populationB, ringB, transferReplaceB );
|
||||||
eaCheckpointContinueB.add( asyncEAEndPointB );
|
eaCheckpointContinueB.add( asyncEAEndPointB );
|
||||||
eoSGATransform< Route > transformB ( crossover, CROSS_RATE, mutation, MUT_RATE );
|
eoSGATransform< Route > transformB ( crossover, CROSS_RATE, mutation, MUT_RATE );
|
||||||
|
|
@ -107,7 +114,7 @@ int main( int __argc, char** __argv ) {
|
||||||
|
|
||||||
peoAsyncDataTransfer coSearchEndPointA( A, A, ring, pushBackA );
|
peoAsyncDataTransfer coSearchEndPointA( A, A, ring, pushBackA );
|
||||||
peoAsyncDataTransfer coSearchEndPointB( B, B, ringB, pushBackB );
|
peoAsyncDataTransfer coSearchEndPointB( B, B, ringB, pushBackB );
|
||||||
|
|
||||||
CoSearch coSearch( A, B, coSearchEndPointA, coSearchEndPointB );
|
CoSearch coSearch( A, B, coSearchEndPointA, coSearchEndPointB );
|
||||||
peoWrapper paraCoSearch( coSearch );
|
peoWrapper paraCoSearch( coSearch );
|
||||||
coSearchEndPointA.setOwner( paraCoSearch );
|
coSearchEndPointA.setOwner( paraCoSearch );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue