removed omp_apply.h and added to apply.h, added dynamicity computation

This commit is contained in:
Caner Candan 2010-11-22 17:33:11 +01:00
commit c9843c3cfa
3 changed files with 58 additions and 56 deletions

View file

@ -43,4 +43,35 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
}
}
/**
This is a variant of apply<EOT> which is called in parallel
thanks to OpenMP.
@ingroup Utilities
*/
template <class EOT>
void omp_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{
#pragma omp parallel for default(none) shared(_proc, _pop)
for (unsigned i = 0; i < _pop.size(); ++i)
{
_proc(_pop[i]);
}
}
/**
And now we are using the dynamic scheduling.
@ingroup Utilities
*/
template <class EOT>
void omp_dynamic_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{
#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic)
for (unsigned i = 0; i < _pop.size(); ++i)
{
_proc(_pop[i]);
}
}
#endif

View file

@ -1,51 +0,0 @@
// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
//-----------------------------------------------------------------------------
// eoApply.h
// (c) Maarten Keijzer 2000
/*
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; either
version 2 of the License, or (at your option) any later version.
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: todos@geneura.ugr.es, http://geneura.ugr.es
mak@dhi.dk
*/
//-----------------------------------------------------------------------------
#ifndef _omp_apply_h
#define _omp_apply_h
#include <eoFunctor.h>
#include <vector>
/**
Applies a unary function to a std::vector of things.
This is a variant of apply<EOT> which is called in parallel
thanks to OpenMP.
@ingroup Utilities
*/
template <class EOT>
void omp_apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
{
#pragma omp parallel for default(none) shared(_proc, _pop) schedule(dynamic)
for (unsigned i = 0; i < _pop.size(); ++i)
{
//#pragma omp critical
_proc(_pop[i]);
}
}
#endif

View file

@ -41,6 +41,7 @@ int main(int ac, char** av)
std::string speedupFileName = parser.getORcreateParam(std::string("speedup"), "speedupFileName", "Speedup file name", 0, "Results").value();
std::string efficiencyFileName = parser.getORcreateParam(std::string("efficiency"), "efficiencyFileName", "Efficiency file name", 0, "Results").value();
std::string dynamicityFileName = parser.getORcreateParam(std::string("dynamicity"), "dynamicityFileName", "Dynamicity file name", 0, "Results").value();
uint32_t seedParam = parser.getORcreateParam((uint32_t)0, "seed", "Random number seed", 0).value();
if (seedParam == 0) { seedParam = time(0); }
@ -65,6 +66,7 @@ int main(int ac, char** av)
params << "-p" << popMin << "-P" << popMax << "-d" << dimMin << "-D" << dimMax << "-r" << nRun << "-s" << seedParam;
std::ofstream speedupFile( std::string( speedupFileName + params.str() ).c_str() );
std::ofstream efficiencyFile( std::string( efficiencyFileName + params.str() ).c_str() );
std::ofstream dynamicityFile( std::string( dynamicityFileName + params.str() ).c_str() );
size_t nbtask = 1;
#pragma omp parallel
@ -86,6 +88,7 @@ int main(int ac, char** av)
double Ts;
double Tp;
double Tpd;
// sequential scope
{
@ -105,20 +108,39 @@ int main(int ac, char** av)
Tp = t2 - t1;
}
if ( ( Ts / Tp ) > nbtask ) { continue; }
// parallel scope dynamic
{
eoPop< EOT > pop( p, init );
double t1 = omp_get_wtime();
omp_dynamic_apply< EOT >(eval, pop);
double t2 = omp_get_wtime();
Tpd = t2 - t1;
}
speedupFile << Ts / Tp << ' ';
efficiencyFile << Ts / ( nbtask * Tp ) << ' ';
double speedup = Ts / Tp;
if ( speedup > nbtask ) { continue; }
double efficiency = speedup / nbtask;
double dynamicity = Tp / Tpd;
speedupFile << speedup << ' ';
efficiencyFile << efficiency << ' ';
dynamicityFile << dynamicity << ' ';
eo::log << eo::debug;
eo::log << "Ts = " << Ts << std::endl;
eo::log << "Tp = " << Tp << std::endl;
eo::log << "S_p = " << Ts / Tp << std::endl;
eo::log << "E_p = " << Ts / ( nbtask * Tp ) << std::endl;
eo::log << "Tpd = " << Tpd << std::endl;
eo::log << "S_p = " << speedup << std::endl;
eo::log << "E_p = " << efficiency << std::endl;
eo::log << "D_p = " << dynamicity << std::endl;
} // end of runs
speedupFile << std::endl;
efficiencyFile << std::endl;
dynamicityFile << std::endl;
} // end of dimension