Commit ec641e68 authored by Dave Moxey's avatar Dave Moxey

Merge branch 'feature/tidy-timer' into 'master'

Use <chrono> in Timer

See merge request !807
parents e97a170a 6f1b7215
......@@ -9,6 +9,7 @@ v5.0.0
- Significant overhaul of CMake infrastructure (!770, !804)
- Fix ThridpartyCCM options (!802)
- Fix Windows CRLF tokens in GEO reader and improve comment handling (!805)
- Use chrono in Timer (!807)
**NekMesh**:
- Add feature to read basic 2D geo files as CAD (!731)
......
......@@ -10,7 +10,7 @@
MESSAGE(STATUS "Searching for Boost:")
SET(MIN_VER "1.56.0")
SET(NEEDED_BOOST_LIBS thread iostreams date_time filesystem system
program_options regex timer chrono)
program_options regex)
SET(Boost_DEBUG 0)
SET(Boost_NO_BOOST_CMAKE ON)
IF( BOOST_ROOT )
......
......@@ -347,7 +347,7 @@ OperatorImpMap CollectionOptimisation::SetWithTimings(
Array<OneD, NekDouble> outarray2(maxsize);
Array<OneD, NekDouble> outarray3(maxsize);
Timer t;
LibUtilities::Timer t;
if(verbose)
{
......
......@@ -37,10 +37,9 @@
#include <cstdlib>
#include <iomanip>
#include <boost/timer/timer.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/Communication/Comm.h>
#include <MultiRegions/ExpList3D.h>
#include <Collections/Collection.h>
......@@ -49,11 +48,6 @@
using namespace std;
using namespace Nektar;
using boost::timer::cpu_timer;
using boost::timer::cpu_times;
using boost::timer::nanosecond_type;
using boost::timer::format;
MultiRegions::ExpListSharedPtr SetupExpList(
int N,
LibUtilities::SessionReaderSharedPtr session,
......@@ -71,33 +65,21 @@ MultiRegions::ExpListSharedPtr SetupExpList(
return expList;
}
void printOutput(int N, int Ntest, cpu_timer &timer, bool fmt)
void printOutput(int N, int Ntest, LibUtilities::Timer &timer, bool fmt)
{
cpu_times times = timer.elapsed();
nanosecond_type total = times.user + times.system;
const double sec = 1000000000.0L;
// Normalize timings
double wall_sec = times.wall / sec;
double total_sec = total / sec;
wall_sec /= Ntest;
total_sec /= Ntest;
// Get timings
NekDouble total_sec = timer.TimePerTest(Ntest);
if (fmt)
{
cout << setw(6) << N-1
<< setw(18) << wall_sec
<< setw(18) << total_sec
<< endl;
}
else
{
cout << "P = " << N-1 << ": "
<< wall_sec << " (wall) "
<< total_sec << " (total), "
<< (100.0 * total_sec / wall_sec) << "% CPU"
<< total_sec << " s, "
<< endl;
}
}
......@@ -113,7 +95,7 @@ int main(int argc, char *argv[])
MultiRegions::ExpListSharedPtr expList;
cpu_timer timer;
LibUtilities::Timer timer;
int Ntest, maxOrder;
session->LoadParameter("Ntest", Ntest, 1000);
......@@ -141,12 +123,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> input (expList->GetNcoeffs());
Array<OneD, NekDouble> output(expList->GetNpoints());
timer.start();
timer.Start();
for (int i = 0; i < Ntest; ++i)
{
expList->BwdTrans(input, output);
}
timer.stop();
timer.Stop();
printOutput(N, Ntest, timer, fmt);
}
......@@ -158,12 +140,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> input (expList->GetNpoints());
Array<OneD, NekDouble> output(expList->GetNcoeffs());
timer.start();
timer.Start();
for (int i = 0; i < Ntest; ++i)
{
expList->IProductWRTBase(input, output);
}
timer.stop();
timer.Stop();
printOutput(N, Ntest, timer, fmt);
}
......@@ -181,12 +163,12 @@ int main(int argc, char *argv[])
input[i] = Array<OneD, NekDouble>(expList->GetNpoints());
}
timer.start();
timer.Start();
for (int i = 0; i < Ntest; ++i)
{
expList->IProductWRTDerivBase(input, output);
}
timer.stop();
timer.Stop();
printOutput(N, Ntest, timer, fmt);
}
......@@ -200,12 +182,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> output1(expList->GetNpoints());
Array<OneD, NekDouble> output2(expList->GetNpoints());
timer.start();
timer.Start();
for (int i = 0; i < Ntest; ++i)
{
expList->PhysDeriv(input, output0, output1, output2);
}
timer.stop();
timer.Stop();
printOutput(N, Ntest, timer, fmt);
}
......
......@@ -77,7 +77,7 @@ InputXml::~InputXml()
*/
void InputXml::Process(po::variables_map &vm)
{
Timer timerpart;
LibUtilities::Timer timerpart;
if (m_f->m_verbose)
{
if (m_f->m_comm->TreatAsRankZero())
......
......@@ -45,7 +45,6 @@
#include <vector>
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/Communication/CommSerial.h>
#include <StdRegions/StdNodalTriExp.h>
......
......@@ -67,7 +67,7 @@ void ProcessCreateExp::Process(po::variables_map &vm)
if(m_f->m_graph)
{
int i, j;
Timer timerpart;
LibUtilities::Timer timerpart;
if (m_f->m_verbose)
{
if (m_f->m_comm->TreatAsRankZero())
......
......@@ -43,6 +43,7 @@
#include "ProcessIsoContour.h"
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/Progressbar.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
......@@ -217,7 +218,7 @@ void ProcessIsoContour::Process(po::variables_map &vm)
if(smoothing)
{
Timer timersm;
LibUtilities::Timer timersm;
if(verbose)
{
......
......@@ -37,91 +37,28 @@
namespace Nektar
{
Timer::Timer() :
m_start(),
m_end(),
m_resolution()
{
}
Timer::~Timer()
{
}
void Timer::Start()
{
#ifdef _WIN32
QueryPerformanceCounter(&m_start);
#elif defined(__APPLE__)
gettimeofday(&m_start, 0);
#else
clock_gettime(CLOCK_REALTIME, &m_start);
#endif
}
void Timer::Stop()
{
#ifdef _WIN32
QueryPerformanceCounter(&m_end);
#elif defined(__APPLE__)
gettimeofday(&m_end, 0);
#else
clock_gettime(CLOCK_REALTIME, &m_end);
#endif
}
namespace LibUtilities
{
Timer::CounterType Timer::Elapsed()
{
#ifdef _WIN32
CounterType result;
result.QuadPart = m_end.QuadPart - m_start.QuadPart;
return result;
#elif defined(__APPLE__)
CounterType result = m_end;
if( result.tv_usec < m_start.tv_usec)
{
result.tv_sec -= 1;
result.tv_usec += 1000000;
}
result.tv_sec -= m_start.tv_sec;
result.tv_usec -= m_start.tv_usec;
return result;
#else
CounterType result = m_end;
void Timer::Start()
{
m_start = Clock::now();
}
if( result.tv_nsec < m_start.tv_nsec)
{
result.tv_sec -= 1;
result.tv_nsec += 1000000000;
}
result.tv_sec -= m_start.tv_sec;
result.tv_nsec -= m_start.tv_nsec;
void Timer::Stop()
{
m_end = Clock::now();
}
return result;
#endif
}
Timer::Seconds Timer::Elapsed()
{
return std::chrono::duration_cast<Seconds>(m_end - m_start);
}
NekDouble Timer::TimePerTest(unsigned int n)
{
#ifdef _WIN32
CounterType frequency;
QueryPerformanceFrequency(&frequency);
return Elapsed().QuadPart/static_cast<NekDouble>(n) * 1.0/frequency.QuadPart;
#elif defined(__APPLE__)
CounterType elapsed = Elapsed();
NekDouble result = elapsed.tv_sec/static_cast<NekDouble>(n) +
( elapsed.tv_usec/static_cast<NekDouble>(n) * 1.0e-6);
return result;
#else
CounterType elapsed = Elapsed();
NekDouble result = elapsed.tv_sec/static_cast<NekDouble>(n) +
( elapsed.tv_nsec/static_cast<NekDouble>(n) * 1.0e-9);
return result;
#endif
}
NekDouble Timer::TimePerTest(unsigned int n)
{
return Elapsed().count() / static_cast<NekDouble>(n);
}
}
}
}
......@@ -37,50 +37,44 @@
#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#else
#include <sys/time.h>
#include <time.h>
#endif
#include <chrono>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/BasicConst/NektarUnivConsts.hpp>
namespace Nektar
{
class Timer
{
public:
#ifdef _WIN32
typedef LARGE_INTEGER CounterType;
#elif defined(__APPLE__)
typedef timeval CounterType;
#else
typedef timespec CounterType;
#endif
namespace LibUtilities
{
class Timer
{
public:
using Clock = std::chrono::steady_clock;
using CounterType = Clock::time_point;
using Seconds = std::chrono::duration<NekDouble>;
public:
LIB_UTILITIES_EXPORT Timer();
LIB_UTILITIES_EXPORT ~Timer();
public:
LIB_UTILITIES_EXPORT Timer() = default;
LIB_UTILITIES_EXPORT ~Timer() = default;
LIB_UTILITIES_EXPORT void Start();
LIB_UTILITIES_EXPORT void Stop();
LIB_UTILITIES_EXPORT CounterType Elapsed();
Timer(const Timer& rhs) = delete;
Timer& operator=(const Timer& rhs) = delete;
/// \brief Returns amount of seconds per iteration in
/// a test with n iterations.
LIB_UTILITIES_EXPORT NekDouble TimePerTest(unsigned int n);
LIB_UTILITIES_EXPORT void Start();
LIB_UTILITIES_EXPORT void Stop();
LIB_UTILITIES_EXPORT Seconds Elapsed();
private:
Timer(const Timer& rhs);
Timer& operator=(const Timer& rhs);
/// \brief Returns amount of seconds per iteration in
/// a test with n iterations.
LIB_UTILITIES_EXPORT NekDouble TimePerTest(unsigned int n);
CounterType m_start;
CounterType m_end;
CounterType m_resolution;
};
private:
CounterType m_start;
CounterType m_end;
};
}
}
#endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
......@@ -35,7 +35,6 @@
///////////////////////////////////////////////////////////////////////////////
#include <MultiRegions/GlobalLinSysIterativeStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp>
#include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp>
......
......@@ -35,7 +35,6 @@
///////////////////////////////////////////////////////////////////////////////
#include <MultiRegions/GlobalLinSysStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp>
#include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp>
......
......@@ -36,7 +36,6 @@
#include <LibUtilities/Communication/Xxt.hpp>
#include <LibUtilities/BasicUtils/VDmathArray.hpp>
#include <MultiRegions/GlobalLinSysXxtStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
using namespace std;
......
......@@ -126,7 +126,7 @@ private:
int m_checksteps;
int NumVar_SFD;
Timer timer;
LibUtilities::Timer timer;
NekDouble cpuTime;
NekDouble totalTime;
NekDouble elapsed;
......
......@@ -249,7 +249,7 @@ namespace Nektar
"Only one of IO_CheckTime and IO_CheckSteps "
"should be set!");
Timer timer;
LibUtilities::Timer timer;
bool doCheckTime = false;
int step = m_initialStep;
NekDouble intTime = 0.0;
......
......@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda;
vector<string> vFilenames;
//defining timing variables
Timer timer;
LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime = 0.0;
if(argc < 6)//< allows to parse "verbose" option
......
......@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda;
vector<string> vFilenames;
//defining timing variables
Timer timer;
LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime = 0.0;
if(argc < 6)//< is added to be able to submit "verbose" option
......
......@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda;
vector<string> vFilenames;
//defining timing variables
Timer timer;
LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime;
if(argc < 6)//< allows to parse "verbose" option
......
......@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda;
vector<string> vFilenames;
//defining timing variables
Timer timer;
LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime;
if(argc < 6)//< is used to be able to submit "verbose" option
......
......@@ -455,7 +455,7 @@ namespace Nektar
::AllocateSharedPtr(nsize_p_m1,nsize_p_m1,blkmatStorage);
Timer timer;
LibUtilities::Timer timer;
timer.Start();
for(n = 0; n < nel; ++n)
{
......@@ -1445,7 +1445,7 @@ namespace Nektar
}
case eSteadyNavierStokes:
{
Timer Generaltimer;
LibUtilities::Timer Generaltimer;
Generaltimer.Start();
int Check(0);
......@@ -1562,7 +1562,7 @@ namespace Nektar
void CoupledLinearNS::SolveSteadyNavierStokes(void)
{
Timer Newtontimer;
LibUtilities::Timer Newtontimer;
Newtontimer.Start();
Array<OneD, Array<OneD, NekDouble> > RHS_Coeffs(m_velocity.num_elements());
......
......@@ -489,7 +489,7 @@ namespace Nektar
// Time loop
for(n = 0; n < m_steps; ++n)
{
Timer timer;
LibUtilities::Timer timer;
timer.Start();
fields = m_intScheme->TimeIntegrate(n,m_timestep,m_intSoln,m_ode);
//cout<<"integration: "<<fields[0][fields[0].num_elements()-1]<<endl;
......
......@@ -36,6 +36,7 @@
#include <string>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <FieldUtils/Module.h>
using namespace std;
......@@ -50,7 +51,7 @@ void RunModule(ModuleSharedPtr module, po::variables_map &vm, bool verbose);
int main(int argc, char* argv[])
{
Timer timer;
LibUtilities::Timer timer;
timer.Start();
po::options_description desc("Available options");
......@@ -649,7 +650,7 @@ void PrintExecutionSequence(vector<ModuleSharedPtr> &modules)
void RunModule(ModuleSharedPtr module, po::variables_map &vm, bool verbose)
{
Timer moduleTimer;
LibUtilities::Timer moduleTimer;
if(verbose)
{
moduleTimer.Start();
......
......@@ -299,7 +299,7 @@ void ProcessVarOpti::Process()
Thread::ThreadManagerSharedPtr tm =
tms.CreateInstance(Thread::ThreadMaster::SessionJob, nThreads);
Timer t;
LibUtilities::Timer t;
t.Start();
ofstream resFile;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment