Changeset 9dcce3
- Timestamp:
- Jul 6, 2012, 10:18:43 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:
- 685e28
- Parents:
- 311137
- git-author:
- Frederik Heber <heber@…> (05/31/12 08:33:43)
- git-committer:
- Frederik Heber <heber@…> (07/06/12 10:18:43)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/controller.cpp
r311137 r9dcce3 306 306 } 307 307 308 struct ControllerOptions 309 { 310 int parseHelp(boost::program_options::variables_map &vm, const boost::program_options::options_description &desc) { 311 if (vm.count("help")) { 312 std::cout << desc << "\n"; 313 return 1; 314 } 315 return 0; 316 } 317 int parseVerbosity(boost::program_options::variables_map &vm) { 318 if (vm.count("verbosity")) { 319 LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << "."); 320 setVerbosity(vm["verbosity"].as<size_t>()); 321 } else { 322 LOG(0, "STATUS: Verbosity level was not set, defaulting to 5."); 323 setVerbosity(5); 324 } 325 return 0; 326 } 327 328 int parseServerPort(boost::program_options::variables_map &vm) { 329 if (vm.count("server")) { 330 server = vm["server"].as< std::string >(); 331 serverport = server.substr(server.find_last_of(':')+1, std::string::npos); 332 server = server.substr(0, server.find_last_of(':')); 333 try { 334 boost::lexical_cast<size_t>(serverport); 335 } catch (boost::bad_lexical_cast &) { 336 ELOG(1, "Could not interpret " << serverport << " as server:port."); 337 return 255; 338 } 339 LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address."); 340 } else { 341 ELOG(1, "Requiring server's address (host:port) to connect to."); 342 return 255; 343 } 344 return 0; 345 } 346 347 int parseCommand(boost::program_options::variables_map &vm, const std::vector<std::string> &Commands) { 348 if (!vm.count("command")) { 349 ELOG(1, "Controller requires one of the following commands: "+toString(Commands)); 350 return 255; 351 } 352 command = vm["command"].as< std::string >(); 353 return 0; 354 } 355 356 std::string command; 357 std::string server; 358 std::string serverport; 359 360 }; 361 362 struct ControllerOptions_SystemCommandJob : public ControllerOptions 363 { 364 int parseExecutable(boost::program_options::variables_map &vm) { 365 if ((command == "createjobs") || (command == "addjobs")) { 366 if (!vm.count("executable")) { 367 ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand]."); 368 return 255; 369 } 370 executable = vm["executable"].as< std::string >(); 371 } 372 return 0; 373 } 374 375 int parseJobCommand(boost::program_options::variables_map &vm) { 376 if (command == "createjobs") { 377 if (!vm.count("jobcommand")) { 378 ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand]."); 379 return 255; 380 } 381 jobcommand = vm["jobcommand"].as< std::string >(); 382 } 383 return 0; 384 } 385 386 std::string executable; 387 std::string jobcommand; 388 }; 308 389 309 390 int main(int argc, char* argv[]) … … 345 426 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); 346 427 boost::program_options::notify(vm); 347 348 if (vm.count("help")) { 349 std::cout << desc << "\n"; 350 return 1; 351 } 352 353 if (vm.count("verbosity")) { 354 LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << "."); 355 setVerbosity(vm["verbosity"].as<size_t>()); 356 } else { 357 LOG(0, "STATUS: Verbosity level was not set, defaulting to 5."); 358 setVerbosity(5); 359 } 360 361 std::string server; 362 std::string serverport; 363 if (vm.count("server")) { 364 server = vm["server"].as< std::string >(); 365 serverport = server.substr(server.find_last_of(':')+1, std::string::npos); 366 server = server.substr(0, server.find_last_of(':')); 367 try { 368 boost::lexical_cast<size_t>(serverport); 369 } catch (boost::bad_lexical_cast) { 370 ELOG(1, "Could not interpret " << serverport << " as server:port."); 371 return 255; 372 } 373 LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address."); 374 } else { 375 ELOG(1, "Requiring server's address (host:port) to connect to."); 376 return 255; 377 } 378 379 if (!vm.count("command")) { 380 ELOG(1, "Controller requires one of the following commands: "+toString(Commands)); 381 return 255; 382 } 383 const std::string command = vm["command"].as< std::string >(); 384 const CommandIndices commandIndex = getCommandIndex(CommandsMap, command); 428 ControllerOptions_SystemCommandJob ControllerInfo; 429 430 ControllerInfo.parseHelp(vm, desc); 431 432 ControllerInfo.parseVerbosity(vm); 433 434 ControllerInfo.parseServerPort(vm); 435 436 ControllerInfo.parseCommand(vm, Commands); 437 const CommandIndices commandIndex = getCommandIndex(CommandsMap, ControllerInfo.command); 438 439 ControllerInfo.parseExecutable(vm); 440 441 ControllerInfo.parseJobCommand(vm); 385 442 386 443 // check arguments 387 444 switch(commandIndex) { 388 445 case AddJobsIndex: 389 if (!vm.count("executable") && !vm.count("jobfiles")) {390 ELOG(1, "'"+command+"' requires at least two options: [executable] [list of input files ...].");391 return 255;392 }393 break;394 446 case CreateJobsIndex: 395 if (!vm.count("executable") && !vm.count("jobcommand")) {396 ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand].");397 return 255;398 }399 447 break; 400 448 case CheckResultsIndex: … … 404 452 case ReceiveMPQCIndex: 405 453 if (!vm.count("fragment-path")) { 406 ELOG(1, "'"+ command+"' require one option: [path to fragment files].");454 ELOG(1, "'"+ControllerInfo.command+"' require one option: [path to fragment files]."); 407 455 return 255; 408 456 } … … 414 462 case UnknownCommandIndex: 415 463 default: 416 ELOG(1, "Unrecognized command '"+toString( command)+"'.");464 ELOG(1, "Unrecognized command '"+toString(ControllerInfo.command)+"'."); 417 465 return 255; 418 466 break; … … 429 477 switch(commandIndex) { 430 478 case AddJobsIndex: 431 controller.requestIds( server,serverport, vm["jobfiles"].as< std::vector<std::string> >().size());479 controller.requestIds(ControllerInfo.server, ControllerInfo.serverport, vm["jobfiles"].as< std::vector<std::string> >().size()); 432 480 break; 433 481 case CreateJobsIndex: 434 controller.requestIds( server,serverport, 1);482 controller.requestIds(ControllerInfo.server, ControllerInfo.serverport, 1); 435 483 break; 436 484 case CheckResultsIndex: … … 446 494 case UnknownCommandIndex: 447 495 default: 448 ELOG(0, "Unrecognized command '"+toString( command)+"'.");496 ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'."); 449 497 return 255; 450 498 break; … … 474 522 } 475 523 controller.addJobs(jobs); 476 controller.sendJobs( server,serverport);524 controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport); 477 525 break; 478 526 } … … 481 529 const JobId_t next_id = controller.getAvailableId(); 482 530 std::vector<FragmentJob::ptr> jobs; 483 const std::string executable = vm["executable"].as< std::string >(); 484 const std::string jobcommand = vm["jobcommand"].as< std::string >(); 485 createjobs(jobs, executable, jobcommand, next_id); 531 createjobs(jobs, ControllerInfo.executable, ControllerInfo.jobcommand, next_id); 486 532 controller.addJobs(jobs); 487 controller.sendJobs( server,serverport);533 controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport); 488 534 break; 489 535 } 490 536 case CheckResultsIndex: 491 controller.checkResults( server,serverport);537 controller.checkResults(ControllerInfo.server, ControllerInfo.serverport); 492 538 break; 493 539 case ReceiveResultsIndex: 494 540 case ReceiveMPQCIndex: 495 controller.receiveResults( server,serverport);541 controller.receiveResults(ControllerInfo.server, ControllerInfo.serverport); 496 542 break; 497 543 case RemoveAllIndex: 498 controller.removeall( server,serverport);544 controller.removeall(ControllerInfo.server, ControllerInfo.serverport); 499 545 break; 500 546 case ShutdownIndex: 501 controller.shutdown( server,serverport);547 controller.shutdown(ControllerInfo.server, ControllerInfo.serverport); 502 548 break; 503 549 case UnknownCommandIndex: 504 550 default: 505 ELOG(0, "Unrecognized command '"+toString( command)+"'.");551 ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'."); 506 552 return 255; 507 553 break; … … 549 595 case UnknownCommandIndex: 550 596 default: 551 ELOG(0, "Unrecognized command '"+toString( command)+"'.");597 ELOG(0, "Unrecognized command '"+toString(ControllerInfo.command)+"'."); 552 598 return 255; 553 599 break;
Note:
See TracChangeset
for help on using the changeset viewer.