- Timestamp:
- May 17, 2012, 3:21:50 PM (13 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:
- d6fe76
- Parents:
- 73d6fc
- git-author:
- Frederik Heber <heber@…> (12/11/11 16:20:52)
- git-committer:
- Frederik Heber <heber@…> (05/17/12 15:21:50)
- Location:
- src/Fragmentation/Automation
- Files:
-
- 8 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Automation/Controller/FragmentController.cpp
r73d6fc r167b63 23 23 #include "CodePatterns/MemDebug.hpp" 24 24 25 #include <boost/bind.hpp>26 #include <boost/foreach.hpp>27 #include <iostream>28 #include <vector>29 25 #include "Connection.hpp" // Must come before boost/serialization headers. 30 #include <boost/serialization/vector.hpp>31 26 #include "CodePatterns/Info.hpp" 32 27 #include "CodePatterns/Log.hpp" 33 #include "FragmentJob.hpp"34 #include "FragmentResult.hpp"35 #include "ControllerChoices.hpp"36 28 37 29 #include "Controller/FragmentController.hpp" … … 49 41 const std::string& _service) : 50 42 connection_(io_service), 51 host(_host),52 service(_service),53 43 recjobs(connection_, _host, _service), 54 44 checkres(connection_, _host, _service), … … 65 55 {} 66 56 67 /** Handle connect operation to receive jobs from controller68 *69 * \param e error code if something went wrong70 * \param endpoint_iterator endpoint of the connection71 */72 void FragmentController::ReceiveJobsOperation::handle_connect_calc(const boost::system::error_code& e,73 boost::asio::ip::tcp::resolver::iterator endpoint_iterator)74 {75 Info info(__FUNCTION__);76 if (!e)77 {78 // Successfully established connection. Give choice.79 enum ControllerChoices choice = ReceiveJobs;80 connection_.async_write(choice,81 boost::bind(&FragmentController::ReceiveJobsOperation::handle_SendJobs, this,82 boost::asio::placeholders::error));83 } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {84 // Try the next endpoint.85 connection_.socket().close();86 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;87 connection_.socket().async_connect(endpoint,88 boost::bind(&FragmentController::ReceiveJobsOperation::handle_connect_calc, this,89 boost::asio::placeholders::error, ++endpoint_iterator));90 } else {91 // An error occurred. Log it and return. Since we are not starting a new92 // operation the io_service will run out of work to do and the client will93 // exit.94 Exitflag = ErrorFlag;95 ELOG(1, e.message());96 }97 }98 99 /** Callback function when an operation has been completed.100 *101 * \param e error code if something went wrong102 */103 void FragmentController::ReceiveJobsOperation::handle_FinishOperation(const boost::system::error_code& e)104 {105 Info info(__FUNCTION__);106 107 LOG(1, "INFO: Jobs have been sent. Clearing.");108 jobs.clear();109 110 Operation::handle_FinishOperation(e);111 }112 113 114 /** Handle connect operation to send number of done jobs.115 *116 * \param e error code if something went wrong117 * \param endpoint_iterator endpoint of the connection118 */119 void FragmentController::CheckResultsOperation::handle_connect_check(const boost::system::error_code& e,120 boost::asio::ip::tcp::resolver::iterator endpoint_iterator)121 {122 Info info(__FUNCTION__);123 if (!e)124 {125 // Successfully established connection. Give choice.126 enum ControllerChoices choice = CheckState;127 connection_.async_write(choice,128 boost::bind(&FragmentController::CheckResultsOperation::handle_ReceiveDoneJobs, this,129 boost::asio::placeholders::error));130 } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {131 // Try the next endpoint.132 connection_.socket().close();133 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;134 connection_.socket().async_connect(endpoint,135 boost::bind(&FragmentController::CheckResultsOperation::handle_connect_check, this,136 boost::asio::placeholders::error, ++endpoint_iterator));137 } else {138 // An error occurred. Log it and return. Since we are not starting a new139 // operation the io_service will run out of work to do and the client will140 // exit.141 Exitflag = ErrorFlag;142 ELOG(1, e.message());143 }144 }145 146 /** Handle connect operation to send results.147 *148 * \param e error code if something went wrong149 * \param endpoint_iterator endpoint of the connection150 */151 void FragmentController::SendResultsOperation::handle_connect_get(const boost::system::error_code& e,152 boost::asio::ip::tcp::resolver::iterator endpoint_iterator)153 {154 Info info(__FUNCTION__);155 if (!e)156 {157 // Successfully established connection. Give choice.158 enum ControllerChoices choice = SendResults;159 connection_.async_write(choice,160 boost::bind(&FragmentController::SendResultsOperation::handle_ReceivingResults, this,161 boost::asio::placeholders::error));162 } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {163 // Try the next endpoint.164 connection_.socket().close();165 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;166 connection_.socket().async_connect(endpoint,167 boost::bind(&FragmentController::SendResultsOperation::handle_connect_get, this,168 boost::asio::placeholders::error, ++endpoint_iterator));169 } else {170 // An error occurred. Log it and return. Since we are not starting a new171 // operation the io_service will run out of work to do and the client will172 // exit.173 Exitflag = ErrorFlag;174 ELOG(1, e.message());175 }176 }177 178 /** Handle connect operation to shutdown scheduler.179 *180 * \param e error code if something went wrong181 * \param endpoint_iterator endpoint of the connection182 */183 void FragmentController::ShutdownOperation::handle_connect_shutdown(const boost::system::error_code& e,184 boost::asio::ip::tcp::resolver::iterator endpoint_iterator)185 {186 Info info(__FUNCTION__);187 if (!e)188 {189 // Successfully established connection. Give choice.190 enum ControllerChoices choice = Shutdown;191 connection_.async_write(choice,192 boost::bind(&FragmentController::ShutdownOperation::handle_FinishOperation, this,193 boost::asio::placeholders::error));194 } else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator()) {195 // Try the next endpoint.196 connection_.socket().close();197 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;198 connection_.socket().async_connect(endpoint,199 boost::bind(&FragmentController::ShutdownOperation::handle_connect_shutdown, this,200 boost::asio::placeholders::error, ++endpoint_iterator));201 } else {202 // An error occurred. Log it and return. Since we are not starting a new203 // operation the io_service will run out of work to do and the client will204 // exit.205 Exitflag = ErrorFlag;206 ELOG(1, e.message());207 }208 }209 210 /** Callback function when jobs have been sent.211 *212 * \param e error code if something went wrong213 */214 void FragmentController::ReceiveJobsOperation::handle_SendJobs(const boost::system::error_code& e)215 {216 Info info(__FUNCTION__);217 if (!e)218 {219 // Successfully established connection. Start operation to read the vector220 // of jobs. The connection::async_write() function will automatically221 // encode the data that is written to the underlying socket.222 LOG(1, "INFO: Sending "+toString(jobs.size())+" jobs ...");223 connection_.async_write(jobs,224 boost::bind(&ReceiveJobsOperation::handle_FinishOperation, this,225 boost::asio::placeholders::error));226 }227 else228 {229 // An error occurred.230 Exitflag = ErrorFlag;231 ELOG(1, e.message());232 }233 234 // Since we are not starting a new operation the io_service will run out of235 // work to do and the client will exit.236 }237 238 /** Callback function when results have been received.239 *240 * \param e error code if something went wrong241 */242 void FragmentController::SendResultsOperation::handle_ReceivingResults(const boost::system::error_code& e)243 {244 Info info(__FUNCTION__);245 if (!e)246 {247 // The connection::async_read() function will automatically248 // decode the data that is written to the underlying socket.249 connection_.async_read(results,250 boost::bind(&FragmentController::SendResultsOperation::handle_ReceivedResults, this,251 boost::asio::placeholders::error));252 }253 else254 {255 // An error occurred.256 Exitflag = ErrorFlag;257 ELOG(1, e.message());258 }259 260 // Since we are not starting a new operation the io_service will run out of261 // work to do and the client will exit.262 }263 264 /** Callback function when doneJobs have been received.265 *266 * \param e error code if something went wrong267 */268 void FragmentController::SendResultsOperation::handle_ReceivedResults(const boost::system::error_code& e)269 {270 Info info(__FUNCTION__);271 272 LOG(1, "INFO: Received "+toString(results.size())+" results ...");273 274 handle_FinishOperation(e);275 }276 277 /** Callback function when doneJobs have been received.278 *279 * \param e error code if something went wrong280 */281 void FragmentController::CheckResultsOperation::handle_ReceiveDoneJobs(const boost::system::error_code& e)282 {283 Info info(__FUNCTION__);284 if (!e)285 {286 // The connection::async_read() function will automatically287 // decode the data that is written to the underlying socket.288 LOG(1, "INFO: Checking number of done jobs ...");289 connection_.async_read(doneJobs,290 boost::bind(&Operation::handle_FinishOperation, this,291 boost::asio::placeholders::error));292 }293 else294 {295 // An error occurred.296 Exitflag = ErrorFlag;297 ELOG(1, e.message());298 }299 }300 301 /** Internal function to connect to the endpoint of the server asynchronuously.302 *303 * We require internal connetion_ and host and service to be set up for this.304 */305 void FragmentController::ReceiveJobsOperation::connect_calc()306 {307 Info info(__FUNCTION__);308 // Resolve the host name into an IP address.309 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = getEndpointIterator();310 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;311 312 // Start an asynchronous connect operation.313 std::cout << "Connecting to endpoint " << endpoint << " to calc " << std::endl;314 connection_.socket().async_connect(endpoint,315 boost::bind(&FragmentController::ReceiveJobsOperation::handle_connect_calc, this,316 boost::asio::placeholders::error, ++endpoint_iterator));317 }318 319 /** Internal function to connect to the endpoint of the server asynchronuously.320 *321 * We require internal connetion_ and host and service to be set up for this.322 */323 void FragmentController::CheckResultsOperation::connect_check()324 {325 Info info(__FUNCTION__);326 // Resolve the host name into an IP address.327 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = getEndpointIterator();328 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;329 330 // Start an asynchronous connect operation.331 std::cout << "Connecting to endpoint " << endpoint << " to check " << std::endl;332 connection_.socket().async_connect(endpoint,333 boost::bind(&FragmentController::CheckResultsOperation::handle_connect_check, this,334 boost::asio::placeholders::error, ++endpoint_iterator));335 }336 337 /** Internal function to connect to the endpoint of the server asynchronuously.338 *339 * We require internal connetion_ and host and service to be set up for this.340 */341 void FragmentController::SendResultsOperation::connect_get()342 {343 Info info(__FUNCTION__);344 // Resolve the host name into an IP address.345 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = getEndpointIterator();346 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;347 348 // Start an asynchronous connect operation.349 std::cout << "Connecting to endpoint " << endpoint << " to get results " << std::endl;350 connection_.socket().async_connect(endpoint,351 boost::bind(&FragmentController::SendResultsOperation::handle_connect_get, this,352 boost::asio::placeholders::error, ++endpoint_iterator));353 }354 355 /** Internal function to connect to the endpoint of the server asynchronuously.356 *357 * We require internal connetion_ and host and service to be set up for this.358 */359 void FragmentController::ShutdownOperation::connect_shutdown()360 {361 Info info(__FUNCTION__);362 // Resolve the host name into an IP address.363 boost::asio::ip::tcp::resolver::iterator endpoint_iterator = getEndpointIterator();364 boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;365 366 // Start an asynchronous connect operation.367 std::cout << "Connecting to endpoint " << endpoint << " to get results " << std::endl;368 connection_.socket().async_connect(endpoint,369 boost::bind(&FragmentController::ShutdownOperation::handle_connect_shutdown, this,370 boost::asio::placeholders::error, ++endpoint_iterator));371 }372 373 /** Place number of jobs into this controller.374 *375 * \param _jobs jobs to add376 */377 void FragmentController::ReceiveJobsOperation::addJobs(const std::vector<FragmentJob> &_jobs)378 {379 jobs.reserve(jobs.size()+_jobs.size());380 BOOST_FOREACH(FragmentJob job, _jobs) {381 jobs.push_back(job);382 }383 }384 385 /** Prepares the calculation of the results for the current jobs.386 */387 void FragmentController::ReceiveJobsOperation::operator()()388 {389 Info info(__FUNCTION__);390 // connect391 connect_calc();392 //disconnect393 disconnect();394 }395 396 /** Prepares the calculation of the results for the current jobs.397 */398 void FragmentController::CheckResultsOperation::operator()()399 {400 Info info(__FUNCTION__);401 // connect402 connect_check();403 //disconnect404 disconnect();405 }406 407 /** Getter for results.408 *409 * \return vector of results for the added jobs (\sa addJobs()).410 */411 std::vector<FragmentResult> FragmentController::SendResultsOperation::getResults()412 {413 Info info(__FUNCTION__);414 return results;415 }416 417 /** Function to initiate receival of results.418 *419 */420 void FragmentController::SendResultsOperation::operator()()421 {422 // connect423 connect_get();424 //disconnect425 disconnect();426 }427 428 /** Function to initiate shutdown of server.429 *430 */431 void FragmentController::ShutdownOperation::operator()()432 {433 // connect434 connect_shutdown();435 //disconnect436 disconnect();437 }438 439 /** Getter for doneJobs.440 *441 * \sa checkResults()442 * \param doneJobs443 */444 size_t FragmentController::CheckResultsOperation::getDoneJobs() const445 {446 return doneJobs;447 }448 449 /** Getter for number of jobs present in the queue.450 *451 * \return jobs.size()452 */453 size_t FragmentController::ReceiveJobsOperation::getPresentJobs() const454 {455 return jobs.size();456 } -
src/Fragmentation/Automation/Controller/FragmentController.hpp
r73d6fc r167b63 23 23 24 24 #include "Controller/Commands/Operation.hpp" 25 #include "Controller/Commands/CheckResultsOperation.hpp" 26 #include "Controller/Commands/ReceiveJobsOperation.hpp" 27 #include "Controller/Commands/SendResultsOperation.hpp" 28 #include "Controller/Commands/ShutdownOperation.hpp" 25 29 26 30 /** The FragmentController sends bunches of jobs to a FragmentScheduler, … … 38 42 FragmentController(boost::asio::io_service& io_service, const std::string& _host, const std::string& _service); 39 43 ~FragmentController(); 40 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 ReceiveJobsOperation47 ~ReceiveJobsOperation() {}48 49 public:50 /// Placing receive jobs operations into an io_service51 virtual void operator()();52 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);56 57 /// Callback function when bunch of jobs have been sent.58 void handle_SendJobs(const boost::system::error_code& e);59 60 /// Handle completion of an operation.61 void handle_FinishOperation(const boost::system::error_code& e);62 63 /// internal function to connect to server and send jobs for calculation64 void connect_calc();65 66 /// Setter for jobs67 void addJobs(const std::vector<FragmentJob> &jobs);68 69 /// Getter for number of size of jobs70 size_t getPresentJobs() const;71 72 protected:73 /// bunch of jobs74 std::vector<FragmentJob> jobs;75 };76 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 CheckResultsOperation85 ~CheckResultsOperation() {}86 87 public:88 // placing receive jobs operations into an io_service89 virtual void operator()();90 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);94 95 /// Callback function when doneJobs have been received.96 void handle_ReceiveDoneJobs(const boost::system::error_code& e);97 98 /// Handle completion of an operation.99 void handle_FinishOperation(const boost::system::error_code& e);100 101 /// internal function to connect to server and check done jobs102 void connect_check();103 104 /// Getter for doneJobs105 size_t getDoneJobs() const;106 107 protected:108 /// currently calculated results109 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 SendResultsOperation118 ~SendResultsOperation() {}119 120 public:121 // placing receive jobs operations into an io_service122 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 128 /// Callback function when results are about to be received.129 void handle_ReceivingResults(const boost::system::error_code& e);130 131 /// Callback function when results have been received.132 void handle_ReceivedResults(const boost::system::error_code& e);133 134 /// internal function to connect to server and receive calculated results135 void connect_get();136 137 /// Getter for results138 std::vector<FragmentResult> getResults();139 140 protected:141 /// bunch of results142 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 ShutdownOperation151 ~ShutdownOperation() {}152 153 public:154 // placing receive jobs operations into an io_service155 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 results162 void connect_shutdown();163 164 };165 44 166 45 protected: -
src/Fragmentation/Automation/Makefile.am
r73d6fc r167b63 32 32 atexit.cpp \ 33 33 Controller/FragmentController.cpp \ 34 Controller/Commands/Operation.cpp 34 Controller/Commands/CheckResultsOperation.cpp \ 35 Controller/Commands/Operation.cpp \ 36 Controller/Commands/ReceiveJobsOperation.cpp \ 37 Controller/Commands/SendResultsOperation.cpp \ 38 Controller/Commands/ShutdownOperation.cpp 35 39 36 40 FRAGMENTATIONAUTOMATIONHEADER = \ … … 39 43 ControllerChoices.hpp \ 40 44 Controller/FragmentController.hpp \ 41 Controller/Commands/Operation.hpp 45 Controller/Commands/CheckResultsOperation.hpp \ 46 Controller/Commands/Operation.hpp \ 47 Controller/Commands/ReceiveJobsOperation.hpp \ 48 Controller/Commands/SendResultsOperation.hpp \ 49 Controller/Commands/ShutdownOperation.hpp 42 50 43 51 noinst_LTLIBRARIES += libMolecuilderFragmentationAutomation.la
Note:
See TracChangeset
for help on using the changeset viewer.