Changeset 267b8d
- Timestamp:
- Jul 2, 2012, 8:32:05 AM (13 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- af9b9ff
- Parents:
- d9373b
- git-author:
- Frederik Heber <heber@…> (05/03/12 11:14:23)
- git-committer:
- Frederik Heber <heber@…> (07/02/12 08:32:05)
- Location:
- src/Fragmentation/Automation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Automation/FragmentScheduler.cpp
rd9373b r267b8d 562 562 } 563 563 564 /** Function to shutdown server properly, e.g. for use as signal handler. 565 * 566 * @param sig signal number 567 */ 568 void FragmentScheduler::shutdown(int sig) 569 { 570 LOG(0, "STATUS: Shutting down due to signal " << sig << "."); 571 572 if (!pool.presentIdleWorkers() && !pool.hasBusyWorkers()) { 573 shutdown(); 574 } else { 575 removeAllWorkers(); 576 } 577 } 578 564 579 /** Helper function to shutdown the server properly. 565 580 * -
src/Fragmentation/Automation/FragmentScheduler.hpp
rd9373b r267b8d 49 49 ~FragmentScheduler(); 50 50 51 void shutdown(int sig); 51 52 private: 52 53 void sendJobToWorker(const WorkerAddress &address, FragmentJob::ptr &job); … … 60 61 void recieveNotification(Observable *publisher, Notification_ptr notification); 61 62 void subjectKilled(Observable *publisher); 62 63 63 64 64 class WorkerListener_t : public Listener -
src/Fragmentation/Automation/Server.cpp
rd9373b r267b8d 29 29 #include <boost/program_options.hpp> 30 30 #include <iostream> 31 #include <signal.h> 31 32 32 33 #include "atexit.hpp" … … 35 36 #include "FragmentScheduler.hpp" 36 37 38 39 //!> global shutdown function 40 boost::function<void (int)> shutdownfunction; 41 //!> global signal vector for later releasing 42 std::vector<size_t> signals; 43 //!> counter for the number of received signals 44 size_t NoSignalsReceived = 0; 45 //!> maximum number of received signals after which the handlers are released 46 const size_t MAX_NOSIGNALSRECEIVED = 3; 47 48 void signalhandler(int sig) 49 { 50 // increment received signal counter 51 ++NoSignalsReceived; 52 53 // shutdown if we have handler 54 if (shutdownfunction) 55 shutdownfunction(sig); 56 57 if (NoSignalsReceived >= MAX_NOSIGNALSRECEIVED) { 58 // release signal hook again 59 for (std::vector<size_t>::const_iterator iter = signals.begin(); 60 iter != signals.end(); ++iter) 61 signal(*iter, NULL); 62 } 63 } 37 64 38 65 int main(int argc, char* argv[]) … … 47 74 ("help,h", "produce help message") 48 75 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level") 76 ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)") 49 77 ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers") 50 78 ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller") … … 101 129 boost::asio::io_service io_service; 102 130 FragmentScheduler Server(io_service, workerport, controllerport); 131 132 // catch ctrl-c and shutdown worker properly 133 shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1); 134 if (vm.count("signal")) { 135 signals = vm["signal"].as< std::vector<size_t> >(); 136 for (std::vector<size_t>::const_iterator iter = signals.begin(); 137 iter != signals.end(); ++iter) { 138 LOG(0, "STATUS: Catching signal " << *iter << " via signal handler."); 139 signal(*iter, &signalhandler); 140 } 141 } else { 142 LOG(0, "STATUS: No signals are caught."); 143 } 144 103 145 { 104 146 Info info("io_service"); -
src/Fragmentation/Automation/poolworker.cpp
rd9373b r267b8d 42 42 //!> global signal vector for later releasing 43 43 std::vector<size_t> signals; 44 //!> counter for the number of received signals 45 size_t NoSignalsReceived = 0; 46 //!> maximum number of received signals after which the handlers are released 47 const size_t MAX_NOSIGNALSRECEIVED = 3; 44 48 45 49 void signalhandler(int sig) 46 50 { 51 // increment received signal counter 52 ++NoSignalsReceived; 53 47 54 // shutdown if we have handler 48 55 if (shutdownfunction) 49 56 shutdownfunction(sig); 50 57 51 // release signal hook again 52 for (std::vector<size_t>::const_iterator iter = signals.begin(); 53 iter != signals.end(); ++iter) 54 signal(*iter, NULL); 58 if (NoSignalsReceived >= MAX_NOSIGNALSRECEIVED) { 59 // release signal hook again 60 for (std::vector<size_t>::const_iterator iter = signals.begin(); 61 iter != signals.end(); ++iter) 62 signal(*iter, NULL); 63 } 55 64 } 56 65
Note:
See TracChangeset
for help on using the changeset viewer.