MultiJob and OneShotJob allow to choose job's way of termination (Kill for multi, Finish for one shot).

This commit is contained in:
Benjamin Bouvier 2012-07-10 17:32:18 +02:00
commit 008f2571b2
3 changed files with 37 additions and 5 deletions

View file

@ -199,10 +199,12 @@ namespace eo
public: public:
Job( AssignmentAlgorithm& _algo, Job( AssignmentAlgorithm& _algo,
int _masterRank, int _masterRank,
int _workerStopCondition,
JobStore<JobData> & store JobStore<JobData> & store
) : ) :
assignmentAlgo( _algo ), assignmentAlgo( _algo ),
masterRank( _masterRank ), masterRank( _masterRank ),
workerStopCondition( _workerStopCondition ),
comm( Node::comm() ), comm( Node::comm() ),
// Functors // Functors
sendTask( store.sendTask() ), sendTask( store.sendTask() ),
@ -339,7 +341,7 @@ namespace eo
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[W" << comm.rank() << "] Waiting for an order..." << std::endl; eo::log << "[W" << comm.rank() << "] Waiting for an order..." << std::endl;
# endif # endif
if ( order == Message::Kill ) if ( order == workerStopCondition )
{ {
# ifndef NDEBUG # ifndef NDEBUG
eo::log << "[W" << comm.rank() << "] Leaving worker task." << std::endl; eo::log << "[W" << comm.rank() << "] Leaving worker task." << std::endl;
@ -375,6 +377,7 @@ namespace eo
AssignmentAlgorithm& assignmentAlgo; AssignmentAlgorithm& assignmentAlgo;
int masterRank; int masterRank;
const int workerStopCondition;
bmpi::communicator& comm; bmpi::communicator& comm;
SendTaskFunction<JobData> & sendTask; SendTaskFunction<JobData> & sendTask;
@ -383,6 +386,35 @@ namespace eo
IsFinishedFunction<JobData> & isFinished; IsFinishedFunction<JobData> & isFinished;
bool _isMaster; bool _isMaster;
};
template< class JobData >
class OneShotJob : public Job< JobData >
{
// TODO commentaire : ce job s'arrête sur message terminate
public:
OneShotJob( AssignmentAlgorithm& algo,
int masterRank,
JobStore<JobData> & store )
: Job<JobData>( algo, masterRank, Message::Finish, store )
{
// empty
}
};
template< class JobData >
class MultiJob : public Job< JobData >
{
public:
// TODO commentaire : ce job s'arrête sur message kill
MultiJob ( AssignmentAlgorithm& algo,
int masterRank,
JobStore<JobData> & store )
: Job<JobData>( algo, masterRank, Message::Kill, store )
{
// empty
}
}; };
} }
} }

View file

@ -207,7 +207,7 @@ namespace eo
// TODO commentaire : impossible de faire un typedef sur un template sans passer // TODO commentaire : impossible de faire un typedef sur un template sans passer
// par un traits => complique la tâche de l'utilisateur pour rien. // par un traits => complique la tâche de l'utilisateur pour rien.
template< typename EOT > template< typename EOT >
class ParallelApply : public Job< ParallelApplyData<EOT> > class ParallelApply : public MultiJob< ParallelApplyData<EOT> >
{ {
public: public:
@ -216,7 +216,7 @@ namespace eo
int _masterRank, int _masterRank,
ParallelApplyStore<EOT> & store ParallelApplyStore<EOT> & store
) : ) :
Job< ParallelApplyData<EOT> >( algo, _masterRank, store ) MultiJob< ParallelApplyData<EOT> >( algo, _masterRank, store )
{ {
// empty // empty
} }

View file

@ -65,10 +65,10 @@ namespace eo
void* data() { return 0; } void* data() { return 0; }
}; };
struct EmptyJob : public Job<void> struct EmptyJob : public OneShotJob<void>
{ {
EmptyJob( AssignmentAlgorithm& algo, int masterRank ) : EmptyJob( AssignmentAlgorithm& algo, int masterRank ) :
Job<void>( algo, masterRank, *(new DummyJobStore) ) OneShotJob<void>( algo, masterRank, *(new DummyJobStore) )
// FIXME memory leak => will be corrected by using const correctness // FIXME memory leak => will be corrected by using const correctness
{ {
// empty // empty