From fed65c4f082bc508820a3f432c573d16684af78c Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 18 Jun 2012 17:02:41 +0200 Subject: [PATCH] Added eoParallelPopEvalFunc and allow compilation of full library. --- eo/src/CMakeLists.txt | 1 + eo/src/apply.h | 15 ++++++++++----- eo/src/eoPopEvalFunc.h | 20 ++++++++++++++++++++ eo/src/eompi.cpp | 4 ++++ eo/src/eompi.h | 2 -- 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 eo/src/eompi.cpp diff --git a/eo/src/CMakeLists.txt b/eo/src/CMakeLists.txt index f674da4e..3d46be7a 100644 --- a/eo/src/CMakeLists.txt +++ b/eo/src/CMakeLists.txt @@ -41,6 +41,7 @@ SET(EO_SOURCES eoCtrlCContinue.cpp eoScalarFitnessAssembled.cpp eoSIGContinue.cpp + eompi.cpp ) ADD_LIBRARY(eo STATIC ${EO_SOURCES}) diff --git a/eo/src/apply.h b/eo/src/apply.h index 39a36505..c01ac574 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -79,8 +79,17 @@ void apply(eoUF& _proc, std::vector& _pop) #else // _OPENMP + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } + +#endif // !_OPENMP +} + #ifdef WITH_MPI +template +void parallelApply(eoUF& _proc, std::vector& _pop) +{ ParallelApply job( _proc, _pop ); + MasterNode* master = dynamic_cast( MpiNodeStore::instance() ); if ( master ) { @@ -92,12 +101,8 @@ void apply(eoUF& _proc, std::vector& _pop) WorkerNode* wrk = dynamic_cast( MpiNodeStore::instance() ); wrk->run( job ); } -#else // !_MPI - for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } -#endif - -#endif // !_OPENMP } +#endif /** This is a variant of apply which is called in parallel diff --git a/eo/src/eoPopEvalFunc.h b/eo/src/eoPopEvalFunc.h index aba74d9a..cbd38b21 100644 --- a/eo/src/eoPopEvalFunc.h +++ b/eo/src/eoPopEvalFunc.h @@ -77,6 +77,26 @@ private: eoEvalFunc & eval; }; +#ifdef WITH_MPI +// TODO TODOB commenter +template +class eoParallelPopLoopEval : public eoPopEvalFunc { +public: + /** Ctor: set value of embedded eoEvalFunc */ + eoParallelPopLoopEval(eoEvalFunc & _eval) : eval(_eval) {} + + /** Do the job: simple loop over the offspring */ + void operator()(eoPop & _parents, eoPop & _offspring) + { + (void)_parents; + parallelApply(eval, _offspring); + } + +private: + eoEvalFunc & eval; +}; +#endif + ///////////////////////////////////////////////////////////// // eoTimeVaryingLoopEval ///////////////////////////////////////////////////////////// diff --git a/eo/src/eompi.cpp b/eo/src/eompi.cpp new file mode 100644 index 00000000..eff6bc39 --- /dev/null +++ b/eo/src/eompi.cpp @@ -0,0 +1,4 @@ +# include "eompi.h" + +MpiNode* MpiNodeStore::singleton; + diff --git a/eo/src/eompi.h b/eo/src/eompi.h index 82d1a585..9abcbb0f 100644 --- a/eo/src/eompi.h +++ b/eo/src/eompi.h @@ -46,8 +46,6 @@ class MpiNodeStore static MpiNode* singleton; }; -MpiNode* MpiNodeStore::singleton; - class MpiNode { protected: