Automatic deleting functors, only if necessary.
This commit is contained in:
parent
d805800731
commit
108c0bcf35
4 changed files with 60 additions and 20 deletions
|
|
@ -40,11 +40,19 @@ namespace eo
|
|||
template< typename JobData, typename Wrapped >
|
||||
struct SharedDataFunction
|
||||
{
|
||||
SharedDataFunction( Wrapped * w = 0 ) : _wrapped( w )
|
||||
SharedDataFunction( Wrapped * w = 0 ) : _wrapped( w ), _needDelete( false )
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
virtual ~SharedDataFunction()
|
||||
{
|
||||
if( _wrapped && _wrapped->needDelete() )
|
||||
{
|
||||
delete _wrapped;
|
||||
}
|
||||
}
|
||||
|
||||
void wrapped( Wrapped * w )
|
||||
{
|
||||
_wrapped = w;
|
||||
|
|
@ -59,9 +67,13 @@ namespace eo
|
|||
}
|
||||
}
|
||||
|
||||
bool needDelete() { return _needDelete; }
|
||||
void needDelete( bool b ) { _needDelete = b; }
|
||||
|
||||
protected:
|
||||
JobData* d;
|
||||
Wrapped* _wrapped;
|
||||
bool _needDelete;
|
||||
};
|
||||
|
||||
template< typename JobData >
|
||||
|
|
@ -119,7 +131,6 @@ namespace eo
|
|||
template< typename JobData >
|
||||
struct JobStore
|
||||
{
|
||||
// TODO commentaire: ces pointeurs devraient être alloués avec new pour éviter segfault on quit.
|
||||
JobStore(
|
||||
SendTaskFunction<JobData>* stf,
|
||||
HandleResponseFunction<JobData>* hrf,
|
||||
|
|
@ -138,12 +149,10 @@ namespace eo
|
|||
|
||||
~JobStore()
|
||||
{
|
||||
// TODO commentaire: Composition Pattern => délégation de la destruction => destruction homogène => new
|
||||
// et delete partout.
|
||||
delete _stf;
|
||||
delete _hrf;
|
||||
delete _ptf;
|
||||
delete _iff;
|
||||
if( _stf->needDelete() ) delete _stf;
|
||||
if( _hrf->needDelete() ) delete _hrf;
|
||||
if( _ptf->needDelete() ) delete _ptf;
|
||||
if( _iff->needDelete() ) delete _iff;
|
||||
}
|
||||
|
||||
SendTaskFunction<JobData> & sendTask() { return *_stf; }
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ namespace eo
|
|||
|
||||
~ProcessTaskParallelEval()
|
||||
{
|
||||
delete _wrapped;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -39,7 +38,6 @@ namespace eo
|
|||
ParallelEvalStore(
|
||||
eoUF<EOT&, void> & _proc,
|
||||
int _masterRank,
|
||||
// long _maxTime = 0,
|
||||
int _packetSize = 1
|
||||
) :
|
||||
ParallelApplyStore< EOT >( _proc, *( new std::vector<EOT> ), _masterRank, _packetSize )
|
||||
|
|
|
|||
|
|
@ -21,17 +21,23 @@ namespace eo
|
|||
{
|
||||
ParallelApplyData(
|
||||
eoUF<EOT&, void> & _proc,
|
||||
std::vector<EOT> & _pop,
|
||||
int _masterRank,
|
||||
// long _maxTime = 0,
|
||||
int _packetSize
|
||||
int _packetSize,
|
||||
std::vector<EOT> * _pop = 0
|
||||
) :
|
||||
_data( &_pop ), func( _proc ), index( 0 ), size( _pop.size() ), packetSize( _packetSize ), masterRank( _masterRank ), comm( Node::comm() )
|
||||
_data( _pop ), func( _proc ), index( 0 ), packetSize( _packetSize ), masterRank( _masterRank ), comm( Node::comm() )
|
||||
{
|
||||
if ( _packetSize <= 0 )
|
||||
{
|
||||
throw std::runtime_error("Packet size should not be negative.");
|
||||
}
|
||||
|
||||
if( _pop )
|
||||
{
|
||||
size = _pop->size();
|
||||
}
|
||||
|
||||
tempArray = new EOT[ _packetSize ];
|
||||
}
|
||||
|
||||
|
|
@ -172,18 +178,36 @@ namespace eo
|
|||
|
||||
ParallelApplyStore(
|
||||
eoUF<EOT&, void> & _proc,
|
||||
std::vector<EOT>& _pop,
|
||||
int _masterRank,
|
||||
// long _maxTime = 0,
|
||||
int _packetSize = 1,
|
||||
// JobStore functors
|
||||
SendTaskParallelApply<EOT> * stpa = new SendTaskParallelApply<EOT>,
|
||||
HandleResponseParallelApply<EOT>* hrpa = new HandleResponseParallelApply<EOT>,
|
||||
ProcessTaskParallelApply<EOT>* ptpa = new ProcessTaskParallelApply<EOT>,
|
||||
IsFinishedParallelApply<EOT>* ifpa = new IsFinishedParallelApply<EOT>
|
||||
SendTaskParallelApply<EOT> * stpa = 0,
|
||||
HandleResponseParallelApply<EOT>* hrpa = 0,
|
||||
ProcessTaskParallelApply<EOT>* ptpa = 0,
|
||||
IsFinishedParallelApply<EOT>* ifpa = 0
|
||||
) :
|
||||
_data( _proc, _pop, _masterRank, _packetSize )
|
||||
_data( _proc, _masterRank, _packetSize )
|
||||
{
|
||||
if( stpa == 0 ) {
|
||||
stpa = new SendTaskParallelApply<EOT>;
|
||||
stpa->needDelete( true );
|
||||
}
|
||||
|
||||
if( hrpa == 0 ) {
|
||||
hrpa = new HandleResponseParallelApply<EOT>;
|
||||
hrpa->needDelete( true );
|
||||
}
|
||||
|
||||
if( ptpa == 0 ) {
|
||||
ptpa = new ProcessTaskParallelApply<EOT>;
|
||||
ptpa->needDelete( true );
|
||||
}
|
||||
|
||||
if( ifpa == 0 ) {
|
||||
ifpa = new IsFinishedParallelApply<EOT>;
|
||||
ifpa->needDelete( true );
|
||||
}
|
||||
|
||||
_stf = stpa;
|
||||
_hrf = hrpa;
|
||||
_ptf = ptpa;
|
||||
|
|
@ -192,6 +216,11 @@ namespace eo
|
|||
|
||||
ParallelApplyData<EOT>* data() { return &_data; }
|
||||
|
||||
void data( std::vector<EOT>& _pop )
|
||||
{
|
||||
_data.init( _pop );
|
||||
}
|
||||
|
||||
virtual ~ParallelApplyStore()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,9 +49,13 @@ namespace eo
|
|||
DummyJobStore()
|
||||
{
|
||||
_stf = new DummySendTaskFunction;
|
||||
_stf->needDelete( true );
|
||||
_hrf = new DummyHandleResponseFunction;
|
||||
_hrf->needDelete( true );
|
||||
_ptf = new DummyProcessTaskFunction;
|
||||
_ptf->needDelete( true );
|
||||
_iff = new DummyIsFinishedFunction;
|
||||
_iff->needDelete( true );
|
||||
}
|
||||
|
||||
void* data() { return 0; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue