Changeset c5324f for src/Actions


Ignore:
Timestamp:
Nov 8, 2012, 1:13:19 PM (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:
188639
Parents:
1e7dd4
git-author:
Frederik Heber <heber@…> (07/15/12 11:26:51)
git-committer:
Frederik Heber <heber@…> (11/08/12 13:13:19)
Message:

Refactored FragmentationAutomationAction, pulling out bracketed function parts into distinct functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/FragmentationAutomationAction.cpp

    r1e7dd4 rc5324f  
    276276}
    277277
    278 Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
    279   boost::asio::io_service io_service;
    280   FragmentController controller(io_service);
    281 
    282   // TODO: Have io_service run in second thread and merge with current again eventually
    283 
    284   // Phase One: obtain ids
    285   std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
    286   controller.requestIds(params.host.get(), params.port.get(), jobfiles.size());
    287   {
    288     io_service.reset();
    289     Info info("io_service: Phase One");
    290     io_service.run();
    291   }
    292   // Phase Two: create and add jobs
    293   {
    294     std::vector<FragmentJob::ptr> jobs;
    295     for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles .begin();
    296         iter != jobfiles .end(); ++iter) {
    297       const std::string &filename = (*iter).string();
    298       if (boost::filesystem::exists(filename)) {
    299         const JobId_t next_id = controller.getAvailableId();
    300         LOG(1, "INFO: Creating MPQCCommandJob with filename'"
    301             +filename+"', and id "+toString(next_id)+".");
    302         parsejob(jobs, params.executable.get().string(), filename, next_id);
    303       } else {
    304         ELOG(1, "Fragment job "+filename+" does not exist.");
    305         return Action::failure;
    306       }
     278
     279void RunService(
     280    boost::asio::io_service &io_service,
     281    std::string message)
     282{
     283  message = std::string("io_service: ") + message;
     284  io_service.reset();
     285  Info info(message.c_str());
     286  io_service.run();
     287}
     288
     289void requestIds(
     290    FragmentController &controller,
     291    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
     292    const size_t numberjobs)
     293{
     294  controller.requestIds(params.host.get(), params.port.get(), numberjobs);
     295}
     296
     297bool createJobsFromFiles(
     298    FragmentController &controller,
     299    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
     300    const std::vector< boost::filesystem::path > &jobfiles)
     301{
     302  std::vector<FragmentJob::ptr> jobs;
     303  for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
     304      iter != jobfiles .end(); ++iter) {
     305    const std::string &filename = (*iter).string();
     306    if (boost::filesystem::exists(filename)) {
     307      const JobId_t next_id = controller.getAvailableId();
     308      LOG(1, "INFO: Creating MPQCCommandJob with filename'"
     309          +filename+"', and id "+toString(next_id)+".");
     310      parsejob(jobs, params.executable.get().string(), filename, next_id);
     311    } else {
     312      ELOG(1, "Fragment job "+filename+" does not exist.");
     313      return false;
    307314    }
    308     controller.addJobs(jobs);
    309     controller.sendJobs(params.host.get(), params.port.get());
    310   }
    311   {
    312     io_service.reset();
    313     Info info("io_service: Phase Two");
    314     io_service.run();
    315   }
    316   // Phase Three: calculate result
     315  }
     316  controller.addJobs(jobs);
     317  controller.sendJobs(params.host.get(), params.port.get());
     318  return true;
     319}
     320
     321void WaitforResults(
     322    boost::asio::io_service &io_service,
     323    FragmentController &controller,
     324    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
     325    const size_t NoExpectedResults
     326    )
     327{
    317328  size_t NoCalculatedResults = 0;
    318   while (NoCalculatedResults != jobfiles.size()) {
     329  while (NoCalculatedResults != NoExpectedResults) {
    319330    // wait a bit
    320331    boost::asio::deadline_timer timer(io_service);
     
    323334    // then request status
    324335    controller.checkResults(params.host.get(), params.port.get());
    325     {
    326       io_service.reset();
    327       Info info("io_service: Phase Three");
    328       io_service.run();
    329     }
     336    RunService(io_service, "Checking on results");
     337
    330338    const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
    331339    LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
    332340    NoCalculatedResults = JobStatus.second;
    333341  }
     342}
     343
     344
     345Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
     346  boost::asio::io_service io_service;
     347  FragmentController controller(io_service);
     348
     349  // TODO: Have io_service run in second thread and merge with current again eventually
     350
     351  // Phase One: obtain ids
     352  std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
     353  requestIds(controller, params, jobfiles.size());
     354  RunService(io_service, "Requesting ids");
     355
     356  // Phase Two: create and add jobs
     357  if (!createJobsFromFiles(controller, params, jobfiles))
     358    return Action::failure;
     359  RunService(io_service, "Adding jobs");
     360
     361  // Phase Three: calculate result
     362  WaitforResults(io_service, controller, params, jobfiles.size());
     363
    334364  // Phase Three: get result
    335365  controller.receiveResults(params.host.get(), params.port.get());
    336   {
    337     io_service.reset();
    338     Info info("io_service: Phase Four");
    339     io_service.run();
    340   }
     366  RunService(io_service, "Phase Four");
     367
    341368  // Final phase: print result
    342369  {
Note: See TracChangeset for help on using the changeset viewer.