uptodate
This commit is contained in:
commit
2eac2fa7c3
6 changed files with 199 additions and 4 deletions
|
|
@ -44,6 +44,12 @@ ENABLE_LANGUAGE(C)
|
|||
### 2) Include required modules / configuration files
|
||||
#####################################################################################
|
||||
|
||||
FIND_PACKAGE(OpenMP REQUIRED)
|
||||
IF(OPENMP_FOUND)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
ENDIF()
|
||||
|
||||
INCLUDE(CMakeBackwardCompatibilityCXX)
|
||||
|
||||
INCLUDE(FindDoxygen)
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ with a member like: operator()(eoPop<EOT>). Once called on a given population, i
|
|||
search for the optimum of a given problem.
|
||||
|
||||
Generally, operators are instanciated once and then binded in an algorithm by reference.
|
||||
Thus, you can easily build you own algorithm by trying several combination of operators.
|
||||
Thus, you can easily build your own algorithm by trying several combination of operators.
|
||||
|
||||
For an more detailled introduction to the design of %EO you can look at the
|
||||
For a more detailled introduction to the design of %EO you can look at the
|
||||
slides from a talk at EA 2001 or at the corresponding
|
||||
article in Lecture Notes In Computer Science, 2310, Selected Papers from the 5th European Conference on Artificial Evolution:
|
||||
- http://portal.acm.org/citation.cfm?id=727742
|
||||
|
|
|
|||
51
eo/src/omp_apply.h
Normal file
51
eo/src/omp_apply.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// eoApply.h
|
||||
// (c) Maarten Keijzer 2000
|
||||
/*
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: todos@geneura.ugr.es, http://geneura.ugr.es
|
||||
mak@dhi.dk
|
||||
*/
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _omp_apply_h
|
||||
#define _omp_apply_h
|
||||
|
||||
#include <eoFunctor.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
Applies a unary function to a std::vector of things.
|
||||
|
||||
This is a variant of apply<EOT> which is called in parallel
|
||||
thanks to OpenMP.
|
||||
|
||||
@ingroup Utilities
|
||||
*/
|
||||
template <class EOT>
|
||||
void omp_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
|
||||
{
|
||||
#pragma omp parallel for default(none) shared(_proc, _pop)
|
||||
for (unsigned i = 0; i < _pop.size(); ++i)
|
||||
{
|
||||
//#pragma omp critical
|
||||
_proc(_pop[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -65,8 +65,7 @@ SET (TEST_LIST
|
|||
t-eoExtendedVelocity
|
||||
t-eoLogger
|
||||
t-eoIQRStat
|
||||
t-eoDualFitness
|
||||
t-eoParser
|
||||
t-openmp
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -94,6 +93,18 @@ ELSEIF(ENABLE_CMAKE_TESTING)
|
|||
INSTALL(TARGETS ${test} RUNTIME DESTINATION share/eo/test COMPONENT test)
|
||||
ENDFOREACH (test)
|
||||
|
||||
SET(RESOURCES
|
||||
boxplot.py
|
||||
)
|
||||
|
||||
FOREACH(file ${RESOURCES})
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${file}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${file}
|
||||
)
|
||||
ENDFOREACH(file)
|
||||
|
||||
ENDIF(ENABLE_MINIMAL_CMAKE_TESTING)
|
||||
|
||||
######################################################################################
|
||||
|
|
|
|||
10
eo/test/boxplot.py
Executable file
10
eo/test/boxplot.py
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from pylab import *
|
||||
import sys
|
||||
|
||||
DEFAULT_RESULTS_NAME = 'results.txt'
|
||||
|
||||
if __name__ == '__main__':
|
||||
boxplot( [ [ float(value) for value in line.split() ] for line in open( DEFAULT_RESULTS_NAME if len(sys.argv) < 2 else sys.argv[1] ).readlines() ] )
|
||||
show()
|
||||
117
eo/test/t-openmp.cpp
Normal file
117
eo/test/t-openmp.cpp
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-openmp.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <climits>
|
||||
|
||||
#include <utils/eoLogger.h>
|
||||
#include <utils/eoParserLogger.h>
|
||||
|
||||
#include <eo>
|
||||
#include <es/make_real.h>
|
||||
|
||||
#include <apply.h>
|
||||
#include <omp_apply.h>
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
#include "real_value.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoReal< eoMinimizingFitness > EOT;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
int main(int ac, char** av)
|
||||
{
|
||||
eoParserLogger parser(ac, av);
|
||||
|
||||
unsigned int popMin = parser.getORcreateParam((unsigned int)1, "popMin", "Population Min", 'p', "Evolution Engine").value();
|
||||
unsigned int popMax = parser.getORcreateParam((unsigned int)100, "popMax", "Population Max", 'P', "Evolution Engine").value();
|
||||
|
||||
unsigned int dimMin = parser.getORcreateParam((unsigned int)1, "dimMin", "Dimension Min", 'd', "Evolution Engine").value();
|
||||
unsigned int dimMax = parser.getORcreateParam((unsigned int)100, "dimMax", "Dimension Max", 'D', "Evolution Engine").value();
|
||||
|
||||
unsigned int nRun = parser.getORcreateParam((unsigned int)100, "nRun", "Number of runs", 'r', "Evolution Engine").value();
|
||||
|
||||
std::string resultsFileName = parser.getORcreateParam(std::string("results.txt"), "resultsFileName", "Results file name", 0, "Evolution Engine").value();
|
||||
|
||||
double threshold = parser.getORcreateParam((double)3.0, "threshold", "Threshold of max speedup", 0, "Evolution Engine").value();
|
||||
|
||||
uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value();
|
||||
if (seedParam == 0) { seedParam = time(0); }
|
||||
|
||||
if (parser.userNeedsHelp())
|
||||
{
|
||||
parser.printHelp(std::cout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
make_help(parser);
|
||||
make_verbose(parser);
|
||||
|
||||
rng.reseed( seedParam );
|
||||
|
||||
eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value );
|
||||
eoEvalFuncCounter<EOT> eval( mainEval );
|
||||
|
||||
eoUniformGenerator< double > gen(-5, 5);
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << resultsFileName << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-t" << threshold << "-s" << seedParam;
|
||||
std::ofstream resultsFile( ss.str().c_str() );
|
||||
|
||||
for ( size_t p = popMin; p <= popMax; ++p )
|
||||
{
|
||||
for ( size_t d = dimMin; d <= dimMax; ++d )
|
||||
{
|
||||
eo::log << eo::logging << p << 'x' << d << std::endl;
|
||||
|
||||
for ( size_t r = 0; r < nRun; ++r )
|
||||
{
|
||||
eoInitFixedLength< EOT > init( d, gen );
|
||||
|
||||
double Ts;
|
||||
double Tp;
|
||||
|
||||
// sequential scope
|
||||
{
|
||||
eoPop< EOT > pop( p, init );
|
||||
double t1 = omp_get_wtime();
|
||||
apply< EOT >(eval, pop);
|
||||
double t2 = omp_get_wtime();
|
||||
Ts = t2 - t1;
|
||||
}
|
||||
|
||||
// parallel scope
|
||||
{
|
||||
eoPop< EOT > pop( p, init );
|
||||
double t1 = omp_get_wtime();
|
||||
omp_apply< EOT >(eval, pop);
|
||||
double t2 = omp_get_wtime();
|
||||
Tp = t2 - t1;
|
||||
}
|
||||
|
||||
if ( ( Ts / Tp ) > threshold ) { continue; }
|
||||
|
||||
resultsFile << Ts / Tp << ' ';
|
||||
|
||||
eo::log << eo::debug;
|
||||
eo::log << "Ts = " << Ts << std::endl;
|
||||
eo::log << "Tp = " << Tp << std::endl;
|
||||
eo::log << "S_p = " << Ts / Tp << std::endl;
|
||||
} // end of runs
|
||||
|
||||
resultsFile << std::endl;
|
||||
|
||||
} // end of dimension
|
||||
|
||||
} // end of population
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Loading…
Add table
Add a link
Reference in a new issue