Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WorkUnitBase.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/WorkUnitBase.hh
11 /// @brief
12 /// @author Mike Tyka
13 
14 #ifndef INCLUDED_protocols_wum_WorkUnitBase_hh
15 #define INCLUDED_protocols_wum_WorkUnitBase_hh
16 
18 
19 //#include <protocols/wum/WorkUnitList.hh>
20 // AUTO-REMOVED #include <core/import_pose/pose_stream/MetaPoseInputStream.hh>
21 #include <core/pose/Pose.fwd.hh>
22 #include <core/types.hh>
23 //#include <protocols/loops/BackboneDB.hh>
24 #include <protocols/moves/Mover.hh>
26 #include <utility/pointer/ReferenceCount.hh>
27 
28 #include <string>
29 #include <vector>
30 // AUTO-REMOVED #include <iostream>
31 
32 #include <utility/vector1.hh>
33 
34 
35 namespace protocols {
36 namespace wum {
37 
38 /// @brief The base class for all work units
39 
41  public:
42  friend class MPI_WorkUnitManager;
44  friend class WorkUnitManager;
45  friend class WorkUnitQueue;
46 
47  WorkUnitBase();
48 
49  virtual ~WorkUnitBase (){}
50 
52  return new WorkUnitBase( *this );
53  }
54 
55  /// @brief Remove all data, make sure that the memory is also cleared, hence the cals to reserve
56  virtual void clear_serial_data(){
57  serial_data_.clear();
58  serial_data_.reserve(2);
59  runtime_assert( serial_data_.capacity() == 2 );
60  };
61 
62  /// @brief Run the workunit - overloaded by children of this class
63  virtual void run();
64 
65  /// @brief Print header information to the stream, single line by default or verbose if verbose is set to true
66  void print( std::ostream & out, bool verbose = false ) const ;
67 
68  /// @brief Accessor to the ID of the WorkUnit
69  core::Size id(){ return header.id_; }
70 
71  /// @brief Accessor to the extra_data_1 and 3 field of the header
72  // Needed for blacklisting based on start_ir and ssid
75 
76  /// @brief Adds to the blacklist
77  void add_blacklist( int mpi_rank );
78 
79  /// @brief Erases the blacklist
80  void clear_blacklist();
81 
82  /// @brief Finds in blacklist, true if is, false if it isn't
83  bool in_blacklist( int mpi_rank );
84 
85  protected:
86  /// @brief Make ready for sending
87  virtual void serialize() {};
88 
89  /// @brief Make ready for working - i.o.w. take information in serial_data_ and turn it into whatever real data the derivative class has.
90  virtual void deserialize() {} ;
91 
92  /// @brief Make a unique number out of Processor Number and unix timestamp ?
93  virtual void create_unique_id(){};
94 
95 protected:
96 
97  /// @brief Accessor to the serial data field
99 
100  /// @brief Accessor to the serial data field
101  const std::string &serial_data() const { return serial_data_; }
102 
103  /// @brief Accesor to the "options" text field
104  void set_options( const std::string &text );
105 
106  /// @brief Set the unixtime of the start of the execution of this WorkUnit
107  void set_run_start();
108 
109  /// @brief Set the unixtime of the stop of the execution of this WorkUnit
110  void set_run_stop();
111 
112 
113 public:
114 
115  /// @brief Returns the differrence between unix start and stop times
117 
118  /// @brief Accessor to header structure, return the WorkUnit Type
119  std::string get_wu_type() const;
120 
121  /// @brief Accessor to header structure, sets the WorkUnit Type
122  void set_wu_type( const std::string &text );
123 
124  /// @brief Optain the options string from the header
125  std::string get_options() const;
126 
127 
128 private: // functions for serialization and sending of data
129  unsigned int raw_data_size() const;
130 
131  /// @brief This allocates and returns a pointer to a block of memory with the
132  /// workunit data totally serialized. Note that it is that *callers*
133  /// responsibility to call delete [] on this memory when they're done with it.
134  unsigned int raw_data_dump( unsigned char ** raw_data_ptr ) const;
135 
136  /// Read in Header and serial data from a raw block of memeory, like one you'd get from a lowlevel network communication
137  void raw_data_load( const unsigned char * raw_data_ptr, unsigned int size );
138 
139 
140 
141 public:
142 
143  /// @brief Return the memory usage of this WorkUnit
144  virtual core::Size mem_footprint() const {
145  return sizeof( WorkUnitBase::WU_Header ) + serial_data().capacity();
146  }
147 
148  /// @brief this structure can contain any non-dynamicly allocated data.
149  /// Any simple data types can be used here, ints, real, floats, char, etc..
150  struct WU_Header{
151  char wu_type_[128];
152  // Some unique id
154 
155  /// Unixtime of when this WU was created
157 
158  /// Unixtime of when this workunit began execution
160 
161  /// Unixtime of when this workunit finished execution
167 
168  /// protocols can put arbitrary small header data here
169  char options_[128];
170  };
171 
173 protected:
174  /// @brief The header data
176 
177  /// @brief Contains the serial number of whatever Rank/Node this WU was last receeived from
179 
180  /// @brief Contains blacklist of nodes. This data is NOT sent, and is only used on the sending side to determine where not to send a workunit.
181  std::vector< int > blacklist_;
182 
183 private: // data
184 
185  /// @brief Contains more data, such as decoys, silent structucts, .. whatever
186  /// really. Must be serialized, i.e. in plain text form
187  /// read for transmission.
189 };
190 
191 
192 
193 
195  public:
196  WorkUnit_Wait( long wait_time = 2 ):
197  WorkUnitBase ()
198  {
199  header.extra_data_1_ = wait_time;
200  }
201 
202  virtual ~WorkUnit_Wait(){}
203 
205  return new WorkUnit_Wait( *this );
206  }
207 
208  // @brief Run the workunit - overloaded by children of this class
209  virtual void run();
210  private:
211 };
212 
213 
214 
215 
216 
217 /// @brief This WorkUnit type has structures in it. Most Workunits should derive from this one rather
218 /// THe the Base class.
220  public:
222  WorkUnitBase ()
223  {
224  }
225 
227 
229  return new WorkUnit_SilentStructStore( *this );
230  }
231 
232  /// @brief This Work unit doesnt do *anything* - its just keeps the structures
233  virtual void run(){};
234 
235  /// @brief write decoys into serial data store overwritinge whatever was there before. It basically syncs the silent struct store with the derial data
236  virtual void serialize();
237 
238  /// @brief Make ready for working
239  virtual void deserialize();
240 
241  /// @brief Accessor for decoy store
243 
244  /// @brief Accessor for decoy store
246 
247  private:
248  /// @brief This WorkUnit type has structures in it.
250 
251 };
252 
253 
254 
255 
256 
257 /// @brief This WorkUnit type can encapsulate any MoverOP. When registering this WOrkunit
258 /// provide it with a MoverOP and then, when executed on the slaves, this workunit will run the mover
259 /// On every single input structure and return the results.
261  public:
263 
265 
267  return new WorkUnit_MoverWrapper( *this );
268  }
269 
270  // @brief Run the workunit - overloaded by children of this class
271  virtual void run();
272 
273  protected:
274 
275  void set_defaults();
276  private:
278 };
279 
280 
281 
282 
283 
284 
285 
286 }
287 }
288 
289 #endif
290