Merge branch 'openmp'
This commit is contained in:
commit
5ab24a3dd6
18 changed files with 827 additions and 15 deletions
|
|
@ -27,7 +27,8 @@ SET (EOUTILS_SOURCES eoData.cpp
|
|||
make_help.cpp
|
||||
pipecom.cpp
|
||||
eoLogger.cpp
|
||||
eoParserLogger.cpp)
|
||||
eoParserLogger.cpp
|
||||
eoParallel.cpp)
|
||||
|
||||
|
||||
ADD_LIBRARY(eoutils STATIC ${EOUTILS_SOURCES})
|
||||
|
|
|
|||
115
eo/src/utils/eoParallel.cpp
Normal file
115
eo/src/utils/eoParallel.cpp
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
// -*- 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 <caner.candan@thalesgroup.com>
|
||||
|
||||
*/
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
#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' ),
|
||||
_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
|
||||
{
|
||||
return "eoParallel";
|
||||
}
|
||||
|
||||
std::string eoParallel::prefix() const
|
||||
{
|
||||
std::string value( _prefix.value() );
|
||||
|
||||
if ( _isEnabled.value() )
|
||||
{
|
||||
if ( _isDynamic.value() )
|
||||
{
|
||||
value += "_dynamic.out";
|
||||
}
|
||||
else
|
||||
{
|
||||
value += "_parallel.out";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
value += "_sequential.out";
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void eoParallel::_createParameters( eoParser& parser )
|
||||
{
|
||||
std::string section("Parallelization");
|
||||
parser.processParam( _isEnabled, section );
|
||||
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)
|
||||
{
|
||||
eo::parallel._createParameters( parser );
|
||||
|
||||
#ifdef _OPENMP
|
||||
if ( eo::parallel.isEnabled() )
|
||||
{
|
||||
if ( eo::parallel.nthreads() > 0 )
|
||||
{
|
||||
omp_set_num_threads( eo::parallel.nthreads() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( eo::parallel.doMeasure() )
|
||||
{
|
||||
eo::parallel._t_start = omp_get_wtime();
|
||||
}
|
||||
#endif // !_OPENMP
|
||||
}
|
||||
|
||||
eoParallel eo::parallel;
|
||||
88
eo/src/utils/eoParallel.h
Normal file
88
eo/src/utils/eoParallel.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
// -*- 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 <caner.candan@thalesgroup.com>
|
||||
|
||||
*/
|
||||
|
||||
/** @defgroup Parallel Parallel
|
||||
* @ingroup Utilities
|
||||
@{
|
||||
*/
|
||||
|
||||
#ifndef eoParallel_h
|
||||
#define eoParallel_h
|
||||
|
||||
#include "eoObject.h"
|
||||
#include "eoParser.h"
|
||||
|
||||
/**
|
||||
* eoParallel
|
||||
* Class providing parameters for parallelization
|
||||
* Use of a global variable eo::parallel to easily use the parallelization parameters anywhere
|
||||
*/
|
||||
class eoParallel : public eoObject
|
||||
{
|
||||
public:
|
||||
eoParallel();
|
||||
~eoParallel();
|
||||
|
||||
virtual std::string className() const;
|
||||
|
||||
inline bool isEnabled() const { return _isEnabled.value(); }
|
||||
inline bool isDynamic() const { return _isDynamic.value(); }
|
||||
|
||||
std::string prefix() const;
|
||||
|
||||
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:
|
||||
void _createParameters( eoParser& );
|
||||
|
||||
private:
|
||||
eoValueParam<bool> _isEnabled;
|
||||
eoValueParam<bool> _isDynamic;
|
||||
eoValueParam<std::string> _prefix;
|
||||
eoValueParam<unsigned int> _nthreads;
|
||||
eoValueParam<bool> _enableResults;
|
||||
eoValueParam<bool> _doMeasure;
|
||||
double _t_start;
|
||||
};
|
||||
|
||||
void make_parallel(eoParser&);
|
||||
|
||||
namespace eo
|
||||
{
|
||||
/**
|
||||
* parallel is an external global variable defined in order to use where ever you want the parallel parameters
|
||||
*/
|
||||
extern eoParallel parallel;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif // !eoParallel_h
|
||||
|
|
@ -61,7 +61,6 @@ eoParameterLoader::~eoParameterLoader()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
eoParser::eoParser ( unsigned _argc, char **_argv , string _programDescription,
|
||||
string _lFileParamName, char _shortHand) :
|
||||
programName(_argv[0]),
|
||||
|
|
|
|||
|
|
@ -92,8 +92,6 @@ private :
|
|||
std::vector<eoParam*> ownedParams;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
eoParser: command line parser and configuration file reader
|
||||
This class is persistent, so it can be stored and reloaded to restore
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue