ALPSCore reference
stop_callback.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #ifndef ALPS_CALLBACK_HPP
8 #define ALPS_CALLBACK_HPP
9 
10 #include <alps/config.hpp>
12 
14 
15 #ifdef ALPS_HAVE_MPI
16 #include <boost/optional.hpp>
17 # include "alps/utilities/mpi.hpp"
18 #endif
19 
20 namespace alps {
22 
25  class stop_callback {
26  private:
27  typedef detail::posix_wall_clock clock_type;
28  typedef clock_type::time_duration_type time_duration_type;
29  typedef clock_type::time_point_type time_point_type;
30 
31  public:
33 
34  stop_callback(std::size_t timelimit);
35 #ifdef ALPS_HAVE_MPI
36 
40  stop_callback(alps::mpi::communicator const & cm, std::size_t timelimit);
41 #endif
42  bool operator()() const;
44  private:
45  const time_duration_type limit;
46  alps::signal signals;
47  const time_point_type start;
48 #ifdef ALPS_HAVE_MPI
49  boost::optional<alps::mpi::communicator> comm;
50 #endif
51  };
52 
54 
58  private:
59  typedef detail::posix_wall_clock clock_type;
60  typedef clock_type::time_duration_type time_duration_type;
61  typedef clock_type::time_point_type time_point_type;
62 
63  public:
65 
66  simple_time_callback(std::size_t timelimit);
67 
69  bool operator()() const;
70  private:
71  const time_duration_type limit;
72  const time_point_type start;
73  };
74 }
75 
76 #endif
bool operator()() const
Returns true if it&#39;s time to stop (time is up or signal is received)
Header for object-oriented interface to MPI (similar to boost::mpi)
Encapsulation of an MPI communicator and some communicator-related operations.
Definition: mpi.hpp:111
stop_callback(std::size_t timelimit)
Initializes the functor with the desired time duration.
Functor-predicate: is it time to stop?
Functor-predicate: is it time to stop?