From 24c29db6f3f8caeabbda8cf5c893e3788738b93e Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 3 Jul 2012 15:53:19 +0200 Subject: [PATCH] Using again parallel apply into eoPopEvalFunc::eoParallelPopEvalFunc. --- eo/src/apply.h | 4 +- eo/src/eoPopEvalFunc.h | 9 ++++ eo/src/mpi/eoMultiParallelApply.h | 52 ++++++++++++----------- eo/src/mpi/eoParallelApply.h | 21 ++++++---- eo/src/mpi/eoTerminateJob.h | 68 +++++++++++++++++++++++++++++++ eo/test/mpi/eval.cpp | 5 ++- eo/test/mpi/parallelApply.cpp | 1 - 7 files changed, 125 insertions(+), 35 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index 7e59c21b..86fc8927 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -36,6 +36,7 @@ # ifdef WITH_MPI # include # include +# include # endif // WITH_MPI /** @@ -94,7 +95,8 @@ void parallelApply( int _packetSize, int _maxTime) { - eo::mpi::MultiParallelApply job( _proc, _pop, _algo, _masterRank, _packetSize, _maxTime ); + eo::mpi::ParallelEvalStore store( _proc, _pop, _masterRank, _packetSize ); + eo::mpi::ParallelApply job( _algo, _masterRank, store ); job.run(); } #endif diff --git a/eo/src/eoPopEvalFunc.h b/eo/src/eoPopEvalFunc.h index 77473eb1..1b7b447f 100644 --- a/eo/src/eoPopEvalFunc.h +++ b/eo/src/eoPopEvalFunc.h @@ -99,6 +99,15 @@ public: // empty } + ~eoParallelPopLoopEval() + { + if( eo::mpi::Node::comm().rank() == masterRank ) + { + eo::mpi::EmptyJob job( assignAlgo, masterRank ); + job.run(); + } + } + /** Do the job: simple loop over the offspring */ void operator()(eoPop & _parents, eoPop & _offspring) { diff --git a/eo/src/mpi/eoMultiParallelApply.h b/eo/src/mpi/eoMultiParallelApply.h index f3df801d..121e0b74 100644 --- a/eo/src/mpi/eoMultiParallelApply.h +++ b/eo/src/mpi/eoMultiParallelApply.h @@ -1,4 +1,3 @@ - # ifndef __EO_MULTI_PARALLEL_APPLY_H__ # define __EO_MULTI_PARALLEL_APPLY_H__ @@ -8,36 +7,41 @@ namespace eo { namespace mpi { - template< typename EOT > - class MultiParallelApply : public ParallelApply + template< class EOT > + class ProcessTaskParallelEval : public ProcessTaskParallelApply { public: - // using ParallelApply::comm; - using ParallelApply::masterRank; + using ProcessTaskParallelApply::_wrapped; + using ProcessTaskParallelApply::d; - MultiParallelApply( - eoUF & _proc, - std::vector& _pop, - AssignmentAlgorithm & algo, - int _masterRank, - int _packetSize = 1, - long _maxTime = 0 - ) : - ParallelApply( _proc, _pop, algo, _masterRank, _packetSize, _maxTime ) + void operator()() + { + int order = Message::Continue; + while( order != Message::Finish ) { - // empty + _wrapped->operator()(); + d->comm.recv( d->masterRank, Channel::Commands, order ); } + } + }; - virtual void processTask( ) - { - int order = Message::Continue; - while( order != Message::Finish ) - { - ParallelApply::processTask( ); - ParallelApply::comm.recv( masterRank, Channel::Commands, order ); - } - } + template< class EOT > + struct ParallelEvalStore : public ParallelApplyStore< EOT > + { + using ParallelApplyStore::wrapProcessTask; + + ParallelEvalStore( + eoUF & _proc, + std::vector& _pop, + int _masterRank, + // long _maxTime = 0, + int _packetSize = 1 + ) : + ParallelApplyStore< EOT >( _proc, _pop, _masterRank, _packetSize ) + { + wrapProcessTask( new ProcessTaskParallelEval ); + } }; } } diff --git a/eo/src/mpi/eoParallelApply.h b/eo/src/mpi/eoParallelApply.h index 1487da9f..f195965a 100644 --- a/eo/src/mpi/eoParallelApply.h +++ b/eo/src/mpi/eoParallelApply.h @@ -24,7 +24,7 @@ namespace eo std::vector& _pop, int _masterRank, // long _maxTime = 0, - int _packetSize // FIXME = 1 ? + int _packetSize ) : data( _pop ), func( _proc ), index( 0 ), size( _pop.size() ), packetSize( _packetSize ), masterRank( _masterRank ), comm( Node::comm() ) { @@ -163,14 +163,19 @@ namespace eo std::vector& _pop, int _masterRank, // long _maxTime = 0, - int _packetSize = 1 - ) - : _data( _proc, _pop, _masterRank, _packetSize ) + int _packetSize = 1, + // JobStore functors + SendTaskParallelApply * stpa = new SendTaskParallelApply, + HandleResponseParallelApply* hrpa = new HandleResponseParallelApply, + ProcessTaskParallelApply* ptpa = new ProcessTaskParallelApply, + IsFinishedParallelApply* ifpa = new IsFinishedParallelApply + ) : + _data( _proc, _pop, _masterRank, _packetSize ) { - _stf = new SendTaskParallelApply; - _hrf = new HandleResponseParallelApply; - _ptf = new ProcessTaskParallelApply; - _iff = new IsFinishedParallelApply; + _stf = stpa; + _hrf = hrpa; + _ptf = ptpa; + _iff = ifpa; } ParallelApplyData* data() { return &_data; } diff --git a/eo/src/mpi/eoTerminateJob.h b/eo/src/mpi/eoTerminateJob.h index 4cb18225..6c63cb69 100644 --- a/eo/src/mpi/eoTerminateJob.h +++ b/eo/src/mpi/eoTerminateJob.h @@ -7,6 +7,73 @@ namespace eo { namespace mpi { + struct DummySendTaskFunction : public SendTaskFunction + { + void operator()( int _ ) + { + } + }; + + struct DummyHandleResponseFunction : public HandleResponseFunction + { + void operator()( int _ ) + { + } + }; + + struct DummyProcessTaskFunction : public ProcessTaskFunction + { + void operator()() + { + // nothing! + } + }; + + struct DummyIsFinishedFunction : public IsFinishedFunction + { + bool operator()() + { + return true; + } + }; + + struct DummyJobStore : public JobStore + { + using JobStore::_stf; + using JobStore::_hrf; + using JobStore::_ptf; + using JobStore::_iff; + + DummyJobStore() + { + _stf = new DummySendTaskFunction; + _hrf = new DummyHandleResponseFunction; + _ptf = new DummyProcessTaskFunction; + _iff = new DummyIsFinishedFunction; + } + + ~DummyJobStore() + { + delete _stf; + delete _hrf; + delete _ptf; + delete _iff; + } + + void* data() { return 0; } + }; + + struct EmptyJob : public Job + { + EmptyJob( AssignmentAlgorithm& algo, int masterRank ) : + Job( algo, masterRank, *(new DummyJobStore) ) + // FIXME memory leak => will be corrected by using const correctness + { + // empty + } + }; + + /* class TerminateJob : public Job { public: @@ -36,6 +103,7 @@ namespace eo return true; } }; + */ } } diff --git a/eo/test/mpi/eval.cpp b/eo/test/mpi/eval.cpp index 7e15ac6f..7d8666cb 100644 --- a/eo/test/mpi/eval.cpp +++ b/eo/test/mpi/eval.cpp @@ -11,6 +11,8 @@ #include +#include + #include #include @@ -83,6 +85,7 @@ typedef eoRealSerializable EOT; int main(int ac, char** av) { eo::mpi::Node::init( ac, av ); + eo::log << eo::setlevel( eo::debug ); eoParser parser(ac, av); @@ -110,7 +113,7 @@ int main(int ac, char** av) eo::log << eo::setlevel( eo::debug ); eo::mpi::DynamicAssignmentAlgorithm assign; - eoParallelPopLoopEval< EOT > popEval( eval, assign, 0, 3 ); + eoParallelPopLoopEval< EOT > popEval( eval, assign, eo::mpi::DEFAULT_MASTER, 3 ); popEval( pop, pop ); eo::log << eo::quiet << "DONE!" << std::endl; diff --git a/eo/test/mpi/parallelApply.cpp b/eo/test/mpi/parallelApply.cpp index 7ccbf3d9..d562ef0e 100644 --- a/eo/test/mpi/parallelApply.cpp +++ b/eo/test/mpi/parallelApply.cpp @@ -110,7 +110,6 @@ int main(int argc, char** argv) for( unsigned int i = 0; i < tests.size(); ++i ) { - // ParallelApply job( plusOneInstance, v, *(tests[i].assign), 0, store, 3 ); ParallelApplyStore< int > store( plusOneInstance, v, eo::mpi::DEFAULT_MASTER, 3 ); // Job< JobData > job( *(tests[i].assign), eo::mpi::DEFAULT_MASTER, store ); ParallelApply< int > job( *(tests[i].assign), eo::mpi::DEFAULT_MASTER, store );