Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MPI_LoopHashRefine_Emperor.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/loophash/MPI_LoopHashRefine_Emperor.cc
11 /// @brief
12 /// @author Mike Tyka
13 
14 #define TRDEBUG TR.Debug
15 
16 // MPI headers
17 #ifdef USEMPI
18 #include <mpi.h> //keep this first
19 #endif
20 
23 // AUTO-REMOVED #include <protocols/loophash/WorkUnit_LoopHash.hh>
25 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
26 // AUTO-REMOVED #include <core/pose/util.hh>
27 // AUTO-REMOVED #include <core/chemical/ChemicalManager.hh>
28 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
29 
30 // AUTO-REMOVED #include <core/import_pose/pose_stream/MetaPoseInputStream.hh>
31 // AUTO-REMOVED #include <core/import_pose/pose_stream/util.hh>
32 // AUTO-REMOVED #include <core/io/silent/SilentFileData.hh>
33 // AUTO-REMOVED #include <core/io/silent/SilentStructFactory.hh>
37 // AUTO-REMOVED #include <basic/options/keys/in.OptionKeys.gen.hh>
38 // AUTO-REMOVED #include <basic/options/keys/out.OptionKeys.gen.hh>
39 // AUTO-REMOVED #include <basic/options/keys/relax.OptionKeys.gen.hh>
40 #include <basic/options/keys/lh.OptionKeys.gen.hh>
41 #include <basic/options/option.hh>
42 // AUTO-REMOVED #include <core/pose/Pose.hh>
43 // AUTO-REMOVED #include <core/scoring/ScoreFunctionFactory.hh>
44 // AUTO-REMOVED #include <core/scoring/ScoreFunction.hh>
45 #include <basic/Tracer.hh>
47 #include <ObjexxFCL/format.hh>
48 /// ObjexxFCL headers
49 #include <ObjexxFCL/string.functions.hh>
50 
51 #include <numeric/random/random.hh>
52 
53 #ifndef _WIN32 // REQUIRED FOR WINDOWS
54 // AUTO-REMOVED #include <unistd.h>
55 
56 #include <utility/vector1.hh>
57 
58 #endif
59 
60 using namespace ObjexxFCL;
61 using namespace ObjexxFCL::fmt;
62 
63 namespace protocols {
64 namespace loophash {
65 
66 using namespace protocols::wum;
67 
68 static basic::Tracer TR("MPI.LHR.Emperor");
69 
70 static numeric::random::RandomGenerator RG(1248321); // <- Magic number, do not change it (and dont try and use it anywhere else)
71 
72 
73 void
74 MPI_LoopHashRefine_Emperor::set_defaults(){
75  using namespace basic::options;
76  using namespace basic::options::OptionKeys;
77 
78  set_max_lib_size( option[ OptionKeys::lh::max_emperor_lib_size]() );
79  max_emperor_lib_round_ = option[ OptionKeys::lh::max_emperor_lib_round ]();
80 }
81 
82 
83 void
85  // Are we resuming an old job ?
86  if( mpi_resume() != "" ){
87  TR << "Resuming job from IDENT: " << mpi_resume() << std::endl;
88  load_state( mpi_resume() );
89  };
90 
91  // Emperors have different library rules!
92  set_mpi_feedback( "add_n_replace" );
93 
94  TR << "STARTLIB: " << std::endl;
95  print_library();
96 }
97 
98 void
99 MPI_LoopHashRefine_Emperor::go()
100 {
101  // initialize master (this is a virtual functino call and this function is overloaded by the children of this class)
102  TR << "Init Master: " << mpi_rank() << std::endl;
103  init();
104 
105  TR << "Emperor Node: Waiting for data ..." << std::endl;
106  while(true){
107  // process any incoming messages such as incoming
108  TRDEBUG << "Emperor: processing msgs.." << std::endl;
109  process_incoming_msgs();
110 
111  TRDEBUG << "Emperor: process incoming" << std::endl;
112  process_inbound_wus(); // lets borrow a master's routine
113 
114  TRDEBUG << "Emperor: process outbound" << std::endl;
115  process_outbound_wus();// lets borrow a master's routine
116 
117  // ok, we've done all our work, now wait until we hear from our slaves/masters
118  process_incoming_msgs( true );
119 
120  print_stats_auto();
121  }
122 }
123 
124 
125 void
126 MPI_LoopHashRefine_Emperor::process_inbound_wus(){
127  if( inbound().size() > 0 ){
128  TR << "Processing inbound WUs on emperor .." << std::endl;
129  }
130 
131  while( inbound().size() > 0 )
132  {
133  WorkUnitBaseOP next_wu = inbound().pop_next();
134  runtime_assert( next_wu );
135  WorkUnit_SilentStructStoreOP structure_wu = dynamic_cast< WorkUnit_SilentStructStore * > ( next_wu() );
136 
137  if ( structure_wu.get() == NULL ){
138  TR << "Cannot save structural data for WU: " << std::endl;
139  next_wu->print( TR );
140  continue;
141  }
142 
143  SilentStructStore &decoys = structure_wu->decoys();
144  decoys.all_sort_silent_scores();
145  if ( structure_wu->get_wu_type() == "resultpack" ){
146  TR << "Emperor: receivd structures: " << decoys.size() << std::endl;
147  // dump structures
148  add_structures_to_library( decoys );
149  } else
150  if ( structure_wu->get_wu_type() == "getnewstruct" ){
151  TR << "Emperor: received expired structures: " << decoys.size() << std::endl;
152  // dump structures
153  if( decoys.size() > 0 ){
154  add_structures_to_library( decoys );
155  // Always send back a structure so the master can continue its life.
156  TR << "Sending a new random structure to master:" << structure_wu->last_received_from() << std::endl;
157  // send back a random ssid. crude way to prevent interference from old returning structures on the master. really crude. sorry, this could be better i know.
158  send_random_library_struct( structure_wu->last_received_from(), (core::Size) numeric::random::random_range(0,9999) );
159  TR << "Done." << std::endl;
160  }
161  } else {
162  TR.Error << "ERROR: Unknown workunit received. " << std::endl;
163  }
164 
165  }
166 
167  save_state_auto();
168  print_stats();
169 }
170 
171 
172 
173 void
174 MPI_LoopHashRefine_Emperor::process_outbound_wus(){
175 }
176 
177 
178 // iterate through the structure store and add strucutres to the central library according to the algorithm specified or the default algorithm
179 bool
180 MPI_LoopHashRefine_Emperor::add_structures_to_library( SilentStructStore &new_structs, std::string add_algorithm ){
181  using namespace basic::options;
182  using namespace basic::options::OptionKeys;
183  bool result = false;
184 
185  for( SilentStructStore::const_iterator it = new_structs.begin();
186  it != new_structs.end(); ++it )
187  {
188  runtime_assert( *it );
189  core::io::silent::SilentStruct *pss = &(*(*it));
190 
191  // Filter for max_emperor_lib_round_
192 
193  if( max_emperor_lib_round_ > 0 ){
194  core::Size structure_round = (core::Size) pss->get_energy("round");
195  if( structure_round > max_emperor_lib_round_ ) continue;
196  }
197 
198  // add the structure if it passes energy and rms filters evaluated further down there
199  runtime_assert( pss );
200  pss->add_energy( "emperor_count", pss->get_energy( "emperor_count" ) );
201  bool local_result = add_structure_to_library( *pss, add_algorithm );
202  result |= local_result;
203  }
204 
205  // always dump *everything* returned to emperor!
206  dump_structures( new_structs, false );
207 
208  limit_library();
209  print_library();
210  return result;
211 }
212 
213 
214 } // namespace loophash
215 } // namespace protocols
216 
217