46 #include <basic/options/option.hh>
47 #include <utility/exit.hh>
48 #include <basic/Tracer.hh>
49 #include <utility/excn/Exceptions.hh>
52 #include <basic/prof.hh>
53 #include <basic/datacache/BasicDataCache.hh>
59 #include <basic/options/keys/run.OptionKeys.gen.hh>
60 #include <basic/options/keys/jd2.OptionKeys.gen.hh>
61 #include <basic/options/keys/out.OptionKeys.gen.hh>
63 #include <utility/vector1.hh>
74 static basic::Tracer
tr(
"protocols.jd2.JobDistributor");
81 #include <boost/thread/tss.hpp>
87 boost::thread_specific_pointer< JobDistributor > jd_ptr;
92 if ( jd_ptr.get() == 0 )
140 current_job_(
JD2_BOGUS_JOB), current_job_id_(0), last_completed_job_(0), current_batch_id_(
152 current_job_(
JD2_BOGUS_JOB), current_job_id_(0), last_completed_job_(0), current_batch_id_(
175 tr.Debug <<
"batches present... " << std::endl;
183 }
catch (utility::excn::EXCN_Base & excn) {
185 <<
"ERROR: Exception caught by JobDistributor while trying to initialize the JobInputter of type '"
190 << excn << std::endl;
198 }
catch (utility::excn::EXCN_Base & excn) {
200 <<
"ERROR: Exception caught by JobDistributor while trying to fill the input jobs with JobInputter of type type '"
205 << excn << std::endl;
217 if (basic::options::option[basic::options::OptionKeys::run::batches].user())
221 basic::options::option[basic::options::OptionKeys::run::batches]);
222 std::copy(fns.begin(), fns.end(), std::back_inserter(
batches_));
256 using namespace basic::options;
257 time_t
const allstarttime = time(NULL);
264 bool first_job(
true);
266 bool using_parser(
false);
271 <<
"Parser is present. Input mover will be overwritten with whatever the parser creates."
273 }PROF_START( basic::JD2);
275 #ifdef BOINC_GRAPHICS
277 protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
284 time_t
const jobstarttime = time(NULL);
285 core::Size const elapsedtime(jobstarttime - allstarttime);
287 if ((option[OptionKeys::run::maxruntime].user())
288 && (option[OptionKeys::run::maxruntime]() > 0)
289 && (option[OptionKeys::run::maxruntime]() <
int(elapsedtime)))
292 basic::Error() <<
"Run terminating because runtime of "
293 << elapsedtime <<
" s exceeded maxruntime of "
294 << option[OptionKeys::run::maxruntime]() <<
" s "
301 if (!option[OptionKeys::run::no_prof_info_in_silentout])
316 if (option[OptionKeys::run::show_simulation_in_pymol].user()
317 && option[OptionKeys::run::show_simulation_in_pymol].value()
322 option[OptionKeys::run::keep_pymol_simulation_history](),
323 option[OptionKeys::run::show_simulation_in_pymol].value());
327 #ifdef BOINC_GRAPHICS
330 protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
333 }
catch (utility::excn::EXCN_Base& excn)
336 <<
"ERROR: Exception caught by JobDistributor while trying to get pose from job "
338 << excn << std::endl;
340 <<
"Treating failure as bad input; canceling similar jobs"
349 bool reinitialize_new_input(
false);
350 bool new_input(
false);
354 tr.Debug <<
"new input detected, is: " <<
current_job_->input_tag()
355 <<
", last was: " << last_inner_job_tag << std::endl;
358 retries_this_job = 0;
362 && (mover->reinitialize_for_new_input()
363 || option[OptionKeys::run::reinitialize_mover_for_new_input]))
365 reinitialize_new_input =
true;
370 if (option[OptionKeys::jd2::delete_old_poses].user())
396 tr.Debug <<
"new batch detected: get fresh instance from mover"
399 reinitialize_new_input =
true;
405 && (reinitialize_new_input || mover->reinitialize_for_each_job()
406 || option[OptionKeys::run::reinitialize_mover_for_each_job]))
408 tr.Trace <<
"reinitializing the mover" << std::endl;
409 PROF_STOP( basic::JD2);
410 PROF_START( basic::JD2_INIT_MOVER);
411 mover_copy = mover->fresh_instance();
412 PROF_STOP( basic::JD2_INIT_MOVER);
413 PROF_START( basic::JD2);
415 else if (using_parser)
417 tr.Trace <<
"Allowing the Parser to create a new Mover if desired"
423 }
catch (utility::excn::EXCN_Base& excn)
426 <<
"ERROR: Exception caught by JobDistributor while trying to get pose from job "
430 <<
"Treating failure as bad input; canceling similar jobs"
439 #ifdef BOINC_GRAPHICS
442 protocols::boinc::Boinc::attach_graphics_current_pose_observer( pose );
452 tr.Trace <<
"not reinitializing mover" << std::endl;
459 mover_copy->reset_status();
461 mover_copy->clear_info();
469 PROF_STOP( basic::JD2);
472 if (basic::options::option[basic::options::OptionKeys::out::std_IO_exit_error_code]()
474 std::cout.exceptions(std::ios_base::badbit);
476 tr.Debug <<
"run mover... " << std::endl;
477 mover_copy->set_current_tag(
479 mover_copy->apply(pose);
480 status = mover_copy->get_last_move_status();
485 }
catch (std::ios_base::failure& ex)
487 std::cerr <<
"std::IO error detected... exiting..." << std::endl;
489 basic::options::option[basic::options::OptionKeys::out::std_IO_exit_error_code]());
491 }
catch (utility::excn::EXCN_BadInput& excn)
494 <<
"\n\n[ERROR] Exception caught by JobDistributor for job "
499 }
catch (utility::excn::EXCN_Base& excn)
502 <<
"\n\n[ERROR] Exception caught by JobDistributor for job "
507 std::cout.exceptions(std::ios_base::goodbit);
509 PROF_START( basic::JD2);
510 core::Size jobtime(time(NULL) - jobstarttime);
513 PROF_START( basic::JD2_OUTPUT);
523 using namespace basic::options::OptionKeys::jd2;
525 if (option[ntrials].user()
526 && (retries_this_job >= (
core::Size) option[ntrials].value()))
530 <<
" reported failure " << retries_this_job
531 <<
" times and will no longer retry (permanent failure)"
539 <<
" reported failure and will retry" << std::endl;
546 <<
" reported failure and will NOT retry" << std::endl;
552 <<
" reported that its input was bad and will not retry"
559 PROF_STOP( basic::JD2_OUTPUT);
562 }PROF_STOP( basic::JD2);
566 tr.Info <<
jobs_.size() <<
" jobs in last batch... in total ";
570 tr.Info <<
jobs_.size() <<
" jobs considered, ";
572 tr.Info << tried_jobs <<
" jobs attempted in "
573 << (time(NULL) - allstarttime) <<
" seconds" << std::endl;
575 tr.Info <<
"no jobs were attempted, did you forget to pass -overwrite?"
604 if (reconsider_current_job)
633 utility_exit_with_message(
634 "JobDistributor: nonexistent job returned in obtain_new_job()");
656 jobs_[job_id]->set_completed();
658 <<
" reported success in " << run_time <<
" seconds" << std::endl;
664 jobs_[job_id]->set_bad();
746 tr.Error <<
"[ERROR] illegeal attempt to set batch_id to " << setting
747 <<
" where we have only " <<
batches_.size() <<
" batches"
749 utility_exit_with_message(
"wrong batch_id");
762 tr.Info <<
"no more batches to process... " << std::endl;
774 tr.Trace <<
"last batch is CANCELLED: run next_batch()" << std::endl;
852 std::cout <<
"Got some signal... It is:" << signal_ << std::endl;
853 if (signal_ == SIGINT)
854 std::cout <<
"Ctrl-c was pressed!" << std::endl;
855 if (signal_ == SIGABRT)
856 std::cout <<
"Process was aborted!" << std::endl;
857 if (signal_ == SIGTERM)
858 std::cout <<
"Process was terminated!" << std::endl;
861 if (signal_ == SIGKILL)
862 std::cout <<
"Process was SIGKILL!" << std::endl;
863 if (signal_ == SIGQUIT)
864 std::cout <<
"Process was SIGQUIT!" << std::endl;
880 signal(SIGINT, signal_fn);
881 signal(SIGABRT, signal_fn);
882 signal(SIGTERM, signal_fn);
885 signal(SIGKILL, signal_fn);
886 signal(SIGQUIT, signal_fn);
893 signal(SIGINT, SIG_DFL);
894 signal(SIGABRT, SIG_DFL);
895 signal(SIGTERM, SIG_DFL);
897 signal(SIGKILL, SIG_DFL);
898 signal(SIGQUIT, SIG_DFL);