Chris@16: // Copyright (C) 2006 Douglas Gregor Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: /** @file timer.hpp Chris@16: * Chris@16: * This header provides the @c timer class, which provides access to Chris@16: * the MPI timers. Chris@16: */ Chris@16: #ifndef BOOST_MPI_TIMER_HPP Chris@16: #define BOOST_MPI_TIMER_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace mpi { Chris@16: Chris@16: /** @brief A simple timer that provides access to the MPI timing Chris@16: * facilities. Chris@16: * Chris@16: * The @c timer class is a simple wrapper around the MPI timing Chris@16: * facilities that mimics the interface of the Boost Timer library. Chris@16: */ Chris@16: class BOOST_MPI_DECL timer { Chris@16: public: Chris@16: /** Initializes the timer Chris@16: * Chris@16: * @post @c elapsed() == 0 Chris@16: */ Chris@16: timer(); Chris@16: Chris@16: /** Restart the timer. Chris@16: * Chris@16: * @post @c elapsed() == 0 Chris@16: */ Chris@16: void restart(); Chris@16: Chris@16: /** Return the amount of time that has elapsed since the last Chris@16: * construction or reset, in seconds. Chris@16: */ Chris@16: double elapsed() const; Chris@16: Chris@16: /** Return an estimate of the maximum possible value of Chris@16: * elapsed(). Note that this routine may return too high a value on Chris@16: * some systems. Chris@16: */ Chris@16: double elapsed_max() const; Chris@16: Chris@16: /** Returns the minimum non-zero value that @c elapsed() may Chris@16: * return. This is the resolution of the timer. Chris@16: */ Chris@16: double elapsed_min() const; Chris@16: Chris@16: /** Determines whether the elapsed time values are global times or Chris@16: local processor times. */ Chris@16: static bool time_is_global(); Chris@16: Chris@16: private: Chris@16: double start_time; Chris@16: }; // timer Chris@16: Chris@16: inline timer::timer() Chris@16: { Chris@16: restart(); Chris@16: } Chris@16: Chris@16: inline void timer::restart() Chris@16: { Chris@16: start_time = MPI_Wtime(); Chris@16: } Chris@16: Chris@16: inline double timer::elapsed() const Chris@16: { Chris@16: return MPI_Wtime() - start_time; Chris@16: } Chris@16: Chris@16: inline double timer::elapsed_max() const Chris@16: { Chris@16: return (std::numeric_limits::max)(); Chris@16: } Chris@16: Chris@16: inline double timer::elapsed_min() const Chris@16: { Chris@16: return MPI_Wtick(); Chris@16: } Chris@16: Chris@16: } } // end namespace boost::mpi Chris@16: Chris@16: #endif // BOOST_MPI_TIMER_HPP