source: src/JobMarket/Controller/controller_SystemCommandJob.cpp@ 404d2b

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 404d2b was 404d2b, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/JobMarket/' content from commit e194722

git-subtree-dir: ThirdParty/JobMarket
git-subtree-split: e19472277e62c493f6c10f1483fe21e64c1039e9

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Project: JobMarket
3 * Description: asynchronous Server/Controller/Client-approach to parallel computing, based on boost::asio
4 * Copyright (C) 2012 Frederik Heber. All rights reserved.
5 *
6 */
7
8/*
9 * controller_SystemCommandJob.cpp
10 *
11 * Created on: 01.06.2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20// boost asio needs specific operator new
21#include <boost/asio.hpp>
22
23#include "CodePatterns/MemDebug.hpp"
24
25#include "JobMarket/Controller/controller_SystemCommandJob.hpp"
26
27#include <boost/assign.hpp>
28#include <boost/bind.hpp>
29#include "CodePatterns/Log.hpp"
30#include <vector>
31
32#include "JobMarket/Controller/ControllerCommand.hpp"
33#include "JobMarket/Controller/ControllerCommandRegistry.hpp"
34#include "JobMarket/Controller/ControllerOptions_SystemCommandJob.hpp"
35#include "JobMarket/Controller/FragmentController.hpp"
36#include "JobMarket/Jobs/NoOpJob.hpp"
37#include "JobMarket/Jobs/SystemCommandJob.hpp"
38#include "JobMarket/Results/FragmentResult.hpp"
39#include "JobMarket/types.hpp"
40
41
42/** Print received results.
43 *
44 * @param results received results to print
45 */
46void printReceivedResults(const std::vector<FragmentResult::ptr> &results)
47{
48 for (std::vector<FragmentResult::ptr>::const_iterator iter = results.begin();
49 iter != results.end(); ++iter)
50 LOG(1, "RESULT: job #"+toString((*iter)->getId())+": "+toString((*iter)->result));
51}
52
53/** Creates a SystemCommandJob out of give \a command with \a argument.
54 *
55 * @param controller reference to controller to add jobs
56 * @param ControllerInfo information on the job
57 */
58void createJobs(FragmentController &controller, const ControllerOptions_SystemCommandJob &ControllerInfo)
59{
60 if ((!ControllerInfo.jobcommand.empty()) && (!ControllerInfo.executable.empty())) {
61 LOG(2, "DEBUG: Creating " << ControllerInfo.times << " new SystemCommandJob(s) with '"
62 +toString(ControllerInfo.executable)+"' and argument '"
63 +toString(ControllerInfo.jobcommand)+"'.");
64 std::vector<FragmentJob::ptr> jobs;
65 for (size_t times=ControllerInfo.times; times--;) {
66 const JobId_t next_id = controller.getAvailableId();
67 FragmentJob::ptr testJob(
68 new SystemCommandJob(ControllerInfo.executable, ControllerInfo.jobcommand, next_id) );
69 jobs.push_back(testJob);
70 }
71 controller.addJobs(jobs);
72 controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
73 LOG(1, "INFO: Added SystemCommandJobs.");
74 } else {
75 LOG(2, "DEBUG: Creating " << ControllerInfo.times << " new NoOpJob(s).");
76 std::vector<FragmentJob::ptr> jobs;
77 for (size_t times=ControllerInfo.times; times--;) {
78 const JobId_t next_id = controller.getAvailableId();
79 FragmentJob::ptr testJob( new NoOpJob(next_id) );
80 jobs.push_back(testJob);
81 }
82 controller.addJobs(jobs);
83 controller.sendJobs(ControllerInfo.server, ControllerInfo.serverport);
84 LOG(1, "INFO: Added NoOpJobs.");
85 }
86}
87
88inline std::vector<std::string> getListOfCommands(const ControllerCommandRegistry &ControllerCommands)
89{
90 std::vector<std::string> Commands;
91 for (ControllerCommandRegistry::const_iterator iter = ControllerCommands.getBeginIter();
92 iter != ControllerCommands.getEndIter(); ++iter)
93 Commands.push_back(iter->first);
94
95 return Commands;
96}
97
98ControllerOptions *controller_SystemCommandJob::allocateControllerInfo()
99{
100 return new ControllerOptions_SystemCommandJob();
101}
102
103void controller_SystemCommandJob::addSpecificCommands(
104 boost::function<void (ControllerCommand *)> &registrator,
105 FragmentController &controller,
106 ControllerOptions &ControllerInfo)
107{
108 ControllerOptions_SystemCommandJob &CI =
109 reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
110 registrator(new ControllerCommand("createjobs",
111 boost::assign::list_of< ControllerCommand::commands_t >
112 (boost::bind(&FragmentController::requestIds,
113 boost::ref(controller),
114 boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport), boost::cref(CI.times)))
115 (boost::bind(&createJobs, boost::ref(controller), boost::cref(CI)))
116 ));
117 registrator(new ControllerCommand("receiveresults",
118 boost::assign::list_of< ControllerCommand::commands_t >
119 (boost::bind(&FragmentController_JobIdProxy::setJobids,
120 boost::ref(controller), boost::cref(CI.ids)))
121 (boost::bind(&FragmentController::receiveResults,
122 boost::ref(controller), boost::cref(ControllerInfo.server), boost::cref(ControllerInfo.serverport)))
123 (boost::bind(&printReceivedResults,
124 boost::bind(&FragmentController::getReceivedResults, boost::ref(controller))))
125 ));
126}
127
128void controller_SystemCommandJob::addSpecificOptions(
129 boost::program_options::options_description_easy_init option)
130{
131 option
132 ("jobcommand", boost::program_options::value< std::string >(), "command argument for executable for 'createjobs'")
133 ("executable", boost::program_options::value< std::string >(), "executable for commands 'createjobs'")
134 ("ids", boost::program_options::value< std::vector<JobId_t> >()->multitoken(), "ids to receive for 'receiveresults'")
135 ("times", boost::program_options::value< size_t >(), "sets the number of times the 'createjobs' job is added")
136 ;
137}
138
139int controller_SystemCommandJob::addOtherParsings(
140 ControllerOptions &ControllerInfo,
141 boost::program_options::variables_map &vm)
142{
143 ControllerOptions_SystemCommandJob &CI =
144 reinterpret_cast<ControllerOptions_SystemCommandJob &>(ControllerInfo);
145 int status = 0;
146 status = CI.parseExecutable(vm);
147 if (status) return status;
148 status = CI.parseJobCommand(vm);
149 if (status) return status;
150 status = CI.parseTimes(vm);
151 if (status) return status;
152 status = CI.parseIds(vm);
153 return status;
154}
Note: See TracBrowser for help on using the repository browser.