X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Ftimer.h;h=9e4118eba052e5213788b92c1b279658017c3abb;hp=dd88d7bf4a7d5c4d8b7929ba9dfcfca1bf9b0a9b;hb=f7ee98f7d964ed361068179f0e7ea4475ed1abdf;hpb=9df4442f0783f3aade89d4520a873164141fd012 diff --git a/include/timer.h b/include/timer.h index dd88d7b..9e4118e 100644 --- a/include/timer.h +++ b/include/timer.h @@ -4,7 +4,7 @@ ** Name: timer.h ** Purpose: Header file for Timer class ** Author: Kevin Rosenberg -** Date Started: Sep 2000 +** Date Started: Sep 2000 ** ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg @@ -28,11 +28,6 @@ #ifndef _TIMER_H #define _TIMER_H -// pragma line required for Fedora 4 and wxWin 2.4.2 -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "timer.h" -#endif - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -49,33 +44,33 @@ class Timer { public: Timer (void) - { m_timeStart = ttime(); } + { m_timeStart = ttime(); } virtual ~Timer (void) - {} + {} virtual double timerEnd (void) { - m_timeEnd = ttime(); - m_timeElapsed = m_timeEnd - m_timeStart; - - return (m_timeElapsed); + m_timeEnd = ttime(); + m_timeElapsed = m_timeEnd - m_timeStart; + + return (m_timeElapsed); } virtual void timerReport (const char* const msg) const { - std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; + std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; } virtual double timerEndAndReport (const char* const msg) { - double t = timerEnd (); - timerReport (msg); - return (t); + double t = timerEnd (); + timerReport (msg); + return (t); } double getTimeElapsed (void) const - { return m_timeElapsed; } + { return m_timeElapsed; } protected: double m_timeStart; @@ -83,21 +78,21 @@ class Timer double m_timeElapsed; double ttime(void) const - { + { #ifdef HAVE_GETTIMEOFDAY - struct timeval now; - if (gettimeofday (&now, NULL)) - return 0; - - return (now.tv_sec + static_cast(now.tv_usec) / 1000000.); + struct timeval now; + if (gettimeofday (&now, NULL)) + return 0; + + return (now.tv_sec + static_cast(now.tv_usec) / 1000000.); #elif defined(MSVC) - struct _timeb now; - _ftime (&now); - return (now.time + static_cast(now.millitm) / 1000.); + struct _timeb now; + _ftime (&now); + return (now.time + static_cast(now.millitm) / 1000.); #else - return 0; + return 0; #endif - } + } }; @@ -109,9 +104,9 @@ class TimerMPI : public Timer { public: TimerMPI (MPI::Intracomm& comm) - : m_comm(comm) + : m_comm(comm) { - m_timeStart = MPI::Wtime(); + m_timeStart = MPI::Wtime(); } virtual ~TimerMPI (void) @@ -119,28 +114,28 @@ class TimerMPI : public Timer virtual double timerEnd (void) { - m_timeEnd = MPI::Wtime(); - m_timeElapsed = m_timeEnd - m_timeStart; - - return (m_timeElapsed); + m_timeEnd = MPI::Wtime(); + m_timeElapsed = m_timeEnd - m_timeStart; + + return (m_timeElapsed); } virtual void timerReport (const char* const msg) { - if (m_comm.Get_rank() == 0) - std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; + if (m_comm.Get_rank() == 0) + std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; } virtual double timerEndAndReport (const char* const msg) { - double t = timerEnd (); - timerReport (msg); - return (t); + double t = timerEnd (); + timerReport (msg); + return (t); } virtual void timerReportAllProcesses (const char* const msg) { - timerReport (msg); + timerReport (msg); } protected: @@ -151,10 +146,10 @@ class TimerCollectiveMPI : public TimerMPI { public: TimerCollectiveMPI (MPI::Intracomm& comm) - : TimerMPI::TimerMPI (comm) + : TimerMPI::TimerMPI (comm) { - m_comm.Barrier(); - m_timeStart = MPI::Wtime(); + m_comm.Barrier(); + m_timeStart = MPI::Wtime(); } virtual ~TimerCollectiveMPI (void) @@ -162,30 +157,30 @@ class TimerCollectiveMPI : public TimerMPI virtual double timerEnd (void) { - m_timeEnd = MPI::Wtime(); - m_timeElapsed = m_timeEnd - m_timeStart; - m_comm.Reduce (&m_timeElapsed, &m_timeMin, 1, MPI::DOUBLE, MPI::MIN, 0); - m_comm.Reduce (&m_timeElapsed, &m_timeMax, 1, MPI::DOUBLE, MPI::MAX, 0); - - return (m_timeElapsed); + m_timeEnd = MPI::Wtime(); + m_timeElapsed = m_timeEnd - m_timeStart; + m_comm.Reduce (&m_timeElapsed, &m_timeMin, 1, MPI::DOUBLE, MPI::MIN, 0); + m_comm.Reduce (&m_timeElapsed, &m_timeMax, 1, MPI::DOUBLE, MPI::MAX, 0); + + return (m_timeElapsed); } virtual double timerEndAndReport (const char* const msg) { - double t = timerEnd (); - timerReport (msg); - return (t); + double t = timerEnd (); + timerReport (msg); + return (t); } virtual void timerReport (const char* const msg) { - if (m_comm.Get_rank() == 0) - std::cout << msg << " " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds" << std::endl; + if (m_comm.Get_rank() == 0) + std::cout << msg << " " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds" << std::endl; } virtual void timerReportAllProcesses (const char* const msg) { - std::cout << msg << ": " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds (Rank " << m_comm.Get_rank() << ")" << std::endl; + std::cout << msg << ": " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds (Rank " << m_comm.Get_rank() << ")" << std::endl; } private: