Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShuffleJobDistributor.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 // Unit headers
13 // Package headers
15 #include <protocols/jd2/Job.hh>
16 
17 // AUTO-REMOVED #include <protocols/moves/Mover.hh>
18 
19 // Utility headers
20 #include <basic/Tracer.hh>
21 #include <basic/options/option.hh>
22 #include <utility/exit.hh>
23 #include <numeric/random/random.hh>
24 
25 // Option headers
26 #include <basic/options/keys/out.OptionKeys.gen.hh>
27 
28 
29 // C++ headers
30 #include <string>
31 
32 #include <utility/vector1.hh>
33 
34 
35 static basic::Tracer TR("protocols.jd2.ShuffleFileSystemJobDistributor");
36 static numeric::random::RandomGenerator RG(10419); // Magic Number
37 
38 
39 namespace protocols {
40 namespace jd2 {
41 
42 ///@details constructor. Notice it calls the parent class! It also builds some internal variables for determining
43 ///which processor it is in MPI land.
46 {
47  next_random_job_ = 0; // indicate that list needs generating
48 
49 }
50 
51 ///@brief dtor
52 ///WARNING WARNING! SINGLETONS' DESTRUCTORS ARE NEVER CALLED IN MINI! DO NOT TRY TO PUT THINGS IN THIS FUNCTION!
53 ///here's a nice link explaining why: http://www.research.ibm.com/designpatterns/pubs/ph-jun96.txt
55 { }
56 
57 
58 
59 ///@brief dummy for master/slave version
62 {
63  Jobs const & jobs( get_jobs() );
64  if( jobs.size() == 0 ) return 0; // no jobs;
65 
66  JobOutputterOP outputter = job_outputter();
67 
68  if( next_random_job_ == 0 ){
69  scrambled_job_order_.clear();
70  for( int i=0; i < basic::options::option[ basic::options::OptionKeys::out::nstruct ].value() ; i++ ){
71  scrambled_job_order_.push_back( RG.random_range(1,jobs.size() ) );
72  }
73 
74 
75  }
77 
78 // for( core::Size ijob = 1; ijob <= jobs.size(); ijob ++ ){
79 // std::cerr << "JL: " << jobs[ ijob ]->input_tag() << " " << jobs[ ijob ]->nstruct_index() << " Done? " << outputter->job_has_completed( jobs[ ijob ] ) << std::endl;
80 // }
81 //
83  if((int)next_random_job_ > (int)basic::options::option[ basic::options::OptionKeys::out::nstruct ].value() ) return 0; // we're done (nstruct decoys done)
84  if(next_random_job_ > scrambled_job_order_.size()) next_random_job_ = 0; // re-scramble the list
85 
86  // Now go backwards to find the last nstruct that hasn't been done yet.
87  // If we're not done
88  if( choice <= 0 ) choice = 1;
89  if( choice > jobs.size() ) choice = jobs.size();
90  if( !outputter->job_has_completed( jobs[ choice ] ) ) {
91  while ( ( choice > 1 ) &&
92  ( !outputter->job_has_completed( jobs[ choice-1 ]) ) &&
93  ( jobs[ choice - 1 ]->input_tag() == jobs[ choice ]->input_tag() )
94  ) {
95  choice -- ;
96  }
97 
98  }
99 
100  if( choice <= 0 ) choice = 1;
101  if( choice > jobs.size() ) choice = jobs.size();
102  if(outputter->job_has_completed( jobs[ choice ] ) ){
103  while ( ( choice <= (jobs.size()-1) ) &&
104  ( outputter->job_has_completed( jobs[ choice ]) )
105  ) {
106  choice ++ ;
107  }
108  }
109 
110  // still no luck ? then go back wards again looking for anything non-completed.
111  if( choice <= 0 ) choice = 1;
112  if( choice > jobs.size() ) choice = jobs.size();
113  if(outputter->job_has_completed( jobs[ choice ] ) ){
114  while ( ( choice > 1 ) &&
115  ( outputter->job_has_completed( jobs[ choice ]) )
116  ) {
117  choice -- ;
118  }
119  }
120 
121  // if at 0 and still completed status is true, we must have done all the jobs - return 0;
122  if( choice <= 0 ) choice = 1;
123  if( choice > jobs.size() ) choice = jobs.size();
124  if( outputter->job_has_completed( jobs[ choice ] ) ){
125  TR << "No more jobs found." << std::endl;
126  return 0;
127  }
128 
129  // Now go backwards to find the last nstruct that hasn't been done yet.
130  // If we're not done
131  if( choice <= 0 ) choice = 1;
132  if( choice > jobs.size() ) choice = jobs.size();
133  if( !outputter->job_has_completed( jobs[ choice ] ) ) {
134  while ( ( choice > 1 ) &&
135  ( !outputter->job_has_completed( jobs[ choice-1 ]) ) &&
136  ( jobs[ choice - 1 ]->input_tag() == jobs[ choice ]->input_tag() )
137  ) {
138  choice -- ;
139  }
140 
141  }
142 
143 
144  return choice;
145 }
146 
147 void
149 {
150  // do nothing - no repetitions allowed. Behave as if job had succeeded (handled by job_failed)
151 }
152 
153 }//jd2
154 }//protocols