From 8c23e6b9615942ac464414b788c5f68b7f66e39d Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Mon, 19 Jun 2000 19:12:05 +0000 Subject: [PATCH] r111: initial cvs import --- include/timer.h | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 include/timer.h diff --git a/include/timer.h b/include/timer.h new file mode 100644 index 0000000..781ee94 --- /dev/null +++ b/include/timer.h @@ -0,0 +1,147 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +class Timer +{ + public: + Timer (void) + { m_timeStart = ttime(); } + + virtual ~Timer (void) + {} + + virtual double timerEnd (void) + { + m_timeEnd = ttime(); + m_timeElapsed = m_timeEnd - m_timeStart; + + return (m_timeElapsed); + } + + virtual void timerReport (const char* const msg) const + { + cout << msg << ": " << m_timeElapsed << " seconds" << endl; + } + + virtual double timerEndAndReport (const char* const msg) + { + timerEnd (); + timerReport (msg); + } + + double getTimeElapsed (void) const + { return m_timeElapsed; } + + protected: + double m_timeStart; + double m_timeEnd; + double m_timeElapsed; + + double ttime(void) const + { + struct timeval now; + if (gettimeofday (&now, NULL)) + return 0; + + return (now.tv_sec + static_cast(now.tv_usec) / 1000000.); + } +}; + + +#ifdef HAVE_MPI + +#include "mpi++.h" + +class TimerMPI : public Timer +{ + public: + TimerMPI (MPI::Intracomm& comm) + : m_comm(comm) + { + m_timeStart = MPI::Wtime(); + } + + virtual ~TimerMPI (void) + {} + + virtual double timerEnd (void) + { + 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) + cout << msg << ": " << m_timeElapsed << " seconds" << endl; + } + + virtual double timerEndAndReport (const char* const msg) + { + timerEnd (); + timerReport (msg); + } + + virtual void timerReportAllProcesses (const char* const msg) + { + timerReport (msg); + } + + protected: + MPI::Intracomm& m_comm; +}; + +class TimerCollectiveMPI : public TimerMPI +{ + public: + TimerCollectiveMPI (MPI::Intracomm& comm) + : TimerMPI::TimerMPI (comm) + { + m_comm.Barrier(); + m_timeStart = MPI::Wtime(); + } + + virtual ~TimerCollectiveMPI (void) + {} + + 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); + } + + virtual double timerEndAndReport (const char* const msg) + { + timerEnd (); + timerReport (msg); + } + + virtual void timerReport (const char* const msg) + { + if (m_comm.Get_rank() == 0) + cout << msg << " " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds" << endl; + } + + virtual void timerReportAllProcesses (const char* const msg) + { + cout << msg << ": " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds (Rank " << m_comm.Get_rank() << ")" << endl; + } + + private: + double m_timeMin; + double m_timeMax; +}; +#endif + + + + -- 2.34.1