Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WorkUnit.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/wum2/WorkUnitBase.hh
11 /// @brief Base work unit (abstract) for wum2 and some commonly used derived work units
12 /// @author Ken Jung
13 
14 #ifndef INCLUDED_protocols_wum2_WorkUnit_hh
15 #define INCLUDED_protocols_wum2_WorkUnit_hh
16 
21 
22 
23 #include <core/pose/Pose.hh>
24 #include <core/types.hh>
25 
26 #ifdef USEBOOSTSERIALIZE
27 #include <boost/serialization/base_object.hpp>
28 #endif
29 
30 #ifdef USELUA
31 #include <lua.hpp>
32 #include <luabind/luabind.hpp>
33 #endif
34 
35 namespace protocols {
36 namespace wum2 {
37 
38 #ifdef USELUA
39 void lregister_WorkUnit( lua_State * lstate );
40 void lregister_WorkUnit_Wait( lua_State * lstate );
41 void lregister_WorkUnit_ElScripts( lua_State * lstate );
42 #endif
43 
44 /// @brief The base class for all work units, this is abstract
45 
46 class WorkUnit {
47 
48 public:
49  // boost serialize requires empty constructor
51  // mpi rank of master node, index of trajectory on that master node
54 
55  virtual ~WorkUnit (){}
56 
57  /// @brief Run the workunit
58  virtual void run() = 0;
59 
60  /// @brief Print WU details to the stream, single line by default
61  virtual void print( std::ostream & out, bool verbose = false ) const ;
62 
63  /// @brief Set the unixtime of the start of the execution of this WorkUnit
64  void set_run_start();
65 
66  /// @brief Set the unixtime of the stop of the execution of this WorkUnit
67  void set_run_stop();
68 
69  /// @brief Returns the difference between unix start and stop times
71 
72  // Accessors/Mutators
73  void id( int id ) { id_ = id; }
74  int id() { return id_; }
75 
76  void master( int master ) { master_ = master; }
77  int master() { return master_; }
78 
80  int trajectory_idx() { return trajectory_idx_; }
81 
83  bool prioritize() { return prioritize_; }
84 
85  // links a cache with the WU so it can use it in run()
86  // cache is not seralized nor transferred with WU
88 
89 private:
90 #ifdef USEBOOSTSERIALIZE
91  friend class boost::serialization::access;
92 
93  template<class Archive>
94  void serialize(Archive & ar, const unsigned int version) {
95  ar & prioritize_;
96  ar & id_;
97  ar & master_;
98  ar & trajectory_idx_;
99  ar & unixtime_creation_;
100  ar & unixtime_start_;
101  ar & unixtime_stop_;
102  }
103 #endif
104 
105 protected:
106 
107  // whether the WU gets pushed onto the front vs back of the queue
109 
110  // Generates unique id for this WU, from rank and unix timestamp
111  void create_unique_id();
112 
113  // Unique id for this WU, from rank and unix timestamp
114  int id_;
115 
116  // For MPI, what master and what trajectory on that master created this WU
117  // master = mpi rank of node where WU was created
118  int master_;
120 
121  /// Important unixtimes
125 
126  // Cache pointer, is only valid after link_cache() is called
127  // is not serialized, is not sent with WU
129 }; // class WorkUnit
130 
131 
132 /// @brief WorkUnit that sleeps for X seconds
133 class WorkUnit_Wait: public WorkUnit {
134 public:
135  // boost serialize requires empty constructor
139  long wait_time);
140 
142 
143  void run();
144 
146  long wait_time() { return wait_time_; }
147 
148 private:
149 #ifdef USEBOOSTSERIALIZE
150  friend class boost::serialization::access;
151 
152  template<class Archive>
153  void serialize(Archive & ar, const unsigned int version) {
154  ar & boost::serialization::base_object<WorkUnit>(*this);
155  ar & wait_time_;
156  }
157 #endif
158 
159  // in seconds
161 }; // class WorkUnit_Wait
162 
163 // Basic work unit that holds state for ElScripts
164 class WorkUnit_ElScripts : public WorkUnit {
165 public:
166  // boost serialize requires empty constructor
172  std::string name );
173 
175  virtual void run();
176 
177  // no copy constructor needed, shallow copy is fine for current use
178 
181  }
182 
185  }
186 
187  // cpp doesnt let you overload by return type boohoo
190  }
191 
192  // just renames pipes from old name to new name
193  // Undefined, commenting out to fix PyRosetta build void rename_pipes( core::io::serialization::PipeMapSP p, std::map< std::string, std::string > new_names );
194 
195  std::string name() { return name_; }
196  void name( std::string name ) { name_ = name; }
197 
198 #ifdef USEBOOSTSERIALIZE
199  friend class boost::serialization::access;
200 
201  template<class Archive>
202  void serialize(Archive & ar, const unsigned int version) {
203  ar & boost::serialization::base_object<WorkUnit>(*this);
204  ar & pipemap_;
205  ar & state_;
206  ar & name_;
207  }
208 #endif
209 
210 protected:
211 
212  // makes sense to put name here instead of at base class, as this WU is used as the result WU
213  // it should hold the name of the WU that generated the result it is holding
217 }; // class WorkUnit_ElScripts
218 }
219 }
220 
221 #endif