X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=include%2Ftimer.h;h=226d258c85ca181fcaf1abe478be1efdb796de02;hb=d16eb37cbc73f67fc29a60645e0b1ac7fe32767e;hp=781ee941c9fdec87e207a8f945a97d4d2ddbef1c;hpb=8c23e6b9615942ac464414b788c5f68b7f66e39d;p=ctsim.git diff --git a/include/timer.h b/include/timer.h index 781ee94..226d258 100644 --- a/include/timer.h +++ b/include/timer.h @@ -1,8 +1,45 @@ +/***************************************************************************** +** FILE IDENTIFICATION +** +** Name: timer.h +** Purpose: Header file for Timer class +** Author: Kevin Rosenberg +** Date Started: Sep 2000 +** +** This is part of the CTSim program +** Copyright (c) 1983-2001 Kevin Rosenberg +** +** $Id: timer.h,v 1.7 2001/02/22 11:05:38 kevin Exp $ +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License (version 2) as +** published by the Free Software Foundation. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +#ifndef _TIMER_H +#define _TIMER_H + + #ifdef HAVE_CONFIG_H #include "config.h" #endif +#ifdef HAVE_SYS_TIME_H #include +#endif + +#ifdef MSVC +#include +#endif class Timer { @@ -23,13 +60,14 @@ class Timer virtual void timerReport (const char* const msg) const { - cout << msg << ": " << m_timeElapsed << " seconds" << endl; + std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; } virtual double timerEndAndReport (const char* const msg) { - timerEnd (); + double t = timerEnd (); timerReport (msg); + return (t); } double getTimeElapsed (void) const @@ -42,11 +80,19 @@ class Timer 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.); +#elif defined(MSVC) + struct _timeb now; + _ftime (&now); + return (now.time + static_cast(now.millitm) / 1000.); +#else + return 0; +#endif } }; @@ -78,13 +124,14 @@ class TimerMPI : public Timer virtual void timerReport (const char* const msg) { if (m_comm.Get_rank() == 0) - cout << msg << ": " << m_timeElapsed << " seconds" << endl; + std::cout << msg << ": " << m_timeElapsed << " seconds" << std::endl; } virtual double timerEndAndReport (const char* const msg) { - timerEnd (); + double t = timerEnd (); timerReport (msg); + return (t); } virtual void timerReportAllProcesses (const char* const msg) @@ -121,19 +168,20 @@ class TimerCollectiveMPI : public TimerMPI virtual double timerEndAndReport (const char* const msg) { - timerEnd (); + double t = timerEnd (); timerReport (msg); + return (t); } virtual void timerReport (const char* const msg) { if (m_comm.Get_rank() == 0) - cout << msg << " " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds" << endl; + std::cout << msg << " " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds" << std::endl; } virtual void timerReportAllProcesses (const char* const msg) { - cout << msg << ": " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds (Rank " << m_comm.Get_rank() << ")" << endl; + std::cout << msg << ": " << "Minimum=" << m_timeMin << ", Maximum=" << m_timeMax << " seconds (Rank " << m_comm.Get_rank() << ")" << std::endl; } private: @@ -143,5 +191,6 @@ class TimerCollectiveMPI : public TimerMPI #endif +#endif // _TIMER_H