Commit 953a9ecb authored by Dave Moxey's avatar Dave Moxey

Merge remote-tracking branch 'upstream/feature/tidy-timer' into feature/boost-std-cleanup

parents 18d5e6d0 6f1b7215
...@@ -9,6 +9,7 @@ v5.0.0 ...@@ -9,6 +9,7 @@ v5.0.0
- Significant overhaul of CMake infrastructure (!770, !804) - Significant overhaul of CMake infrastructure (!770, !804)
- Fix ThridpartyCCM options (!802) - Fix ThridpartyCCM options (!802)
- Fix Windows CRLF tokens in GEO reader and improve comment handling (!805) - Fix Windows CRLF tokens in GEO reader and improve comment handling (!805)
- Use chrono in Timer (!807)
**NekMesh**: **NekMesh**:
- Add feature to read basic 2D geo files as CAD (!731) - Add feature to read basic 2D geo files as CAD (!731)
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
MESSAGE(STATUS "Searching for Boost:") MESSAGE(STATUS "Searching for Boost:")
SET(MIN_VER "1.56.0") SET(MIN_VER "1.56.0")
SET(NEEDED_BOOST_LIBS thread iostreams date_time filesystem system SET(NEEDED_BOOST_LIBS thread iostreams date_time filesystem system
program_options regex timer chrono) program_options regex)
SET(Boost_DEBUG 0) SET(Boost_DEBUG 0)
SET(Boost_NO_BOOST_CMAKE ON) SET(Boost_NO_BOOST_CMAKE ON)
IF( BOOST_ROOT ) IF( BOOST_ROOT )
......
...@@ -337,7 +337,7 @@ OperatorImpMap CollectionOptimisation::SetWithTimings( ...@@ -337,7 +337,7 @@ OperatorImpMap CollectionOptimisation::SetWithTimings(
Array<OneD, NekDouble> outarray2(maxsize); Array<OneD, NekDouble> outarray2(maxsize);
Array<OneD, NekDouble> outarray3(maxsize); Array<OneD, NekDouble> outarray3(maxsize);
Timer t; LibUtilities::Timer t;
if(verbose) if(verbose)
{ {
......
...@@ -37,10 +37,9 @@ ...@@ -37,10 +37,9 @@
#include <cstdlib> #include <cstdlib>
#include <iomanip> #include <iomanip>
#include <boost/timer/timer.hpp>
#include <LibUtilities/Memory/NekMemoryManager.hpp> #include <LibUtilities/Memory/NekMemoryManager.hpp>
#include <LibUtilities/BasicUtils/SessionReader.h> #include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/Communication/Comm.h> #include <LibUtilities/Communication/Comm.h>
#include <MultiRegions/ExpList3D.h> #include <MultiRegions/ExpList3D.h>
#include <Collections/Collection.h> #include <Collections/Collection.h>
...@@ -49,11 +48,6 @@ ...@@ -49,11 +48,6 @@
using namespace std; using namespace std;
using namespace Nektar; 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( MultiRegions::ExpListSharedPtr SetupExpList(
int N, int N,
LibUtilities::SessionReaderSharedPtr session, LibUtilities::SessionReaderSharedPtr session,
...@@ -71,33 +65,21 @@ MultiRegions::ExpListSharedPtr SetupExpList( ...@@ -71,33 +65,21 @@ MultiRegions::ExpListSharedPtr SetupExpList(
return expList; 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(); // Get timings
nanosecond_type total = times.user + times.system; NekDouble total_sec = timer.TimePerTest(Ntest);
const double sec = 1000000000.0L;
// Normalize timings
double wall_sec = times.wall / sec;
double total_sec = total / sec;
wall_sec /= Ntest;
total_sec /= Ntest;
if (fmt) if (fmt)
{ {
cout << setw(6) << N-1 cout << setw(6) << N-1
<< setw(18) << wall_sec
<< setw(18) << total_sec << setw(18) << total_sec
<< endl; << endl;
} }
else else
{ {
cout << "P = " << N-1 << ": " cout << "P = " << N-1 << ": "
<< wall_sec << " (wall) " << total_sec << " s, "
<< total_sec << " (total), "
<< (100.0 * total_sec / wall_sec) << "% CPU"
<< endl; << endl;
} }
} }
...@@ -113,7 +95,7 @@ int main(int argc, char *argv[]) ...@@ -113,7 +95,7 @@ int main(int argc, char *argv[])
MultiRegions::ExpListSharedPtr expList; MultiRegions::ExpListSharedPtr expList;
cpu_timer timer; LibUtilities::Timer timer;
int Ntest, maxOrder; int Ntest, maxOrder;
session->LoadParameter("Ntest", Ntest, 1000); session->LoadParameter("Ntest", Ntest, 1000);
...@@ -141,12 +123,12 @@ int main(int argc, char *argv[]) ...@@ -141,12 +123,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> input (expList->GetNcoeffs()); Array<OneD, NekDouble> input (expList->GetNcoeffs());
Array<OneD, NekDouble> output(expList->GetNpoints()); Array<OneD, NekDouble> output(expList->GetNpoints());
timer.start(); timer.Start();
for (int i = 0; i < Ntest; ++i) for (int i = 0; i < Ntest; ++i)
{ {
expList->BwdTrans(input, output); expList->BwdTrans(input, output);
} }
timer.stop(); timer.Stop();
printOutput(N, Ntest, timer, fmt); printOutput(N, Ntest, timer, fmt);
} }
...@@ -158,12 +140,12 @@ int main(int argc, char *argv[]) ...@@ -158,12 +140,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> input (expList->GetNpoints()); Array<OneD, NekDouble> input (expList->GetNpoints());
Array<OneD, NekDouble> output(expList->GetNcoeffs()); Array<OneD, NekDouble> output(expList->GetNcoeffs());
timer.start(); timer.Start();
for (int i = 0; i < Ntest; ++i) for (int i = 0; i < Ntest; ++i)
{ {
expList->IProductWRTBase(input, output); expList->IProductWRTBase(input, output);
} }
timer.stop(); timer.Stop();
printOutput(N, Ntest, timer, fmt); printOutput(N, Ntest, timer, fmt);
} }
...@@ -181,12 +163,12 @@ int main(int argc, char *argv[]) ...@@ -181,12 +163,12 @@ int main(int argc, char *argv[])
input[i] = Array<OneD, NekDouble>(expList->GetNpoints()); input[i] = Array<OneD, NekDouble>(expList->GetNpoints());
} }
timer.start(); timer.Start();
for (int i = 0; i < Ntest; ++i) for (int i = 0; i < Ntest; ++i)
{ {
expList->IProductWRTDerivBase(input, output); expList->IProductWRTDerivBase(input, output);
} }
timer.stop(); timer.Stop();
printOutput(N, Ntest, timer, fmt); printOutput(N, Ntest, timer, fmt);
} }
...@@ -200,12 +182,12 @@ int main(int argc, char *argv[]) ...@@ -200,12 +182,12 @@ int main(int argc, char *argv[])
Array<OneD, NekDouble> output1(expList->GetNpoints()); Array<OneD, NekDouble> output1(expList->GetNpoints());
Array<OneD, NekDouble> output2(expList->GetNpoints()); Array<OneD, NekDouble> output2(expList->GetNpoints());
timer.start(); timer.Start();
for (int i = 0; i < Ntest; ++i) for (int i = 0; i < Ntest; ++i)
{ {
expList->PhysDeriv(input, output0, output1, output2); expList->PhysDeriv(input, output0, output1, output2);
} }
timer.stop(); timer.Stop();
printOutput(N, Ntest, timer, fmt); printOutput(N, Ntest, timer, fmt);
} }
......
...@@ -77,7 +77,7 @@ InputXml::~InputXml() ...@@ -77,7 +77,7 @@ InputXml::~InputXml()
*/ */
void InputXml::Process(po::variables_map &vm) void InputXml::Process(po::variables_map &vm)
{ {
Timer timerpart; LibUtilities::Timer timerpart;
if (m_f->m_verbose) if (m_f->m_verbose)
{ {
if (m_f->m_comm->TreatAsRankZero()) if (m_f->m_comm->TreatAsRankZero())
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include <vector> #include <vector>
#include <LibUtilities/BasicUtils/NekFactory.hpp> #include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/Communication/CommSerial.h> #include <LibUtilities/Communication/CommSerial.h>
#include <StdRegions/StdNodalTriExp.h> #include <StdRegions/StdNodalTriExp.h>
......
...@@ -67,7 +67,7 @@ void ProcessCreateExp::Process(po::variables_map &vm) ...@@ -67,7 +67,7 @@ void ProcessCreateExp::Process(po::variables_map &vm)
if(m_f->m_graph) if(m_f->m_graph)
{ {
int i, j; int i, j;
Timer timerpart; LibUtilities::Timer timerpart;
if (m_f->m_verbose) if (m_f->m_verbose)
{ {
if (m_f->m_comm->TreatAsRankZero()) if (m_f->m_comm->TreatAsRankZero())
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include "ProcessIsoContour.h" #include "ProcessIsoContour.h"
#include <LibUtilities/BasicUtils/SharedArray.hpp> #include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ParseUtils.hpp> #include <LibUtilities/BasicUtils/ParseUtils.hpp>
#include <LibUtilities/BasicUtils/Progressbar.hpp> #include <LibUtilities/BasicUtils/Progressbar.hpp>
#include <boost/math/special_functions/fpclassify.hpp> #include <boost/math/special_functions/fpclassify.hpp>
...@@ -217,7 +218,7 @@ void ProcessIsoContour::Process(po::variables_map &vm) ...@@ -217,7 +218,7 @@ void ProcessIsoContour::Process(po::variables_map &vm)
if(smoothing) if(smoothing)
{ {
Timer timersm; LibUtilities::Timer timersm;
if(verbose) if(verbose)
{ {
......
...@@ -37,91 +37,28 @@ ...@@ -37,91 +37,28 @@
namespace Nektar namespace Nektar
{ {
Timer::Timer() : namespace LibUtilities
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
}
Timer::CounterType Timer::Elapsed() void Timer::Start()
{ {
#ifdef _WIN32 m_start = Clock::now();
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;
if( result.tv_nsec < m_start.tv_nsec) void Timer::Stop()
{ {
result.tv_sec -= 1; m_end = Clock::now();
result.tv_nsec += 1000000000; }
}
result.tv_sec -= m_start.tv_sec;
result.tv_nsec -= m_start.tv_nsec;
return result; Timer::Seconds Timer::Elapsed()
#endif {
} return std::chrono::duration_cast<Seconds>(m_end - m_start);
}
NekDouble Timer::TimePerTest(unsigned int n) NekDouble Timer::TimePerTest(unsigned int n)
{ {
#ifdef _WIN32 return Elapsed().count() / static_cast<NekDouble>(n);
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
}
} }
}
...@@ -37,50 +37,44 @@ ...@@ -37,50 +37,44 @@
#ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
#define NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
#ifdef _WIN32 #include <chrono>
#define NOMINMAX
#include <windows.h>
#else
#include <sys/time.h>
#include <time.h>
#endif
#include <LibUtilities/LibUtilitiesDeclspec.h> #include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/BasicConst/NektarUnivConsts.hpp> #include <LibUtilities/BasicConst/NektarUnivConsts.hpp>
namespace Nektar namespace Nektar
{ {
class Timer namespace LibUtilities
{ {
public:
#ifdef _WIN32 class Timer
typedef LARGE_INTEGER CounterType; {
#elif defined(__APPLE__) public:
typedef timeval CounterType; using Clock = std::chrono::steady_clock;
#else using CounterType = Clock::time_point;
typedef timespec CounterType; using Seconds = std::chrono::duration<NekDouble>;
#endif
public: public:
LIB_UTILITIES_EXPORT Timer(); LIB_UTILITIES_EXPORT Timer() = default;
LIB_UTILITIES_EXPORT ~Timer(); LIB_UTILITIES_EXPORT ~Timer() = default;
LIB_UTILITIES_EXPORT void Start(); Timer(const Timer& rhs) = delete;
LIB_UTILITIES_EXPORT void Stop(); Timer& operator=(const Timer& rhs) = delete;
LIB_UTILITIES_EXPORT CounterType Elapsed();
/// \brief Returns amount of seconds per iteration in LIB_UTILITIES_EXPORT void Start();
/// a test with n iterations. LIB_UTILITIES_EXPORT void Stop();
LIB_UTILITIES_EXPORT NekDouble TimePerTest(unsigned int n); LIB_UTILITIES_EXPORT Seconds Elapsed();
private: /// \brief Returns amount of seconds per iteration in
Timer(const Timer& rhs); /// a test with n iterations.
Timer& operator=(const Timer& rhs); LIB_UTILITIES_EXPORT NekDouble TimePerTest(unsigned int n);
CounterType m_start; private:
CounterType m_end; CounterType m_start;
CounterType m_resolution; CounterType m_end;
}; };
}
} }
#endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H #endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_TIMER_H
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <MultiRegions/GlobalLinSysIterativeStaticCond.h> #include <MultiRegions/GlobalLinSysIterativeStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp> #include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp> #include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp>
#include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp> #include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp>
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include <MultiRegions/GlobalLinSysStaticCond.h> #include <MultiRegions/GlobalLinSysStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp> #include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp> #include <LibUtilities/LinearAlgebra/StorageSmvBsr.hpp>
#include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp> #include <LibUtilities/LinearAlgebra/SparseDiagBlkMatrix.hpp>
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include <LibUtilities/Communication/Xxt.hpp> #include <LibUtilities/Communication/Xxt.hpp>
#include <LibUtilities/BasicUtils/VDmathArray.hpp> #include <LibUtilities/BasicUtils/VDmathArray.hpp>
#include <MultiRegions/GlobalLinSysXxtStaticCond.h> #include <MultiRegions/GlobalLinSysXxtStaticCond.h>
#include <LibUtilities/BasicUtils/Timer.h>
using namespace std; using namespace std;
......
...@@ -126,7 +126,7 @@ private: ...@@ -126,7 +126,7 @@ private:
int m_checksteps; int m_checksteps;
int NumVar_SFD; int NumVar_SFD;
Timer timer; LibUtilities::Timer timer;
NekDouble cpuTime; NekDouble cpuTime;
NekDouble totalTime; NekDouble totalTime;
NekDouble elapsed; NekDouble elapsed;
......
...@@ -245,7 +245,7 @@ namespace Nektar ...@@ -245,7 +245,7 @@ namespace Nektar
"Only one of IO_CheckTime and IO_CheckSteps " "Only one of IO_CheckTime and IO_CheckSteps "
"should be set!"); "should be set!");
Timer timer; LibUtilities::Timer timer;
bool doCheckTime = false; bool doCheckTime = false;
int step = m_initialStep; int step = m_initialStep;
NekDouble intTime = 0.0; NekDouble intTime = 0.0;
......
...@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) ...@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda; NekDouble lambda;
vector<string> vFilenames; vector<string> vFilenames;
//defining timing variables //defining timing variables
Timer timer; LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime = 0.0; NekDouble exeTime, fullTime, ppTime = 0.0;
if(argc < 6)//< allows to parse "verbose" option if(argc < 6)//< allows to parse "verbose" option
......
...@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) ...@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda; NekDouble lambda;
vector<string> vFilenames; vector<string> vFilenames;
//defining timing variables //defining timing variables
Timer timer; LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime = 0.0; NekDouble exeTime, fullTime, ppTime = 0.0;
if(argc < 6)//< is added to be able to submit "verbose" option if(argc < 6)//< is added to be able to submit "verbose" option
......
...@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) ...@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda; NekDouble lambda;
vector<string> vFilenames; vector<string> vFilenames;
//defining timing variables //defining timing variables
Timer timer; LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime; NekDouble exeTime, fullTime, ppTime;
if(argc < 6)//< allows to parse "verbose" option if(argc < 6)//< allows to parse "verbose" option
......
...@@ -20,7 +20,7 @@ int main(int argc, char *argv[]) ...@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
NekDouble lambda; NekDouble lambda;
vector<string> vFilenames; vector<string> vFilenames;
//defining timing variables //defining timing variables
Timer timer; LibUtilities::Timer timer;
NekDouble exeTime, fullTime, ppTime; NekDouble exeTime, fullTime, ppTime;