+ eoParallel: nthreads option * apply.h: mangled the openmp code with pre-processing conditions

This commit is contained in:
Caner Candan 2011-01-27 10:43:13 +01:00
commit 3d06d4a42a
3 changed files with 22 additions and 8 deletions

View file

@ -40,6 +40,10 @@
template <class EOT> template <class EOT>
void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop) void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{ {
#ifdef _OPENMP
omp_set_num_threads(eo::parallel.nthreads());
size_t size = _pop.size(); size_t size = _pop.size();
double t1 = omp_get_wtime(); double t1 = omp_get_wtime();
@ -60,7 +64,13 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
double t2 = omp_get_wtime(); double t2 = omp_get_wtime();
eoLogger log; 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
} }
/** /**

View file

@ -27,10 +27,11 @@ Authors:
#include "eoParallel.h" #include "eoParallel.h"
eoParallel::eoParallel() eoParallel::eoParallel() :
: _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ), _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ),
_isDynamic( false, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\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' ) _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 std::string eoParallel::className() const
@ -67,6 +68,7 @@ void eoParallel::_createParameters( eoParser& parser )
parser.processParam( _isEnabled, section ); parser.processParam( _isEnabled, section );
parser.processParam( _isDynamic, section ); parser.processParam( _isDynamic, section );
parser.processParam( _prefix, section ); parser.processParam( _prefix, section );
parser.processParam( _nthreads, section );
} }
void make_parallel(eoParser& parser) void make_parallel(eoParser& parser)

View file

@ -52,6 +52,8 @@ public:
std::string prefix() const; std::string prefix() const;
inline unsigned int nthreads() const { return _nthreads.value(); }
friend void make_parallel(eoParser&); friend void make_parallel(eoParser&);
private: private: