From 008f2571b2f4e2571c13a0bf9bd6a6b5663145dd Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 10 Jul 2012 17:32:18 +0200 Subject: [PATCH] MultiJob and OneShotJob allow to choose job's way of termination (Kill for multi, Finish for one shot). --- eo/src/mpi/eoMpi.h | 34 +++++++++++++++++++++++++++++++++- eo/src/mpi/eoParallelApply.h | 4 ++-- eo/src/mpi/eoTerminateJob.h | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/eo/src/mpi/eoMpi.h b/eo/src/mpi/eoMpi.h index 0ef80c120..8521d5c30 100644 --- a/eo/src/mpi/eoMpi.h +++ b/eo/src/mpi/eoMpi.h @@ -199,10 +199,12 @@ namespace eo public: Job( AssignmentAlgorithm& _algo, int _masterRank, + int _workerStopCondition, JobStore & store ) : assignmentAlgo( _algo ), masterRank( _masterRank ), + workerStopCondition( _workerStopCondition ), comm( Node::comm() ), // Functors sendTask( store.sendTask() ), @@ -339,7 +341,7 @@ namespace eo # ifndef NDEBUG eo::log << "[W" << comm.rank() << "] Waiting for an order..." << std::endl; # endif - if ( order == Message::Kill ) + if ( order == workerStopCondition ) { # ifndef NDEBUG eo::log << "[W" << comm.rank() << "] Leaving worker task." << std::endl; @@ -375,6 +377,7 @@ namespace eo AssignmentAlgorithm& assignmentAlgo; int masterRank; + const int workerStopCondition; bmpi::communicator& comm; SendTaskFunction & sendTask; @@ -383,6 +386,35 @@ namespace eo IsFinishedFunction & isFinished; 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 & store ) + : Job( 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 & store ) + : Job( algo, masterRank, Message::Kill, store ) + { + // empty + } }; } } diff --git a/eo/src/mpi/eoParallelApply.h b/eo/src/mpi/eoParallelApply.h index a02254716..4ef588303 100644 --- a/eo/src/mpi/eoParallelApply.h +++ b/eo/src/mpi/eoParallelApply.h @@ -207,7 +207,7 @@ namespace eo // 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 > + class ParallelApply : public MultiJob< ParallelApplyData > { public: @@ -216,7 +216,7 @@ namespace eo int _masterRank, ParallelApplyStore & store ) : - Job< ParallelApplyData >( algo, _masterRank, store ) + MultiJob< ParallelApplyData >( algo, _masterRank, store ) { // empty } diff --git a/eo/src/mpi/eoTerminateJob.h b/eo/src/mpi/eoTerminateJob.h index d85aeeb05..bda085a02 100644 --- a/eo/src/mpi/eoTerminateJob.h +++ b/eo/src/mpi/eoTerminateJob.h @@ -65,10 +65,10 @@ namespace eo void* data() { return 0; } }; - struct EmptyJob : public Job + struct EmptyJob : public OneShotJob { EmptyJob( AssignmentAlgorithm& algo, int masterRank ) : - Job( algo, masterRank, *(new DummyJobStore) ) + OneShotJob( algo, masterRank, *(new DummyJobStore) ) // FIXME memory leak => will be corrected by using const correctness { // empty