diff --git a/eo/src/apply.h b/eo/src/apply.h index 5c683671..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,9 @@ void apply(eoUF& _proc, std::vector& _pop) for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); } } - double t2 = omp_get_wtime(); - if ( eo::parallel.enableResults() ) { + double t2 = omp_get_wtime(); eoLogger log; log << eo::file(eo::parallel.prefix()) << t2 - t1 << ' '; } diff --git a/eo/src/utils/eoParallel.cpp b/eo/src/utils/eoParallel.cpp index e58585ef..e0ce63aa 100644 --- a/eo/src/utils/eoParallel.cpp +++ b/eo/src/utils/eoParallel.cpp @@ -28,14 +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' ), - _enableResults( false, "parallelize-enable-results", "Enable the generation of results", '\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 { @@ -73,6 +89,7 @@ void eoParallel::_createParameters( eoParser& parser ) parser.processParam( _prefix, section ); parser.processParam( _nthreads, section ); parser.processParam( _enableResults, section ); + parser.processParam( _doMeasure, section ); } void make_parallel(eoParser& parser) @@ -87,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 54b42821..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; @@ -55,6 +56,7 @@ 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&); @@ -67,6 +69,8 @@ private: eoValueParam _prefix; eoValueParam _nthreads; eoValueParam _enableResults; + eoValueParam _doMeasure; + double _t_start; }; void make_parallel(eoParser&);