Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MPI_WorkUnitManager.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/wum/MPI_WorkUnitManager.hh
11 /// @brief
12 /// @author Mike Tyka
13 
14 #ifndef INCLUDED_protocols_wum_MPI_WorkUnitManager_hh
15 #define INCLUDED_protocols_wum_MPI_WorkUnitManager_hh
16 
17 
18 #ifdef USEMPI
19 #include <mpi.h> //keep this first
20 #else
21 #define MPI_ANY_SOURCE 0
22 #endif
23 
27 #include <core/pose/Pose.fwd.hh>
28 #include <core/types.hh>
29 
30 #include <string>
31 #include <vector>
32 
33 #include <utility/vector1.hh>
34 
35 
36 
37 namespace protocols {
38 namespace wum {
39 
40 
41 /// @brief Helper function - returns rank of the current node.
42 int mpi_rank();
43 
44 /// @brief Helper function - returns total number of nodes
45 int mpi_npes();
46 
47 /// @brief Get a time in seconds. If MPI is enabled you'll get an accuracy of microsecs
49 
50 
52  public:
54  char machine_letter
55  );
56 
58 
59  // @brief Main start function. This gets overloaded of course
60  virtual void go() = 0;
61 
62  protected: // Emperor specific fucntions
63 
64  virtual void init() = 0;
65 
66  virtual void process_inbound_wus()=0;
67 
68  virtual void process_outbound_wus()=0;
69 
70  protected:
71 
72  /// @brief Print a line with general run statistics, now
73  virtual void print_stats();
74 
75  /// @brief Print a line with general run statistics, only if enough time has pased since the last statistics printout
76  virtual void print_stats_auto();
77 
78  /// @brief Reset all the stats counters
79  void reset_timing_stats();
80 
81  protected: /// MPI Communication function
82 
83  /// @brief Check for messages and process them accordingly
84  void process_incoming_msgs( bool wait_until_message = false);
85 
86  /// @brief Send a workunit to an arbitrary recipient
87  void send_MPI_workunit( const WorkUnitBaseOP &wu, int dest_rank ) const;
88 
89  /// @brief Receive a workunit and add it to the inbound queue. By default accept any workunit
90  /// or accept a specific source rank. Note that this function is *blocking* and will onyl return once a workunit has been received.
92 
94 
95  /// @brief How many masters are there in total ?
96  //core::Size n_masters() const;
97 
98  /// @brief This is for masters only - returns a serial master number, i.e. 0 is the first master, N-1 is the last master.
99  /// Returns the running serial number (0 based) of a master. Returns 0 if emperor
100  /// The first master returns 0, the second returns 1, etc..
101  //core::Size my_master_rank() const;
102 
103  // @brief Return a single char depending on type: E = emperor, M = master and S = Slave
104  char get_machine_letter();
105 
106  enum MPI_TIMING {
107  TIMING_WAIT=0, // Waiting is defined as waiting for a responce
108  TIMING_TRANSFER_SEND, // Raw sending time, time spent in MPI_send essentially
109  TIMING_TRANSFER_RECV, // Raw receiving time, time spent in MPI_Recv
110  TIMING_CPU, // CPU time
111  TIMING_IO_WRITE, // Disk writing
112  TIMING_IO_READ, // Disk reaading
113  TIMING_IDLE, // Explicit idling (whenever sleep(x) is invoked). This is differnet from WAITing as in it indicated a lack of stuff to do rather then waiting for some other player.
114  TIMING_end }; // just an end marker for loops.
115 
116  /// @brief This initiates a new timer block. Note that there is no end_timer() function - you just keep calling start_timer, which automatically ends the previous block (and records times etc)
117  core::Real start_timer( MPI_TIMING timing_mode ) const;
118 
119  /// @brief Display the timing statistics
120  void print_timing_stats();
121 
122  /// @brief Return the total life time of this class in seconds.
123  long wall_time() const;
124 
125  private: // ------- variables of the timing system --------------
126 
127  /// @brief Minimum time in seconds between statistics updates (to screen)
129 
130  /// @brief when did the last timing block start ? (unixtime)
132 
133  /// @brief Timing type that is currently active
135 
136  /// @brief Running sums of total time spent in for any given timing type.
138 
139  /// @brief Start unixtime of this class (set once in contructor)
141 
142  /// @brief Last unixtime when stats were printed
143  mutable long last_stats_;
144 
145  /// @brief Total amount of traffic received, in bytes
147 
148  /// @brief Total amount of traffic sent, in bytes
150 
151  /// @brief Total time spent in MPI_Send
153 
154  /// @brief Total number of sends
156 
157  ///@brief Total time spent in MPI_Recv
159 
160  /// @brief Total time of receives
162 
164 };
165 
166 
167 
168 
169 
170 
171 
172 }
173 }
174 
175 #endif
176