From 3d06d4a42a6dae784e11eaaad07efc3fb3499e3f Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 27 Jan 2011 10:43:13 +0100 Subject: [PATCH] + 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