diff --git a/eo/src/apply.h b/eo/src/apply.h index 024dd896..33b354fc 100644 --- a/eo/src/apply.h +++ b/eo/src/apply.h @@ -44,7 +44,12 @@ void apply(eoUF& _proc, std::vector& _pop) #ifdef _OPENMP - double t1 = omp_get_wtime(); + double t1 = 0; + + if ( eo::parallel.enableResults() ) + { + t1 = omp_get_wtime(); + } if (!eo::parallel.isDynamic()) { @@ -59,10 +64,12 @@ void apply(eoUF& _proc, std::vector& _pop) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } } - double t2 = omp_get_wtime(); - - eoLogger log; - log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; + if ( eo::parallel.enableResults() ) + { + double t2 = omp_get_wtime(); + eoLogger log; + log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; + } #else // _OPENMP diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index fdc047ac..e0ce63aa 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -28,13 +28,30 @@ Caner Candan #include #include "eoParallel.h" +#include "eoLogger.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' ), - _nthreads( 0, "parallelize-nthreads", "Define the number of threads you want to use, nthreads = 0 means you want to use all threads available", '\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' ), + _enableResults( false, "parallelize-enable-results", "Enable the generation of results", '\0' ), + _doMeasure( false, "parallelize-do-measure", "Do some measures during execution", '\0' ), + _t_start(0) +{ +} + +eoParallel::~eoParallel() +{ +#ifdef _OPENMP + if ( doMeasure() ) + { + double _t_end = omp_get_wtime(); + eoLogger log; + log << eo::file("measure_" + prefix()) << _t_end - _t_start << std::endl; + } +#endif // !_OPENMP +} std::string eoParallel::className() const { @@ -71,6 +88,8 @@ void eoParallel::_createParameters( eoParser& parser ) parser.processParam( _isDynamic, section ); parser.processParam( _prefix, section ); parser.processParam( _nthreads, section ); + parser.processParam( _enableResults, section ); + parser.processParam( _doMeasure, section ); } void make_parallel(eoParser& parser) @@ -85,6 +104,11 @@ void make_parallel(eoParser& parser) omp_set_num_threads( eo::parallel.nthreads() ); } } + + if ( eo::parallel.doMeasure() ) + { + eo::parallel._t_start = omp_get_wtime(); + } #endif // !_OPENMP } diff --git a/eo/src/utils/eoParallel.h b/eo/src/utils/eoParallel.h index 79cedfda..3f22f6c4 100644 --- a/eo/src/utils/eoParallel.h +++ b/eo/src/utils/eoParallel.h @@ -44,6 +44,7 @@ class eoParallel : public eoObject { public: eoParallel(); + ~eoParallel(); virtual std::string className() const; @@ -54,6 +55,9 @@ public: inline unsigned int nthreads() const { return _nthreads.value(); } + inline bool enableResults() const { return _enableResults.value(); } + inline bool doMeasure() const { return _doMeasure.value(); } + friend void make_parallel(eoParser&); private: @@ -64,6 +68,9 @@ private: eoValueParam _isDynamic; eoValueParam _prefix; eoValueParam _nthreads; + eoValueParam _enableResults; + eoValueParam _doMeasure; + double _t_start; }; void make_parallel(eoParser&); diff --git a/eo/test/t-openmp.cpp b/eo/test/t-openmp.cpp index 325cb653..cd345080 100644 --- a/eo/test/t-openmp.cpp +++ b/eo/test/t-openmp.cpp @@ -1,3 +1,29 @@ +// -*- 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 + +*/ + //----------------------------------------------------------------------------- // t-openmp.cpp //----------------------------------------------------------------------------- diff --git a/eo/test/t-openmp.py b/eo/test/t-openmp.py index ab43bb93..5cd9e131 100755 --- a/eo/test/t-openmp.py +++ b/eo/test/t-openmp.py @@ -1,5 +1,28 @@ #!/usr/bin/env python +# +# (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 +# + import optparse, logging, sys, os from datetime import datetime