Changeset af9b9ff for src/Fragmentation
- Timestamp:
- Jul 2, 2012, 8:32:06 AM (12 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:
- e48f5c
- Parents:
- 267b8d
- git-author:
- Frederik Heber <heber@…> (05/03/12 12:46:59)
- git-committer:
- Frederik Heber <heber@…> (07/02/12 08:32:06)
- Location:
- src/Fragmentation/Automation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Automation/Makefile.am
r267b8d raf9b9ff 147 147 $(BOOST_ASIO_LIBS) \ 148 148 $(BOOST_SERIALIZATION_LIBS) \ 149 $(BOOST_PROGRAM_OPTIONS_LIBS) \ 149 150 $(BOOST_THREAD_LIBS) \ 150 151 $(BOOST_SYSTEM_LIBS) \ -
src/Fragmentation/Automation/controller.cpp
r267b8d raf9b9ff 29 29 #include <boost/archive/text_oarchive.hpp> 30 30 #include <boost/archive/text_iarchive.hpp> 31 #include <boost/program_options.hpp> 31 32 #include <fstream> 32 33 #include <iostream> … … 324 325 CommandsMap.insert( std::make_pair("removeall", RemoveAllIndex) ); 325 326 CommandsMap.insert( std::make_pair("shutdown", ShutdownIndex) ); 327 std::vector<std::string> Commands; 328 for (CommandsMap_t::const_iterator iter = CommandsMap.begin(); iter != CommandsMap.end(); ++iter) 329 Commands.push_back(iter->first); 330 331 // Declare the supported options. 332 boost::program_options::options_description desc("Allowed options"); 333 desc.add_options() 334 ("help,h", "produce help message") 335 ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level") 336 ("server", boost::program_options::value< std::string >(), "connect to server at this address (host:port)") 337 ("command", boost::program_options::value< std::string >(), (std::string("command to send to server: ")+toString(Commands)).c_str()) 338 ("executable", boost::program_options::value< std::string >(), "executable for commands 'addjobs' and 'createjobs'") 339 ("fragment-path", boost::program_options::value< std::string >(), "path to fragment files for 'receivempqcresults'") 340 ("jobcommand", boost::program_options::value< std::string >(), "command argument for executable for 'createjobs'") 341 ("jobfiles", boost::program_options::value< std::vector< std::string > >()->multitoken(), "list of files as single argument to executable for 'addjobs'") 342 ; 343 344 boost::program_options::variables_map vm; 345 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); 346 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); 385 386 // check arguments 387 switch(commandIndex) { 388 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 case CreateJobsIndex: 395 if (!vm.count("executable") && !vm.count("jobcommand")) { 396 ELOG(1, "'"+command+"' requires two options: [executable] [jobcommand]."); 397 return 255; 398 } 399 break; 400 case CheckResultsIndex: 401 break; 402 case ReceiveResultsIndex: 403 break; 404 case ReceiveMPQCIndex: 405 if (!vm.count("fragment-path")) { 406 ELOG(1, "'"+command+"' require one option: [path to fragment files]."); 407 return 255; 408 } 409 break; 410 case RemoveAllIndex: 411 break; 412 case ShutdownIndex: 413 break; 414 case UnknownCommandIndex: 415 default: 416 ELOG(1, "Unrecognized command '"+toString(command)+"'."); 417 return 255; 418 break; 419 } 420 326 421 try 327 422 { 328 // Check command line arguments.329 if (argc < 4)330 {331 std::cerr << "Usage: " << argv[0] << " <host> <port> <command> [options to command]" << std::endl;332 std::cerr << "List of available commands:" << std::endl;333 for(CommandsMap_t::const_iterator iter = CommandsMap.begin();334 iter != CommandsMap.end(); ++iter) {335 std::cerr << "\t" << iter->first << std::endl;336 }337 return false;338 }339 423 340 424 boost::asio::io_service io_service; … … 343 427 // Initial phase: information gathering from server 344 428 345 switch( getCommandIndex(CommandsMap, argv[3])) {429 switch(commandIndex) { 346 430 case AddJobsIndex: 347 { 348 if (argc < 6) { 349 ELOG(1, "'addjobs' requires at least two options: [mpqc] [list of input files ...]."); 350 return 255; 351 } else { 352 // get an id for every filename 353 controller.requestIds(argv[1], argv[2], argc-5); 354 } 355 break; 356 } 431 controller.requestIds(server, serverport, vm["jobfiles"].as< std::vector<std::string> >().size()); 432 break; 357 433 case CreateJobsIndex: 358 { 359 std::vector<FragmentJob::ptr> jobs; 360 if (argc < 6) { 361 return 255; 362 ELOG(1, "'createjobs' requires two options: [command] [argument]."); 363 } else { 364 controller.requestIds(argv[1], argv[2], 1); 365 } 366 break; 367 } 434 controller.requestIds(server, serverport, 1); 435 break; 368 436 case CheckResultsIndex: 369 437 break; … … 371 439 break; 372 440 case ReceiveMPQCIndex: 373 if (argc < 5) {374 ELOG(1, "'receivempqc' require one option: [path to fragment files].");375 return 255;376 }377 441 break; 378 442 case RemoveAllIndex: … … 382 446 case UnknownCommandIndex: 383 447 default: 384 ELOG( 1, "Unrecognized command '"+toString(argv[3])+"'.");448 ELOG(0, "Unrecognized command '"+toString(command)+"'."); 385 449 return 255; 386 450 break; … … 395 459 // Second phase: Building jobs and sending information to server 396 460 397 switch( getCommandIndex(CommandsMap, argv[3])) {461 switch(commandIndex) { 398 462 case AddJobsIndex: 399 463 { 400 464 std::vector<FragmentJob::ptr> jobs; 401 const std::string command(argv[4]); 402 for (int argcount = 5; argcount < argc; ++argcount) { 465 const std::string executable(vm["executable"].as< std::string >()); 466 const std::vector< std::string > jobfiles = vm["jobfiles"].as< std::vector< std::string > >(); 467 for (std::vector< std::string >::const_iterator iter = jobfiles.begin(); 468 iter != jobfiles.end(); ++iter) { 403 469 const JobId_t next_id = controller.getAvailableId(); 404 const std::string filename(argv[argcount]);470 const std::string &filename = *iter; 405 471 LOG(1, "INFO: Creating MPQCCommandJob with filename'" 406 472 +filename+"', and id "+toString(next_id)+"."); 407 parsejob(jobs, command, filename, next_id);473 parsejob(jobs, executable, filename, next_id); 408 474 } 409 475 controller.addJobs(jobs); 410 controller.sendJobs( argv[1], argv[2]);476 controller.sendJobs(server, serverport); 411 477 break; 412 478 } … … 415 481 const JobId_t next_id = controller.getAvailableId(); 416 482 std::vector<FragmentJob::ptr> jobs; 417 createjobs(jobs, argv[4], argv[5], next_id); 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); 418 486 controller.addJobs(jobs); 419 controller.sendJobs( argv[1], argv[2]);487 controller.sendJobs(server, serverport); 420 488 break; 421 489 } 422 490 case CheckResultsIndex: 423 { 424 controller.checkResults(argv[1], argv[2]); 425 break; 426 } 491 controller.checkResults(server, serverport); 492 break; 427 493 case ReceiveResultsIndex: 428 {429 controller.receiveResults(argv[1], argv[2]);430 break;431 }432 494 case ReceiveMPQCIndex: 433 { 434 controller.receiveResults(argv[1], argv[2]); 435 break; 436 } 495 controller.receiveResults(server, serverport); 496 break; 437 497 case RemoveAllIndex: 438 { 439 controller.removeall(argv[1], argv[2]); 440 break; 441 } 498 controller.removeall(server, serverport); 499 break; 442 500 case ShutdownIndex: 443 { 444 controller.shutdown(argv[1], argv[2]); 445 break; 446 } 501 controller.shutdown(server, serverport); 502 break; 447 503 case UnknownCommandIndex: 448 504 default: 449 ELOG(0, "Unrecognized command '"+toString( argv[3])+"'.");505 ELOG(0, "Unrecognized command '"+toString(command)+"'."); 450 506 return 255; 451 507 break; … … 460 516 // Final phase: Print result of command 461 517 462 switch( getCommandIndex(CommandsMap, argv[3])) {518 switch(commandIndex) { 463 519 case AddJobsIndex: 464 520 case CreateJobsIndex: 465 521 break; 466 522 case CheckResultsIndex: 467 {468 523 controller.printDoneJobs(); 469 524 break; 470 }471 525 case ReceiveResultsIndex: 472 526 { … … 477 531 case ReceiveMPQCIndex: 478 532 { 479 const std::string path = argv[4];533 const std::string path = vm["fragment-path"].as< std::string >(); 480 534 LOG(1, "INFO: Parsing fragment files from " << path << "."); 481 535 std::vector<FragmentResult::ptr> results = controller.getReceivedResults(); … … 492 546 case UnknownCommandIndex: 493 547 default: 494 ELOG(0, "Unrecognized command '"+toString( argv[3])+"'.");548 ELOG(0, "Unrecognized command '"+toString(command)+"'."); 495 549 return 255; 496 550 break;
Note:
See TracChangeset
for help on using the changeset viewer.