Changeset 5ac92e


Ignore:
Timestamp:
Jul 2, 2012, 8:32:03 AM (12 years ago)
Author:
Frederik Heber <heber@…>
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:
012c98
Parents:
dc759c
git-author:
Frederik Heber <heber@…> (04/25/12 10:27:55)
git-committer:
Frederik Heber <heber@…> (07/02/12 08:32:03)
Message:

PoolWorker now parses command line options via boost::program_options.

  • all of poolworkers command line arguments are now parsed via boost::program_options.
  • As a sideeffect multiple signals may now be specified to catch on the command line.
  • TESTFIX: Usage of poolworker has changed, hence adapted regression tests.
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Automation/Makefile.am

    rdc759c r5ac92e  
    160160  $(BOOST_ASIO_LIBS) \
    161161  $(BOOST_SERIALIZATION_LIBS) \
     162  $(BOOST_PROGRAM_OPTIONS_LIBS) \
    162163  $(BOOST_THREAD_LIBS) \
    163164  $(BOOST_SYSTEM_LIBS) \
  • src/Fragmentation/Automation/poolworker.cpp

    rdc759c r5ac92e  
    2828
    2929#include <iostream>
     30#include <boost/program_options.hpp>
    3031#include <boost/lexical_cast.hpp>
    3132#include <signal.h>
     33#include <vector>
    3234
    3335#include "atexit.hpp"
     
    3638#include "Pool/PoolWorker.hpp"
    3739
     40//!> global shutdown function
    3841boost::function<void (int)> shutdownfunction;
     42//!> global signal vector for later releasing
     43std::vector<size_t> signals;
    3944
    4045void signalhandler(int sig)
    4146{
     47  // shutdown if we have handler
    4248  if (shutdownfunction)
    4349    shutdownfunction(sig);
    44   signal(SIGINT, NULL);
     50
     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);
    4555}
    4656
     
    5161  atexit(cleanUp);
    5262
    53   setVerbosity(3);
     63  // Declare the supported options.
     64  boost::program_options::options_description desc("Allowed options");
     65  desc.add_options()
     66      ("help,h", "produce help message")
     67      ("verbosity,v", boost::program_options::value<size_t>(), "set verbosity level")
     68      ("signal", boost::program_options::value< std::vector<size_t> >(), "set signal to catch (can be given multiple times)")
     69      ("server", boost::program_options::value< std::string>(), "connect to server at this address (host:port)")
     70      ("listen", boost::program_options::value< std::string >(), "listen on this port")
     71      ("hostname", boost::program_options::value< std::string>(), "name of host on which this codes runs and which server can resolve")
     72  ;
     73
     74  boost::program_options::variables_map vm;
     75  boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
     76  boost::program_options::notify(vm);
     77
     78  if (vm.count("help")) {
     79    std::cout << desc << "\n";
     80    return 1;
     81  }
     82
     83  if (vm.count("verbosity")) {
     84    LOG(0, "STATUS: Verbosity level was set to " << vm["verbosity"].as<size_t>() << ".");
     85    setVerbosity(vm["verbosity"].as<size_t>());
     86  } else {
     87    LOG(0, "STATUS: Verbosity level was not set, defaulting to 5.");
     88    setVerbosity(5);
     89  }
     90
     91  std::string server;
     92  std::string serverport;
     93  if (vm.count("server")) {
     94    server = vm["server"].as< std::string >();
     95    serverport = server.substr(server.find_last_of(':')+1, std::string::npos);
     96    server = server.substr(0, server.find_last_of(':'));
     97    try {
     98      boost::lexical_cast<size_t>(serverport);
     99    } catch (boost::bad_lexical_cast) {
     100      ELOG(1, "Could not interpret " << serverport << " as server:port.");
     101      return 255;
     102    }
     103    LOG(1, "INFO: Using " << server << ":" << serverport << " as server's address.");
     104  } else {
     105    ELOG(1, "Requiring server's address (host:port) to connect to.");
     106    return 255;
     107  }
     108
     109  std::string hostname("localhost");
     110  if (vm.count("hostname")) {
     111    hostname = vm["hostname"].as< std::string >();
     112    LOG(1, "INFO: Using " << hostname << " as host's name.");
     113  } else {
     114    ELOG(1, "Requiring port to listen on .");
     115    return 255;
     116  }
     117
     118  std::string listenport;
     119  if (vm.count("listen")) {
     120    try {
     121      listenport = vm["listen"].as< std::string >();
     122    } catch (boost::bad_lexical_cast) {
     123      ELOG(1, "Could not read " << vm["listen"].as< std::string >() << " as digits.");
     124      return 255;
     125    }
     126    LOG(1, "INFO: Using port " << listenport << " to listen to server connects.");
     127  } else {
     128    ELOG(1, "Requiring port to listen on .");
     129    return 255;
     130  }
    54131
    55132  size_t exitflag = 0;
    56133  try
    57134  {
    58     // Check command line arguments.
    59     if (argc != 5)
    60     {
    61       std::cerr << "Usage: " << argv[0] << " <host> <port> <listenhost> <listenport>" << std::endl;
    62       return 1;
    63     }
    64 
    65135    boost::asio::io_service io_service;
    66     PoolWorker client(io_service, argv[1], argv[2], argv[3], argv[4]);
     136    PoolWorker client(io_service, server, serverport, hostname, listenport);
    67137
    68138    // catch ctrl-c and shutdown worker properly
    69139    shutdownfunction = boost::bind(&PoolWorker::shutdown, boost::ref(client), _1);
    70 //    signal(SIGABRT, &signalhandler);
    71 //    signal(SIGTERM, &signalhandler);
    72     signal(SIGINT, &signalhandler);
     140    if (vm.count("signal")) {
     141      signals =  vm["signal"].as< std::vector<size_t> >();
     142      for (std::vector<size_t>::const_iterator iter = signals.begin();
     143          iter != signals.end(); ++iter) {
     144        LOG(0, "STATUS: Catching signal " << *iter << " via signal handler.");
     145        signal(*iter, &signalhandler);
     146      }
     147    } else {
     148      LOG(0, "STATUS: No signals are caught.");
     149    }
    73150
    74151    // process io requests
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-addingjobs.at

    rdc759c r5ac92e  
    1919
    2020# enlist a worker to work on jobs
    21 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT &
     21${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT &
    2222worker_pid=$!
    2323AT_CHECK([sleep 1], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-completerun.at

    rdc759c r5ac92e  
    2727
    2828# enlist a worker to work on jobs
    29 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT &
     29${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT &
    3030worker_pid=$!
    3131AT_CHECK([sleep 2], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-enrollinpool.at

    rdc759c r5ac92e  
    1313AT_CHECK([sleep 1], 0, [ignore], [ignore], [kill $server_pid])
    1414
     15# check help of poolworker
     16AT_CHECK([${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -h], 1, [ignore], [ignore], [kill $server_pid])
     17
    1518# let worker enroll in pool
    16 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT &
     19${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT &
    1720worker_pid=$!
    1821AT_CHECK([sleep 1], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
    1922
    20 # send kill signal to worker such that it shuts down
    21 AT_CHECK([kill -INT $worker_pid], 0, [stdout], [ignore], [kill $server_pid $worker_pid])
     23# send kill signal to worker such that it shuts down properly
     24AT_CHECK([kill -2 $worker_pid], 0, [stdout], [ignore], [kill $server_pid $worker_pid])
    2225
    2326# shutdown server as well
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-mpqc-jobs.at

    rdc759c r5ac92e  
    2828
    2929# enlist a worker to work on jobs
    30 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT &
     30${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT &
    3131worker_pid=$!
    3232AT_CHECK([sleep 5], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-resubmitjobs.at

    rdc759c r5ac92e  
    1919
    2020# enlist a worker to work on jobs
    21 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT 2>workererr &
     21${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT 2>workererr &
    2222worker_pid=$!
    2323AT_CHECK([sleep 2], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
  • tests/regression/Fragmentation/Automation/testsuite-fragmentation-automation-server-worker.at

    rdc759c r5ac92e  
    1818
    1919# enlist a worker to work on jobs
    20 ${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker 127.0.0.1 $WORKERPORT 127.0.0.1 $WORKERLISTENPORT &
     20${AUTOTEST_PATH}/Fragmentation/Automation/PoolWorker -v 5 --signal 2 --server 127.0.0.1:${WORKERPORT} --hostname 127.0.0.1 --listen $WORKERLISTENPORT &
    2121worker_pid=$!
    2222AT_CHECK([sleep 2], 0, [ignore], [ignore], [kill $server_pid $worker_pid])
Note: See TracChangeset for help on using the changeset viewer.