]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/include/boost/mpi/timer.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / mpi / include / boost / mpi / timer.hpp
1 // Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>
2
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 /** @file timer.hpp
8 *
9 * This header provides the @c timer class, which provides access to
10 * the MPI timers.
11 */
12 #ifndef BOOST_MPI_TIMER_HPP
13 #define BOOST_MPI_TIMER_HPP
14
15 #include <boost/mpi/config.hpp>
16 #include <boost/limits.hpp>
17
18 namespace boost { namespace mpi {
19
20 /** @brief A simple timer that provides access to the MPI timing
21 * facilities.
22 *
23 * The @c timer class is a simple wrapper around the MPI timing
24 * facilities that mimics the interface of the Boost Timer library.
25 */
26 class BOOST_MPI_DECL timer {
27 public:
28 /** Initializes the timer
29 *
30 * @post @c elapsed() == 0
31 */
32 timer();
33
34 /** Restart the timer.
35 *
36 * @post @c elapsed() == 0
37 */
38 void restart();
39
40 /** Return the amount of time that has elapsed since the last
41 * construction or reset, in seconds.
42 */
43 double elapsed() const;
44
45 /** Return an estimate of the maximum possible value of
46 * elapsed(). Note that this routine may return too high a value on
47 * some systems.
48 */
49 double elapsed_max() const;
50
51 /** Returns the minimum non-zero value that @c elapsed() may
52 * return. This is the resolution of the timer.
53 */
54 double elapsed_min() const;
55
56 /** Determines whether the elapsed time values are global times or
57 local processor times. */
58 static bool time_is_global();
59
60 private:
61 double start_time;
62 }; // timer
63
64 inline timer::timer()
65 {
66 restart();
67 }
68
69 inline void timer::restart()
70 {
71 start_time = MPI_Wtime();
72 }
73
74 inline double timer::elapsed() const
75 {
76 return MPI_Wtime() - start_time;
77 }
78
79 inline double timer::elapsed_max() const
80 {
81 return (std::numeric_limits<double>::max)();
82 }
83
84 inline double timer::elapsed_min() const
85 {
86 return MPI_Wtick();
87 }
88
89 } } // end namespace boost::mpi
90
91 #endif // BOOST_MPI_TIMER_HPP