Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:46:56

0001 // Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>
0002 
0003 // Use, modification and distribution is subject to the Boost Software
0004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 /** @file timer.hpp
0008  *
0009  *  This header provides the @c timer class, which provides access to
0010  *  the MPI timers.
0011  */
0012 #ifndef BOOST_MPI_TIMER_HPP
0013 #define BOOST_MPI_TIMER_HPP
0014 
0015 #include <boost/mpi/config.hpp>
0016 #include <boost/limits.hpp>
0017 
0018 namespace boost { namespace mpi {
0019 
0020 /** @brief A simple timer that provides access to the MPI timing
0021  * facilities.
0022  *
0023  *  The @c timer class is a simple wrapper around the MPI timing
0024  *  facilities that mimics the interface of the Boost Timer library.
0025  */
0026 class BOOST_MPI_DECL timer {
0027 public:
0028   /** Initializes the timer
0029    *
0030    * @post @c elapsed() == 0
0031    */
0032   timer();
0033 
0034   /** Restart the timer.
0035    *
0036    * @post @c elapsed() == 0
0037    */
0038   void restart();
0039 
0040   /** Return the amount of time that has elapsed since the last
0041    *  construction or reset, in seconds.
0042    */
0043   double elapsed() const;
0044 
0045   /** Return an estimate of the maximum possible value of
0046    *  elapsed(). Note that this routine may return too high a value on
0047    *  some systems. 
0048    */
0049   double elapsed_max() const;  
0050 
0051   /** Returns the minimum non-zero value that @c elapsed() may
0052    *  return. This is the resolution of the timer.
0053    */
0054   double elapsed_min() const;
0055 
0056   /** Determines whether the elapsed time values are global times or
0057       local processor times. */
0058   static bool time_is_global();
0059 
0060 private:
0061   double start_time;
0062 }; // timer
0063 
0064 inline timer::timer() 
0065 { 
0066   restart(); 
0067 }
0068 
0069 inline void timer::restart()
0070 {
0071   start_time = MPI_Wtime();
0072 }
0073 
0074 inline double timer::elapsed() const
0075 {
0076   return MPI_Wtime() - start_time;
0077 }
0078 
0079 inline double timer::elapsed_max() const
0080 {
0081   return (std::numeric_limits<double>::max)();
0082 }
0083 
0084 inline double timer::elapsed_min() const
0085 {
0086   return MPI_Wtick();
0087 }
0088 
0089 } } // end namespace boost::mpi
0090 
0091 #endif // BOOST_MPI_TIMER_HPP