source: src/Fragmentation/Automation/Controller/FragmentController.hpp@ 73d6fc

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 Candidate_v1.7.0 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
Last change on this file since 73d6fc was 73d6fc, checked in by Frederik Heber <heber@…>, 13 years ago

Shifted all Controller stuff into own subfolder, extract class Operation.

  • Property mode set to 100644
File size: 6.4 KB
RevLine 
[db03d9]1/*
2 * FragmentController.hpp
3 *
4 * Created on: Nov 27, 2011
5 * Author: heber
6 */
7
8#ifndef FRAGMENTCONTROLLER_HPP_
9#define FRAGMENTCONTROLLER_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <boost/asio.hpp>
17#include <string>
18#include <vector>
19
20#include "Connection.hpp"
21#include "FragmentJob.hpp"
22#include "FragmentResult.hpp"
23
[73d6fc]24#include "Controller/Commands/Operation.hpp"
25
[db03d9]26/** The FragmentController sends bunches of jobs to a FragmentScheduler,
27 * waits for their calculation and is called when they are done. Then,
28 * he loads the bunch of results from the Scheduler.
29 *
30 * While the FragmentScheduler and FragmentWorker rather act on their own
31 * this is the piece to implant into the user software to allow for
32 * communication with the Server/Worker duo to perform the calculation
33 * of the fragments on distant computers.
34 */
35class FragmentController
36{
37public:
[5adb84]38 FragmentController(boost::asio::io_service& io_service, const std::string& _host, const std::string& _service);
[db03d9]39 ~FragmentController();
40
[5adb84]41 class ReceiveJobsOperation : public Operation {
42 public:
43 /// Constructor for class ReceiveJobsOperation.
44 ReceiveJobsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
45 Operation(_connection, _host, _service) {}
46 /// Destructor for class ReceiveJobsOperation
47 ~ReceiveJobsOperation() {}
[db03d9]48
[5adb84]49 public:
50 /// Placing receive jobs operations into an io_service
51 virtual void operator()();
[778abb]52
[5adb84]53 /// Handle completion of a calculate operation.
54 void handle_connect_calc(const boost::system::error_code& e,
55 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
[0196c6]56
[5adb84]57 /// Callback function when bunch of jobs have been sent.
58 void handle_SendJobs(const boost::system::error_code& e);
[778abb]59
[5adb84]60 /// Handle completion of an operation.
61 void handle_FinishOperation(const boost::system::error_code& e);
[3c4a5e]62
[5adb84]63 /// internal function to connect to server and send jobs for calculation
64 void connect_calc();
[3c4a5e]65
[5adb84]66 /// Setter for jobs
67 void addJobs(const std::vector<FragmentJob> &jobs);
[dba6d1]68
[5adb84]69 /// Getter for number of size of jobs
70 size_t getPresentJobs() const;
71
72 protected:
73 /// bunch of jobs
74 std::vector<FragmentJob> jobs;
75 };
[db03d9]76
[5adb84]77 struct CheckResultsOperation : public Operation {
78 public:
79 /// Constructor for class CheckResultsOperation.
80 CheckResultsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
81 Operation(_connection, _host, _service),
82 doneJobs(0)
83 {}
84 /// Destructor for class CheckResultsOperation
85 ~CheckResultsOperation() {}
[db03d9]86
[5adb84]87 public:
88 // placing receive jobs operations into an io_service
89 virtual void operator()();
[3c4a5e]90
[5adb84]91 /// Handle completion of a CheckResults operation.
92 void handle_connect_check(const boost::system::error_code& e,
93 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
[778abb]94
[5adb84]95 /// Callback function when doneJobs have been received.
96 void handle_ReceiveDoneJobs(const boost::system::error_code& e);
[0196c6]97
[5adb84]98 /// Handle completion of an operation.
99 void handle_FinishOperation(const boost::system::error_code& e);
[db03d9]100
[5adb84]101 /// internal function to connect to server and check done jobs
102 void connect_check();
103
104 /// Getter for doneJobs
105 size_t getDoneJobs() const;
106
107 protected:
108 /// currently calculated results
109 size_t doneJobs;
110 };
111
112 struct SendResultsOperation : public Operation {
113 public:
114 /// Constructor for class SendResultsOperation.
115 SendResultsOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
116 Operation(_connection, _host, _service) {}
117 /// Destructor for class SendResultsOperation
118 ~SendResultsOperation() {}
119
120 public:
121 // placing receive jobs operations into an io_service
122 virtual void operator()();
123
124 /// Handle completion of a GetResults operation.
125 void handle_connect_get(const boost::system::error_code& e,
126 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
127
[73d6fc]128 /// Callback function when results are about to be received.
129 void handle_ReceivingResults(const boost::system::error_code& e);
[5adb84]130
[73d6fc]131 /// Callback function when results have been received.
132 void handle_ReceivedResults(const boost::system::error_code& e);
[5adb84]133
134 /// internal function to connect to server and receive calculated results
135 void connect_get();
136
137 /// Getter for results
138 std::vector<FragmentResult> getResults();
139
140 protected:
141 /// bunch of results
142 std::vector<FragmentResult> results;
143 };
144
145 struct ShutdownOperation : public Operation {
146 public:
147 /// Constructor for class ShutdownOperation.
148 ShutdownOperation(Connection &_connection, const std::string& _host, const std::string& _service) :
149 Operation(_connection, _host, _service) {}
150 /// Destructor for class ShutdownOperation
151 ~ShutdownOperation() {}
152
153 public:
154 // placing receive jobs operations into an io_service
155 virtual void operator()();
156
157 /// Handle completion of a Shutdown operation.
158 void handle_connect_shutdown(const boost::system::error_code& e,
159 boost::asio::ip::tcp::resolver::iterator endpoint_iterator);
160
161 /// internal function to connect to server and receive calculated results
162 void connect_shutdown();
163
164 };
165
166protected:
[db03d9]167 /// The Connection to the server.
168 Connection connection_;
169
[5adb84]170public:
[db03d9]171
[5adb84]172 ReceiveJobsOperation recjobs;
173 CheckResultsOperation checkres;
174 SendResultsOperation sendres;
175 ShutdownOperation shutdown;
176
177 // get the exit flag of the last operations
178 size_t getExitflag() const
179 {
180 if (recjobs.getExitflag() != 0)
181 return recjobs.getExitflag();
182 if (checkres.getExitflag() != 0)
183 return checkres.getExitflag();
184 if (sendres.getExitflag() != 0)
185 return sendres.getExitflag();
186 if (shutdown.getExitflag() != 0)
187 return shutdown.getExitflag();
188 return 0;
189 }
190
191 /// place number of jobs into this controller
192 void addJobs(const std::vector<FragmentJob> &jobs)
193 {
194 recjobs.addJobs(jobs);
195 }
[db03d9]196
[5adb84]197 /// get the results for the current jobs
198 std::vector<FragmentResult> getResults()
199 {
200 return sendres.getResults();
201 }
[db03d9]202
[5adb84]203 /// Getter for doneJobs
204 size_t getDoneJobs() const
205 {
206 return checkres.getDoneJobs();
207 }
[3c4a5e]208
[5adb84]209 /// Getter for number of jobs in the queue
210 size_t getPresentJobs() const
211 {
212 return recjobs.getPresentJobs();
213 }
[778abb]214
[5adb84]215private:
216 /// host name of server
217 const std::string host;
218
219 // service to connect to to
220 const std::string service;
[db03d9]221};
222
223#endif /* FRAGMENTCONTROLLER_HPP_ */
Note: See TracBrowser for help on using the repository browser.