EvolvingObjects
eoParallel.cpp
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 /*
00004 
00005 (c) Thales group, 2010
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation;
00010     version 2 of the license.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 Contact: http://eodev.sourceforge.net
00022 
00023 Authors:
00024     Caner Candan <caner.candan@thalesgroup.com>
00025 
00026 */
00027 
00028 #ifdef _OPENMP
00029 #include <omp.h>
00030 #endif
00031 
00032 #include "eoParallel.h"
00033 #include "eoLogger.h"
00034 
00035 eoParallel::eoParallel() :
00036     _isEnabled( false, "parallelize-loop", "Enable memory shared parallelization into evaluation's loops", '\0' ),
00037     _isDynamic( true, "parallelize-dynamic", "Enable dynamic memory shared parallelization", '\0' ),
00038     _prefix( "results", "parallelize-prefix", "Here's the prefix filename where the results are going to be stored", '\0' ),
00039     _nthreads( 0, "parallelize-nthreads", "Define the number of threads you want to use, nthreads = 0 means you want to use all threads available", '\0' ),
00040     _enableResults( false, "parallelize-enable-results", "Enable the generation of results", '\0' ),
00041     _doMeasure( false, "parallelize-do-measure", "Do some measures during execution", '\0' ),
00042     _packetSize( 1U, "parallelize-packet-size", "Number of elements which should be sent in a single message during a parallel evaluation based on message passing.", '\0'),
00043     _t_start(0)
00044 {
00045 }
00046 
00047 eoParallel::~eoParallel()
00048 {
00049 #ifdef _OPENMP
00050     if ( doMeasure() )
00051         {
00052             double _t_end = omp_get_wtime();
00053             eoLogger log;
00054             log << eo::file("measure_" + prefix()) << _t_end - _t_start << std::endl;
00055         }
00056 #endif // !_OPENMP
00057 }
00058 
00059 std::string eoParallel::className() const
00060 {
00061     return "eoParallel";
00062 }
00063 
00064 std::string eoParallel::prefix() const
00065 {
00066     std::string value( _prefix.value() );
00067 
00068     if ( _isEnabled.value() )
00069         {
00070             if ( _isDynamic.value() )
00071                 {
00072                     value += "_dynamic.out";
00073                 }
00074             else
00075                 {
00076                     value += "_parallel.out";
00077                 }
00078         }
00079     else
00080         {
00081             value += "_sequential.out";
00082         }
00083 
00084     return value;
00085 }
00086 
00087 void eoParallel::_createParameters( eoParser& parser )
00088 {
00089     std::string section("Parallelization");
00090     parser.processParam( _isEnabled, section );
00091     parser.processParam( _isDynamic, section );
00092     parser.processParam( _prefix, section );
00093     parser.processParam( _nthreads, section );
00094     parser.processParam( _enableResults, section );
00095     parser.processParam( _doMeasure, section );
00096     parser.processParam( _packetSize, section );
00097 }
00098 
00099 void make_parallel(eoParser& parser)
00100 {
00101     eo::parallel._createParameters( parser );
00102 
00103 #ifdef _OPENMP
00104     if ( eo::parallel.isEnabled() )
00105         {
00106             if ( eo::parallel.nthreads() > 0 )
00107                 {
00108                     omp_set_num_threads( eo::parallel.nthreads() );
00109                 }
00110         }
00111 
00112     if ( eo::parallel.doMeasure() )
00113         {
00114             eo::parallel._t_start = omp_get_wtime();
00115         }
00116 #endif // !_OPENMP
00117 }
00118 
00119 eoParallel eo::parallel;
 All Classes Namespaces Files Functions Variables Typedefs Friends