eoPopEvalFunc updated for parallel evaluation.

This commit is contained in:
Benjamin Bouvier 2012-06-25 14:55:15 +02:00
commit fc68c3b81e
3 changed files with 41 additions and 21 deletions

View file

@ -34,7 +34,7 @@
#include <omp.h>
# ifdef WITH_MPI
# include <mpi/eompi.h>
# include <mpi/eoMpi.h>
# include <mpi/eoParallelApply.h>
# endif // WITH_MPI
@ -86,21 +86,15 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
#ifdef WITH_MPI
template<class EOT>
void parallelApply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
void parallelApply(
eoUF<EOT&, void>& _proc,
std::vector<EOT>& _pop,
eo::mpi::AssignmentAlgorithm& _algo,
int _masterRank,
int _packetSize)
{
ParallelApply<EOT> job( _proc, _pop );
MasterNode* master = dynamic_cast<MasterNode*>( MpiNodeStore::instance() );
if ( master )
{
DynamicAssignmentAlgorithm algo;
master->setAssignmentAlgorithm( &algo );
master->run( job );
} else
{
WorkerNode* wrk = dynamic_cast<WorkerNode*>( MpiNodeStore::instance() );
wrk->run( job );
}
eo::mpi::ParallelApply<EOT> job( _proc, _pop, _algo, _masterRank, _packetSize );
job.run();
}
#endif

View file

@ -83,17 +83,33 @@ template<class EOT>
class eoParallelPopLoopEval : public eoPopEvalFunc<EOT> {
public:
/** Ctor: set value of embedded eoEvalFunc */
eoParallelPopLoopEval(eoEvalFunc<EOT> & _eval) : eval(_eval) {}
eoParallelPopLoopEval(
eoEvalFunc<EOT> & _eval,
eo::mpi::AssignmentAlgorithm& _assignAlgo,
int _masterRank,
int _packetSize = 1
) :
eval(_eval),
assignAlgo( _assignAlgo ),
masterRank( _masterRank ),
packetSize( _packetSize )
{
// empty
}
/** Do the job: simple loop over the offspring */
void operator()(eoPop<EOT> & _parents, eoPop<EOT> & _offspring)
{
(void)_parents;
parallelApply<EOT>(eval, _offspring);
parallelApply<EOT>(eval, _offspring, assignAlgo, masterRank, packetSize);
}
private:
eoEvalFunc<EOT> & eval;
eo::mpi::AssignmentAlgorithm & assignAlgo;
int masterRank;
int packetSize;
};
#endif

View file

@ -3,12 +3,19 @@
//-----------------------------------------------------------------------------
#include <eo>
#include <eoPopEvalFunc.h>
#include <es/make_real.h>
//#include <apply.h>
#include "real_value.h"
// #include <apply.h>
#include "../real_value.h"
#include <mpi/eoMpi.h>
#include <boost/mpi.hpp>
#include <vector>
using namespace std;
//-----------------------------------------------------------------------------
class eoRealSerializable : public eoReal< eoMinimizingFitness >, public eoserial::Persistent
@ -75,7 +82,7 @@ typedef eoRealSerializable EOT;
int main(int ac, char** av)
{
MpiSingletonFactory::init( ac, av );
eo::mpi::Node::init( ac, av );
eoParser parser(ac, av);
@ -100,7 +107,10 @@ int main(int ac, char** av)
eo::log << "Size of population : " << popSize << std::endl;
eoPopLoopEval< EOT > popEval( eval );
eo::log << eo::setlevel( eo::debug );
eo::mpi::DynamicAssignmentAlgorithm assign;
eoParallelPopLoopEval< EOT > popEval( eval, assign, 0, 3 );
popEval( pop, pop );
eo::log << eo::quiet << "DONE!" << std::endl;