- Timestamp:
- Jul 6, 2012, 10:18:46 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:
- a10cc0
- Parents:
- fd4d5e
- git-author:
- Frederik Heber <heber@…> (06/04/12 07:41:05)
- git-committer:
- Frederik Heber <heber@…> (07/06/12 10:18:46)
- Location:
- src
- Files:
-
- 6 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
rfd4d5e r7546b0 446 446 bin_PROGRAMS += Controller PoolWorker Server 447 447 448 Controller_SOURCES = controller.cpp controller_main. hpp controller_AddOn_MPQCCommandJob.cpp448 Controller_SOURCES = controller.cpp controller_main.cpp controller_main.hpp controller_AddOn_MPQCCommandJob.cpp 449 449 Controller_LDFLAGS = $(AM_LDFLAGS) 450 450 Controller_CXXFLAGS = $(AM_CPPFLAGS) … … 459 459 $(BOOST_PROGRAM_OPTIONS_LIBS) $(BOOST_PROGRAM_OPTIONS_LDFLAGS) 460 460 461 PoolWorker_SOURCES = poolworker.cpp 461 PoolWorker_SOURCES = poolworker.cpp poolworker_main.cpp poolworker_main.hpp 462 462 PoolWorker_LDFLAGS = $(AM_LDFLAGS) 463 463 PoolWorker_CXXFLAGS = $(AM_CPPFLAGS) … … 470 470 $(BOOST_PROGRAM_OPTIONS_LIBS) $(BOOST_PROGRAM_OPTIONS_LDFLAGS) 471 471 472 Server_SOURCES = Server.cpp 472 Server_SOURCES = Server.cpp server_main.cpp server_main.hpp 473 473 Server_LDFLAGS = $(AM_LDFLAGS) 474 474 Server_CXXFLAGS = $(AM_CPPFLAGS) -
src/Server.cpp
rfd4d5e r7546b0 2 2 * Project: MoleCuilder 3 3 * Description: creates and alters molecular systems 4 * Copyright (C) 201 1-2012 University of Bonn. All rights reserved.4 * Copyright (C) 2012 University of Bonn. All rights reserved. 5 5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. 6 6 */ … … 9 9 * \file Server.cpp 10 10 * 11 * This file strongly follows the Serialization example from the boost::asio 12 * library (see server.cpp) 13 * 14 * Created on: Oct 21, 2011 11 * Created on: Jun 04, 2012 15 12 * Author: heber 16 13 */ … … 21 18 #endif 22 19 23 // boost asio needs specific operator new24 #include <boost/asio.hpp>25 26 20 #include "CodePatterns/MemDebug.hpp" 27 21 28 #include <boost/program_options.hpp> 29 #include <iostream> 30 31 #include "Fragmentation/Automation/atexit.hpp" 32 #include "CodePatterns/Info.hpp" 33 #include "CodePatterns/Log.hpp" 34 #include "atexit.hpp" 35 #include "FragmentScheduler.hpp" 36 #include "Jobs/SystemCommandJob.hpp" 37 #include "ServerOptions.hpp" 38 #include "SignalHandler.hpp" 39 22 #include "server_main.hpp" 40 23 41 24 int main(int argc, char* argv[]) 42 25 { 43 // from this moment on, we need to be sure to deinitialize in the correct order 44 // this is handled by the cleanup function 45 atexit(cleanUp); 26 return server_main(argc, argv); 27 } 46 28 47 ServerOptions ServerOpts;48 49 // Declare the supported options.50 boost::program_options::options_description desc("Allowed options");51 desc.add_options()52 ("help,h", "produce help message")53 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")54 ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")55 ("workerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting workers")56 ("controllerport", boost::program_options::value< unsigned short >(), "listen on this port for connecting controller")57 ;58 59 boost::program_options::variables_map vm;60 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);61 boost::program_options::notify(vm);62 63 int status = 0;64 status = ServerOpts.parseHelp(vm, desc);65 if (status) return status;66 status = ServerOpts.parseVerbosity(vm);67 if (status) return status;68 status = ServerOpts.parseWorkerPort(vm);69 if (status) return status;70 status = ServerOpts.parseControllerPort(vm);71 if (status) return status;72 status = ServerOpts.parseSignals(vm);73 if (status) return status;74 75 size_t Exitflag = 0;76 try77 {78 boost::asio::io_service io_service;79 FragmentScheduler Server(io_service, ServerOpts.workerport, ServerOpts.controllerport);80 81 // catch ctrl-c and shutdown worker properly82 boost::function<void (int)> shutdownfunction = boost::bind(&FragmentScheduler::shutdown, boost::ref(Server), _1);83 SignalHandler signalhandler(shutdownfunction, ServerOpts.signals);84 85 {86 Info info("io_service");87 io_service.run();88 }89 Exitflag = Server.getExitflag();90 }91 catch (std::exception& e)92 {93 std::cerr << e.what() << std::endl;94 }95 96 return Exitflag;97 } -
src/controller.cpp
rfd4d5e r7546b0 2 2 * Project: MoleCuilder 3 3 * Description: creates and alters molecular systems 4 * Copyright (C) 201 1University of Bonn. All rights reserved.4 * Copyright (C) 2012 University of Bonn. All rights reserved. 5 5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. 6 6 */ … … 9 9 * \file controller.cpp 10 10 * 11 * This file strongly follows the Serialization example from the boost::asio 12 * library (see client.cpp) 13 * 14 * Created on: Nov 27, 2011 11 * Created on: Jun 04, 2012 15 12 * Author: heber 16 13 */ … … 22 19 #endif 23 20 24 // boost asio needs specific operator new25 #include <boost/asio.hpp>26 27 21 #include "CodePatterns/MemDebug.hpp" 28 22 29 #include <boost/assign.hpp> 30 #include <boost/program_options.hpp> 31 #include <deque> 32 #include <fstream> 33 #include <iostream> 34 #include <map> 35 #include <sstream> 36 #include <streambuf> 37 #include <vector> 38 39 #include "CodePatterns/Assert.hpp" 40 #include "CodePatterns/Info.hpp" 41 #include "CodePatterns/Log.hpp" 42 43 #include "atexit.hpp" 44 #include "FragmentController.hpp" 45 #include "ControllerCommandRegistry.hpp" 46 #include "ControllerOptions.hpp" 47 #include "controller_AddOn.hpp" 48 49 /** Print the status of scheduled and done jobs. 50 * 51 * @param status pair of number of schedule and done jobs 52 */ 53 void printJobStatus(const std::pair<size_t, size_t> &JobStatus) 54 { 55 LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" 56 << JobStatus.second << " jobs are calculated so far."); 57 } 58 59 inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands) 60 { 61 std::vector<std::string> Commands; 62 for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter(); 63 iter != ControllerCommands.getEndIter(); ++iter) 64 Commands.push_back(iter->first); 65 66 return Commands; 67 } 23 #include "controller_main.hpp" 68 24 69 25 int main(int argc, char* argv[]) 70 26 { 71 // from this moment on, we need to be sure to deeinitialize in the correct order 72 // this is handled by the cleanup function 73 atexit(cleanUp); 74 75 size_t Exitflag = 0; 76 77 controller_AddOn *AddOn = getAddOn(); 78 ASSERT(AddOn != NULL, 79 "main() - returned AddOn is NULL."); 80 81 ControllerOptions *ControllerInfo = AddOn->allocateControllerInfo(); 82 boost::asio::io_service io_service; 83 FragmentController controller(io_service); 84 boost::program_options::variables_map vm; 85 86 // prepare ControllerCommand 87 // note: we need "< ControllerCommand::commands_t >" because parseExecutable(),... return int 88 // in contrast to other functions that return void 89 ControllerCommandRegistry ControllerCommands; 90 boost::function<void (ControllerCommand *)> registrator = 91 (boost::bind(&Registry<ControllerCommand>::registerInstance, boost::ref(ControllerCommands), _1)); 92 registrator(new ControllerCommand("checkresults", 93 boost::assign::list_of< ControllerCommand::commands_t > 94 (boost::bind(&FragmentController::checkResults, 95 boost::ref(controller), boost::cref(ControllerInfo->server), boost::cref(ControllerInfo->serverport))) 96 (boost::bind(&printJobStatus, 97 boost::bind(&FragmentController::getJobStatus, boost::ref(controller)))) 98 )); 99 registrator(new ControllerCommand("removeall", 100 boost::assign::list_of< ControllerCommand::commands_t > 101 (boost::bind(&FragmentController::removeall, 102 boost::ref(controller), boost::cref(ControllerInfo->server), boost::cref(ControllerInfo->serverport))) 103 )); 104 registrator(new ControllerCommand("shutdown", 105 boost::assign::list_of< ControllerCommand::commands_t > 106 (boost::bind(&FragmentController::shutdown, 107 boost::ref(controller), boost::cref(ControllerInfo->server), boost::cref(ControllerInfo->serverport))) 108 )); 109 AddOn->addSpecificCommands(registrator, controller, *ControllerInfo); 110 111 // Declare the supported options. 112 boost::program_options::options_description desc("Allowed options"); 113 desc.add_options() 114 ("help,h", "produce help message") 115 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level") 116 ("server", boost::program_options::value< std::string >(), "connect to server at this address (host:port)") 117 ("command", boost::program_options::value< std::string >(), (std::string("command to send to server: ")+toString(getListOfCommands(ControllerCommands))).c_str()) 118 ; 119 AddOn->addSpecificOptions(desc.add_options()); 120 121 // parse command line 122 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); 123 boost::program_options::notify(vm); 124 125 // set controller information 126 int status = 0; 127 status = ControllerInfo->parseHelp(vm, desc); 128 if (status) return status; 129 status = ControllerInfo->parseVerbosity(vm); 130 if (status) return status; 131 status = ControllerInfo->parseServerPort(vm); 132 if (status) return status; 133 status = ControllerInfo->parseCommand(vm, getListOfCommands(ControllerCommands)); 134 if (status) return status; 135 136 // all later parse functions depend on parsed command 137 status = AddOn->addOtherParsings(*ControllerInfo, vm); 138 if (status) return status; 139 140 // parse given ControllerCommand 141 if(!ControllerCommands.isPresentByName(ControllerInfo->command)) { 142 ELOG(1, "Unrecognized command '"+toString(ControllerInfo->command)+"'."); 143 return 255; 144 } 145 const ControllerCommand *commands = ControllerCommands.getByName(ControllerInfo->command); 146 try 147 { 148 // execute each command in the queue synchronously 149 size_t phase = 1; 150 for (ControllerCommand::const_iterator iter = commands->begin(); 151 iter != commands->end(); ++iter, ++phase) { 152 (*iter)(); 153 { 154 io_service.reset(); 155 Info info((std::string("io_service: ")+toString(phase)).c_str()); 156 io_service.run(); 157 } 158 } 159 Exitflag = controller.getExitflag(); 160 } 161 catch (std::exception& e) 162 { 163 std::cerr << e.what() << std::endl; 164 } 165 delete AddOn; 166 167 return Exitflag; 27 return controller_main(argc,argv); 168 28 } 169 29 -
src/poolworker.cpp
rfd4d5e r7546b0 8 8 /* 9 9 * \file poolworker.cpp 10 *11 * This file strongly follows the Serialization example from the boost::asio12 * library (see client.cpp)13 10 * 14 11 * Created on: Feb 28, 2012 … … 22 19 #endif 23 20 24 // boost asio needs specific operator new25 #include <boost/asio.hpp>26 27 21 #include "CodePatterns/MemDebug.hpp" 28 22 29 #include <iostream> 30 #include <boost/program_options.hpp> 31 #include <boost/lexical_cast.hpp> 32 #include <vector> 33 34 #include "Fragmentation/Automation/atexit.hpp" 35 #include "CodePatterns/Info.hpp" 36 #include "CodePatterns/Log.hpp" 37 #include "Pool/PoolWorker.hpp" 38 #include "atexit.hpp" 39 #include "Jobs/SystemCommandJob.hpp" 40 #include "SignalHandler.hpp" 41 #include "WorkerOptions.hpp" 23 #include "poolworker_main.hpp" 42 24 43 25 44 26 int main(int argc, char* argv[]) 45 27 { 46 // from this moment on, we need to be sure to deeinitialize in the correct order 47 // this is handled by the cleanup function 48 atexit(cleanUp); 28 return poolworker_main(argc,argv); 29 } 49 30 50 WorkerOptions WorkerOpts;51 boost::program_options::variables_map vm;52 53 // Declare the supported options.54 boost::program_options::options_description desc("Allowed options");55 desc.add_options()56 ("help,h", "produce help message")57 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")58 ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")59 ("server", boost::program_options::value< std::string>(), "connect to server at this address (host:port)")60 ("listen", boost::program_options::value< std::string >(), "listen on this port")61 ("hostname", boost::program_options::value< std::string>(), "name of host on which this codes runs and which server can resolve")62 ;63 64 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);65 boost::program_options::notify(vm);66 67 int status = 0;68 if (status) return status;69 status = WorkerOpts.parseHelp(vm, desc);70 if (status) return status;71 status = WorkerOpts.parseVerbosity(vm);72 if (status) return status;73 status = WorkerOpts.parseServer(vm);74 if (status) return status;75 status = WorkerOpts.parseListenPort(vm);76 if (status) return status;77 status = WorkerOpts.parseLocalhost(vm);78 if (status) return status;79 status = WorkerOpts.parseSignals(vm);80 if (status) return status;81 82 size_t exitflag = 0;83 try84 {85 boost::asio::io_service io_service;86 PoolWorker client(io_service, WorkerOpts.server, WorkerOpts.serverport, WorkerOpts.hostname, WorkerOpts.listenport);87 88 // catch ctrl-c and shutdown worker properly89 boost::function<void (int)> shutdownfunction = boost::bind(&PoolWorker::shutdown, boost::ref(client), _1);90 SignalHandler signalhandler(shutdownfunction, WorkerOpts.signals);91 92 // process io requests93 {94 Info info("io_service");95 io_service.run();96 }97 exitflag = client.getFlag();98 }99 catch (std::exception& e)100 {101 std::cerr << e.what() << std::endl;102 }103 104 105 return exitflag;106 }
Note:
See TracChangeset
for help on using the changeset viewer.