MpiJob now just deal with loop logic, not with handled data. Handled data is now handled by the MpiJob subclasses. Tests updated.
This commit is contained in:
parent
33e062d166
commit
28ab2004ea
4 changed files with 84 additions and 28 deletions
|
|
@ -7,28 +7,53 @@
|
|||
# include <vector>
|
||||
|
||||
template< typename EOT >
|
||||
class ParallelApply : public MpiJob< EOT >
|
||||
struct ParallelApplyContinuator : public BaseContinuator
|
||||
{
|
||||
ParallelApplyContinuator( int index, int size )
|
||||
{
|
||||
_index = index;
|
||||
_size = size;
|
||||
}
|
||||
|
||||
void index( int i ) { _index = i; }
|
||||
|
||||
bool operator()()
|
||||
{
|
||||
return _index < _size;
|
||||
}
|
||||
|
||||
private:
|
||||
int _index;
|
||||
int _size;
|
||||
};
|
||||
|
||||
template< typename EOT >
|
||||
class ParallelApply : public MpiJob
|
||||
{
|
||||
public:
|
||||
using MpiJob<EOT>::comm;
|
||||
using MpiJob<EOT>::data;
|
||||
using MpiJob<EOT>::_masterRank;
|
||||
|
||||
ParallelApply( eoUF<EOT&, void> & _proc, std::vector<EOT>& _pop, AssignmentAlgorithm & algo, int _masterRank ) :
|
||||
MpiJob<EOT>( _pop, algo, _masterRank ),
|
||||
func( _proc )
|
||||
MpiJob( algo,
|
||||
new ParallelApplyContinuator<EOT>( 0, _pop.size() ),
|
||||
_masterRank ),
|
||||
func( _proc ),
|
||||
index( 0 ),
|
||||
data( _pop )
|
||||
{
|
||||
// empty
|
||||
pa_continuator = static_cast<ParallelApplyContinuator<EOT>*>( _continuator );
|
||||
}
|
||||
|
||||
virtual void sendTask( int wrkRank, int index )
|
||||
virtual void sendTask( int wrkRank )
|
||||
{
|
||||
assignedTasks[ wrkRank ] = index;
|
||||
comm.send( wrkRank, 1, data[ index ] );
|
||||
++index;
|
||||
pa_continuator->index( index );
|
||||
}
|
||||
|
||||
virtual void handleResponse( int wrkRank, int index )
|
||||
virtual void handleResponse( int wrkRank )
|
||||
{
|
||||
comm.recv( wrkRank, 1, data[ index ] );
|
||||
comm.recv( wrkRank, 1, data[ assignedTasks[ wrkRank ] ] );
|
||||
}
|
||||
|
||||
virtual void processTask( )
|
||||
|
|
@ -40,7 +65,11 @@ class ParallelApply : public MpiJob< EOT >
|
|||
}
|
||||
|
||||
protected:
|
||||
vector<EOT> & data;
|
||||
eoUF<EOT&, void>& func;
|
||||
int index;
|
||||
ParallelApplyContinuator<EOT> * pa_continuator;
|
||||
std::map< int /* worker rank */, int /* index in vector */> assignedTasks;
|
||||
};
|
||||
|
||||
# endif // __EO_PARALLEL_APPLY_H__
|
||||
|
|
|
|||
Reference in a new issue