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;
|
||||
|
||||
struct AbstractEntity {
|
||||
|
||||
virtual ~AbstractEntity() {}
|
||||
|
||||
template < typename EntityType > operator EntityType& () {
|
||||
|
||||
return ( dynamic_cast< Entity< EntityType >& >( *this ) ).entity;
|
||||
}
|
||||
};
|
||||
struct AbstractEntity
|
||||
{
|
||||
|
||||
struct AbstractFunctor : virtual public AbstractEntity {
|
||||
virtual ~AbstractEntity() {}
|
||||
|
||||
virtual ~AbstractFunctor() {}
|
||||
|
||||
virtual void operator()() {}
|
||||
};
|
||||
template < typename EntityType > operator EntityType& ()
|
||||
{
|
||||
|
||||
struct AbstractUnaryFunctor : virtual public AbstractEntity {
|
||||
return ( dynamic_cast< Entity< EntityType >& >( *this ) ).entity;
|
||||
}
|
||||
};
|
||||
|
||||
virtual ~AbstractUnaryFunctor() {}
|
||||
|
||||
virtual void operator()( AbstractEntity& dataEntity ) {}
|
||||
};
|
||||
struct AbstractFunctor : virtual public AbstractEntity
|
||||
{
|
||||
|
||||
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 {
|
||||
|
||||
Entity( EntityType& externalEntityRef ) : entity( externalEntityRef ) {}
|
||||
|
||||
EntityType& entity;
|
||||
};
|
||||
template < typename EntityType > struct Entity : virtual public AbstractEntity
|
||||
{
|
||||
|
||||
template < typename FunctorType, typename DataType > struct FunctorEx : public Entity< DataType >, public AbstractFunctor {
|
||||
|
||||
FunctorEx( FunctorType& externalFunctorRef, DataType& externalDataRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor( Entity< DataType > :: entity );
|
||||
}
|
||||
|
||||
FunctorType& externalFunctor;
|
||||
};
|
||||
Entity( EntityType& externalEntityRef ) : entity( externalEntityRef ) {}
|
||||
|
||||
template < typename FunctorType > struct FunctorEx< FunctorType, void > : public Entity< AbstractEntity >, public AbstractFunctor {
|
||||
|
||||
FunctorEx( FunctorType& externalFunctorRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor();
|
||||
}
|
||||
EntityType& entity;
|
||||
};
|
||||
|
||||
FunctorType& externalFunctor;
|
||||
};
|
||||
template < typename FunctorType, typename DataType > struct FunctorEx : public Entity< DataType >, public AbstractFunctor
|
||||
{
|
||||
|
||||
template < typename ReturnType, typename DataType > struct FnFunctorEx
|
||||
: public Entity< DataType >, public AbstractFunctor {
|
||||
FunctorEx( FunctorType& externalFunctorRef, DataType& externalDataRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||
|
||||
FnFunctorEx( ReturnType (*externalFunctorRef)( DataType& ), DataType& externalDataRef )
|
||||
: externalFunctor( externalFunctorRef ), Entity< DataType >( externalDataRef ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor( Entity< DataType > :: entity );
|
||||
}
|
||||
|
||||
ReturnType (*externalFunctor)( DataType& );
|
||||
};
|
||||
void operator()()
|
||||
{
|
||||
|
||||
externalFunctor( Entity< DataType > :: entity );
|
||||
}
|
||||
|
||||
FunctorType& externalFunctor;
|
||||
};
|
||||
|
||||
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 >
|
||||
: public Entity< AbstractEntity >, public AbstractFunctor {
|
||||
: public Entity< AbstractEntity >, public AbstractFunctor
|
||||
{
|
||||
|
||||
FnFunctorEx( ReturnType (*externalFunctorRef)() )
|
||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||
|
||||
void operator()() {
|
||||
|
||||
externalFunctor();
|
||||
}
|
||||
|
||||
ReturnType (*externalFunctor)();
|
||||
};
|
||||
FnFunctorEx( ReturnType (*externalFunctorRef)() )
|
||||
: externalFunctor( externalFunctorRef ), Entity< AbstractEntity >( *this ) {}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
|
||||
externalFunctor();
|
||||
}
|
||||
|
||||
ReturnType (*externalFunctor)();
|
||||
};
|
||||
|
||||
|
||||
|
||||
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 FunctorType > struct UnaryFunctor : public Entity< FunctorType >, public AbstractUnaryFunctor
|
||||
{
|
||||
|
||||
template < typename ReturnType, typename DataType > struct UnaryFnFunctor
|
||||
: public Entity< AbstractEntity >, public AbstractUnaryFunctor {
|
||||
|
||||
UnaryFnFunctor( ReturnType (*externalFnRef)( DataType& ) ) : Entity< AbstractEntity >( *this ), externalFn( externalFnRef ) {
|
||||
}
|
||||
|
||||
void operator()( AbstractEntity& dataEntity ) {
|
||||
|
||||
externalFn( dataEntity );
|
||||
}
|
||||
UnaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||
|
||||
ReturnType (*externalFn)( DataType& );
|
||||
};
|
||||
void operator()( AbstractEntity& dataEntity )
|
||||
{
|
||||
|
||||
template < typename FunctorType > struct BinaryFunctor : public Entity< FunctorType >, public AbstractBinaryFunctor {
|
||||
|
||||
BinaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||
|
||||
void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB ) {
|
||||
Entity< FunctorType > :: entity( dataEntity );
|
||||
}
|
||||
};
|
||||
|
||||
Entity< FunctorType > :: entity( dataEntityA, dataEntityB );
|
||||
}
|
||||
};
|
||||
template < typename ReturnType, typename DataType > struct UnaryFnFunctor
|
||||
: public Entity< AbstractEntity >, public AbstractUnaryFunctor
|
||||
{
|
||||
|
||||
struct AbstractMsgTransferQueue : virtual public AbstractEntity {
|
||||
|
||||
virtual ~AbstractMsgTransferQueue() {}
|
||||
|
||||
virtual void pushMessage() {}
|
||||
virtual void popMessage() {}
|
||||
|
||||
virtual bool empty() { return true; }
|
||||
|
||||
virtual void packMessage() {}
|
||||
virtual void unpackMessage() {}
|
||||
};
|
||||
UnaryFnFunctor( ReturnType (*externalFnRef)( DataType& ) ) : Entity< AbstractEntity >( *this ), externalFn( externalFnRef )
|
||||
{
|
||||
}
|
||||
|
||||
template < typename EntityType > struct MsgTransferQueue : public Entity< EntityType >, public AbstractMsgTransferQueue {
|
||||
|
||||
MsgTransferQueue( EntityType& externalDataRef )
|
||||
: Entity< EntityType >( externalDataRef ) {
|
||||
|
||||
aggregationFunctor = new BinaryFunctor< AssignmentFunctor >( assignmentFunctor );
|
||||
}
|
||||
|
||||
template < typename FunctorType >
|
||||
MsgTransferQueue( EntityType& externalDataRef, FunctorType& externalFunctorRef )
|
||||
: 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;
|
||||
};
|
||||
void operator()( AbstractEntity& dataEntity )
|
||||
{
|
||||
|
||||
externalFn( dataEntity );
|
||||
}
|
||||
|
||||
ReturnType (*externalFn)( DataType& );
|
||||
};
|
||||
|
||||
template < typename FunctorType > struct BinaryFunctor : public Entity< FunctorType >, public AbstractBinaryFunctor
|
||||
{
|
||||
|
||||
BinaryFunctor( FunctorType& externalFunctorRef ) : Entity< FunctorType >( externalFunctorRef ) {}
|
||||
|
||||
void operator()( AbstractEntity& dataEntityA, AbstractEntity& dataEntityB )
|
||||
{
|
||||
|
||||
Entity< FunctorType > :: entity( dataEntityA, dataEntityB );
|
||||
}
|
||||
};
|
||||
|
||||
struct AbstractMsgTransferQueue : virtual public AbstractEntity
|
||||
{
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
MsgTransferQueue( EntityType& externalDataRef )
|
||||
: Entity< EntityType >( externalDataRef )
|
||||
{
|
||||
|
||||
aggregationFunctor = new BinaryFunctor< AssignmentFunctor >( assignmentFunctor );
|
||||
}
|
||||
|
||||
template < typename FunctorType >
|
||||
MsgTransferQueue( EntityType& externalDataRef, FunctorType& externalFunctorRef )
|
||||
: 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"
|
||||
|
||||
|
||||
class peoAsyncDataTransfer : public Cooperative, public eoUpdater {
|
||||
|
||||
public:
|
||||
|
||||
template< typename EndPointType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
class peoAsyncDataTransfer : public Cooperative, public eoUpdater
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
template< typename EndPointType, typename FunctorType >
|
||||
public:
|
||||
|
||||
template< typename EndPointType >
|
||||
peoAsyncDataTransfer(
|
||||
|
||||
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 >
|
||||
|
||||
EndPointType& __endPoint,
|
||||
Topology& __topology
|
||||
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
destination = new MsgTransferQueue< EndPointType >( __endPoint );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
template< typename EndPointType, typename FunctorType >
|
||||
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(
|
||||
|
||||
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 operator()();
|
||||
|
||||
void pack();
|
||||
void unpack();
|
||||
|
||||
void packSynchronizeReq();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void sendData();
|
||||
void receiveData();
|
||||
|
||||
|
||||
private:
|
||||
SourceEndPointType& __source,
|
||||
DestinationEndPointType& __destination,
|
||||
Topology& __topology
|
||||
|
||||
// the neighboring topology
|
||||
Topology& topology;
|
||||
|
||||
// source and destination end-points
|
||||
AbstractMsgTransferQueue* source;
|
||||
AbstractMsgTransferQueue* destination;
|
||||
|
||||
std :: queue< Cooperative* > coop_em;
|
||||
};
|
||||
) : topology( __topology )
|
||||
{
|
||||
|
||||
source = new MsgTransferQueue< SourceEndPointType >( __source );
|
||||
destination = new MsgTransferQueue< DestinationEndPointType >( __destination );
|
||||
__topology.add( *this );
|
||||
}
|
||||
|
||||
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 ();
|
||||
|
||||
|
||||
::pack( coop_em.front()->getKey() );
|
||||
source->packMessage();
|
||||
coop_em.pop();
|
||||
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: unpack() {
|
||||
|
||||
void peoAsyncDataTransfer :: unpack()
|
||||
{
|
||||
|
||||
lock ();
|
||||
destination->unpackMessage();
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: packSynchronizeReq() {
|
||||
void peoAsyncDataTransfer :: packSynchronizeReq()
|
||||
{
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: sendData() {
|
||||
|
||||
void peoAsyncDataTransfer :: sendData()
|
||||
{
|
||||
|
||||
std :: vector< Cooperative* > in, out;
|
||||
topology.setNeighbors( this, in, out );
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i++ ) {
|
||||
|
||||
source->pushMessage();
|
||||
|
||||
coop_em.push( out[i] );
|
||||
send( out[i] );
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: sending data." );
|
||||
}
|
||||
|
||||
for ( unsigned i = 0; i < out.size(); i++ )
|
||||
{
|
||||
|
||||
source->pushMessage();
|
||||
|
||||
coop_em.push( out[i] );
|
||||
send( out[i] );
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: sending data." );
|
||||
}
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: receiveData() {
|
||||
|
||||
void peoAsyncDataTransfer :: receiveData()
|
||||
{
|
||||
|
||||
lock ();
|
||||
{
|
||||
|
||||
while ( !( destination->empty() ) ) {
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoAsyncDataTransfer: done reading data." );
|
||||
}
|
||||
|
||||
while ( !( destination->empty() ) )
|
||||
{
|
||||
|
||||
printDebugMessage( "peoAsyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoAsyncDataTransfer: done reading data." );
|
||||
}
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void peoAsyncDataTransfer :: operator()() {
|
||||
|
||||
void peoAsyncDataTransfer :: operator()()
|
||||
{
|
||||
|
||||
sendData(); // sending data
|
||||
receiveData(); // receiving data
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,131 +22,134 @@
|
|||
|
||||
|
||||
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() );
|
||||
source->packMessage();
|
||||
coop_em.pop();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: unpack() {
|
||||
void peoSyncDataTransfer :: unpack()
|
||||
{
|
||||
|
||||
destination->unpackMessage();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: packSynchronizeReq() {
|
||||
void peoSyncDataTransfer :: packSynchronizeReq()
|
||||
{
|
||||
|
||||
packSynchronRequest( all );
|
||||
}
|
||||
|
|
@ -154,92 +157,107 @@ void peoSyncDataTransfer :: packSynchronizeReq() {
|
|||
extern void wakeUpCommunicator();
|
||||
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();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: receiveData() {
|
||||
|
||||
void peoSyncDataTransfer :: receiveData()
|
||||
{
|
||||
|
||||
assert( !( destination->empty() ) );
|
||||
|
||||
while ( !( destination->empty() ) ) {
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoSyncDataTransfer: done extracting received data." );
|
||||
}
|
||||
while ( !( destination->empty() ) )
|
||||
{
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: received data." );
|
||||
destination->popMessage();
|
||||
printDebugMessage( "peoSyncDataTransfer: done extracting received data." );
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: operator()() {
|
||||
void peoSyncDataTransfer :: operator()()
|
||||
{
|
||||
|
||||
standbyTransfer = false;
|
||||
nbTransfersIn = nbTransfersOut = 0;
|
||||
|
||||
topology.setNeighbors( this, in, out ); all = topology;
|
||||
|
||||
synchronizeCoopEx(); stop();
|
||||
|
||||
|
||||
topology.setNeighbors( this, in, out );
|
||||
all = topology;
|
||||
|
||||
synchronizeCoopEx();
|
||||
stop();
|
||||
|
||||
// sending data out
|
||||
sendData();
|
||||
// synchronizing
|
||||
sem_wait( &sync );
|
||||
// receiving data in
|
||||
receiveData();
|
||||
|
||||
synchronizeCoopEx(); stop();
|
||||
|
||||
synchronizeCoopEx();
|
||||
stop();
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySending() {
|
||||
void peoSyncDataTransfer :: notifySending()
|
||||
{
|
||||
|
||||
nbTransfersOut++;
|
||||
|
||||
|
||||
printDebugMessage( "peoSyncDataTransfer: notified of the completion of a transfer round." );
|
||||
|
||||
|
||||
getOwner()->setActive();
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() ) {
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||
{
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifyReceiving() {
|
||||
void peoSyncDataTransfer :: notifyReceiving()
|
||||
{
|
||||
|
||||
nbTransfersIn++;
|
||||
printDebugMessage( "peoSyncIslandMig: notified of incoming data." );
|
||||
|
||||
if ( standbyTransfer ) {
|
||||
getOwner()->setActive();
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
if ( nbTransfersIn == in.size() ) {
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: finished collecting incoming data." );
|
||||
sem_post( &sync );
|
||||
}
|
||||
|
||||
if ( standbyTransfer )
|
||||
{
|
||||
getOwner()->setActive();
|
||||
if ( nbTransfersOut == out.size() && nbTransfersIn < in.size() )
|
||||
getOwner()->setPassive();
|
||||
}
|
||||
|
||||
if ( nbTransfersIn == in.size() )
|
||||
{
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: finished collecting incoming data." );
|
||||
sem_post( &sync );
|
||||
}
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySendingSyncReq () {
|
||||
|
||||
void peoSyncDataTransfer :: notifySendingSyncReq ()
|
||||
{
|
||||
|
||||
getOwner()->setPassive();
|
||||
printDebugMessage( "peoSyncIslandMig: synchronization request sent." );
|
||||
}
|
||||
|
||||
void peoSyncDataTransfer :: notifySynchronized () {
|
||||
|
||||
void peoSyncDataTransfer :: notifySynchronized ()
|
||||
{
|
||||
|
||||
printDebugMessage( "peoSyncIslandMig: cooperators synchronized." );
|
||||
|
||||
|
||||
standbyTransfer = true;
|
||||
getOwner()->setActive();
|
||||
resume();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue