Added eoParallelPopEvalFunc and allow compilation of full library.

This commit is contained in:
Benjamin Bouvier 2012-06-18 17:02:41 +02:00
commit fed65c4f08
5 changed files with 35 additions and 7 deletions

View file

@ -41,6 +41,7 @@ SET(EO_SOURCES
eoCtrlCContinue.cpp eoCtrlCContinue.cpp
eoScalarFitnessAssembled.cpp eoScalarFitnessAssembled.cpp
eoSIGContinue.cpp eoSIGContinue.cpp
eompi.cpp
) )
ADD_LIBRARY(eo STATIC ${EO_SOURCES}) ADD_LIBRARY(eo STATIC ${EO_SOURCES})

View file

@ -79,8 +79,17 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
#else // _OPENMP #else // _OPENMP
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
#endif // !_OPENMP
}
#ifdef WITH_MPI #ifdef WITH_MPI
template<class EOT>
void parallelApply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{
ParallelApply<EOT> job( _proc, _pop ); ParallelApply<EOT> job( _proc, _pop );
MasterNode* master = dynamic_cast<MasterNode*>( MpiNodeStore::instance() ); MasterNode* master = dynamic_cast<MasterNode*>( MpiNodeStore::instance() );
if ( master ) if ( master )
{ {
@ -92,12 +101,8 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
WorkerNode* wrk = dynamic_cast<WorkerNode*>( MpiNodeStore::instance() ); WorkerNode* wrk = dynamic_cast<WorkerNode*>( MpiNodeStore::instance() );
wrk->run( job ); 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<EOT> which is called in parallel This is a variant of apply<EOT> which is called in parallel

View file

@ -77,6 +77,26 @@ private:
eoEvalFunc<EOT> & eval; eoEvalFunc<EOT> & eval;
}; };
#ifdef WITH_MPI
// TODO TODOB commenter
template<class EOT>
class eoParallelPopLoopEval : public eoPopEvalFunc<EOT> {
public:
/** Ctor: set value of embedded eoEvalFunc */
eoParallelPopLoopEval(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
/** Do the job: simple loop over the offspring */
void operator()(eoPop<EOT> & _parents, eoPop<EOT> & _offspring)
{
(void)_parents;
parallelApply<EOT>(eval, _offspring);
}
private:
eoEvalFunc<EOT> & eval;
};
#endif
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// eoTimeVaryingLoopEval // eoTimeVaryingLoopEval
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////

4
eo/src/eompi.cpp Normal file
View file

@ -0,0 +1,4 @@
# include "eompi.h"
MpiNode* MpiNodeStore::singleton;

View file

@ -46,8 +46,6 @@ class MpiNodeStore
static MpiNode* singleton; static MpiNode* singleton;
}; };
MpiNode* MpiNodeStore::singleton;
class MpiNode class MpiNode
{ {
protected: protected: