JobStore has now getters, setters and wrappers methods.
This commit is contained in:
parent
6bb2ccfbd6
commit
63f12c4e1c
3 changed files with 106 additions and 55 deletions
|
|
@ -25,6 +25,7 @@ namespace eo
|
|||
namespace Channel
|
||||
{
|
||||
const int Commands = 0;
|
||||
const int Messages = 1;
|
||||
}
|
||||
|
||||
namespace Message
|
||||
|
|
@ -33,26 +34,32 @@ namespace eo
|
|||
const int Finish = 1;
|
||||
}
|
||||
|
||||
|
||||
template< typename JobData, typename Wrapped >
|
||||
struct SharedDataFunction
|
||||
{
|
||||
SharedDataFunction( Wrapped * w )
|
||||
SharedDataFunction( Wrapped * w = 0 ) : _wrapped( w )
|
||||
{
|
||||
wrapped = w;
|
||||
// empty
|
||||
}
|
||||
|
||||
void wrapped( Wrapped * w )
|
||||
{
|
||||
_wrapped = w;
|
||||
}
|
||||
|
||||
void data( JobData* _d )
|
||||
{
|
||||
d = _d;
|
||||
if( wrapped )
|
||||
if( _wrapped )
|
||||
{
|
||||
wrapped->data( _d );
|
||||
_wrapped->data( _d );
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
JobData* d;
|
||||
Wrapped* wrapped;
|
||||
Wrapped* _wrapped;
|
||||
};
|
||||
|
||||
template< typename JobData >
|
||||
|
|
@ -110,11 +117,78 @@ namespace eo
|
|||
template< typename JobData >
|
||||
struct JobStore
|
||||
{
|
||||
virtual SendTaskFunction<JobData> & sendTask() const = 0;
|
||||
virtual HandleResponseFunction<JobData> & handleResponse() const = 0;
|
||||
virtual ProcessTaskFunction<JobData> & processTask() const = 0;
|
||||
virtual IsFinishedFunction<JobData> & isFinished() const = 0;
|
||||
JobStore(
|
||||
SendTaskFunction<JobData>* stf,
|
||||
HandleResponseFunction<JobData>* hrf,
|
||||
ProcessTaskFunction<JobData>* ptf,
|
||||
IsFinishedFunction<JobData>* iff
|
||||
) :
|
||||
_stf( stf ), _hrf( hrf ), _ptf( ptf ), _iff( iff )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
JobStore()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
SendTaskFunction<JobData> & sendTask() { return *_stf; }
|
||||
HandleResponseFunction<JobData> & handleResponse() { return *_hrf; }
|
||||
ProcessTaskFunction<JobData> & processTask() { return *_ptf; }
|
||||
IsFinishedFunction<JobData> & isFinished() { return *_iff; }
|
||||
|
||||
void sendTask( SendTaskFunction<JobData>* stf ) { _stf = stf; }
|
||||
void handleResponse( HandleResponseFunction<JobData>* hrf ) { _hrf = hrf; }
|
||||
void processTask( ProcessTaskFunction<JobData>* ptf ) { _ptf = ptf; }
|
||||
void isFinished( IsFinishedFunction<JobData>* iff ) { _iff = iff; }
|
||||
|
||||
void wrapSendTask( SendTaskFunction<JobData>* stf )
|
||||
{
|
||||
if( stf )
|
||||
{
|
||||
stf->wrapped( _stf );
|
||||
_stf = stf;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapHandleResponse( HandleResponseFunction<JobData>* hrf )
|
||||
{
|
||||
if( hrf )
|
||||
{
|
||||
hrf->wrapped( _hrf );
|
||||
_hrf = hrf;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapProcessTask( ProcessTaskFunction<JobData>* ptf )
|
||||
{
|
||||
if( ptf )
|
||||
{
|
||||
ptf->wrapped( _ptf );
|
||||
_ptf = ptf;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapIsFinished( IsFinishedFunction<JobData>* iff )
|
||||
{
|
||||
if( iff )
|
||||
{
|
||||
iff->wrapped( _iff );
|
||||
_iff = iff;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO commenter : laissé à la couche d'en dessous car impossible d'initialiser une donnée membre d'une classe mère depuis une classe fille.
|
||||
virtual JobData* data() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
// TODO commenter : Utiliser des pointeurs pour éviter d'écraser les fonctions wrappées
|
||||
SendTaskFunction< JobData >* _stf;
|
||||
HandleResponseFunction< JobData >* _hrf;
|
||||
ProcessTaskFunction< JobData >* _ptf;
|
||||
IsFinishedFunction< JobData >* _iff;
|
||||
};
|
||||
|
||||
template< class JobData >
|
||||
|
|
@ -141,15 +215,6 @@ namespace eo
|
|||
isFinished.data( store.data() );
|
||||
}
|
||||
|
||||
/*
|
||||
// master
|
||||
virtual bool isFinished() = 0;
|
||||
virtual void sendTask( int wrkRank ) = 0;
|
||||
virtual void handleResponse( int wrkRank ) = 0;
|
||||
// worker
|
||||
virtual void processTask( ) = 0;
|
||||
*/
|
||||
|
||||
protected:
|
||||
|
||||
SendTaskFunction<JobData> & sendTask;
|
||||
|
|
|
|||
|
|
@ -153,6 +153,11 @@ namespace eo
|
|||
template< class EOT >
|
||||
struct ParallelApplyStore : public JobStore< ParallelApplyData<EOT> >
|
||||
{
|
||||
using JobStore< ParallelApplyData<EOT> >::_stf;
|
||||
using JobStore< ParallelApplyData<EOT> >::_hrf;
|
||||
using JobStore< ParallelApplyData<EOT> >::_ptf;
|
||||
using JobStore< ParallelApplyData<EOT> >::_iff;
|
||||
|
||||
ParallelApplyStore(
|
||||
eoUF<EOT&, void> & _proc,
|
||||
std::vector<EOT>& _pop,
|
||||
|
|
@ -162,42 +167,28 @@ namespace eo
|
|||
)
|
||||
: _data( _proc, _pop, _masterRank, _packetSize )
|
||||
{
|
||||
stpa = new SendTaskParallelApply<EOT>;
|
||||
hrpa = new HandleResponseParallelApply<EOT>;
|
||||
ptpa = new ProcessTaskParallelApply<EOT>;
|
||||
ispa = new IsFinishedParallelApply<EOT>;
|
||||
_stf = new SendTaskParallelApply<EOT>;
|
||||
_hrf = new HandleResponseParallelApply<EOT>;
|
||||
_ptf = new ProcessTaskParallelApply<EOT>;
|
||||
_iff = new IsFinishedParallelApply<EOT>;
|
||||
}
|
||||
|
||||
~ParallelApplyStore()
|
||||
{
|
||||
delete stpa;
|
||||
delete hrpa;
|
||||
delete ptpa;
|
||||
delete ispa;
|
||||
}
|
||||
|
||||
SendTaskParallelApply< EOT >& sendTask() const { return *stpa; }
|
||||
HandleResponseParallelApply< EOT >& handleResponse() const { return *hrpa; }
|
||||
ProcessTaskParallelApply< EOT > & processTask() const { return *ptpa; }
|
||||
IsFinishedParallelApply< EOT >& isFinished() const { return *ispa; }
|
||||
|
||||
void sendTask( SendTaskParallelApply< EOT >* _stpa ) { stpa = _stpa; }
|
||||
void handleResponse( HandleResponseParallelApply< EOT >* _hrpa ) { hrpa = _hrpa; }
|
||||
void processTask( ProcessTaskParallelApply< EOT >* _ptpa ) { ptpa = _ptpa; }
|
||||
void isFinished( IsFinishedParallelApply< EOT >* _ispa ) { ispa = _ispa; }
|
||||
|
||||
ParallelApplyData<EOT>* data() { return &_data; }
|
||||
|
||||
protected:
|
||||
// TODO commenter : Utiliser des pointeurs pour éviter d'écraser les fonctions wrappées
|
||||
SendTaskParallelApply<EOT>* stpa;
|
||||
HandleResponseParallelApply<EOT>* hrpa;
|
||||
ProcessTaskParallelApply<EOT>* ptpa;
|
||||
IsFinishedParallelApply<EOT>* ispa;
|
||||
~ParallelApplyStore()
|
||||
{
|
||||
delete _stf;
|
||||
delete _hrf;
|
||||
delete _ptf;
|
||||
delete _iff;
|
||||
}
|
||||
|
||||
protected:
|
||||
ParallelApplyData<EOT> _data;
|
||||
};
|
||||
|
||||
// TODO commentaire : impossible de faire un typedef sur un template sans passer
|
||||
// par un traits => complique la tâche de l'utilisateur pour rien.
|
||||
template< typename EOT >
|
||||
class ParallelApply : public Job< ParallelApplyData<EOT> >
|
||||
{
|
||||
|
|
@ -212,10 +203,6 @@ namespace eo
|
|||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// bmpi::communicator& comm;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,16 +19,16 @@ struct plusOne : public eoUF< int&, void >
|
|||
template< class EOT >
|
||||
struct ShowWrappedResult : public IsFinishedParallelApply<EOT>
|
||||
{
|
||||
using IsFinishedParallelApply<EOT>::wrapped;
|
||||
using IsFinishedParallelApply<EOT>::_wrapped;
|
||||
|
||||
ShowWrappedResult ( IsFinishedParallelApply<EOT> * w ) : IsFinishedParallelApply<EOT>( w ), times( 0 )
|
||||
ShowWrappedResult ( IsFinishedParallelApply<EOT> * w = 0 ) : IsFinishedParallelApply<EOT>( w ), times( 0 )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
bool wrappedValue = wrapped->operator()(); // (*wrapped)();
|
||||
bool wrappedValue = _wrapped->operator()(); // (*_wrapped)();
|
||||
cout << times << ") Wrapped function would say that it is " << ( wrappedValue ? "":"not ") << "finished" << std::endl;
|
||||
++times;
|
||||
return wrappedValue;
|
||||
|
|
@ -61,12 +61,11 @@ int main(int argc, char** argv)
|
|||
StaticAssignmentAlgorithm assign( v.size() );
|
||||
|
||||
ParallelApplyStore< int > store( plusOneInstance, v, 0, 1 );
|
||||
IsFinishedParallelApply< int >& wrapped = store.isFinished();
|
||||
ShowWrappedResult< int >* wrapper = new ShowWrappedResult<int>( &wrapped );
|
||||
store.isFinished( wrapper );
|
||||
store.wrapIsFinished( new ShowWrappedResult<int> );
|
||||
|
||||
// Job< ParallelApplyData<int> > job( assign, 0, store );
|
||||
ParallelApply<int> job( assign, 0, store );
|
||||
// Equivalent to:
|
||||
// Job< ParallelApplyData<int> > job( assign, 0, store );
|
||||
job.run();
|
||||
|
||||
if( job.isMaster() )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue