Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BOINCJobDistributor.cc
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/jd2/BOINCJobDistributor.cc
11 /// @brief implementation of BOINCJobDistributor
12 /// @author Mike Tyka
13 
14 
15 // -- IMPORTANT --
16 // This has to come before boinc.hh or we get this error on VC++
17 // '_read' : is not a member of 'std::basic_istream<_Elem,_Traits>'
18 #include <utility/io/izstream.hh>
19 
20 
21 #ifdef BOINC
22  #include <protocols/boinc/boinc.hh>
23 #endif // BOINC
24 
25 #include <core/io/silent/util.hh>
27 #ifdef BOINC
28 #ifdef USEMPI
29 Throw a compiler error because MPI and BOINC cannot be used together!
30 If you got this message, something is wrong with your build settings.
31 #endif
32 #endif
33 
34 // Unit headers
36 // Package headers
37 #ifdef BOINC
39 #endif
40 
41 #include <protocols/jd2/Job.hh>
42 
43 #include <protocols/moves/Mover.hh>
44 // AUTO-REMOVED #include <basic/options/option.hh>
45 // AUTO-REMOVED #include <basic/options/keys/run.OptionKeys.gen.hh>
46 
47 // Utility headers
48 #include <basic/Tracer.hh>
49 #include <numeric/random/random.hh>
50 #include <utility/file/file_sys_util.hh>
51 #include <utility/io/ozstream.hh>
52 
53 // C++ headers
54 #include <string>
55 
56 #include <utility/vector1.hh>
57 #include <basic/options/keys/OptionKeys.hh>
58 
59 
60 static basic::Tracer TR("protocols.jd2.BOINCJobDistributor");
61 
62 
63 namespace protocols {
64 namespace jd2 {
65 
66 ///@details constructor. Notice it calls the parent class!
69  total_completed_nstruct_( 0 )
70 {
71 #ifdef BOINC
74 #endif
75 }
76 
77 ///@brief dtor
78 ///WARNING WARNING! SINGLETONS' DESTRUCTORS ARE NEVER CALLED IN MINI! DO NOT TRY TO PUT THINGS IN THIS FUNCTION!
79 ///here's a nice link explaining why: http://www.research.ibm.com/designpatterns/pubs/ph-jun96.txt
81 
82 void
84 {
85 
86 #ifdef BOINC
87  Jobs const & jobs( get_jobs() );
88  JobOutputterOP outputter = job_outputter();
89  // Count completed jobs
90  for( core::Size i = 1; i <= jobs.size(); i ++ ){
91  if( outputter->job_has_completed( jobs[ i ] ) ) total_completed_nstruct_++;
92  }
93 #endif
94 
96 
97  // gzip the output silent files.
99 
100  // ideally these would be called in the dtor but the way we have the singleton pattern set up the dtors don't get
101  // called
102 #ifdef BOINC
103 // Jobs const & jobs( get_jobs() );
104 // JobOutputterOP outputter = job_outputter();
105 
106  // Count completed jobs:
107 // core::Size count=0;
108 // for( core::Size i = 1; i <= jobs.size(); i ++ ){
109 // if( outputter->job_has_completed( jobs[ i ] ) ) count ++;
110 // }
112 // protocols::boinc::Boinc::worker_finish_summary( count + 1, count + 1, jobs.size() );
114  protocols::boinc::Boinc::worker_shutdown(); // Does not return.
115 #endif
116 }
117 
118 void
120 {
122  static time_t last_chkpt_time = time(NULL);
123  time_t time_now = time(NULL);
124  // Refuse to checkpoint more than once a minute, no matter what BOINC wants.
125  // Random number checkpoint files can be large (100k or more uncompressed).
126  if( time_now - last_chkpt_time > 60 ) {
127 #ifdef BOINC
128  // BOINC automatically handles begin/end_critical_section() calls.
129  utility::io::ozstream ozs("rng.state.gz");
130  numeric::random::RandomGenerator::saveAllStates(ozs);
131  ozs.close();
132 #endif // BOINC
134  last_chkpt_time = time_now;
135  }
137 }
138 
139 void
141 {
143 #ifdef BOINC
144  if( utility::file::file_exists("rng.state.gz") ) {
145  utility::io::izstream izs("rng.state.gz");
146  numeric::random::RandomGenerator::restoreAllStates(izs);
147  izs.close();
148  }
149 #endif // BOINC
151 }
152 
153 void
155 {
156 #ifdef BOINC
157  if( utility::file::file_exists("rng.state.gz") ) {
158  utility::file::file_delete("rng.state.gz");
159  }
160 #endif // BOINC
161 }
162 
163 ///@brief dummy for master/slave version
166 {
167 #ifdef BOINC
168  //if( next_random_job() > 0 ){
169  //if (protocols::boinc::Boinc::worker_is_finished( next_random_job() - 1 )) return 0; // we're done no matter what nstruct syays
170  if (protocols::boinc::Boinc::worker_is_finished( total_completed_nstruct_ )) return 0; // we're done no matter what nstruct syays
171  //}
172 #endif
174 }
175 
176 void
178 {
179  // do nothing - no repetitions allowed. Behave as if job had succeeded
180 }
181 
182 void BOINCJobDistributor::job_failed( core::pose::Pose& pose, bool /*will_retry*/ ) {
183  using namespace basic::options;
184 
185  current_job()->set_status_prefix("FAILURE");
186  job_succeeded( pose, 0 ); //i.e., job_outputter_->final_pose( current_job(), pose );
187 }
188 
189 void
191 {
192  FileSystemJobDistributor::job_succeeded( pose, run_time );
193 #ifdef BOINC
196 #endif
197 }
198 
200 #ifdef BOINC
201  boinc_begin_critical_section();
202 #endif // BOINC
203 }
204 
206 #ifdef BOINC
207  boinc_end_critical_section();
208 #endif // BOINC
209 }
210 
211 
212 }//jd2
213 }//protocols
214 
215