From 54e2a8b91e4cad695d5090101de48d97615f7594 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Fri, 28 Jan 2011 14:38:50 +0100 Subject: [PATCH 1/2] * apply.h: size variable missing without openmp --- eo/CMakeLists.txt | 2 +- eo/src/apply.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eo/CMakeLists.txt b/eo/CMakeLists.txt index 548f1b54..3a5fe04b 100644 --- a/eo/CMakeLists.txt +++ b/eo/CMakeLists.txt @@ -106,7 +106,7 @@ ENDIF (ENABLE_CMAKE_TESTING) ### 5) Where must cmake go now ? ###################################################################################### -ADD_SUBDIRECTORY(app) +#ADD_SUBDIRECTORY(app) ADD_SUBDIRECTORY(doc) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(test) diff --git a/eo/src/apply.h b/eo/src/apply.h index 63044c38..ba6d2f9a 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -40,12 +40,12 @@ template void apply(eoUF& _proc, std::vector& _pop) { + size_t size = _pop.size(); + #ifdef _OPENMP omp_set_num_threads(eo::parallel.nthreads()); - size_t size = _pop.size(); - double t1 = omp_get_wtime(); if (!eo::parallel.isDynamic()) From 2044d92eff240d90e7b86eff662bfda5319f48d9 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Wed, 2 Feb 2011 23:50:58 +0100 Subject: [PATCH 2/2] * eoParallel: added the call to omp_set_num_threads to define the number of threads with parameters --- eo/src/apply.h | 2 -- eo/src/utils/eoParallel.cpp | 12 ++++++++++++ eo/test/t-eoParallel.cpp | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/eo/src/apply.h b/eo/src/apply.h index ba6d2f9a..024dd896 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -44,8 +44,6 @@ void apply(eoUF& _proc, std::vector& _pop) #ifdef _OPENMP - omp_set_num_threads(eo::parallel.nthreads()); - double t1 = omp_get_wtime(); if (!eo::parallel.isDynamic()) diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index e267ce7f..fdc047ac 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -25,6 +25,8 @@ Caner Candan */ +#include + #include "eoParallel.h" eoParallel::eoParallel() : @@ -74,6 +76,16 @@ void eoParallel::_createParameters( eoParser& parser ) void make_parallel(eoParser& parser) { eo::parallel._createParameters( parser ); + +#ifdef _OPENMP + if ( eo::parallel.isEnabled() ) + { + if ( eo::parallel.nthreads() > 0 ) + { + omp_set_num_threads( eo::parallel.nthreads() ); + } + } +#endif // !_OPENMP } eoParallel eo::parallel; diff --git a/eo/test/t-eoParallel.cpp b/eo/test/t-eoParallel.cpp index 055f4598..72d4f264 100644 --- a/eo/test/t-eoParallel.cpp +++ b/eo/test/t-eoParallel.cpp @@ -2,6 +2,8 @@ // t-eoParallel.cpp //----------------------------------------------------------------------------- +#include + #include #include //#include @@ -40,6 +42,14 @@ int main(int ac, char** av) eo::log << eo::quiet << "DONE!" << std::endl; +#pragma omp parallel + { + if ( 0 == omp_get_thread_num() ) + { + eo::log << "num of threads: " << omp_get_num_threads() << std::endl; + } + } + return 0; }