From ad1ec3669de3a0657d5a49e274b42ad18cf457be Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 17 Nov 2010 14:43:18 +0100 Subject: [PATCH 01/57] functor operator applying to population in parallel --- eo/CMakeLists.txt | 6 ++++++ eo/doc/index.h | 4 ++-- eo/src/apply.h | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index eea4df299..07becc2ba 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -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) diff --git a/eo/doc/index.h b/eo/doc/index.h index 7d7921fe0..2fad16e2f 100644 --- a/eo/doc/index.h +++ b/eo/doc/index.h @@ -51,9 +51,9 @@ with a member like: operator()(eoPop). 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 diff --git a/eo/src/apply.h b/eo/src/apply.h index 0eb3484e5..049983fe4 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -37,8 +37,10 @@ template void apply(eoUF& _proc, std::vector& _pop) { +#pragma omp parallel for default(none) shared(_proc, _pop) for (unsigned i = 0; i < _pop.size(); ++i) { +#pragma omp critical _proc(_pop[i]); } } From ebaf81ae8d6a5cd944cbd6630369e62b3a4609d4 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 17 Nov 2010 17:27:55 +0100 Subject: [PATCH 02/57] added a apply.h variant for parallel execution --- eo/src/apply.h | 2 -- eo/src/omp_apply.h | 51 +++++++++++++++++++++++++++++++++++ eo/test/CMakeLists.txt | 1 + eo/test/t-openmp.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 eo/src/omp_apply.h create mode 100644 eo/test/t-openmp.cpp diff --git a/eo/src/apply.h b/eo/src/apply.h index 049983fe4..0eb3484e5 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -37,10 +37,8 @@ template void apply(eoUF& _proc, std::vector& _pop) { -#pragma omp parallel for default(none) shared(_proc, _pop) for (unsigned i = 0; i < _pop.size(); ++i) { -#pragma omp critical _proc(_pop[i]); } } diff --git a/eo/src/omp_apply.h b/eo/src/omp_apply.h new file mode 100644 index 000000000..bbdc4065b --- /dev/null +++ b/eo/src/omp_apply.h @@ -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 +#include + +/** + Applies a unary function to a std::vector of things. + + This is a variant of apply which is called in parallel + thanks to OpenMP. + + @ingroup Utilities +*/ +template +void omp_apply(eoUF& _proc, std::vector& _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 diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 4f194681e..fe28b21f5 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -65,6 +65,7 @@ SET (TEST_LIST t-eoExtendedVelocity t-eoLogger t-eoIQRStat + t-openmp ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp new file mode 100644 index 000000000..d098ac35f --- /dev/null +++ b/eo/test/t-openmp.cpp @@ -0,0 +1,61 @@ +//----------------------------------------------------------------------------- +// t-openmp.cpp +//----------------------------------------------------------------------------- + +#include +#include + +#include +#include + +#include +#include + +#include + +#include "real_value.h" + +//----------------------------------------------------------------------------- + +typedef eoReal< eoMinimizingFitness > EOT; + +//----------------------------------------------------------------------------- + +int main(int ac, char** av) +{ + eoParserLogger parser(ac, av); + eoState state; + + eoRealInitBounded& init = make_genotype( parser, state, EOT() ); + eoPop< EOT >& pop = make_pop( parser, state, init ); + eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); + eoEvalFuncCounter eval( mainEval ); + + if (parser.userNeedsHelp()) + { + parser.printHelp(std::cout); + exit(1); + } + + make_help(parser); + make_verbose(parser); + + double ts1 = omp_get_wtime(); + apply< EOT >( eval, pop ); + //sleep(1); + double ts2 = omp_get_wtime(); + + eoPop< EOT >& pop2 = make_pop( parser, state, init ); + + double tp1 = omp_get_wtime(); + omp_apply< EOT >( eval, pop2 ); + //sleep(1); + double tp2 = omp_get_wtime(); + + eo::log << "Ts = " << ts2 - ts1 << std::endl; + eo::log << "Tp = " << tp2 - tp1 << std::endl; + + return 0; +} + +//----------------------------------------------------------------------------- From 790153f6aa9cbb0381941f352ecc3c8f845abbde Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 19 Nov 2010 11:48:42 +0100 Subject: [PATCH 03/57] openmp test updated --- eo/test/t-openmp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index d098ac35f..0e5f72388 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -28,6 +28,7 @@ int main(int ac, char** av) eoRealInitBounded& init = make_genotype( parser, state, EOT() ); eoPop< EOT >& pop = make_pop( parser, state, init ); + eoPop< EOT >& pop2 = make_pop( parser, state, init ); eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); eoEvalFuncCounter eval( mainEval ); @@ -45,8 +46,6 @@ int main(int ac, char** av) //sleep(1); double ts2 = omp_get_wtime(); - eoPop< EOT >& pop2 = make_pop( parser, state, init ); - double tp1 = omp_get_wtime(); omp_apply< EOT >( eval, pop2 ); //sleep(1); From 6625cd247bb2015dbffd58af59a9224d90e6dc5c Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 20 Nov 2010 01:01:45 +0100 Subject: [PATCH 04/57] openmp testing up-to-date --- eo/test/CMakeLists.txt | 12 ++++++ eo/test/boxplot.py | 10 +++++ eo/test/t-openmp.cpp | 89 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 95 insertions(+), 16 deletions(-) create mode 100755 eo/test/boxplot.py diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index fe28b21f5..8d7956bab 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -93,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) ###################################################################################### diff --git a/eo/test/boxplot.py b/eo/test/boxplot.py new file mode 100755 index 000000000..0590e4e97 --- /dev/null +++ b/eo/test/boxplot.py @@ -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() diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 0e5f72388..4ccc54ad6 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -2,6 +2,10 @@ // t-openmp.cpp //----------------------------------------------------------------------------- +#include +#include +#include + #include #include @@ -24,13 +28,21 @@ typedef eoReal< eoMinimizingFitness > EOT; int main(int ac, char** av) { eoParserLogger parser(ac, av); - eoState state; - eoRealInitBounded& init = make_genotype( parser, state, EOT() ); - eoPop< EOT >& pop = make_pop( parser, state, init ); - eoPop< EOT >& pop2 = make_pop( parser, state, init ); - eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); - eoEvalFuncCounter eval( mainEval ); + 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()) { @@ -41,18 +53,63 @@ int main(int ac, char** av) make_help(parser); make_verbose(parser); - double ts1 = omp_get_wtime(); - apply< EOT >( eval, pop ); - //sleep(1); - double ts2 = omp_get_wtime(); + rng.reseed( seedParam ); - double tp1 = omp_get_wtime(); - omp_apply< EOT >( eval, pop2 ); - //sleep(1); - double tp2 = omp_get_wtime(); + eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); + eoEvalFuncCounter eval( mainEval ); - eo::log << "Ts = " << ts2 - ts1 << std::endl; - eo::log << "Tp = " << tp2 - tp1 << std::endl; + 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; } From eb9937ee0c668d515ce88512cd146dcf5d079062 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 20 Nov 2010 01:57:30 +0100 Subject: [PATCH 05/57] added stepping parameters --- eo/test/boxplot.py | 3 ++- eo/test/t-openmp.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/eo/test/boxplot.py b/eo/test/boxplot.py index 0590e4e97..581fef0c3 100755 --- a/eo/test/boxplot.py +++ b/eo/test/boxplot.py @@ -7,4 +7,5 @@ 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() + #show() + savefig( sys.argv[1] + ".png" ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 4ccc54ad6..89082b8d8 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -30,9 +30,11 @@ 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 popStep = parser.getORcreateParam((unsigned int)1, "popStep", "Population Step", 0, "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 dimStep = parser.getORcreateParam((unsigned int)1, "dimStep", "Dimension Step", 0, "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(); @@ -64,9 +66,9 @@ int main(int ac, char** av) 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 p = popMin; p <= popMax; p += popStep ) { - for ( size_t d = dimMin; d <= dimMax; ++d ) + for ( size_t d = dimMin; d <= dimMax; d += dimStep ) { eo::log << eo::logging << p << 'x' << d << std::endl; From cb8e6ab1c3eee099f073f719dc59d45220e5dafa Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 14:07:47 +0100 Subject: [PATCH 06/57] added efficienty computation --- eo/test/boxplot.py | 15 +++++++++------ eo/test/t-openmp.cpp | 27 ++++++++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/eo/test/boxplot.py b/eo/test/boxplot.py index 581fef0c3..2b5141af6 100755 --- a/eo/test/boxplot.py +++ b/eo/test/boxplot.py @@ -1,11 +1,14 @@ #!/usr/bin/env python -from pylab import * +import pylab 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() - savefig( sys.argv[1] + ".png" ) + if len(sys.argv) < 3: + print 'Usage: boxplot.py [Results files, ...] [output file in .png]' + sys.exit() + + for i in range(1, len(sys.argv) - 1): + pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) + + pylab.savefig( sys.argv[ len(sys.argv) - 1 ] ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 89082b8d8..c4b885702 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -39,10 +39,11 @@ int main(int ac, char** av) 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(); + std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value(); + std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value(); + uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value(); if (seedParam == 0) { seedParam = time(0); } @@ -62,9 +63,18 @@ int main(int ac, char** av) 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() ); + std::ostringstream params; + params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-t" << threshold << "-s" << seedParam; + std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); + std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); + + size_t nbtask = 1; +#pragma omp parallel + { + nbtask = omp_get_num_threads(); + } + + eo::log << eo::logging << "Nb task: " << nbtask << std::endl; for ( size_t p = popMin; p <= popMax; p += popStep ) { @@ -99,15 +109,18 @@ int main(int ac, char** av) if ( ( Ts / Tp ) > threshold ) { continue; } - resultsFile << Ts / Tp << ' '; + speedupFile << Ts / Tp << ' '; + efficiencyFile << Ts / ( nbtask * 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; + eo::log << "E_p = " << Ts / ( nbtask * Tp ) << std::endl; } // end of runs - resultsFile << std::endl; + speedupFile << std::endl; + efficiencyFile << std::endl; } // end of dimension From 78b4da4c319754fe4c9447168ec1621646adc1a4 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 14:47:55 +0100 Subject: [PATCH 07/57] remove threshold parameter and move from static schedule to dynamic --- eo/src/omp_apply.h | 2 +- eo/test/t-openmp.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/eo/src/omp_apply.h b/eo/src/omp_apply.h index bbdc4065b..b899b5e1a 100644 --- a/eo/src/omp_apply.h +++ b/eo/src/omp_apply.h @@ -40,7 +40,7 @@ template void omp_apply(eoUF& _proc, std::vector& _pop) { -#pragma omp parallel for default(none) shared(_proc, _pop) +#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic) for (unsigned i = 0; i < _pop.size(); ++i) { //#pragma omp critical diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index c4b885702..7cf7ac8e8 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -39,8 +39,6 @@ int main(int ac, char** av) unsigned int nRun = parser.getORcreateParam((unsigned int)100, "nRun", "Number of runs", 'r', "Evolution Engine").value(); - double threshold = parser.getORcreateParam((double)3.0, "threshold", "Threshold of max speedup", 0, "Evolution Engine").value(); - std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value(); std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value(); @@ -64,7 +62,7 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-t" << threshold << "-s" << seedParam; + params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); @@ -107,10 +105,10 @@ int main(int ac, char** av) Tp = t2 - t1; } - if ( ( Ts / Tp ) > threshold ) { continue; } + if ( ( Ts / Tp ) > nbtask ) { continue; } speedupFile << Ts / Tp << ' '; - efficiencyFile << Ts / ( nbtask * Tp ); + efficiencyFile << Ts / ( nbtask * Tp ) << ' '; eo::log << eo::debug; eo::log << "Ts = " << Ts << std::endl; From c9843c3cfadb45654d9c4940ecd996b2a3b1c9ed Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 17:33:11 +0100 Subject: [PATCH 08/57] removed omp_apply.h and added to apply.h, added dynamicity computation --- eo/src/apply.h | 31 +++++++++++++++++++++++++++ eo/src/omp_apply.h | 51 -------------------------------------------- eo/test/t-openmp.cpp | 32 ++++++++++++++++++++++----- 3 files changed, 58 insertions(+), 56 deletions(-) delete mode 100644 eo/src/omp_apply.h diff --git a/eo/src/apply.h b/eo/src/apply.h index 0eb3484e5..2cd977b08 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -43,4 +43,35 @@ void apply(eoUF& _proc, std::vector& _pop) } } +/** + This is a variant of apply which is called in parallel + thanks to OpenMP. + + @ingroup Utilities +*/ +template +void omp_apply(eoUF& _proc, std::vector& _pop) +{ +#pragma omp parallel for default(none) shared(_proc, _pop) + for (unsigned i = 0; i < _pop.size(); ++i) + { + _proc(_pop[i]); + } +} + +/** + And now we are using the dynamic scheduling. + + @ingroup Utilities +*/ +template +void omp_dynamic_apply(eoUF& _proc, std::vector& _pop) +{ +#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic) + for (unsigned i = 0; i < _pop.size(); ++i) + { + _proc(_pop[i]); + } +} + #endif diff --git a/eo/src/omp_apply.h b/eo/src/omp_apply.h deleted file mode 100644 index b899b5e1a..000000000 --- a/eo/src/omp_apply.h +++ /dev/null @@ -1,51 +0,0 @@ -// -*- 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 -#include - -/** - Applies a unary function to a std::vector of things. - - This is a variant of apply which is called in parallel - thanks to OpenMP. - - @ingroup Utilities -*/ -template -void omp_apply(eoUF& _proc, std::vector& _pop) -{ -#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic) - for (unsigned i = 0; i < _pop.size(); ++i) - { - //#pragma omp critical - _proc(_pop[i]); - } -} - -#endif diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 7cf7ac8e8..c4e3ac035 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -41,6 +41,7 @@ int main(int ac, char** av) std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value(); std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value(); + std::string dynamicityFileName = parser.getORcreateParam(std::string("dynamicity"), "dynamicityFileName", "Dynamicity file name", 0, "Results").value(); uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value(); if (seedParam == 0) { seedParam = time(0); } @@ -65,6 +66,7 @@ int main(int ac, char** av) params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); + std::ofstream dynamicityFile( std::string( dynamicityFileName + params.str() ).c_str() ); size_t nbtask = 1; #pragma omp parallel @@ -86,6 +88,7 @@ int main(int ac, char** av) double Ts; double Tp; + double Tpd; // sequential scope { @@ -105,20 +108,39 @@ int main(int ac, char** av) Tp = t2 - t1; } - if ( ( Ts / Tp ) > nbtask ) { continue; } + // parallel scope dynamic + { + eoPop< EOT > pop( p, init ); + double t1 = omp_get_wtime(); + omp_dynamic_apply< EOT >(eval, pop); + double t2 = omp_get_wtime(); + Tpd = t2 - t1; + } - speedupFile << Ts / Tp << ' '; - efficiencyFile << Ts / ( nbtask * Tp ) << ' '; + double speedup = Ts / Tp; + + if ( speedup > nbtask ) { continue; } + + double efficiency = speedup / nbtask; + + double dynamicity = Tp / Tpd; + + speedupFile << speedup << ' '; + efficiencyFile << efficiency << ' '; + dynamicityFile << dynamicity << ' '; eo::log << eo::debug; eo::log << "Ts = " << Ts << std::endl; eo::log << "Tp = " << Tp << std::endl; - eo::log << "S_p = " << Ts / Tp << std::endl; - eo::log << "E_p = " << Ts / ( nbtask * Tp ) << std::endl; + eo::log << "Tpd = " << Tpd << std::endl; + eo::log << "S_p = " << speedup << std::endl; + eo::log << "E_p = " << efficiency << std::endl; + eo::log << "D_p = " << dynamicity << std::endl; } // end of runs speedupFile << std::endl; efficiencyFile << std::endl; + dynamicityFile << std::endl; } // end of dimension From 849a5ec670cd0707abc7b4ca90592444d07b559d Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 17:35:06 +0100 Subject: [PATCH 09/57] created two boxplot script files one to generate image the other to display with matplotlab --- eo/test/CMakeLists.txt | 1 + eo/test/boxplot.py | 8 ++++---- eo/test/boxplot_to_png.py | 14 ++++++++++++++ eo/test/t-openmp.cpp | 1 - 4 files changed, 19 insertions(+), 5 deletions(-) create mode 100755 eo/test/boxplot_to_png.py diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 8d7956bab..07dbee08a 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -95,6 +95,7 @@ ELSEIF(ENABLE_CMAKE_TESTING) SET(RESOURCES boxplot.py + boxplot_to_png.py ) FOREACH(file ${RESOURCES}) diff --git a/eo/test/boxplot.py b/eo/test/boxplot.py index 2b5141af6..39a65944a 100755 --- a/eo/test/boxplot.py +++ b/eo/test/boxplot.py @@ -4,11 +4,11 @@ import pylab import sys if __name__ == '__main__': - if len(sys.argv) < 3: - print 'Usage: boxplot.py [Results files, ...] [output file in .png]' + if len(sys.argv) < 2: + print 'Usage: boxplot.py [Results files, ...]' sys.exit() - for i in range(1, len(sys.argv) - 1): + for i in range(1, len(sys.argv)): pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) - pylab.savefig( sys.argv[ len(sys.argv) - 1 ] ) + pylab.show() diff --git a/eo/test/boxplot_to_png.py b/eo/test/boxplot_to_png.py new file mode 100755 index 000000000..2b5141af6 --- /dev/null +++ b/eo/test/boxplot_to_png.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +import pylab +import sys + +if __name__ == '__main__': + if len(sys.argv) < 3: + print 'Usage: boxplot.py [Results files, ...] [output file in .png]' + sys.exit() + + for i in range(1, len(sys.argv) - 1): + pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) + + pylab.savefig( sys.argv[ len(sys.argv) - 1 ] ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index c4e3ac035..f1ddffe81 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -13,7 +13,6 @@ #include #include -#include #include From 50d91c3ab6bf4aecc88834d3e74e47b7c2e19064 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 17:37:44 +0100 Subject: [PATCH 10/57] added popStep and dimStep value on the result filename --- eo/test/t-openmp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index f1ddffe81..d7a418a57 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -62,7 +62,9 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; + params << "--popStep" << popStep << "-p" << popMin << "-P" << popMax + << "--dimStep" << dimStep << "-d" << dimMin << "-D" << dimMax + << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); std::ofstream dynamicityFile( std::string( dynamicityFileName + params.str() ).c_str() ); From bb0efdc0671f7bcff39d4b7326f9240ba2ce35f3 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 17:43:52 +0100 Subject: [PATCH 11/57] popStep and dimStep replaced by pS and dS on the results filename --- eo/test/t-openmp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index d7a418a57..31aeeca0e 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -62,8 +62,8 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "--popStep" << popStep << "-p" << popMin << "-P" << popMax - << "--dimStep" << dimStep << "-d" << dimMin << "-D" << dimMax + params << "--pS" << popStep << "-p" << popMin << "-P" << popMax + << "--dS" << dimStep << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); From 4059e16b1e9db445872bd11cf2e2d62b5d5a4bcc Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 18:08:58 +0100 Subject: [PATCH 12/57] updated to D_p = T_Dp / T_p and avoid all D_p higher than the number of tasks used --- eo/test/t-openmp.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 31aeeca0e..8b09bfad1 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -124,19 +124,24 @@ int main(int ac, char** av) double efficiency = speedup / nbtask; - double dynamicity = Tp / Tpd; - speedupFile << speedup << ' '; efficiencyFile << efficiency << ' '; - dynamicityFile << dynamicity << ' '; eo::log << eo::debug; eo::log << "Ts = " << Ts << std::endl; eo::log << "Tp = " << Tp << std::endl; - eo::log << "Tpd = " << Tpd << std::endl; eo::log << "S_p = " << speedup << std::endl; eo::log << "E_p = " << efficiency << std::endl; + + double dynamicity = Tpd / Tp; + + if ( dynamicity > nbtask ) { continue; } + + eo::log << "Tpd = " << Tpd << std::endl; eo::log << "D_p = " << dynamicity << std::endl; + + dynamicityFile << dynamicity << ' '; + } // end of runs speedupFile << std::endl; From cfac1f8a7ea396fb4b2d64055763ec6ec5917633 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 18:20:38 +0100 Subject: [PATCH 13/57] remode two - on results filename --- eo/test/t-openmp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 8b09bfad1..97d5f9691 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -62,8 +62,8 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "--pS" << popStep << "-p" << popMin << "-P" << popMax - << "--dS" << dimStep << "-d" << dimMin << "-D" << dimMax + params << "-pS" << popStep << "-p" << popMin << "-P" << popMax + << "-dS" << dimStep << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); From 4a8efc6ca6ca90a7c97b36216d151ea0b84cf930 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Mon, 22 Nov 2010 19:16:09 +0100 Subject: [PATCH 14/57] updated Dp = Tp / TDp --- eo/test/t-openmp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 97d5f9691..932da257a 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -133,7 +133,7 @@ int main(int ac, char** av) eo::log << "S_p = " << speedup << std::endl; eo::log << "E_p = " << efficiency << std::endl; - double dynamicity = Tpd / Tp; + double dynamicity = Tp / Tpd; if ( dynamicity > nbtask ) { continue; } From 69434a5bc2f1b7b10dbd46c7c7ca38d7da81230c Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 16:19:51 +0100 Subject: [PATCH 15/57] added prefix parameter on t-openmp --- eo/test/t-openmp.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 932da257a..cb21f4456 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -38,6 +38,8 @@ int main(int ac, char** av) unsigned int nRun = parser.getORcreateParam((unsigned int)100, "nRun", "Number of runs", 'r', "Evolution Engine").value(); + std::string fileNamesPrefix = parser.getORcreateParam(std::string("notitle"), "fileNamesPrefix", "Prefix of all results files name", 'H', "Results").value(); + std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value(); std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value(); std::string dynamicityFileName = parser.getORcreateParam(std::string("dynamicity"), "dynamicityFileName", "Dynamicity file name", 0, "Results").value(); @@ -65,9 +67,9 @@ int main(int ac, char** av) params << "-pS" << popStep << "-p" << popMin << "-P" << popMax << "-dS" << dimStep << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; - std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() ); - std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() ); - std::ofstream dynamicityFile( std::string( dynamicityFileName + params.str() ).c_str() ); + std::ofstream speedupFile( std::string( fileNamesPrefix + "_" + speedupFileName + params.str() ).c_str() ); + std::ofstream efficiencyFile( std::string( fileNamesPrefix + "_" + efficiencyFileName + params.str() ).c_str() ); + std::ofstream dynamicityFile( std::string( fileNamesPrefix + "_" + dynamicityFileName + params.str() ).c_str() ); size_t nbtask = 1; #pragma omp parallel From 2141719076021c89407a7b3520312d61c1fe6316 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 21:24:07 +0100 Subject: [PATCH 16/57] added t-openmp.py --- eo/test/CMakeLists.txt | 2 + eo/test/boxplot.py | 1 + eo/test/boxplot_to_pdf.py | 15 +++++++ eo/test/boxplot_to_png.py | 5 ++- eo/test/t-openmp.cpp | 8 ++-- eo/test/t-openmp.py | 91 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 6 deletions(-) create mode 100755 eo/test/boxplot_to_pdf.py create mode 100755 eo/test/t-openmp.py diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 07dbee08a..220063504 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -96,6 +96,8 @@ ELSEIF(ENABLE_CMAKE_TESTING) SET(RESOURCES boxplot.py boxplot_to_png.py + boxplot_to_pdf.py + t-openmp.py ) FOREACH(file ${RESOURCES}) diff --git a/eo/test/boxplot.py b/eo/test/boxplot.py index 39a65944a..bf6e84b5d 100755 --- a/eo/test/boxplot.py +++ b/eo/test/boxplot.py @@ -11,4 +11,5 @@ if __name__ == '__main__': for i in range(1, len(sys.argv)): pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) + pylab.xlabel('iterations') pylab.show() diff --git a/eo/test/boxplot_to_pdf.py b/eo/test/boxplot_to_pdf.py new file mode 100755 index 000000000..f29edeb21 --- /dev/null +++ b/eo/test/boxplot_to_pdf.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +import pylab +import sys + +if __name__ == '__main__': + if len(sys.argv) < 3: + print 'Usage: boxplot_to_pdf.py [Results files, ...] [output file in .pdf]' + sys.exit() + + for i in range(1, len(sys.argv) - 1): + pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) + + pylab.xlabel('iterations') + pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='pdf', transparent=True ) diff --git a/eo/test/boxplot_to_png.py b/eo/test/boxplot_to_png.py index 2b5141af6..17fb35bc9 100755 --- a/eo/test/boxplot_to_png.py +++ b/eo/test/boxplot_to_png.py @@ -5,10 +5,11 @@ import sys if __name__ == '__main__': if len(sys.argv) < 3: - print 'Usage: boxplot.py [Results files, ...] [output file in .png]' + print 'Usage: boxplot_to_png.py [Results files, ...] [output file in .png]' sys.exit() for i in range(1, len(sys.argv) - 1): pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) - pylab.savefig( sys.argv[ len(sys.argv) - 1 ] ) + pylab.xlabel('iterations') + pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='png', transparent=True, papertype='a0' ) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index cb21f4456..297662b62 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -38,7 +38,7 @@ int main(int ac, char** av) unsigned int nRun = parser.getORcreateParam((unsigned int)100, "nRun", "Number of runs", 'r', "Evolution Engine").value(); - std::string fileNamesPrefix = parser.getORcreateParam(std::string("notitle"), "fileNamesPrefix", "Prefix of all results files name", 'H', "Results").value(); + std::string fileNamesPrefix = parser.getORcreateParam(std::string(""), "fileNamesPrefix", "Prefix of all results files name", 'H', "Results").value(); std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value(); std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value(); @@ -67,9 +67,9 @@ int main(int ac, char** av) params << "-pS" << popStep << "-p" << popMin << "-P" << popMax << "-dS" << dimStep << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; - std::ofstream speedupFile( std::string( fileNamesPrefix + "_" + speedupFileName + params.str() ).c_str() ); - std::ofstream efficiencyFile( std::string( fileNamesPrefix + "_" + efficiencyFileName + params.str() ).c_str() ); - std::ofstream dynamicityFile( std::string( fileNamesPrefix + "_" + dynamicityFileName + params.str() ).c_str() ); + std::ofstream speedupFile( std::string( fileNamesPrefix + speedupFileName + params.str() ).c_str() ); + std::ofstream efficiencyFile( std::string( fileNamesPrefix + efficiencyFileName + params.str() ).c_str() ); + std::ofstream dynamicityFile( std::string( fileNamesPrefix + dynamicityFileName + params.str() ).c_str() ); size_t nbtask = 1; #pragma omp parallel diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py new file mode 100755 index 000000000..3982d682e --- /dev/null +++ b/eo/test/t-openmp.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import pylab +import optparse, logging, sys, os +from datetime import datetime + +LEVELS = {'debug': logging.DEBUG, + 'info': logging.INFO, + 'warning': logging.WARNING, + 'error': logging.ERROR, + 'critical': logging.CRITICAL} + +LOG_DEFAULT_FILENAME='notitle.log' + +OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s' + +def parser(parser=optparse.OptionParser()): + # general parameters + parser.add_option('-v', '--verbose', choices=LEVELS.keys(), default='warning', help='set a verbose level') + parser.add_option('-f', '--file', help='give an input project filename', default='') + parser.add_option('-o', '--output', help='give an output filename for logging', default=LOG_DEFAULT_FILENAME) + # general parameters ends + + parser.add_option('-p', '--popMin', default=1) + parser.add_option('', '--popStep', default=1) + parser.add_option('-P', '--popMax', default=100) + parser.add_option('-d', '--dimMin', default=1) + parser.add_option('', '--dimStep', default=1) + parser.add_option('-D', '--dimMax', default=100) + parser.add_option('-r', '--nRun', default=100) + parser.add_option('-s', '--seed', default=-1) + + topic = str(datetime.today()) + for char in [' ', ':', '-', '.']: topic = topic.replace(char, '_') + parser.add_option('-t', '--topic', default='openmp_' + topic + '/') + + options, args = parser.parse_args() + + logger(options.verbose, options.output) + + return options + +def logger(level_name, filename=LOG_DEFAULT_FILENAME): + logging.basicConfig( + level=logging.DEBUG, + format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', + filename=filename, filemode='a' + ) + + console = logging.StreamHandler() + console.setLevel(LEVELS.get(level_name, logging.NOTSET)) + console.setFormatter(logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')) + logging.getLogger('').addHandler(console) + +options = parser() + +def execute_openmp( p, ps, P, d, ds, D, r, s, v=options.verbose ): + cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, options.topic) + logging.debug( cmd ) + #os.system( cmd ) + +def main(): + # creates first the new topic repository + #os.mkdir( options.topic ) + + # (1) EA in time O(1) + + # (1.1) speedup measure Sp, Ep for P & D + + # (1.1.1) measure for all combinaisons of P n D + execute_openmp( 1, 10, 100, 1, 10, 100, 100, options.seed ) + + # (1.1.1) measure for all combinaisons of P n D + execute_openmp( 1, 10, 100, 1, 10, 100, 100, options.seed ) + + + # pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) + + # pylab.xlabel('iterations') + # pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='pdf', transparent=True ) + + # (2) EA in time O(1) + + +# when executed, just run main(): +if __name__ == '__main__': + logging.debug('### plotting started ###') + + main() + + logging.debug('### plotting ended ###') From 9dcbb94ffbce37cec79e3eb1d0efc192ed7f332a Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 21:27:41 +0100 Subject: [PATCH 17/57] changed output results name --- eo/test/t-openmp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 297662b62..db6b4cfc0 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -64,8 +64,8 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "-pS" << popStep << "-p" << popMin << "-P" << popMax - << "-dS" << dimStep << "-d" << dimMin << "-D" << dimMax + params << "-p" << popMin << "-pS" << popStep << "-P" << popMax + << "-d" << dimMin << "-dS" << dimStep << "-D" << dimMax << "-r" << nRun << "-s" << seedParam; std::ofstream speedupFile( std::string( fileNamesPrefix + speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( fileNamesPrefix + efficiencyFileName + params.str() ).c_str() ); From 20fd5b206f446cd69c2df729bac5c158e847d2d1 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 23:07:11 +0100 Subject: [PATCH 18/57] t-openmp.py released --- eo/test/t-openmp.cpp | 6 ++-- eo/test/t-openmp.py | 69 +++++++++++++++++++++++++++----------------- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index db6b4cfc0..4771c541d 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -64,9 +64,9 @@ int main(int ac, char** av) eoUniformGenerator< double > gen(-5, 5); std::ostringstream params; - params << "-p" << popMin << "-pS" << popStep << "-P" << popMax - << "-d" << dimMin << "-dS" << dimStep << "-D" << dimMax - << "-r" << nRun << "-s" << seedParam; + params << "_p" << popMin << "_pS" << popStep << "_P" << popMax + << "_d" << dimMin << "_dS" << dimStep << "_D" << dimMax + << "_r" << nRun << "_s" << seedParam; std::ofstream speedupFile( std::string( fileNamesPrefix + speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( fileNamesPrefix + efficiencyFileName + params.str() ).c_str() ); std::ofstream dynamicityFile( std::string( fileNamesPrefix + dynamicityFileName + params.str() ).c_str() ); diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 3982d682e..2b7c6842a 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -14,25 +14,21 @@ LOG_DEFAULT_FILENAME='notitle.log' OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s' +RESULT_FILE_FORMAT='%s%s_p%d_pS%d_P%d_d%d_dS%d_D%d_r%d_s%d' + def parser(parser=optparse.OptionParser()): # general parameters - parser.add_option('-v', '--verbose', choices=LEVELS.keys(), default='warning', help='set a verbose level') + parser.add_option('-v', '--verbose', choices=LEVELS.keys(), default='info', help='set a verbose level') parser.add_option('-f', '--file', help='give an input project filename', default='') parser.add_option('-o', '--output', help='give an output filename for logging', default=LOG_DEFAULT_FILENAME) # general parameters ends - parser.add_option('-p', '--popMin', default=1) - parser.add_option('', '--popStep', default=1) - parser.add_option('-P', '--popMax', default=100) - parser.add_option('-d', '--dimMin', default=1) - parser.add_option('', '--dimStep', default=1) - parser.add_option('-D', '--dimMax', default=100) parser.add_option('-r', '--nRun', default=100) - parser.add_option('-s', '--seed', default=-1) + parser.add_option('-s', '--seed', default=1) topic = str(datetime.today()) for char in [' ', ':', '-', '.']: topic = topic.replace(char, '_') - parser.add_option('-t', '--topic', default='openmp_' + topic + '/') + parser.add_option('-t', '--topic', default='openmp_measures_' + topic + '/') options, args = parser.parse_args() @@ -54,33 +50,54 @@ def logger(level_name, filename=LOG_DEFAULT_FILENAME): options = parser() -def execute_openmp( p, ps, P, d, ds, D, r, s, v=options.verbose ): - cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, options.topic) +def get_boxplot_data( filename ): + try: + f = open( filename ) + return [ [ float(value) for value in line.split() ] for line in f.readlines() ] + except: + raise ValueError('got an issue during the reading of file %s' % filename) + +def non_zero( value ): return value if value > 0 else 1 + +def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ): + pwd = options.topic + name + '_' + cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd) logging.debug( cmd ) - #os.system( cmd ) + os.system( cmd ) + + for cur in ['speedup', 'efficiency', 'dynamicity']: + filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s) + pylab.boxplot( get_boxplot_data( filename ) ) + iters = ( non_zero( P - p ) / ps ) * ( non_zero( D - d ) / ds ) + pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) ) + pylab.ylabel('%s - %s' % (cur, name)) + pylab.savefig( filename + '.pdf', format='pdf' ) + pylab.savefig( filename + '.png', format='png' ) + pylab.cla() + pylab.clf() def main(): - # creates first the new topic repository - #os.mkdir( options.topic ) + logging.info('creates first the new topic repository %s', options.topic) + os.mkdir( options.topic ) - # (1) EA in time O(1) + logging.info('do all tests with r = %d and a common seed value = %d' % (options.nRun, options.seed)) - # (1.1) speedup measure Sp, Ep for P & D + logging.info('EA in time O(1) and O(n) - speedup measure Sp, Ep and Dp for P & D') - # (1.1.1) measure for all combinaisons of P n D - execute_openmp( 1, 10, 100, 1, 10, 100, 100, options.seed ) + logging.info('(1) measure for all combinaisons of P n D') + do_measure( '1', 1, 10, 101, 1, 10, 101 ) - # (1.1.1) measure for all combinaisons of P n D - execute_openmp( 1, 10, 100, 1, 10, 100, 100, options.seed ) + logging.info('(2) measure for P \in [1, 100[ with D fixed to 1000') + do_measure( '2', 1, 1, 101, 1000, 1, 1000 ) + logging.info('(3) measure for P \in [1, 1000[ with ps = 10 and D fixed to 1000') + do_measure( '3', 1, 10, 1001, 1000, 1, 1000 ) - # pylab.boxplot( [ [ float(value) for value in line.split() ] for line in open( sys.argv[i] ).readlines() ] ) - - # pylab.xlabel('iterations') - # pylab.savefig( sys.argv[ len(sys.argv) - 1 ], format='pdf', transparent=True ) - - # (2) EA in time O(1) + logging.info('(4) measure for D \in [1, 100[ with P fixed to 1000') + do_measure( '4', 1000, 1, 1000, 1, 1, 101 ) + logging.info('(5) measure for D \in [1, 1000[ with ds = 10 and P fixed to 1000') + do_measure( '5', 1000, 1, 1000, 1, 10, 1001 ) # when executed, just run main(): if __name__ == '__main__': From 6907b262e1d96f0513c7eae2f0787b0228ac3a85 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 23:22:54 +0100 Subject: [PATCH 19/57] onlyexec and onlyprint parameters added on openmp script --- eo/test/t-openmp.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 2b7c6842a..aa3af6868 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -23,12 +23,15 @@ def parser(parser=optparse.OptionParser()): parser.add_option('-o', '--output', help='give an output filename for logging', default=LOG_DEFAULT_FILENAME) # general parameters ends - parser.add_option('-r', '--nRun', default=100) - parser.add_option('-s', '--seed', default=1) + parser.add_option('-r', '--nRun', default=100, help='how many times you would compute each iteration ?') + parser.add_option('-s', '--seed', default=1, help='give here a seed value') topic = str(datetime.today()) for char in [' ', ':', '-', '.']: topic = topic.replace(char, '_') - parser.add_option('-t', '--topic', default='openmp_measures_' + topic + '/') + parser.add_option('-t', '--topic', default='openmp_measures_' + topic + '/', help='give here a topic name used to create the folder') + + parser.add_option('-E', '--onlyexecute', action='store_true', dest='onlyexecute', default=False, help='used this option if you only want to execute measures without generating images') + parser.add_option('-X', '--onlyprint', action='store_true', dest='onlyprint', default=False, help='used this option if you only want to generate images without executing measures, dont forget to set the good path in using --topic with a "/" at the end') options, args = parser.parse_args() @@ -63,22 +66,25 @@ def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='log pwd = options.topic + name + '_' cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd) logging.debug( cmd ) - os.system( cmd ) + if not options.onlyprint: + os.system( cmd ) - for cur in ['speedup', 'efficiency', 'dynamicity']: - filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s) - pylab.boxplot( get_boxplot_data( filename ) ) - iters = ( non_zero( P - p ) / ps ) * ( non_zero( D - d ) / ds ) - pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) ) - pylab.ylabel('%s - %s' % (cur, name)) - pylab.savefig( filename + '.pdf', format='pdf' ) - pylab.savefig( filename + '.png', format='png' ) - pylab.cla() - pylab.clf() + if not options.onlyexecute: + for cur in ['speedup', 'efficiency', 'dynamicity']: + filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s) + pylab.boxplot( get_boxplot_data( filename ) ) + iters = ( non_zero( P - p ) / ps ) * ( non_zero( D - d ) / ds ) + pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) ) + pylab.ylabel('%s - %s' % (cur, name)) + pylab.savefig( filename + '.pdf', format='pdf' ) + pylab.savefig( filename + '.png', format='png' ) + pylab.cla() + pylab.clf() def main(): - logging.info('creates first the new topic repository %s', options.topic) - os.mkdir( options.topic ) + if not options.onlyprint: + logging.info('creates first the new topic repository %s', options.topic) + os.mkdir( options.topic ) logging.info('do all tests with r = %d and a common seed value = %d' % (options.nRun, options.seed)) From bb2934fd09d9baeae476804599f4cc871d40c028 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sat, 27 Nov 2010 23:26:16 +0100 Subject: [PATCH 20/57] onlyexec and onlyprint parameters added on openmp script --- eo/test/t-openmp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index aa3af6868..54338a444 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import pylab import optparse, logging, sys, os from datetime import datetime @@ -53,6 +52,9 @@ def logger(level_name, filename=LOG_DEFAULT_FILENAME): options = parser() +if not options.onlyexecute: + import pylab + def get_boxplot_data( filename ): try: f = open( filename ) From 1aa9db18f3c13a70bfd0a67050946de6ae152bdd Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 00:12:08 +0100 Subject: [PATCH 21/57] added n processus and fixed bound parameters --- eo/test/t-openmp.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 54338a444..2f7ac80f0 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -24,6 +24,8 @@ def parser(parser=optparse.OptionParser()): parser.add_option('-r', '--nRun', default=100, help='how many times you would compute each iteration ?') parser.add_option('-s', '--seed', default=1, help='give here a seed value') + parser.add_option('-n', '--nProc', default=1, help='give a number of processus, this value is multiplied by the measures bounds') + parser.add_option('-F', '--fixedBound', default=1000, help='give the fixed bound value common for all measures') topic = str(datetime.today()) for char in [' ', ':', '-', '.']: topic = topic.replace(char, '_') @@ -92,20 +94,23 @@ def main(): logging.info('EA in time O(1) and O(n) - speedup measure Sp, Ep and Dp for P & D') + n = options.nProc + F = options.fixedBound + logging.info('(1) measure for all combinaisons of P n D') - do_measure( '1', 1, 10, 101, 1, 10, 101 ) + do_measure( '1', 1*n, 10*n, 101*n, 1*n, 10*n, 101*n ) - logging.info('(2) measure for P \in [1, 100[ with D fixed to 1000') - do_measure( '2', 1, 1, 101, 1000, 1, 1000 ) + logging.info('(2) measure for P \in [%d, %d[ with D fixed to %d' % (1*n, 101*n, F)) + do_measure( '2', 1*n, 1*n, 101*n, F, 1, F ) - logging.info('(3) measure for P \in [1, 1000[ with ps = 10 and D fixed to 1000') - do_measure( '3', 1, 10, 1001, 1000, 1, 1000 ) + logging.info('(3) measure for P \in [%d, %d[ with ps = %d and D fixed to %d' % (1*n, 1001*n, 10*n, F)) + do_measure( '3', 1*n, 10*n, 1001*n, F, 1, F ) - logging.info('(4) measure for D \in [1, 100[ with P fixed to 1000') - do_measure( '4', 1000, 1, 1000, 1, 1, 101 ) + logging.info('(4) measure for D \in [%d, %d[ with P fixed to %d' % (1*n, 101*n, F)) + do_measure( '4', F, 1, F, 1*n, 1*n, 101*n ) - logging.info('(5) measure for D \in [1, 1000[ with ds = 10 and P fixed to 1000') - do_measure( '5', 1000, 1, 1000, 1, 10, 1001 ) + logging.info('(5) measure for D \in [%d, %d[ with ds = %d and P fixed to %d' % (1*n, 1001*n, 10*n, F)) + do_measure( '5', F, 1, F, 1*n, 10*n, 1001*n ) # when executed, just run main(): if __name__ == '__main__': From c7a34a6a5ef2b857361c59914700430c20060cea Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 00:19:46 +0100 Subject: [PATCH 22/57] added n processus and fixed bound parameters --- eo/test/t-openmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 2f7ac80f0..330fe666a 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -94,7 +94,7 @@ def main(): logging.info('EA in time O(1) and O(n) - speedup measure Sp, Ep and Dp for P & D') - n = options.nProc + n = int(options.nProc) F = options.fixedBound logging.info('(1) measure for all combinaisons of P n D') From d6b566b538651508b8ac4ea1edc3c967af80a68e Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 03:24:02 +0100 Subject: [PATCH 23/57] added variable time measure --- eo/test/t-openmp.cpp | 141 ++++++++++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 55 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 4771c541d..10c73ce05 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -24,6 +24,66 @@ typedef eoReal< eoMinimizingFitness > EOT; //----------------------------------------------------------------------------- +double variable_time_function(const std::vector&) +{ + ::srand( ::time( NULL ) ); + ::usleep( 10 * ( rand() / RAND_MAX ) ); + return 0.0; +} + +double measure_apply( size_t p, + void (*fct)(eoUF&, std::vector&), + eoInitFixedLength< EOT >& init, + eoEvalFuncCounter< EOT >& eval ) +{ + eoPop< EOT > pop( p, init ); + double t1 = omp_get_wtime(); + fct( eval, pop ); + double t2 = omp_get_wtime(); + return t2 - t1; +} + +void measure( size_t p, + eoInitFixedLength< EOT >& init, + eoEvalFuncCounter< EOT >& eval, + std::ofstream& speedupFile, + std::ofstream& efficiencyFile, + std::ofstream& dynamicityFile, + size_t nbtask ) +{ + // sequential scope + double Ts = measure_apply( p, apply< EOT >, init, eval ); + // parallel scope + double Tp = measure_apply( p, omp_apply< EOT >, init, eval ); + // parallel scope dynamic + double Tpd = measure_apply( p, omp_dynamic_apply< EOT >, init, eval ); + + double speedup = Ts / Tp; + + if ( speedup > nbtask ) { return; } + + double efficiency = speedup / nbtask; + + speedupFile << speedup << ' '; + efficiencyFile << efficiency << ' '; + + eo::log << eo::debug; + eo::log << "Ts = " << Ts << std::endl; + eo::log << "Tp = " << Tp << std::endl; + eo::log << "S_p = " << speedup << std::endl; + eo::log << "E_p = " << efficiency << std::endl; + + double dynamicity = Tp / Tpd; + + if ( dynamicity > nbtask ) { return; } + + eo::log << "Tpd = " << Tpd << std::endl; + eo::log << "D_p = " << dynamicity << std::endl; + + dynamicityFile << dynamicity << ' '; +} + + int main(int ac, char** av) { eoParserLogger parser(ac, av); @@ -47,6 +107,9 @@ int main(int ac, char** av) uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value(); if (seedParam == 0) { seedParam = time(0); } + unsigned int measureConstTime = parser.getORcreateParam((unsigned int)1, "measureConstTime", "Toggle measure of constant time", 'm', "Results").value(); + unsigned int measureVarTime = parser.getORcreateParam((unsigned int)1, "measureVarTime", "Toggle measure of variable time", 'M', "Results").value(); + if (parser.userNeedsHelp()) { parser.printHelp(std::cout); @@ -59,7 +122,10 @@ int main(int ac, char** av) rng.reseed( seedParam ); eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); - eoEvalFuncCounter eval( mainEval ); + eoEvalFuncCounter< EOT > eval( mainEval ); + + eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval_variable( variable_time_function ); + eoEvalFuncCounter< EOT > eval_variable( mainEval_variable ); eoUniformGenerator< double > gen(-5, 5); @@ -67,10 +133,15 @@ int main(int ac, char** av) params << "_p" << popMin << "_pS" << popStep << "_P" << popMax << "_d" << dimMin << "_dS" << dimStep << "_D" << dimMax << "_r" << nRun << "_s" << seedParam; + std::ofstream speedupFile( std::string( fileNamesPrefix + speedupFileName + params.str() ).c_str() ); std::ofstream efficiencyFile( std::string( fileNamesPrefix + efficiencyFileName + params.str() ).c_str() ); std::ofstream dynamicityFile( std::string( fileNamesPrefix + dynamicityFileName + params.str() ).c_str() ); + std::ofstream speedupFile_variable( std::string( fileNamesPrefix + "variable_" + speedupFileName + params.str() ).c_str() ); + std::ofstream efficiencyFile_variable( std::string( fileNamesPrefix + "variable_" + efficiencyFileName + params.str() ).c_str() ); + std::ofstream dynamicityFile_variable( std::string( fileNamesPrefix + "variable_" + dynamicityFileName + params.str() ).c_str() ); + size_t nbtask = 1; #pragma omp parallel { @@ -89,67 +160,27 @@ int main(int ac, char** av) { eoInitFixedLength< EOT > init( d, gen ); - double Ts; - double Tp; - double Tpd; - - // 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; - } - - // parallel scope dynamic - { - eoPop< EOT > pop( p, init ); - double t1 = omp_get_wtime(); - omp_dynamic_apply< EOT >(eval, pop); - double t2 = omp_get_wtime(); - Tpd = t2 - t1; - } - - double speedup = Ts / Tp; - - if ( speedup > nbtask ) { continue; } - - double efficiency = speedup / nbtask; - - speedupFile << speedup << ' '; - efficiencyFile << efficiency << ' '; - - eo::log << eo::debug; - eo::log << "Ts = " << Ts << std::endl; - eo::log << "Tp = " << Tp << std::endl; - eo::log << "S_p = " << speedup << std::endl; - eo::log << "E_p = " << efficiency << std::endl; - - double dynamicity = Tp / Tpd; - - if ( dynamicity > nbtask ) { continue; } - - eo::log << "Tpd = " << Tpd << std::endl; - eo::log << "D_p = " << dynamicity << std::endl; - - dynamicityFile << dynamicity << ' '; + // for constant time measure + if ( measureConstTime == 1 ) + { + measure( p, init, eval, speedupFile, efficiencyFile, dynamicityFile, nbtask ); + } + // for variable time measure + if ( measureVarTime == 1 ) + { + measure( p, init, eval_variable, speedupFile_variable, efficiencyFile_variable, dynamicityFile_variable, nbtask ); + } } // end of runs speedupFile << std::endl; efficiencyFile << std::endl; dynamicityFile << std::endl; + speedupFile_variable << std::endl; + efficiencyFile_variable << std::endl; + dynamicityFile_variable << std::endl; + } // end of dimension } // end of population From 13bb5efa43c31de2818c85845e255d6e3c12acd6 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 03:32:53 +0100 Subject: [PATCH 24/57] added variable time measure --- eo/test/t-openmp.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 330fe666a..0fb091f51 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -11,7 +11,7 @@ LEVELS = {'debug': logging.DEBUG, LOG_DEFAULT_FILENAME='notitle.log' -OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s' +OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s -m=%d -M=%d' RESULT_FILE_FORMAT='%s%s_p%d_pS%d_P%d_d%d_dS%d_D%d_r%d_s%d' @@ -34,6 +34,9 @@ def parser(parser=optparse.OptionParser()): parser.add_option('-E', '--onlyexecute', action='store_true', dest='onlyexecute', default=False, help='used this option if you only want to execute measures without generating images') parser.add_option('-X', '--onlyprint', action='store_true', dest='onlyprint', default=False, help='used this option if you only want to generate images without executing measures, dont forget to set the good path in using --topic with a "/" at the end') + parser.add_option('-m', '--measureConstTime', default=1, help='Toggle measure of constant time') + parser.add_option('-M', '--measureVarTime', default=1, help='Toggle measure of variable time') + options, args = parser.parse_args() logger(options.verbose, options.output) @@ -68,7 +71,7 @@ def non_zero( value ): return value if value > 0 else 1 def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ): pwd = options.topic + name + '_' - cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd) + cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd, options.measureConstTime, options.measureVarTime) logging.debug( cmd ) if not options.onlyprint: os.system( cmd ) From a7024e784c7520fce4ea901e6ea3bf8f54010bfd Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 03:35:21 +0100 Subject: [PATCH 25/57] added variable time measure --- eo/test/t-openmp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 0fb091f51..c9f104be2 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -71,7 +71,8 @@ def non_zero( value ): return value if value > 0 else 1 def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ): pwd = options.topic + name + '_' - cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd, options.measureConstTime, options.measureVarTime) + cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd, + int(options.measureConstTime), int(options.measureVarTime)) logging.debug( cmd ) if not options.onlyprint: os.system( cmd ) From 61ab540d8a96d32f0c9a76b02daf8e822cdf7907 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 03:41:09 +0100 Subject: [PATCH 26/57] update --- eo/test/t-openmp.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 10c73ce05..54d2e7107 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -173,13 +173,19 @@ int main(int ac, char** av) } } // end of runs - speedupFile << std::endl; - efficiencyFile << std::endl; - dynamicityFile << std::endl; + if ( measureConstTime == 1 ) + { + speedupFile << std::endl; + efficiencyFile << std::endl; + dynamicityFile << std::endl; + } - speedupFile_variable << std::endl; - efficiencyFile_variable << std::endl; - dynamicityFile_variable << std::endl; + if ( measureVarTime == 1 ) + { + speedupFile_variable << std::endl; + efficiencyFile_variable << std::endl; + dynamicityFile_variable << std::endl; + } } // end of dimension From e3c3d156283a462eb8fa4cb4c7ec1f4e999ef527 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 13:36:25 +0100 Subject: [PATCH 27/57] using rdtsc for rng seed with mersenne twister --- eo/test/t-openmp.cpp | 6 ++++-- eo/test/t-openmp.py | 32 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 54d2e7107..69e9022ed 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -24,10 +24,12 @@ typedef eoReal< eoMinimizingFitness > EOT; //----------------------------------------------------------------------------- +inline uint32_t get_rdtsc() { __asm__ ("xor %eax, %eax; cpuid; rdtsc"); } + double variable_time_function(const std::vector&) { - ::srand( ::time( NULL ) ); - ::usleep( 10 * ( rand() / RAND_MAX ) ); + eoRng myrng( get_rdtsc() ); + ::usleep( myrng.random( 10 ) ); return 0.0; } diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index c9f104be2..1b166ae6a 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -67,27 +67,33 @@ def get_boxplot_data( filename ): except: raise ValueError('got an issue during the reading of file %s' % filename) -def non_zero( value ): return value if value > 0 else 1 - def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ): pwd = options.topic + name + '_' cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd, - int(options.measureConstTime), int(options.measureVarTime)) + int(options.measureConstTime), + int(options.measureVarTime)) logging.debug( cmd ) if not options.onlyprint: os.system( cmd ) if not options.onlyexecute: - for cur in ['speedup', 'efficiency', 'dynamicity']: - filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s) - pylab.boxplot( get_boxplot_data( filename ) ) - iters = ( non_zero( P - p ) / ps ) * ( non_zero( D - d ) / ds ) - pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) ) - pylab.ylabel('%s - %s' % (cur, name)) - pylab.savefig( filename + '.pdf', format='pdf' ) - pylab.savefig( filename + '.png', format='png' ) - pylab.cla() - pylab.clf() + def generate( filenames ): + for cur in filenames: + filename = RESULT_FILE_FORMAT % (pwd, cur, p, ps, P, d, ds, D, r, s) + pylab.boxplot( get_boxplot_data( filename ) ) + nonzero = lambda x: x if x > 0 else 1 + iters = ( nonzero( P - p ) / ps ) * ( nonzero( D - d ) / ds ) + pylab.xlabel('%d iterations from %d,%d to %d,%d' % ( iters, p, d, P, D) ) + pylab.ylabel('%s - %s' % (cur, name)) + pylab.savefig( filename + '.pdf', format='pdf' ) + pylab.savefig( filename + '.png', format='png' ) + pylab.cla() + pylab.clf() + + if int(options.measureConstTime) == 1: + generate( ['speedup', 'efficiency', 'dynamicity'] ) + if int(options.measureVarTime) == 1: + generate( ['variable_speedup', 'variable_efficiency', 'variable_dynamicity'] ) def main(): if not options.onlyprint: From 16a77fadd956d24acda56f77de477e8f4568fcde Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 28 Nov 2010 14:21:26 +0100 Subject: [PATCH 28/57] now we can select which measures we want --- eo/test/t-openmp.cpp | 4 +-- eo/test/t-openmp.py | 59 +++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 69e9022ed..325cb653a 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -109,8 +109,8 @@ int main(int ac, char** av) uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value(); if (seedParam == 0) { seedParam = time(0); } - unsigned int measureConstTime = parser.getORcreateParam((unsigned int)1, "measureConstTime", "Toggle measure of constant time", 'm', "Results").value(); - unsigned int measureVarTime = parser.getORcreateParam((unsigned int)1, "measureVarTime", "Toggle measure of variable time", 'M', "Results").value(); + unsigned int measureConstTime = parser.getORcreateParam((unsigned int)1, "measureConstTime", "Toggle measure of constant time", 'C', "Results").value(); + unsigned int measureVarTime = parser.getORcreateParam((unsigned int)1, "measureVarTime", "Toggle measure of variable time", 'V', "Results").value(); if (parser.userNeedsHelp()) { diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index 1b166ae6a..ab43bb930 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -11,8 +11,6 @@ LEVELS = {'debug': logging.DEBUG, LOG_DEFAULT_FILENAME='notitle.log' -OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s -m=%d -M=%d' - RESULT_FILE_FORMAT='%s%s_p%d_pS%d_P%d_d%d_dS%d_D%d_r%d_s%d' def parser(parser=optparse.OptionParser()): @@ -22,20 +20,22 @@ def parser(parser=optparse.OptionParser()): parser.add_option('-o', '--output', help='give an output filename for logging', default=LOG_DEFAULT_FILENAME) # general parameters ends - parser.add_option('-r', '--nRun', default=100, help='how many times you would compute each iteration ?') - parser.add_option('-s', '--seed', default=1, help='give here a seed value') - parser.add_option('-n', '--nProc', default=1, help='give a number of processus, this value is multiplied by the measures bounds') - parser.add_option('-F', '--fixedBound', default=1000, help='give the fixed bound value common for all measures') + parser.add_option('-r', '--nRun', type='int', default=100, help='how many times you would compute each iteration ?') + parser.add_option('-s', '--seed', type='int', default=1, help='give here a seed value') + parser.add_option('-n', '--nProc', type='int', default=1, help='give a number of processus, this value is multiplied by the measures bounds') + parser.add_option('-F', '--fixedBound', type='int', default=1000, help='give the fixed bound value common for all measures') topic = str(datetime.today()) for char in [' ', ':', '-', '.']: topic = topic.replace(char, '_') parser.add_option('-t', '--topic', default='openmp_measures_' + topic + '/', help='give here a topic name used to create the folder') - parser.add_option('-E', '--onlyexecute', action='store_true', dest='onlyexecute', default=False, help='used this option if you only want to execute measures without generating images') - parser.add_option('-X', '--onlyprint', action='store_true', dest='onlyprint', default=False, help='used this option if you only want to generate images without executing measures, dont forget to set the good path in using --topic with a "/" at the end') + parser.add_option('-E', '--onlyexecute', action='store_true', default=False, help='used this option if you only want to execute measures without generating images') + parser.add_option('-X', '--onlyprint', action='store_true', default=False, help='used this option if you only want to generate images without executing measures, dont forget to set the good path in using --topic with a "/" at the end') - parser.add_option('-m', '--measureConstTime', default=1, help='Toggle measure of constant time') - parser.add_option('-M', '--measureVarTime', default=1, help='Toggle measure of variable time') + parser.add_option('-C', '--onlyConstTime', action='store_true', default=False, help='only measures constant time problem') + parser.add_option('-V', '--onlyVarTime', action='store_true', default=False, help='only measures variable time problem') + + parser.add_option('-m', '--measure', action='append', type='int', help='select all measure you want to produce, by default all are produced') options, args = parser.parse_args() @@ -68,11 +68,13 @@ def get_boxplot_data( filename ): raise ValueError('got an issue during the reading of file %s' % filename) def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='logging' ): + OPENMP_EXEC_FORMAT='./test/t-openmp -p=%d --popStep=%d -P=%d -d=%d --dimStep=%d -D=%d -r=%d --seed=%d -v=%s -H=%s -C=%d -V=%d' + pwd = options.topic + name + '_' cmd = OPENMP_EXEC_FORMAT % (p, ps, P, d, ds, D, r, s, v, pwd, - int(options.measureConstTime), - int(options.measureVarTime)) - logging.debug( cmd ) + 0 if options.onlyVarTime else 1, + 0 if options.onlyConstTime else 1) + logging.info( cmd ) if not options.onlyprint: os.system( cmd ) @@ -90,9 +92,9 @@ def do_measure( name, p, ps, P, d, ds, D, r=options.nRun, s=options.seed, v='log pylab.cla() pylab.clf() - if int(options.measureConstTime) == 1: + if not options.onlyVarTime: generate( ['speedup', 'efficiency', 'dynamicity'] ) - if int(options.measureVarTime) == 1: + if not options.onlyConstTime: generate( ['variable_speedup', 'variable_efficiency', 'variable_dynamicity'] ) def main(): @@ -104,23 +106,28 @@ def main(): logging.info('EA in time O(1) and O(n) - speedup measure Sp, Ep and Dp for P & D') - n = int(options.nProc) + n = options.nProc F = options.fixedBound - logging.info('(1) measure for all combinaisons of P n D') - do_measure( '1', 1*n, 10*n, 101*n, 1*n, 10*n, 101*n ) + if options.measure is None or 1 in options.measure: + logging.info('(1) measure for all combinaisons of P n D') + do_measure( '1', 1*n, 10*n, 101*n, 1*n, 10*n, 101*n ) - logging.info('(2) measure for P \in [%d, %d[ with D fixed to %d' % (1*n, 101*n, F)) - do_measure( '2', 1*n, 1*n, 101*n, F, 1, F ) + if options.measure is None or 2 in options.measure: + logging.info('(2) measure for P \in [%d, %d[ with D fixed to %d' % (1*n, 101*n, F)) + do_measure( '2', 1*n, 1*n, 101*n, F, 1, F ) - logging.info('(3) measure for P \in [%d, %d[ with ps = %d and D fixed to %d' % (1*n, 1001*n, 10*n, F)) - do_measure( '3', 1*n, 10*n, 1001*n, F, 1, F ) + if options.measure is None or 3 in options.measure: + logging.info('(3) measure for P \in [%d, %d[ with ps = %d and D fixed to %d' % (1*n, 1001*n, 10*n, F)) + do_measure( '3', 1*n, 10*n, 1001*n, F, 1, F ) - logging.info('(4) measure for D \in [%d, %d[ with P fixed to %d' % (1*n, 101*n, F)) - do_measure( '4', F, 1, F, 1*n, 1*n, 101*n ) + if options.measure is None or 4 in options.measure: + logging.info('(4) measure for D \in [%d, %d[ with P fixed to %d' % (1*n, 101*n, F)) + do_measure( '4', F, 1, F, 1*n, 1*n, 101*n ) - logging.info('(5) measure for D \in [%d, %d[ with ds = %d and P fixed to %d' % (1*n, 1001*n, 10*n, F)) - do_measure( '5', F, 1, F, 1*n, 10*n, 1001*n ) + if options.measure is None or 5 in options.measure: + logging.info('(5) measure for D \in [%d, %d[ with ds = %d and P fixed to %d' % (1*n, 1001*n, 10*n, F)) + do_measure( '5', F, 1, F, 1*n, 10*n, 1001*n ) # when executed, just run main(): if __name__ == '__main__': From 821c22e1d5a78c92f1879c3fcf8b886bafa610c4 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 23 Dec 2010 14:31:34 +0100 Subject: [PATCH 29/57] fixed a mistake in cflags setting about openmp flags --- eo/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index 7bdcdba49..6999bd364 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -46,8 +46,8 @@ ENABLE_LANGUAGE(C) 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}") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") ENDIF() INCLUDE(CMakeBackwardCompatibilityCXX) From f5ead806f6fe5c18222bffa564622fd7639e0d75 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Tue, 14 Dec 2010 15:27:26 +0100 Subject: [PATCH 30/57] add the parser/logger to the general header --- eo/src/eo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eo/src/eo b/eo/src/eo index cf18f3ea0..7c988f1c9 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -198,6 +198,8 @@ #include #include +#include + //----------------------------------------------------------------------------- #endif From 60bc4b3b96220222105e3606a732724be14eeb9e Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 16 Dec 2010 15:50:26 +0100 Subject: [PATCH 31/57] evaluator that throw an exception if a maximum CPU user time has been reached, for POSIX systems --- eo/NEWS | 5 ++- eo/src/eo | 1 + eo/src/eoEvalUserTimeThrowException.h | 61 +++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 eo/src/eoEvalUserTimeThrowException.h diff --git a/eo/NEWS b/eo/NEWS index 50e256087..0f067e003 100644 --- a/eo/NEWS +++ b/eo/NEWS @@ -1,4 +1,7 @@ -* release 1.1 (not yet released) +* current + - evaluators that throw an exception if a maximum time has en reached (wallclock and CPU user time for POSIX systems), independently of the number of generations + +* release 1.1 - provide cmake build system, remove the old autotools one - package generation system - GCC 4.3 compatibility diff --git a/eo/src/eo b/eo/src/eo index 7c988f1c9..89ed7da98 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -77,6 +77,7 @@ #include #include #include +#include // Continuators - all include eoContinue.h #include diff --git a/eo/src/eoEvalUserTimeThrowException.h b/eo/src/eoEvalUserTimeThrowException.h new file mode 100644 index 000000000..d47c064ae --- /dev/null +++ b/eo/src/eoEvalUserTimeThrowException.h @@ -0,0 +1,61 @@ +/* +(c) Thales group, 2010 + + 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; + version 2 of the License. + + 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: http://eodev.sourceforge.net + +Authors: +Johann Dréo +*/ + +#include +#include + +#include + +/** Check at each evaluation if a given CPU user time contract has been reached. + * + * Throw an eoMaxTimeException if the given max time has been reached. + * Usefull if you want to end the search independently of generations. + * This class uses (almost-)POSIX headers. + * It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException + * + * @ingroup Evaluation + */ +template< class EOT > +class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT > +{ +public: + eoEvalUserTimeThrowException( eoEvalFunc & func, long max ) : _max(max), eoEvalFuncCounter( func, "CPU-user") {} + + virtual void operator() ( EOT & eo ) + { + if( eo.invalid() ) { + + getrusage(RUSAGE_SELF,&_usage); + + if( _usage.ru_utime.tv_sec >= _max ) { + throw eoMaxTimeException( _usage.ru_utime.tv_sec ); + } else { + func(eo); + } + } + } + +protected: + long _max; + struct rusage _usage; +}; From fbc212f80d2a49f45cc35ab7f9f890dbdc1815d1 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 16 Dec 2010 15:51:28 +0100 Subject: [PATCH 32/57] set the version to 1.1.1-edge --- eo/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index 6999bd364..548f1b548 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -15,11 +15,11 @@ INCLUDE(eo-conf.cmake OPTIONAL) PROJECT(EO) SET(PROJECT_VERSION_MAJOR 1) -SET(PROJECT_VERSION_MINOR 02) +SET(PROJECT_VERSION_MINOR 1) SET(PROJECT_VERSION_PATCH 1) SET(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" CACHE STRING "Package version" FORCE) -SET(VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" CACHE STRING "Global version" FORCE) -SET(VERSION "1.02" CACHE STRING "Global version" FORCE) +#SET(VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" CACHE STRING "Global version" FORCE) +SET(VERSION "1.1.1-edge" CACHE STRING "Global version" FORCE) SET(GLOBAL_VERSION "${VERSION}") SET(PACKAGE_BUGREPORT "eodev-help@sourceforge.net" CACHE STRING "Package bug report" FORCE) From 07c22771cf03de2d97a01f6aaa9e02a1053df2db Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 23 Dec 2010 18:09:25 +0100 Subject: [PATCH 33/57] + now you are able to enable or not parallelization with the option --parallelize-loops=1|0 --- eo/src/apply.h | 14 +++++++++----- eo/src/utils/eoParser.cpp | 7 +++++++ eo/src/utils/eoParser.h | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index 2cd977b08..41d96adba 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -26,6 +26,7 @@ #ifndef _apply_h #define _apply_h +#include #include #include @@ -37,7 +38,8 @@ template void apply(eoUF& _proc, std::vector& _pop) { - for (unsigned i = 0; i < _pop.size(); ++i) + size_t size = _pop.size(); + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } @@ -52,8 +54,9 @@ void apply(eoUF& _proc, std::vector& _pop) template void omp_apply(eoUF& _proc, std::vector& _pop) { -#pragma omp parallel for default(none) shared(_proc, _pop) - for (unsigned i = 0; i < _pop.size(); ++i) + size_t size = _pop.size(); +#pragma omp parallel for if(eo::parallelizeLoopParam.value()) //default(none) shared(_proc, _pop, size) + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } @@ -67,8 +70,9 @@ void omp_apply(eoUF& _proc, std::vector& _pop) template void omp_dynamic_apply(eoUF& _proc, std::vector& _pop) { -#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic) - for (unsigned i = 0; i < _pop.size(); ++i) + size_t size = _pop.size(); +#pragma omp parallel for if(eo::parallelizeLoopParam.value()) schedule(dynamic) //default(none) shared(_proc, _pop, size) + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index f6c81f14a..f7c2aac4c 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -61,6 +61,9 @@ eoParameterLoader::~eoParameterLoader() } } +//multithreading +eoValueParam eo::parallelizeLoopParam = eoValueParam(false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0'); +//multithreading ends eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) : @@ -99,6 +102,10 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, readFrom(stream); processParam(needHelp); processParam(stopOnUnknownParam); + + //multithreading + processParam(eo::parallelizeLoopParam); + //multithreading ends } diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index bb8e5811a..073d1a3e3 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -93,6 +93,12 @@ private : }; +//multithreading +namespace eo +{ + extern eoValueParam parallelizeLoopParam; +} +//multithreading ends /** eoParser: command line parser and configuration file reader From 64f36841be3bd8811f243c2be30be39194adde41 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 23 Dec 2010 23:03:02 +0100 Subject: [PATCH 34/57] added measure into apply function --- eo/src/apply.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eo/src/apply.h b/eo/src/apply.h index 41d96adba..deb13da86 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -29,6 +29,7 @@ #include #include #include +#include /** Applies a unary function to a std::vector of things. @@ -38,11 +39,18 @@ template void apply(eoUF& _proc, std::vector& _pop) { + double t1 = omp_get_wtime(); + size_t size = _pop.size(); +#pragma omp parallel for if(eo::parallelizeLoopParam.value()) //default(none) shared(_proc, _pop, size) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } + + double t2 = omp_get_wtime(); + + eo::log << eo::logging << "### apply called cost: " << t2 - t1 << std::endl; } /** From 40817a09312b3b65b3c7d05b961a9e79258a9093 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 26 Dec 2010 19:09:08 +0100 Subject: [PATCH 35/57] * changed apply.h to use new parallelization s parameters --- eo/src/apply.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index deb13da86..d8bc9796d 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -26,7 +26,7 @@ #ifndef _apply_h #define _apply_h -#include +#include #include #include #include @@ -39,14 +39,22 @@ template void apply(eoUF& _proc, std::vector& _pop) { + size_t size = _pop.size(); + double t1 = omp_get_wtime(); - size_t size = _pop.size(); -#pragma omp parallel for if(eo::parallelizeLoopParam.value()) //default(none) shared(_proc, _pop, size) - for (size_t i = 0; i < size; ++i) - { - _proc(_pop[i]); - } + if (!eo::parallel.isDynamic()) + { +#pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size) + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } + } + else + { +#pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled()) + //doesnot work with gcc 4.1.2 + //default(none) shared(_proc, _pop, size) + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } + } double t2 = omp_get_wtime(); @@ -63,7 +71,9 @@ template void omp_apply(eoUF& _proc, std::vector& _pop) { size_t size = _pop.size(); -#pragma omp parallel for if(eo::parallelizeLoopParam.value()) //default(none) shared(_proc, _pop, size) +#pragma omp parallel for if(eo::parallel.isEnabled()) + //doesnot work with gcc 4.1.2 + //default(none) shared(_proc, _pop, size) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); @@ -79,7 +89,9 @@ template void omp_dynamic_apply(eoUF& _proc, std::vector& _pop) { size_t size = _pop.size(); -#pragma omp parallel for if(eo::parallelizeLoopParam.value()) schedule(dynamic) //default(none) shared(_proc, _pop, size) +#pragma omp parallel for if(eo::parallel.isEnabled()) schedule(dynamic) + //doesnot work with gcc 4.1.2 + //default(none) shared(_proc, _pop, size) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); From 63d28c1c791ff11187e3a13ea4b74df325197060 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 26 Dec 2010 19:11:00 +0100 Subject: [PATCH 36/57] + created new eoParallel class with a global variable eo::parallel in order to store all parameters tied to parallelization and to access from anywhere --- eo/src/utils/eoParallel.cpp | 55 ++++++++++++++++++++++++++ eo/src/utils/eoParallel.h | 77 +++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 eo/src/utils/eoParallel.cpp create mode 100644 eo/src/utils/eoParallel.h diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp new file mode 100644 index 000000000..d85855921 --- /dev/null +++ b/eo/src/utils/eoParallel.cpp @@ -0,0 +1,55 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/* + +(c) Thales group, 2010 + + 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; + version 2 of the license. + + 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: http://eodev.sourceforge.net + +Authors: + Caner Candan + +*/ + +#include "eoParallel.h" + +eoParallel::eoParallel() + : _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ), + _isDynamic( false, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\0' ), + _prefix( "results", "parallelize-prefix", "Enable dynamic memory shared parallelization", '\0' ) +{} + +std::string eoParallel::className() const +{ + return "eoParallel"; +} + +void eoParallel::_createParameters( eoParser& parser ) +{ + std::string section("Parallelization"); + + parser.processParam( _isEnabled, section ); + parser.processParam( _isDynamic, section ); + parser.processParam( _prefix, section ); +} + +void make_parallel(eoParser& parser) +{ + eo::parallel._createParameters( parser ); +} + +eoParallel eo::parallel; diff --git a/eo/src/utils/eoParallel.h b/eo/src/utils/eoParallel.h new file mode 100644 index 000000000..397bb5f0d --- /dev/null +++ b/eo/src/utils/eoParallel.h @@ -0,0 +1,77 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/* +(c) Thales group, 2010 + + 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; + version 2 of the License. + + 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: http://eodev.sourceforge.net + +Authors: +Caner Candan + +*/ + +/** @defgroup Parallel Parallel + * @ingroup Utilities +@{ +*/ + +#ifndef eoParallel_h +#define eoParallel_h + +#include "eoObject.h" +#include "eoParser.h" + +/** + * eoParallel + * Class providing parameters for parallelization + * Use of a global variable eo::parallel to easily use the parallelization parameters anywhere + */ +class eoParallel : public eoObject +{ +public: + eoParallel(); + + virtual std::string className() const; + + inline bool isEnabled() { return _isEnabled.value(); } + inline bool isDynamic() { return _isDynamic.value(); } + inline std::string prefix() { return _prefix.value(); } + + friend void make_parallel(eoParser&); + +private: + void _createParameters( eoParser& ); + +private: + eoValueParam _isEnabled; + eoValueParam _isDynamic; + eoValueParam _prefix; +}; + +void make_parallel(eoParser&); + +namespace eo +{ + /** + * parallel is an external global variable defined in order to use where ever you want the parallel parameters + */ + extern eoParallel parallel; +} + +/** @} */ + +#endif // !eoParallel_h From b7379050bc79037a09ffe4ea6dbb5accb5565864 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 26 Dec 2010 19:12:20 +0100 Subject: [PATCH 37/57] * updated cmakelists.txt to compile new eoParallel class --- eo/src/utils/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo/src/utils/CMakeLists.txt b/eo/src/utils/CMakeLists.txt index ec70053b5..94f994d2b 100644 --- a/eo/src/utils/CMakeLists.txt +++ b/eo/src/utils/CMakeLists.txt @@ -27,7 +27,8 @@ SET (EOUTILS_SOURCES eoData.cpp make_help.cpp pipecom.cpp eoLogger.cpp - eoParserLogger.cpp) + eoParserLogger.cpp + eoParallel.cpp) ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES}) From 85fdbe6aba82b0c8d3ff90856dcb3c19a9513efd Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 26 Dec 2010 19:13:43 +0100 Subject: [PATCH 38/57] - removed old parallelization parameters from the old-style from eoParser class --- eo/src/utils/eoParser.cpp | 8 -------- eo/src/utils/eoParser.h | 7 ------- 2 files changed, 15 deletions(-) diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index f7c2aac4c..23970023d 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -61,10 +61,6 @@ eoParameterLoader::~eoParameterLoader() } } -//multithreading -eoValueParam eo::parallelizeLoopParam = eoValueParam(false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0'); -//multithreading ends - eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, string _lFileParamName, char _shortHand) : programName(_argv[0]), @@ -102,10 +98,6 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, readFrom(stream); processParam(needHelp); processParam(stopOnUnknownParam); - - //multithreading - processParam(eo::parallelizeLoopParam); - //multithreading ends } diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index 073d1a3e3..adce90173 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -93,13 +93,6 @@ private : }; -//multithreading -namespace eo -{ - extern eoValueParam parallelizeLoopParam; -} -//multithreading ends - /** eoParser: command line parser and configuration file reader This class is persistent, so it can be stored and reloaded to restore From 7b87e4107215dfe33a518e391f47658984d6cf86 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Sun, 26 Dec 2010 19:19:20 +0100 Subject: [PATCH 39/57] * added eoParallel header inclusion to eo --- eo/src/eo | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eo/src/eo b/eo/src/eo index 89ed7da98..14dc831cd 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -201,6 +201,8 @@ #include +#include + //----------------------------------------------------------------------------- #endif From 16e6e7f3b7c7c0371ce02bf72af7eb4efd8dd945 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 28 Dec 2010 16:41:14 +0100 Subject: [PATCH 40/57] * apply.h: now results stored to a filename defined with parallelization parameters --- eo/src/apply.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index d8bc9796d..cb46c11d7 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -58,7 +58,8 @@ void apply(eoUF& _proc, std::vector& _pop) double t2 = omp_get_wtime(); - eo::log << eo::logging << "### apply called cost: " << t2 - t1 << std::endl; + eoLogger log; + log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; } /** From 388d81b1ff7737f95aaa3f4ef8f001a0cd90d53b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 28 Dec 2010 16:42:53 +0100 Subject: [PATCH 41/57] * updated eoParallel class in order to define the result filename according to the parallelization mode --- eo/src/utils/eoParallel.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index d85855921..ddfec8fb6 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -44,7 +44,35 @@ void eoParallel::_createParameters( eoParser& parser ) parser.processParam( _isEnabled, section ); parser.processParam( _isDynamic, section ); + + std::string default_value( _prefix.defValue() ); + + if ( _isEnabled.value() ) + { + if ( _isDynamic.value() ) + { + default_value += "_dynamic.out"; + } + else + { + default_value += "_parallel.out"; + } + } + else + { + default_value += "_sequential.out"; + } + + _prefix.defValue( default_value ); + + std::cout << "defvalue: " << _prefix.defValue() << std::endl; + parser.processParam( _prefix, section ); + + std::cout << "value: " << parser.getParamWithLongName("parallelize-prefix")->getValue() << std::endl; + + std::cout << "defvalue: " << _prefix.defValue() << std::endl; + } void make_parallel(eoParser& parser) From bd88da01f769cdec3278955f61039ba6d3d1ffe6 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 28 Dec 2010 16:43:44 +0100 Subject: [PATCH 42/57] + added a test file for eoParallel class --- eo/test/CMakeLists.txt | 1 + eo/test/t-eoParallel.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 eo/test/t-eoParallel.cpp diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 220063504..436c4503c 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -65,6 +65,7 @@ SET (TEST_LIST t-eoExtendedVelocity t-eoLogger t-eoIQRStat + t-eoParallel t-openmp ) diff --git a/eo/test/t-eoParallel.cpp b/eo/test/t-eoParallel.cpp new file mode 100644 index 000000000..055f45987 --- /dev/null +++ b/eo/test/t-eoParallel.cpp @@ -0,0 +1,46 @@ +//----------------------------------------------------------------------------- +// t-eoParallel.cpp +//----------------------------------------------------------------------------- + +#include +#include +//#include +#include "real_value.h" + +//----------------------------------------------------------------------------- + +typedef eoReal< eoMinimizingFitness > EOT; + +int main(int ac, char** av) +{ + eoParser parser(ac, av); + + unsigned int popSize = parser.getORcreateParam((unsigned int)100, "popSize", "Population Size", 'P', "Evolution Engine").value(); + unsigned int dimSize = parser.getORcreateParam((unsigned int)10, "dimSize", "Dimension Size", 'd', "Evolution Engine").value(); + + uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value(); + if (seedParam == 0) { seedParam = time(0); } + + make_parallel(parser); + make_help(parser); + + rng.reseed( seedParam ); + + eoUniformGenerator< double > gen(-5, 5); + eoInitFixedLength< EOT > init( dimSize, gen ); + + eoEvalFuncPtr< EOT, double, const std::vector< double >& > mainEval( real_value ); + eoEvalFuncCounter< EOT > eval( mainEval ); + + eoPop< EOT > pop( popSize, init ); + + //apply< EOT >( eval, pop ); + eoPopLoopEval< EOT > popEval( eval ); + popEval( pop, pop ); + + eo::log << eo::quiet << "DONE!" << std::endl; + + return 0; +} + +//----------------------------------------------------------------------------- From 2013d57fe8bfd397388846079e32f2eb0aff0f3c Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 28 Dec 2010 22:54:10 +0100 Subject: [PATCH 43/57] fixed an issue in eoParallel class --- eo/src/utils/eoParallel.cpp | 30 ++++++++++++------------------ eo/src/utils/eoParallel.h | 7 ++++--- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index ddfec8fb6..d3fd2d665 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -38,41 +38,35 @@ std::string eoParallel::className() const return "eoParallel"; } -void eoParallel::_createParameters( eoParser& parser ) +std::string eoParallel::prefix() const { - std::string section("Parallelization"); - - parser.processParam( _isEnabled, section ); - parser.processParam( _isDynamic, section ); - - std::string default_value( _prefix.defValue() ); + std::string value( _prefix.value() ); if ( _isEnabled.value() ) { if ( _isDynamic.value() ) { - default_value += "_dynamic.out"; + value += "_dynamic.out"; } else { - default_value += "_parallel.out"; + value += "_parallel.out"; } } else { - default_value += "_sequential.out"; + value += "_sequential.out"; } - _prefix.defValue( default_value ); - - std::cout << "defvalue: " << _prefix.defValue() << std::endl; + return value; +} +void eoParallel::_createParameters( eoParser& parser ) +{ + std::string section("Parallelization"); + parser.processParam( _isEnabled, section ); + parser.processParam( _isDynamic, section ); parser.processParam( _prefix, section ); - - std::cout << "value: " << parser.getParamWithLongName("parallelize-prefix")->getValue() << std::endl; - - std::cout << "defvalue: " << _prefix.defValue() << std::endl; - } void make_parallel(eoParser& parser) diff --git a/eo/src/utils/eoParallel.h b/eo/src/utils/eoParallel.h index 397bb5f0d..4e13f8b31 100644 --- a/eo/src/utils/eoParallel.h +++ b/eo/src/utils/eoParallel.h @@ -47,9 +47,10 @@ public: virtual std::string className() const; - inline bool isEnabled() { return _isEnabled.value(); } - inline bool isDynamic() { return _isDynamic.value(); } - inline std::string prefix() { return _prefix.value(); } + inline bool isEnabled() const { return _isEnabled.value(); } + inline bool isDynamic() const { return _isDynamic.value(); } + + std::string prefix() const; friend void make_parallel(eoParser&); From 6ecfab080248c30a5cad2be2e5581341a7ab7a95 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 5 Jan 2011 16:07:08 +0100 Subject: [PATCH 44/57] * --parallelize-prefix parameter description --- eo/src/utils/eoParallel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index d3fd2d665..3ab25e7f5 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -30,7 +30,7 @@ Authors: eoParallel::eoParallel() : _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ), _isDynamic( false, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\0' ), - _prefix( "results", "parallelize-prefix", "Enable dynamic memory shared parallelization", '\0' ) + _prefix( "results", "parallelize-prefix", "Here's the prefix filename where the results are going to be stored", '\0' ) {} std::string eoParallel::className() const From 7357e2a54f31efacc692ee79c05290df91ea93d4 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 6 Jan 2011 09:16:01 +0100 Subject: [PATCH 45/57] * a little update tu be compatible with gnuplot --- eo/src/apply.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index cb46c11d7..175ce51d5 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -59,7 +59,7 @@ void apply(eoUF& _proc, std::vector& _pop) double t2 = omp_get_wtime(); eoLogger log; - log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; + log << eo::file(eo::parallel.prefix()) << t2 - t1 << std::endl; } /** From 914842253657988a126e2a866833c6666e585e3f Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 26 Jan 2011 18:09:37 +0100 Subject: [PATCH 46/57] * doc: solved some mistakes Conflicts: eo/doc/index.h --- eo/doc/index.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eo/doc/index.h b/eo/doc/index.h index 2fad16e2f..52a5758cf 100644 --- a/eo/doc/index.h +++ b/eo/doc/index.h @@ -43,17 +43,17 @@ massively use templates, so that you will not be limited by interfaces when using your own representation. Once you have a representation, you will build your own evolutionary algorithm -by assembling @ref Operators in @ref Algorithms. +by assembling @ref Operators in @ref Algorithms. In %EO, most of the objects are functors, that is classes with an operator(), that you -can call just as if they were classical functions. For example, an algorithm is a -functor, that manipulate a population of individuals, it will be implemented as a functor, +can call just as if they were classical functions. For example, an algorithm is a +functor, that manipulate a population of individuals, it will be implemented as a functor, with a member like: operator()(eoPop). Once called on a given population, it will 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 your own algorithm by trying several combination of operators. -For a 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 From df01e1790e785467bb5aa25e1888b2941bc4c662 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 22 Dec 2010 13:40:49 +0100 Subject: [PATCH 47/57] * package dependancies changed --- eo/Packaging.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eo/Packaging.cmake b/eo/Packaging.cmake index c9e2d44b1..de81fadc3 100644 --- a/eo/Packaging.cmake +++ b/eo/Packaging.cmake @@ -67,7 +67,7 @@ SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME} ${PROJECT_VERSION_MAJOR}.${ ### 4) Set up debian packaging information ###################################################################################### -SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6, libgcc1, libc6, libxml2, libmpich2-1.2") +SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6, libgcc1, libc6, g++") SET(CPACK_DEBIAN_PACKAGE_SECTION "devel") SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") From 9f8521f0862fdce26c2e434b4ec89026ae980047 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 23 Dec 2010 12:22:29 +0100 Subject: [PATCH 48/57] + add the value() method in eoParam used by dae --- eo/src/utils/eoParam.h | 46 +++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/eo/src/utils/eoParam.h b/eo/src/utils/eoParam.h index 1eb97b306..868507cf7 100644 --- a/eo/src/utils/eoParam.h +++ b/eo/src/utils/eoParam.h @@ -169,32 +169,46 @@ public : eoParam::defValue(getValue()); } - /** Parameter value + /** Get a reference on the parameter value @return parameter value */ - ValueType& value() - { return repValue; } + ValueType& value() { return repValue; } - /** Parameter value + /** Get a const reference on the parameter value @overload @return parameter value */ - const ValueType& value() const - { return repValue; } + const ValueType& value() const { return repValue; } + /** Change the parameter value + */ + void value( ValueType val ) + { + // convert to string + std::ostringstream os; + os << val; + + // convert to ValueType + std::istringstream is( os.str() ); + is >> repValue; + } + + + /** Get the string representation of the value + */ std::string getValue(void) const - { - std::ostringstream os; - os << repValue; - return os.str(); - } + { + std::ostringstream os; + os << repValue; + return os.str(); + } - /** @brief Set value according to the speciied string + /** @brief Set the value according to the speciied string For scalar types the textual represenation is typically quite straigtforward. @@ -208,10 +222,10 @@ public : @param _value Textual representation of the new value */ void setValue(const std::string& _value) - { - std::istringstream is(_value); - is >> repValue; - } + { + std::istringstream is(_value); + is >> repValue; + } protected: From aa214e78553d9178ec754e8b22703fb333936b42 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 26 Jan 2011 18:10:34 +0100 Subject: [PATCH 49/57] - removed t-eoDualFitness from test/CMakeLists.txt because it fails Conflicts: eo/test/CMakeLists.txt --- eo/test/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/eo/test/CMakeLists.txt b/eo/test/CMakeLists.txt index 436c4503c..4e68b02ad 100644 --- a/eo/test/CMakeLists.txt +++ b/eo/test/CMakeLists.txt @@ -67,6 +67,8 @@ SET (TEST_LIST t-eoIQRStat t-eoParallel t-openmp + #t-eoDualFitness + t-eoParser ) From 007c29e7361fd50b611d84b05bf637a92c5e1bc1 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:25:22 +0100 Subject: [PATCH 50/57] add the parser/logger to the general header Conflicts: eo/src/eo --- eo/src/eo | 2 -- 1 file changed, 2 deletions(-) diff --git a/eo/src/eo b/eo/src/eo index 14dc831cd..18e91d601 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -203,8 +203,6 @@ #include -//----------------------------------------------------------------------------- - #endif // Local Variables: From ecd8f7ec0336e2e22185796d9eb29b26063bce4b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:29:09 +0100 Subject: [PATCH 51/57] + now you are able to enable or not parallelization with the option --parallelize-loops=1|0 Conflicts: eo/src/apply.h eo/src/utils/eoParser.cpp eo/src/utils/eoParser.h --- eo/src/apply.h | 1 + eo/src/utils/eoParser.cpp | 4 ++++ eo/src/utils/eoParser.h | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index 175ce51d5..bba8adc86 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -27,6 +27,7 @@ #define _apply_h #include +#include #include #include #include diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 23970023d..34726c811 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -98,6 +98,10 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, readFrom(stream); processParam(needHelp); processParam(stopOnUnknownParam); + + //multithreading + processParam(eo::parallelizeLoopParam); + //multithreading ends } diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index adce90173..a96ec1be2 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -92,7 +92,6 @@ private : std::vector ownedParams; }; - /** eoParser: command line parser and configuration file reader This class is persistent, so it can be stored and reloaded to restore From a3dda50b8fc25f6e9dc0ac77ee4aa371e0d8e73a Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:30:40 +0100 Subject: [PATCH 52/57] added measure into apply function Conflicts: eo/src/apply.h --- eo/src/apply.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index bba8adc86..9e112cdc3 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -40,9 +40,8 @@ template void apply(eoUF& _proc, std::vector& _pop) { - size_t size = _pop.size(); - double t1 = omp_get_wtime(); + size_t size = _pop.size(); if (!eo::parallel.isDynamic()) { From 48115ee2f00843dc25c11dbd88fb7fa7841a51a2 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:31:28 +0100 Subject: [PATCH 53/57] * changed apply.h to use new parallelization s parameters Conflicts: eo/src/apply.h --- eo/src/apply.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index 9e112cdc3..bba8adc86 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -40,9 +40,10 @@ template void apply(eoUF& _proc, std::vector& _pop) { - double t1 = omp_get_wtime(); size_t size = _pop.size(); + double t1 = omp_get_wtime(); + if (!eo::parallel.isDynamic()) { #pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size) From 5f67e0e151687a7ab1091a1fe4160aa1118758db Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:35:49 +0100 Subject: [PATCH 54/57] - removed old parallelization parameters from the old-style from eoParser class Conflicts: eo/src/utils/eoParser.h --- eo/src/utils/eoParser.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eo/src/utils/eoParser.cpp b/eo/src/utils/eoParser.cpp index 34726c811..23970023d 100644 --- a/eo/src/utils/eoParser.cpp +++ b/eo/src/utils/eoParser.cpp @@ -98,10 +98,6 @@ eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription, readFrom(stream); processParam(needHelp); processParam(stopOnUnknownParam); - - //multithreading - processParam(eo::parallelizeLoopParam); - //multithreading ends } From 03600594c4275d5cf62f2d2fab7212e79c28e2ca Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Tue, 28 Dec 2010 16:42:53 +0100 Subject: [PATCH 55/57] * updated eoParallel class in order to define the result filename according to the parallelization mode --- eo/src/utils/eoParallel.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index 3ab25e7f5..c590c7ade 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -66,7 +66,35 @@ void eoParallel::_createParameters( eoParser& parser ) std::string section("Parallelization"); parser.processParam( _isEnabled, section ); parser.processParam( _isDynamic, section ); + + std::string default_value( _prefix.defValue() ); + + if ( _isEnabled.value() ) + { + if ( _isDynamic.value() ) + { + default_value += "_dynamic.out"; + } + else + { + default_value += "_parallel.out"; + } + } + else + { + default_value += "_sequential.out"; + } + + _prefix.defValue( default_value ); + + std::cout << "defvalue: " << _prefix.defValue() << std::endl; + parser.processParam( _prefix, section ); + + std::cout << "value: " << parser.getParamWithLongName("parallelize-prefix")->getValue() << std::endl; + + std::cout << "defvalue: " << _prefix.defValue() << std::endl; + } void make_parallel(eoParser& parser) From c8ecdb4beecf740a39352051d5312157acee3c3b Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:39:15 +0100 Subject: [PATCH 56/57] fixed an issue in eoParallel class Conflicts: eo/src/utils/eoParallel.cpp --- eo/src/utils/eoParallel.cpp | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index c590c7ade..3ab25e7f5 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -66,35 +66,7 @@ void eoParallel::_createParameters( eoParser& parser ) std::string section("Parallelization"); parser.processParam( _isEnabled, section ); parser.processParam( _isDynamic, section ); - - std::string default_value( _prefix.defValue() ); - - if ( _isEnabled.value() ) - { - if ( _isDynamic.value() ) - { - default_value += "_dynamic.out"; - } - else - { - default_value += "_parallel.out"; - } - } - else - { - default_value += "_sequential.out"; - } - - _prefix.defValue( default_value ); - - std::cout << "defvalue: " << _prefix.defValue() << std::endl; - parser.processParam( _prefix, section ); - - std::cout << "value: " << parser.getParamWithLongName("parallelize-prefix")->getValue() << std::endl; - - std::cout << "defvalue: " << _prefix.defValue() << std::endl; - } void make_parallel(eoParser& parser) From 3d06d4a42a6dae784e11eaaad07efc3fb3499e3f Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:43:13 +0100 Subject: [PATCH 57/57] + eoParallel: nthreads option * apply.h: mangled the openmp code with pre-processing conditions --- eo/src/apply.h | 12 +++++++++++- eo/src/utils/eoParallel.cpp | 12 +++++++----- eo/src/utils/eoParallel.h | 6 ++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index bba8adc86..63044c385 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -40,6 +40,10 @@ template void apply(eoUF& _proc, std::vector& _pop) { +#ifdef _OPENMP + + omp_set_num_threads(eo::parallel.nthreads()); + size_t size = _pop.size(); double t1 = omp_get_wtime(); @@ -60,7 +64,13 @@ void apply(eoUF& _proc, std::vector& _pop) double t2 = omp_get_wtime(); eoLogger log; - log << eo::file(eo::parallel.prefix()) << t2 - t1 << std::endl; + log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; + +#else // _OPENMP + + for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } + +#endif // !_OPENMP } /** diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index 3ab25e7f5..e267ce7f1 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -21,16 +21,17 @@ Contact: http://eodev.sourceforge.net Authors: - Caner Candan +Caner Candan */ #include "eoParallel.h" -eoParallel::eoParallel() - : _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ), - _isDynamic( false, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\0' ), - _prefix( "results", "parallelize-prefix", "Here's the prefix filename where the results are going to be stored", '\0' ) +eoParallel::eoParallel() : + _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ), + _isDynamic( false, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\0' ), + _prefix( "results", "parallelize-prefix", "Here's the prefix filename where the results are going to be stored", '\0' ), + _nthreads( 0, "parallelize-nthreads", "Define the number of threads you want to use, nthreads = 0 means you want to use all threads available", '\0' ) {} std::string eoParallel::className() const @@ -67,6 +68,7 @@ void eoParallel::_createParameters( eoParser& parser ) parser.processParam( _isEnabled, section ); parser.processParam( _isDynamic, section ); parser.processParam( _prefix, section ); + parser.processParam( _nthreads, section ); } void make_parallel(eoParser& parser) diff --git a/eo/src/utils/eoParallel.h b/eo/src/utils/eoParallel.h index 4e13f8b31..2ce9ea478 100644 --- a/eo/src/utils/eoParallel.h +++ b/eo/src/utils/eoParallel.h @@ -26,7 +26,7 @@ Caner Candan /** @defgroup Parallel Parallel * @ingroup Utilities -@{ + @{ */ #ifndef eoParallel_h @@ -52,6 +52,8 @@ public: std::string prefix() const; + inline unsigned int nthreads() const { return _nthreads.value(); } + friend void make_parallel(eoParser&); private: @@ -65,7 +67,7 @@ private: void make_parallel(eoParser&); -namespace eo +namespace eo { /** * parallel is an external global variable defined in order to use where ever you want the parallel parameters